@font-face {
  font-family: 'Instrument Sans';
  src: url(/fonts/instrument-sans-latin.woff2) format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

/* Black and white like his channel, with one accent: the mint of his own avatar. */
:root {
  --bg: #0a0b0a;
  --bg-raise: #121413;
  --bg-user: #1b1e1c;
  --line: #1f2321;
  --line-strong: #2d322f;
  --text: #f2f4f2;
  --muted: #949b96;
  --dim: #626965;
  --accent: #01e59a;
  --accent-soft: rgba(1, 229, 154, .12);
  --accent-ink: #03150d;
  --danger: #ff8a7a;
  --font: 'Instrument Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --orb: clamp(220px, 24vw, 330px);
  --level: 0;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ------------------------------------------------------------------ layout */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 42%);
  grid-template-areas: "chat stage";
  height: 100vh;
  height: 100dvh;
}

.chat { grid-area: chat; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }

/* ------------------------------------------------------------------ stage (right) */

.stage {
  grid-area: stage;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  padding: 40px 32px;
  overflow: hidden;
  isolation: isolate;
}
.stage::before {
  content: '';
  position: absolute;
  inset: -20%;
  z-index: -1;
  background: radial-gradient(circle at 50% 45%, rgba(1, 229, 154, .09), transparent 42%);
  opacity: calc(.55 + var(--level) * 1.1);
  pointer-events: none;
}

.orb { position: relative; width: var(--orb); aspect-ratio: 1; flex: none; }
.orb img {
  position: absolute; inset: 0; z-index: 3;
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .06), 0 40px 90px -40px rgba(1, 229, 154, .45);
  transform: scale(calc(1 + var(--level) * .018));
}
.halo {
  position: absolute; inset: 6%; z-index: 0;
  border-radius: 50%;
  background: var(--accent);
  filter: blur(calc(var(--orb) * .12));
  opacity: calc(.10 + var(--level) * .45);
  transform: scale(calc(1 + var(--level) * .18));
}
.ring {
  position: absolute; inset: 0; z-index: 1;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  opacity: 0;
  transition: opacity .35s ease;
}
.arc {
  position: absolute; inset: -9px; z-index: 2;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 62%, rgba(1, 229, 154, .5) 85%, var(--accent));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
  opacity: 0;
  transition: opacity .4s ease;
}

.orb[data-state="idle"] img { animation: breathe 6s ease-in-out infinite; }
.orb[data-state="thinking"] .arc { opacity: 1; animation: spin 1.3s linear infinite; }
.orb[data-state="speaking"] .ring-1 { opacity: calc(.2 + var(--level) * .9); transform: scale(calc(1.035 + var(--level) * .09)); }
.orb[data-state="speaking"] .ring-2 { opacity: calc(var(--level) * .55); transform: scale(calc(1.09 + var(--level) * .16)); }
.orb { margin-bottom: 18px; }

@keyframes spin { to { transform: rotate(1turn); } }
@keyframes breathe { 50% { transform: scale(1.012); } }

.who { text-align: center; }
.who h1 { margin: 0; font-size: 26px; line-height: 1.15; font-weight: 600; letter-spacing: -.02em; }
.status { margin: 8px 0 0; color: var(--muted); font-size: 15px; display: inline-flex; align-items: center; gap: 8px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); transition: background .3s; }
.orb[data-state="thinking"] ~ .who .dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.orb[data-state="speaking"] ~ .who .dot { background: var(--accent); }
@keyframes pulse { 50% { opacity: .3; } }

