/* ---------- Ink and Paper ----------
   Two looks built on one set of tokens. Paper — soft off-white, dark ink
   text — is the default, declared on :root so a browser with storage
   blocked still gets it. Ink is the original dark look, applied as
   `data-theme="ink"` on <html> by a head script before first paint (the
   choice lives on the settings page and in localStorage). Hue roles are
   identical in both; Paper darkens the accents so they read as text on a
   light ground. `color-scheme` keeps native selects, checkboxes, and
   scrollbars in step. */
:root {
  color-scheme: light;
  --bg: #f4f1e9;
  --panel: #fbf9f4;
  --panel-2: #ebe6da;
  --border: #d9d3c4;
  --text: #252a33;
  --muted: #6e6a5e;
  --accent: #2f6fdf;
  --green: #0f9d76;
  --red: #d64545;
  --amber: #b45309;
  /* The microphone button at rest: a clear green, apart from the teal
     the transcript uses. */
  --rec-green: #22c55e;
}
html[data-theme="ink"] {
  color-scheme: dark;
  --bg: #0e1117;
  --panel: #161b24;
  --panel-2: #1d2430;
  --border: #2a3342;
  --text: #e6ebf2;
  --muted: #8b96a8;
  --accent: #4f8cff;
  --green: #2dd4a7;
  --red: #ff6b6b;
  --amber: #ffb454;
}

* { box-sizing: border-box; }
html { height: 100%; }

/* ---------- Layout ----------
   Two regions, fixed in proportion on every screen: the top third is the
   header and the microphone, the bottom two thirds the transcript. The
   transcript scrolls inside its region; the page itself never does. `dvh`
   follows a phone's toolbars as they show and hide; `vh` is the fallback. */
body {
  margin: 0;
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(180px, 1fr) 2fr;
  overflow: hidden;
}
.stage {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.transcript { display: flex; flex-direction: column; min-height: 0; }

/* The `hidden` attribute must win.
   A class that sets `display` outranks the browser's own
   `[hidden] { display: none }`, so an element written as hidden — the quota
   notice, the level meter, the settings page — renders anyway, as an empty
   band. Stating it here, with the weight to beat a class, keeps `hidden`
   meaning hidden however an element is styled later. */
[hidden] {
  display: none !important;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 600; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--muted); }
.logo { font-size: 22px; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  min-width: 0;
}
/* The languages in play, as short codes; tapping them opens the settings. */
.lang-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  min-width: 0;
}
.badge {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.badge.source { color: var(--muted); }
.badge.muted { color: var(--muted); font-weight: 400; }
.badge.clinician { border-color: rgba(79, 140, 255, 0.5); color: var(--clinician); }
.badge.patient { border-color: rgba(45, 212, 167, 0.5); color: var(--patient); }
.badge-arrow { color: var(--muted); font-size: 13px; }
.settings-btn { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.settings-icon { font-size: 15px; line-height: 1; }

/* ---------- Microphone ----------
   One large control, centred in what is left of the top third, with its
   caption and status under it and the level meter under those while
   listening. */
.mic-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px 20px 10px;
}
/* Idle: a green circle with a microphone. Listening: the same control
   turned into a red square that pulses, with a stop mark inside — the shape
   changes so the state reads from across a room. */
.rec-btn {
  --rec-size: clamp(64px, 11vh, 96px);
  width: var(--rec-size);
  height: var(--rec-size);
  border-radius: 50%;
  border: none;
  background: var(--rec-green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(34, 197, 94, 0.35);
  transition: transform 80ms ease, border-radius 160ms ease, background 160ms ease;
}
.rec-btn:hover { filter: brightness(1.06); }
.rec-btn:active { transform: scale(0.96); }
.rec-btn.live {
  background: var(--red);
  border-radius: 22%;
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.55); transform: scale(1); }
  50% { transform: scale(1.04); }
  70% { box-shadow: 0 0 0 20px rgba(255, 107, 107, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0); transform: scale(1); }
}
/* Grayed out while starting/stopping (clicks are ignored then). */
.rec-btn:disabled {
  background: var(--panel-2);
  color: var(--muted);
  cursor: default;
  filter: none;
  box-shadow: none;
  animation: none;
}
.rec-icon { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
.rec-mic { width: 48%; height: 48%; display: block; }
.rec-stop { display: none; width: 34%; height: 34%; background: #fff; border-radius: 12%; }
.rec-btn.live .rec-mic { display: none; }
.rec-btn.live .rec-stop { display: block; }

/* Waiting for the VAD model to load: the button goes gray, a comet orbits
   it, and the microphone bobs along — something is happening, and it is not
   yet time to speak. Beats the plain disabled look, which is what a stuck
   button also looks like. */
.rec-btn { position: relative; }
.rec-btn.loading,
.rec-btn.loading:disabled {
  background: var(--panel-2);
  color: var(--muted);
  box-shadow: none;
  animation: none;
  cursor: progress;
}
.rec-btn.loading::before {
  content: '';
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 62%, var(--rec-green) 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  animation: orbit 1.1s linear infinite;
}
.rec-btn.loading .rec-mic { animation: bob 0.9s ease-in-out infinite; }
@keyframes orbit { to { transform: rotate(360deg); } }
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-7deg); }
  50% { transform: translateY(-4px) rotate(7deg); }
}
@media (prefers-reduced-motion: reduce) {
  .rec-btn.loading::before,
  .rec-btn.loading .rec-mic { animation: none; }
}
.rec-label { font-size: 13px; color: var(--muted); }

