:root {
  --fg: #e8eaf0;
  --muted: #8b93a7;
  --surface: #161a22;
  --accent: #4f8cff;
  --border: #2a3040;
  --success: #3fbf7f;
  --warning: #e0a83d;
  --error: #e05c5c;
  --c1: #4f8cff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(120% 100% at 50% 0%, #1b2130 0%, #0b0e14 70%);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

/* ---- Stage: the only thing visible ---- */
 .stage {
   position: fixed;
   inset: 0;
   display: flex;
   flex-direction: column;
   user-select: none;
   cursor: pointer;
   touch-action: manipulation;      /* no double-tap-zoom on the tap target */
   -webkit-tap-highlight-color: transparent;
   padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
 }

 /* The microphone fills the middle of the screen; quiet is the top,
    help is the bottom. Three stacked zones, the centre taking the space. */
 .centre {
   flex: 1 1 auto;
   display: flex;
   flex-direction: column;
   align-items: center;
   justify-content: center;
   gap: 16px;
   padding: 8px 16px;
 }

 /* Top and bottom are tappable, near-invisible zones with a faint label so
    a sighted person can find them without sight being required. */
 .zone {
   appearance: none;
   border: 0;
   background: transparent;
   width: 100%;
   flex: 0 0 auto;
   min-height: 15vh;
   cursor: pointer;
   display: grid;
   place-items: center;
   color: var(--muted);
   -webkit-tap-highlight-color: transparent;
 }
 .zone:active { background: rgba(79, 140, 255, 0.06); }
 .zone:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
 .zone-label {
   font-size: 13px;
   letter-spacing: 0.22em;
   text-transform: uppercase;
   opacity: 0.55;
   user-select: none;
 }

 /* The microphone is the whole experience: one big round control that fills
    the middle of the screen. It starts the assistant on first tap, then
    becomes the on/off switch (silent — the state line shows on/off). */
 .mic {
   position: relative;
   appearance: none;
   border: 2px solid var(--border);
   width: min(88vw, 60vh);
   height: min(88vw, 60vh);
   flex: 0 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2b3550, #161b26 62%, #0e131d);
  color: #9fb4d8;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.3s ease, border-color 0.3s ease, color 0.3s ease;
  box-shadow: 0 0 40px rgba(79, 140, 255, 0.08);
}
.mic svg { width: 38%; height: 38%; }
.mic:hover { border-color: var(--accent); }
.mic:active { transform: scale(0.97); }
.mic:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }

