:root {
  --bg: #0a0b0e;
  --panel: #13151a;
  --line: #24272f;
  --text: #f4f4f2;
  --muted: #8d929d;
  --faint: #5c616c;
  --accent: #7cc4ff;
  --warm: #f5b971;
  --good: #6ee7a8;
  --danger: #ff7a7a;
  --radius: 14px;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%238d929d' stroke-width='1.6'%3E%3Cpath d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Ambient glow that follows the phase */
body::before, body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .45s ease;
}
body::before { background: radial-gradient(1100px 620px at 50% 115%, rgba(124, 196, 255, .17), transparent 62%); }
body::after { background: radial-gradient(1100px 620px at 50% 115%, rgba(245, 185, 113, .12), transparent 62%); }
body[data-phase="listening"]::before { opacity: 1; }
body[data-phase="transcribing"]::after,
body[data-phase="thinking"]::after { opacity: 1; }

/* Top bar */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  position: relative;
  z-index: 1;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--muted);
}
.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
  transition: background .2s, box-shadow .2s;
}
[data-phase="listening"] .brand-dot { background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.bar-actions { display: flex; gap: 6px; align-items: center; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--panel); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--accent); background: rgba(124, 196, 255, .1); }
.icon-btn svg { width: 20px; height: 20px; }

select {
  appearance: none;
  background: var(--bg) var(--chevron) no-repeat right 12px center / 12px;
  padding-right: 34px !important;
  cursor: pointer;
}
.pill-select {
  background-color: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 14px;
  font: inherit;
  font-size: 14px;
  margin-right: 6px;
}

/* Stage */
.stage {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: min(1000px, 100% - 48px);
  margin: 0 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 0;
  position: relative;
  z-index: 1;
}
.heard-label {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--faint);
}
.stage:has(.heard:empty) .heard-label { visibility: hidden; }
.heard {
  margin: 0 0 36px;
  font-size: clamp(17px, 1.6vw, 21px);
  line-height: 1.5;
  color: var(--muted);
  min-height: 1.5em;
}
.heard.live { color: var(--accent); }
.answer {
  margin: 0;
  font-size: clamp(30px, 4.2vw, 52px);
  line-height: 1.22;
  font-weight: 550;
  letter-spacing: -.015em;
  text-wrap: pretty;
  transition: opacity .25s;
}
.answer.empty {
  color: var(--faint);
  font-weight: 450;
  font-size: clamp(22px, 2.6vw, 30px);
}
.answer.fresh { animation: rise .35s ease-out; }
[data-phase="listening"] .answer,
[data-phase="transcribing"] .answer,
[data-phase="thinking"] .answer { opacity: .3; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

kbd {
  font: inherit;
  padding: 1px 10px;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 8px;
  color: var(--text);
}

/* Hold button */
.dock {
  display: flex;
  justify-content: center;
  padding: 18px 24px calc(28px + env(safe-area-inset-bottom));
  position: relative;
  z-index: 1;
}
.hold {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 26px 12px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: border-color .2s, color .2s;
}
.orb {
  --level: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 calc(var(--level) * 16px) rgba(124, 196, 255, .22);
  transition: background .2s, box-shadow 60ms linear;
}
[data-phase="idle"] .orb, [data-phase="answering"] .orb { animation: breathe 3.2s ease-in-out infinite; }
[data-phase="listening"] .hold { border-color: rgba(124, 196, 255, .55); color: var(--text); }
[data-phase="listening"] .orb { background: var(--accent); }
[data-phase="transcribing"] .orb, [data-phase="thinking"] .orb { background: var(--warm); animation: pulse .9s ease-in-out infinite; }
[data-phase="answering"] .orb { background: var(--good); }
@keyframes breathe { 50% { opacity: .55; transform: scale(.86); } }
@keyframes pulse { 50% { opacity: .6; transform: scale(.74); } }

/* Drawers */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 10;
}
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.2, .8, .2, 1);
  z-index: 11;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 16px 20px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.drawer-body { flex: 1; overflow-y: auto; padding: 4px 20px 28px; }
.drawer section { padding: 18px 0; border-bottom: 1px solid var(--line); }
.drawer section:last-child { border-bottom: 0; }
.drawer h3 {
  margin: 0 0 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--faint);
  font-weight: 600;
}
.drawer-foot { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
input[type="password"], input[type="text"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
}
input[type="password"], input[type="text"], textarea { background: var(--bg); }
textarea { resize: vertical; line-height: 1.5; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, .dropzone:focus-visible {
  outline: 2px solid rgba(124, 196, 255, .6);
  outline-offset: 1px;
}
.hint { font-size: 12.5px; color: var(--faint); margin: 4px 0 0; line-height: 1.5; }
.link {
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  padding: 8px 0 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link.danger { color: var(--danger); }
.secondary {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.secondary:hover { background: var(--bg); }

/* Knowledge drop zone */
.dropzone {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: rgba(124, 196, 255, .05); }
.dropzone.loaded { border-style: solid; text-align: left; display: flex; gap: 12px; align-items: center; }
.dropzone svg { width: 22px; height: 22px; flex: none; color: var(--good); }
.dz-name { color: var(--text); font-weight: 550; word-break: break-all; }
.dz-meta { font-size: 12.5px; color: var(--faint); margin-top: 2px; }
.dz-meta a { color: var(--muted); }

/* Transcript */
.history-item { padding: 16px 0; border-bottom: 1px solid var(--line); }
.history-time { font-size: 12px; color: var(--faint); }
.history-heard { color: var(--muted); margin: 6px 0; font-size: 14px; line-height: 1.5; }
.history-reply { color: var(--text); font-size: 15px; line-height: 1.5; }
.history-reply.none { color: var(--faint); }
.history-empty { color: var(--faint); font-size: 14px; padding: 18px 0; line-height: 1.5; }

/* First-run gate */
.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(10, 11, 14, .9);
  backdrop-filter: blur(14px);
  padding: 24px;
  overflow-y: auto;
}
.gate-card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.gate h1 { margin: 0 0 8px; font-size: 28px; letter-spacing: -.02em; }
.lede { margin: 0 0 26px; color: var(--muted); line-height: 1.55; }
.steps { list-style: none; padding: 0; margin: 0 0 26px; display: flex; flex-direction: column; gap: 20px; }
.steps li { display: grid; grid-template-columns: 24px 1fr; gap: 12px; align-items: start; }
.steps strong { display: block; font-size: 14px; margin-bottom: 8px; font-weight: 600; }
.check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  display: grid;
  place-items: center;
  transition: background .2s, border-color .2s;
}
.steps li.done .check { background: var(--good); border-color: var(--good); }
.steps li.done .check::after {
  content: "";
  width: 5px;
  height: 10px;
  border: solid var(--bg);
  border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg);
}
.primary {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: 0;
  background: var(--text);
  color: var(--bg);
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.primary:disabled { background: var(--line); color: var(--faint); cursor: not-allowed; }
.error { color: var(--danger); font-size: 13.5px; margin: 12px 0 0; line-height: 1.5; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 104px;
  transform: translateX(-50%);
  background: #2a1517;
  border: 1px solid #5a2a2e;
  color: #ffd9d9;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  max-width: min(640px, 90vw);
  z-index: 30;
}
.toast.info { background: #14202b; border-color: #284256; color: #d9ecff; }

@media (max-width: 560px) {
  .bar { padding: 14px 16px; }
  .brand { display: none; }
  .gate-card { padding: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