/* The browser is refusing the microphone: green would promise what a tap
   cannot deliver. Still tappable, since a tap is how a changed setting is
   picked up; the bold line under it says where that setting is, and takes
   the place of the caption and the idle status so it fits a short phone. */
.rec-btn.blocked:not(.live):not(.loading) {
  background: var(--panel-2);
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--border);
}
.rec-btn.blocked:not(.loading) + .rec-label { display: none; }
.mic-help {
  margin: 2px 0 0;
  max-width: 34em;
  text-align: center;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 700;
  color: var(--text);
}
.mic-help:not([hidden]) ~ .status.idle { display: none; }

/* ---------- Uploaded recording ----------
   The header's upload button, and what stands in for the microphone while
   a recording is being transcribed: the button and its caption go, and a
   line saying what is happening, how far along it is, and a way to stop
   take their place. */
/* Pushed to the right so it sits beside Settings when the phone layout
   spreads the header across the screen. */
.upload-btn { padding-left: 10px; padding-right: 10px; margin-left: auto; }
.upload-icon { width: 17px; height: 17px; display: block; }
.upload-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}
.upload-stage[hidden] { display: none; }
.upload-title { font-size: 17px; font-weight: 700; color: var(--text); }
.upload-progress { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 1.3em; }
.upload-bar {
  width: min(320px, 70vw);
  height: 8px;
  border-radius: 4px;
  background: var(--panel-2);
  overflow: hidden;
}
.upload-bar-fill { height: 100%; width: 0; background: var(--accent); transition: width 200ms ease; }
.mic-stage.uploading .rec-btn,
.mic-stage.uploading .rec-label,
.mic-stage.uploading .mic-help,
.mic-stage.uploading .status,
.mic-stage.uploading .meter { display: none; }

.meter {
  width: min(320px, 70%);
  height: 8px;
  border-radius: 4px;
  background: var(--panel-2);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), var(--amber));
  transition: width 60ms linear;
}

.status {
  font-size: 12.5px;
  color: var(--muted);
  min-width: 80px;
  text-align: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
}
.status.listening { color: var(--accent); }
.status.speaking { color: var(--green); }
.status.error { color: var(--red); }

/* The sign-in and confirmation pages' submit button. */
.mic-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 8px;
  cursor: pointer;
}
.mic-btn:hover { filter: brightness(1.1); }
.mic-btn:disabled {
  background: var(--panel-2);
  color: var(--muted);
  cursor: default;
  filter: none;
}

/* ---------- Settings page ----------
   Everything that is not the microphone or the transcript: the options, the
   interface language, export and clear, and the account. Full-screen, over
   the console, dismissed with Done. */