.controls { display: flex; gap: 10px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 15px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.pill:hover { color: var(--text); border-color: #3d4440; }
.pill:focus-visible, .chip:focus-visible, #sendBtn:focus-visible, .replay:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pill.solid { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
#voiceBtn .i-off { display: none; }
#voiceBtn[aria-pressed="false"] .i-on { display: none; }
#voiceBtn[aria-pressed="false"] .i-off { display: block; }
#voiceBtn[aria-pressed="true"] { color: var(--text); }

/* ------------------------------------------------------------------ chat (left) */

.log { flex: 1; min-height: 0; overflow-y: auto; padding: 32px 32px 16px; overscroll-behavior: contain; }
.log > * { max-width: 700px; margin-inline: auto; }

.intro { min-height: 100%; display: flex; flex-direction: column; justify-content: center; padding-bottom: 6vh; }
.kicker { margin: 0 0 14px; color: var(--accent); font-size: 13px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; }
.intro h2 { margin: 0 0 12px; font-size: clamp(30px, 3.4vw, 44px); line-height: 1.06; font-weight: 600; letter-spacing: -.03em; }
.sub { margin: 0 0 30px; color: var(--muted); font-size: 17px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: transparent;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }

.msg { margin-block: 26px; }
.msg.user { display: flex; justify-content: flex-end; }
.bubble {
  max-width: 82%;
  padding: 11px 16px;
  border-radius: 20px 20px 6px 20px;
  background: var(--bg-user);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.alex .meta {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
}
.replay {
  display: none;
  align-items: center; gap: 6px;
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  font-size: 11px; letter-spacing: .06em;
  cursor: pointer;
}
.replay .i { width: 13px; height: 13px; }
.replay:hover { color: var(--accent); border-color: var(--accent); }
.msg.alex.has-audio .replay { display: inline-flex; }
.answer { font-size: 18px; line-height: 1.62; overflow-wrap: anywhere; }
.answer p { margin: 0 0 .75em; }
.answer p:last-child { margin-bottom: 0; }
.w { animation: word .42s ease-out both; }
@keyframes word { from { opacity: 0; filter: blur(5px); } }
.note { color: var(--danger); font-size: 15px; }

.typing { display: inline-flex; gap: 5px; padding: 10px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); animation: bounce 1.1s ease-in-out infinite; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 30% { transform: translateY(-5px); background: var(--muted); } 60% { transform: none; } }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  width: calc(100% - 64px); max-width: 700px;
  margin: 0 auto;
  padding: 7px 7px 7px 18px;
  border-radius: 24px;
  border: 1px solid var(--line-strong);
  background: var(--bg-raise);
  transition: border-color .15s;
}
.composer:focus-within { border-color: rgba(1, 229, 154, .5); }
#input {
  flex: 1; min-width: 0;
  max-height: 180px;
  padding: 8px 0;
  border: 0; outline: 0; resize: none;
  background: transparent;
  color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.5;
}
#input::placeholder { color: var(--dim); }
#sendBtn {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px;
  border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  cursor: pointer;
  transition: background .15s, transform .1s;
}
#sendBtn .i { stroke-width: 2.2; }
#sendBtn:active { transform: scale(.94); }
#sendBtn:disabled { background: var(--line-strong); color: var(--dim); cursor: default; }
#sendBtn .i-stop { display: none; fill: currentColor; stroke: none; }
#sendBtn.stop { background: var(--text); color: var(--bg); }
#sendBtn.stop .i-send { display: none; }
#sendBtn.stop .i-stop { display: block; }
.fine { margin: 10px 16px 14px; text-align: center; color: var(--dim); font-size: 12px; }

/* ------------------------------------------------------------------ composer modes
   empty: dictate + voice mode   text: dictate + send   busy: stop
   dictating: discard, waveform, stop-and-edit, send   transcribing: discard, "Transcribing…"
   voice: mute + end   (data-mode is set by renderComposer() in app.js) */