/* Live and listening: the ring glows and breathes. */
.mic.listening {
  color: #dfe8ff;
  border-color: var(--accent);
  box-shadow: 0 0 60px rgba(79, 140, 255, 0.35);
  animation: listenGlow 2.4s ease-in-out infinite;
}
/* The assistant is talking: a tighter, faster pulse. */
.mic.speaking {
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 90px rgba(79, 140, 255, 0.55);
  animation: speakGlow 1.1s ease-in-out infinite;
}
/* Paused or stopped by the user: dimmed, struck through, clearly held. */
.mic.muted {
  color: #6b7280;
  border-color: #3a2530;
  background: radial-gradient(circle at 35% 30%, #2a2230, #14101a 62%, #0c0910);
  box-shadow: none;
  animation: none;
}
/* A diagonal "held" bar that only appears when paused/stopped. */
.mic-slash {
  position: absolute;
  left: 18%;
  right: 18%;
  top: 50%;
  height: 6px;
  border-radius: 6px;
  background: var(--error, #e5484d);
  transform: translateY(-50%) rotate(-18deg);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.mic.muted .mic-slash { opacity: 0.9; }

/* Calm: the circle keeps its size and only its glow breathes. The old
   version scaled the whole disc up and down — on a full-screen circle that
   reads as "big movement". Glow-only keeps the feedback, drops the motion. */
@keyframes listenGlow {
  0%, 100% { box-shadow: 0 0 60px rgba(79, 140, 255, 0.35); }
  50%      { box-shadow: 0 0 105px rgba(79, 140, 255, 0.6); }
}
@keyframes speakGlow {
  0%, 100% { box-shadow: 0 0 90px rgba(79, 140, 255, 0.55); }
  50%      { box-shadow: 0 0 130px rgba(79, 140, 255, 0.8); }
}

.state {
  font-size: 16px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  min-height: 1.4em;
}

.whisper {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  opacity: 0.8;
  padding: 0 24px;
  text-align: center;
}

 /* ---- Device log (debug) ---- */
 .debuglog {
   max-height: 160px;
   overflow-y: auto;
   border: 1px solid var(--border);
   border-radius: 10px;
   padding: 8px 10px;
   background: #0c1018;
   font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
   font-size: 11px;
   line-height: 1.5;
   color: var(--muted);
 }
 .debuglog .dbg-line { white-space: pre-wrap; word-break: break-word; }
 .debuglog .dbg-line.stt,
 .debuglog .dbg-line.user { color: #7fd6a4; }
 .debuglog .dbg-line.mic-error,
 .debuglog .dbg-line.tts { color: #e6b566; }
 .debuglog .dbg-line.mute { color: #9fb4d8; }

/* ---- Panel ---- */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(380px, 92vw);
  background: #10141c;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
  box-shadow: -20px 0 60px rgba(0,0,0,0.45);
}
.panel[hidden] { display: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel-head .x {
  background: none; border: none; color: var(--muted);
  font-size: 15px; cursor: pointer;
}
.panel-head .x:hover { color: var(--fg); }

.panel-body {
  padding: 18px 16px;
  overflow-y: auto;
  font-size: 16px;
  line-height: 1.55;
}
.panel-body h2 { margin: 0 0 10px; font-size: 20px; }
 .panel-body h3 { margin: 20px 0 10px; font-size: 14px; color: var(--muted);
   text-transform: uppercase; letter-spacing: 0.08em;
   display: flex; align-items: center; justify-content: space-between; gap: 10px; }
 .panel-body h3 .copylog {
   appearance: none; background: var(--surface); border: 1px solid var(--border);
   color: var(--fg); font: inherit; font-size: 12px; font-weight: 500;
   padding: 4px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap;
   text-transform: none; letter-spacing: 0;
 }
 .panel-body h3 .copylog:hover { border-color: var(--fg); }
.panel-body p { margin: 0 0 14px; }
.muted { color: var(--muted); }
.flow { margin: 0; padding-left: 18px; }
.flow li { margin: 4px 0; }

/* Friend menu: normal, big, unambiguous buttons a helper can press. */
.menu { display: flex; flex-direction: column; gap: 10px; }
.mact {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  text-align: left;
  padding: 14px 16px;
  min-height: 52px;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.mact:hover { border-color: var(--accent); }
.mact:active { transform: scale(0.99); background: #1b2130; }
.mact:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 15px;
  min-height: 44px;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.order-status {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}
.order-status.ok { border-color: var(--success); }
.order-status.warn { border-color: var(--warning); }
.order-status.err { border-color: var(--error); }

.log {
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.log .line { max-width: 95%; padding: 8px 12px; border-radius: 12px; line-height: 1.45; }
.log .line.user {
  align-self: flex-end;
  background: #27407c;
  border: 1px solid #33518f;
}
.log .line.assist {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
}
.log .line.sys {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
}

.typebar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.typebar input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
}
.typebar input:focus { border-color: var(--accent); }
.typebar button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0 16px;
  cursor: pointer;
}

.noscript { color: var(--error); padding: 20px; }

/* Visually hidden, still read by screen readers. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.typebar.details { padding: 0 0 10px; border-top: 0; }

.friend-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; }
.mact.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.typebar select { flex: 1; background: var(--surface); border: 1px solid var(--border); color: var(--fg); border-radius: 8px; padding: 9px 12px; font-size: 14px; }