.settings-page {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.settings-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.settings-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.settings-body {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.settings-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
/* The account's lines — who, the allowance, the buttons — get room to
   breathe; they are read, not scanned. */
#accountSignedIn,
#accountTrial { display: flex; flex-direction: column; gap: 18px; }
.settings-section h3 {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.setting-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.setting-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.spacer { flex: 1; }
.hint { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* Ink / Paper: a two-way pill on the settings page. The active side is the
   look the page is already wearing, so pressing it is its own preview. */
.theme-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.theme-toggle button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  padding: 7px 18px;
  cursor: pointer;
}
.theme-toggle button + button { border-left: 1px solid var(--border); }
.theme-toggle button.on {
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}
.chip.on {
  background: rgba(79, 140, 255, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.subtle { color: var(--muted); }
/* Irreversible: clearing the transcript is the one thing with no undo. */
.btn.danger { border-color: rgba(255, 107, 107, 0.55); color: var(--red); }
.btn.danger:hover { background: rgba(255, 107, 107, 0.12); border-color: var(--red); }

.select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
}

/* ---------- Messages ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.empty {
  color: var(--muted);
  text-align: center;
  margin-top: 80px;
  font-size: 15px;
  line-height: 1.7;
}

.msg {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.msg.error { border-color: var(--red); }

.msg-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}
.msg-idx { font-weight: 600; }
.lang-badge {
  margin-left: auto;
  background: rgba(79, 140, 255, 0.15);
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 999px;
}

.blob {
  border-left: 3px solid var(--accent);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px 12px;
}
.blob.translation { border-left-color: var(--green); }

.blobs {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
}
.blobs:empty { display: none; margin: 0; }

.blob-lang {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 4px;
}
.speak-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
}
.speak-btn:hover { color: var(--accent); }
.speak-btn:disabled { opacity: 0.5; cursor: default; }
.blob-text {
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.blob-text.pending { color: var(--muted); font-style: italic; }
.blob-text.streaming::after {
  content: '▍';
  color: var(--green);
  animation: blink 1s step-end infinite;
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Account (a settings section) ---------- */
.account-email { color: var(--text); font-weight: 500; }
.plan-badge {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
}
.plan-badge.pro {
  background: rgba(45, 212, 167, 0.16);
  color: var(--green);
  font-weight: 600;
}

.quota-wrap { display: flex; align-items: center; gap: 8px; }
.quota-meter {
  width: 120px;
  height: 6px;
  border-radius: 3px;
  background: var(--panel-2);
  overflow: hidden;
}
.quota-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--green);
  transition: width 200ms ease;
}
.quota-fill.low { background: var(--amber); }
.quota-fill.spent { background: var(--red); }
.quota-text { color: var(--muted); font-variant-numeric: tabular-nums; }

.btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.accent:hover { filter: brightness(1.1); }

/* The allowance is spent: interpreting is paused until the window frees up. */
.quota-notice {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 180, 84, 0.12);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.55;
}

/* ---------- Sign-in page ---------- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
}
.auth-card h1 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  font-size: 20px;
}
.auth-lede { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 0 22px; }
.auth-form { display: flex; flex-direction: column; gap: 8px; }
.auth-label { font-size: 12px; color: var(--muted); }
.auth-input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  padding: 11px 13px;
}
.auth-input:focus { outline: none; border-color: var(--accent); }
.auth-submit { margin-top: 6px; width: 100%; }
.auth-msg {
  margin: 16px 0 0;
  padding: 11px 13px;
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.55;
}
.auth-msg.ok { background: rgba(45, 212, 167, 0.14); color: var(--green); }
.auth-msg.error { background: rgba(255, 107, 107, 0.14); color: var(--red); }
.auth-msg a { color: inherit; }
/* The same box, sitting above the form instead of below it. */
.auth-msg-top { margin: 0 0 16px; }
/* The account a sign-in link is about to open, on the confirmation page. */
.auth-account {
  margin: 0 0 6px;
  padding: 11px 13px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  word-break: break-all;
}
.auth-foot {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}


/* Interface-language picker: compact enough to sit in the account bar and
   on the sign-in card without drawing attention to itself. */
.lang-select {
  padding: 5px 8px;
  font-size: 12.5px;
  max-width: 9.5em;
}
.auth-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.auth-top h1 { flex: 1; }

/* An utterance that arrived with no target language selected. */
.same-lang-note {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
  font-style: italic;
}

/* ---------- Mobile (must stay last so it overrides the base rules) ---------- */
@media (max-width: 720px) {
  /* The logo and title go, so the languages and the settings button have
     the width; the big button under them says what the page is. */
  .brand { display: none; }
  .topbar { padding: 8px 12px; }
  .topbar-right { margin-left: 0; width: 100%; justify-content: space-between; }
  .settings-text { display: none; }
  .settings-btn { padding: 7px 10px; }
  .mic-stage { padding: 2px 14px 8px; }
  .messages { padding: 12px; }
  .msg { max-width: 100%; }
  .select.grow { flex: 1 1 100%; }
  .settings-body { padding: 12px 12px 40px; }
  .quota-meter { width: 84px; }
  .quota-notice { padding: 12px 14px; }
}

/* ---------- The trial ----------
   The trial's words are spent: the one message that matters, in the flow
   where the next turn would have appeared. */
.signup-callout {
  margin: 8px auto 0;
  max-width: 560px;
  width: 100%;
  text-align: center;
  padding: 26px 22px;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 14px;
}
.signup-callout h2 { margin: 0 0 8px; font-size: 24px; line-height: 1.3; }
.signup-callout p { margin: 0 0 16px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.btn.lg { padding: 11px 22px; font-size: 15px; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
/* On the trial: what is left of it, under the microphone. */
.trial-line { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.trial-line a { color: var(--accent); font-weight: 600; text-decoration: none; }