#dictCancel, .wave, .transcribing, #micBtn, #dictStop, #muteBtn, #sendBtn, #talkBtn, #endBtn { display: none; }
.composer[data-mode="empty"] :is(#micBtn, #talkBtn),
.composer[data-mode="text"] :is(#micBtn, #sendBtn),
.composer[data-mode="busy"] #sendBtn,
.composer[data-mode="dictating"] :is(#dictCancel, #dictStop, #sendBtn),
.composer[data-mode="transcribing"] :is(#dictCancel, #sendBtn),
.composer[data-mode="voice"] :is(#muteBtn, #endBtn) { display: grid; }
.composer[data-mode="dictating"] .wave { display: block; }
.composer[data-mode="transcribing"] .transcribing { display: block; }
.composer:is([data-mode="dictating"], [data-mode="transcribing"]) { padding-left: 7px; }
.composer:is([data-mode="dictating"], [data-mode="transcribing"]) #input { display: none; }
.composer[data-mode="empty"]:not(.can-talk) #talkBtn,
.composer:not(.can-dictate) #micBtn { display: none; }

.cbtn, .round {
  place-items: center; flex: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s, transform .1s;
}
.cbtn { border: 0; background: transparent; color: var(--muted); }
.cbtn:hover { color: var(--text); background: var(--bg-user); }
#dictCancel, #dictStop { border: 1px solid var(--line-strong); }
.i-fill { fill: currentColor; stroke: none; }
.round { border: 0; }
.round:active, .cbtn:active { transform: scale(.94); }
#talkBtn { background: var(--accent); color: var(--accent-ink); }
#talkBtn .i { stroke-width: 2.2; }
#endBtn { background: var(--text); color: var(--bg); }
#muteBtn .i-off { display: none; }
#muteBtn[aria-pressed="true"] { color: var(--danger); background: rgba(255, 138, 122, .1); }
#muteBtn[aria-pressed="true"] .i-on { display: none; }
#muteBtn[aria-pressed="true"] .i-off { display: block; }
:is(.cbtn, .round):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wave { flex: 1; min-width: 0; height: 40px; color: var(--muted); }
.transcribing { flex: 1; padding: 0 12px; color: var(--muted); line-height: 40px; animation: pulse 1.2s ease-in-out infinite; }

.hint { margin: 0 16px 8px; text-align: center; color: var(--danger); font-size: 13px; }
.hint[hidden] { display: none; }

/* ------------------------------------------------------------------ voice mode: "you" orb
   Sits above the composer and swells with the visitor's voice (--mic, 0..1, set per frame). */

.you { --mic: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 2px auto 14px; }
.you[hidden] { display: none; }
.you-orb {
  position: relative;
  width: 84px; height: 84px;
  border-radius: 50%;
  overflow: hidden;
  background: radial-gradient(circle at 32% 28%, #f4fff9 0 7%, #a6f6d6 26%, var(--accent) 58%, #007a55 100%);
  box-shadow: 0 0 calc(14px + var(--mic) * 46px) rgba(1, 229, 154, calc(.22 + var(--mic) * .45));
  transform: scale(calc(.9 + var(--mic) * .45));
  transition: transform .09s linear, opacity .35s ease, filter .35s ease;
}
.you-orb span {
  position: absolute; inset: -30%;
  background: conic-gradient(from 0deg, transparent 0 10%, rgba(255, 255, 255, .5) 22%, transparent 40%, rgba(0, 70, 45, .45) 62%, transparent 80%);
  filter: blur(7px);
  animation: spin 5s linear infinite;
}
.you[data-state="listening"] .you-orb span { animation-duration: calc(5s - var(--mic) * 3s); }
.you[data-state="waiting"] .you-orb { animation: pulse 1.6s ease-in-out infinite; }
.you[data-state="speaking"] .you-orb { opacity: .3; transform: scale(.78); }
.you[data-state="muted"] .you-orb { filter: grayscale(1); opacity: .45; transform: scale(.86); }
.you[data-state="connecting"] .you-orb { opacity: .5; animation: pulse 1s ease-in-out infinite; }
.you-label { margin: 0; color: var(--muted); font-size: 13px; }

.bubble.live { box-shadow: inset 0 0 0 1px rgba(1, 229, 154, .35); }
.bubble .partial { color: var(--muted); }

dialog {
  width: min(380px, calc(100% - 32px));
  padding: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--bg-raise);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .7); }
dialog h3 { margin: 0 0 6px; font-size: 20px; }
dialog p { margin: 0 0 18px; color: var(--muted); font-size: 15px; }
dialog input {
  width: 100%; height: 44px; margin-bottom: 14px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--text); font: inherit;
}

/* ------------------------------------------------------------------ small screens */

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "stage" "chat"; }
  .chat { border-right: 0; }
  .stage {
    --orb: 52px;
    flex-direction: row; justify-content: flex-start; gap: 14px;
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--line);
  }
  .stage::before { display: none; }
  .halo { filter: blur(8px); }
  .arc { inset: -5px; }
  .orb { margin-bottom: 0; }
  .who { text-align: left; }
  .who h1 { font-size: 17px; }
  .status { margin-top: 2px; font-size: 13px; }
  .controls { margin-left: auto; gap: 6px; }
  .pill { width: 38px; padding: 0; justify-content: center; }
  .pill .label { display: none; }
  .log { padding: 20px 16px 12px; }
  .intro { padding-bottom: 2vh; }
  .composer { width: calc(100% - 24px); }
  .fine { margin-bottom: max(12px, env(safe-area-inset-bottom)); }
  .answer { font-size: 17px; }
  .you-orb { width: 66px; height: 66px; }
  .you { margin-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .w, .orb img, .typing span, .dot { animation: none !important; }
  .orb[data-state="thinking"] .arc { animation-duration: 4s; }
}
