/* English Tutor — "language lab at dusk": a warm paper dictation sheet, marked up
   by a tutor's pen, floating inside a cool ink-petrol console.
   Display: Fraunces · Body: Instrument Sans · Cues & data: Space Mono. */

:root {
  /* cool side — the console/lab */
  --ink: #0f1c1e;
  --ink-2: #142629;
  --ink-3: #1b3236;
  --ink-inset: #0b1618;
  --rule: #294145;
  --rule-soft: #1f353800;
  --fg: #eaf2ee;
  --muted: #8ba39d;
  --muted-2: #61817b;

  /* warm side — the dictation sheet */
  --paper: #f7f2e8;
  --paper-2: #efe8d8;
  --paper-edge: #dccfb4;
  --paper-line: #e3dac6;
  --ink-text: #23302e;
  --ink-muted: #7a8781;

  /* brass — the study-lamp accent (not terracotta) */
  --brass: #e0a63c;
  --brass-deep: #b9821f;
  --live: #3fbf8f;

  /* correction semantics — proofreader ink */
  --err-grammar: #e5484d;
  --err-vocabulary: #cf7a1f;
  --err-pronunciation: #3b82c4;

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 8px;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --mono: "Space Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--sans);
  color: var(--fg);
  background:
    radial-gradient(900px 620px at 85% -10%, #17302f 0%, rgba(23, 48, 47, 0) 60%),
    radial-gradient(700px 500px at -5% 105%, #14262a 0%, rgba(20, 38, 42, 0) 55%),
    var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── shell: console rail + stage ─────────────────────────────────── */
.shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: clamp(1rem, 2.4vw, 2.4rem);
  display: grid;
  /* base (900–1079px): console | stage; the ledger wraps below the console */
  grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  gap: clamp(1rem, 2vw, 2rem);
  align-items: start;
}

/* wide desktop: three rails — console · dictation sheet · ledger */
@media (min-width: 1080px) {
  .shell {
    grid-template-columns: minmax(260px, 300px) minmax(0, 1fr) minmax(250px, 300px);
  }
  .ledger {
    position: sticky;
    top: clamp(1rem, 2.4vw, 2.4rem);
    max-height: calc(100dvh - 2 * clamp(1rem, 2.4vw, 2.4rem));
    overflow-y: auto;
  }
}

.console {
  position: sticky;
  top: clamp(1rem, 2.4vw, 2.4rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── masthead / brand ────────────────────────────────────────────── */
.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}
.brand { display: flex; align-items: center; gap: 0.7rem; }
.brand__mark {
  display: grid;
  grid-template-columns: repeat(2, 7px);
  grid-auto-rows: 7px;
  gap: 3px;
  padding: 5px;
  border-radius: 8px;
  background: var(--ink-inset);
  border: 1px solid var(--rule);
}
.brand__mark i {
  display: block;
  border-radius: 2px;
  background: var(--brass);
}
.brand__mark i:nth-child(2) { background: var(--err-grammar); }
.brand__mark i:nth-child(3) { background: var(--err-pronunciation); }
.brand__mark i:nth-child(4) { background: var(--live); }
.brand__name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.35rem;
  line-height: 0.98;
  letter-spacing: -0.01em;
}

.state {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.32rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  color: var(--muted);
  white-space: nowrap;
}
.state--connecting { color: var(--brass); border-color: var(--brass-deep); }
.state--live {
  color: var(--live);
  border-color: color-mix(in srgb, var(--live) 60%, transparent);
  background: color-mix(in srgb, var(--live) 12%, transparent);
}
.state--live::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px; margin-right: 5px;
  border-radius: 50%;
  background: var(--live);
  vertical-align: middle;
  animation: pulse 1.4s ease-in-out infinite;
}
.state--error { color: var(--err-grammar); border-color: var(--err-grammar); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ── console cards (shared) ──────────────────────────────────────── */
.deck, .mic, .ledger, .past {
  background: var(--ink-2);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 1.05rem 1.1rem;
}
.rail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.7rem;
}
.rail-head h2, .deck__eyebrow {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-2);
  font-weight: 700;
  margin: 0;
}
.deck__eyebrow { margin-bottom: 0.6rem; }

/* ── personas ────────────────────────────────────────────────────── */
.persona-list { display: flex; flex-direction: column; gap: 0.45rem; }
.persona {
  position: relative;
  text-align: left;
  padding: 0.6rem 0.75rem;
  padding-right: 2rem; /* room for the gear */
  border-radius: var(--r-md);
  border: 1px solid var(--rule);
  background: var(--ink-inset);
  color: var(--fg);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.persona:hover { border-color: var(--muted-2); transform: translateX(2px); }
.persona--locked {
  cursor: not-allowed;
  opacity: 0.5;
}
.persona--locked:hover { border-color: var(--rule); transform: none; }

/* voice-settings gear (teacher card only) */
.persona__gear {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: var(--r-sm);
  color: var(--muted-2);
  opacity: 0.7;
  cursor: pointer;
  transition: color 0.12s, opacity 0.12s, background 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.persona__gear:hover,
.persona__gear:focus-visible {
  color: var(--brass);
  opacity: 1;
  background: color-mix(in srgb, var(--brass) 14%, transparent);
  outline: none;
}
.persona--active {
  border-color: var(--brass);
  background: color-mix(in srgb, var(--brass) 12%, var(--ink-inset));
  box-shadow: inset 3px 0 0 var(--brass);
}
.persona__name { font-weight: 600; font-size: 0.95rem; }
.persona__tag {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* ── mic / call control ──────────────────────────────────────────── */
.mic { display: flex; flex-direction: column; gap: 0.85rem; }
.call-btn {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 0.8rem 1rem;
  border-radius: var(--r-md);
  border: 1px solid var(--brass-deep);
  color: var(--ink);
  background: linear-gradient(180deg, #eab54e, var(--brass));
  cursor: pointer;
  transition: filter 0.15s, transform 0.08s;
}
.call-btn:hover { filter: brightness(1.06); }
.call-btn:active { transform: translateY(1px); }
.call-btn:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.4); }
.mic__gauge { display: flex; align-items: center; gap: 0.6rem; }
.mic__dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  background: var(--muted-2);
  transition: background 0.2s, box-shadow 0.2s;
}
.mic--on { background: var(--live); box-shadow: 0 0 0 4px color-mix(in srgb, var(--live) 22%, transparent); }
.level { flex: 1; height: 5px; border-radius: 999px; background: var(--ink-inset); overflow: hidden; }
.level__bar {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--live), var(--brass));
  transition: width 0.08s linear;
}
.now {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-family: var(--mono);
  line-height: 1.45;
}

/* ── ledger (progress) ───────────────────────────────────────────── */
.ledger__group + .ledger__group { margin-top: 0.9rem; }
.ledger__group h3 {
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin: 0 0 0.4rem;
}
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.list li {
  font-size: 0.82rem;
  padding: 0.5rem 0.6rem;
  background: var(--ink-inset);
  border-radius: var(--r-sm);
  border: 1px solid var(--rule);
  line-height: 1.35;
}
.list b { color: var(--brass); font-weight: 600; }
.list i { color: var(--muted); font-style: normal; font-size: 0.72rem; }

/* ── correction category tag: hover for context, click to jump ────── */
.corr-tag {
  font: inherit;
  font-weight: 600;
  color: var(--brass);
  background: none;
  border: none;
  border-bottom: 1px dotted color-mix(in srgb, var(--brass) 55%, transparent);
  padding: 0 1px;
  margin: 0;
  cursor: help;
  -webkit-tap-highlight-color: transparent;
}
.corr-tag--grammar { color: var(--err-grammar); border-bottom-color: color-mix(in srgb, var(--err-grammar) 55%, transparent); }
.corr-tag--vocabulary { color: var(--err-vocabulary); border-bottom-color: color-mix(in srgb, var(--err-vocabulary) 55%, transparent); }
.corr-tag--pronunciation { color: var(--err-pronunciation); border-bottom-color: color-mix(in srgb, var(--err-pronunciation) 55%, transparent); }
.corr-tag--link { cursor: pointer; }
.corr-tag--link:hover { background: color-mix(in srgb, currentColor 14%, transparent); border-radius: 3px; }

/* ── correction groups: the recurring-error tracker ("Articles ×7") ─ */
.corr-group-head {
  background: transparent !important;
  border: none !important;
  padding: 0.5rem 0 0.15rem !important;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-2);
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}
.list li.corr-group-head:first-child { padding-top: 0 !important; }
.corr-group-count { color: var(--brass); font-weight: 700; }

/* ── masthead: streak + spoken-minutes ──────────────────────────── */
.masthead__right { display: flex; align-items: center; gap: 0.55rem; }
.streak {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.02em;
  color: var(--brass);
  white-space: nowrap;
}
.streak[hidden] { display: none; }

/* remove a ledger word/correction */
.list li { position: relative; padding-right: 1.7rem; }
.del-btn {
  position: absolute;
  top: 0.35rem;
  right: 0.4rem;
  width: 1.1rem;
  height: 1.1rem;
  line-height: 1;
  padding: 0;
  font-size: 0.95rem;
  color: var(--muted-2);
  background: none;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.list li:hover .del-btn { opacity: 1; }
.del-btn:hover { color: #e5675c; background: color-mix(in srgb, #e5675c 16%, transparent); }
@media (max-width: 900px) { .del-btn { opacity: 0.85; } }

/* select transcript text → add-to-dictionary bubble (portal on <body>) */
.select-action {
  position: fixed;
  z-index: 1001;
}
.select-action[hidden] { display: none; }
.select-action__btn {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
  background: linear-gradient(180deg, #eab54e, var(--brass));
  border: 1px solid var(--brass-deep);
  border-radius: var(--r-sm);
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  box-shadow: 0 10px 26px -10px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
}
.select-action__btn:hover { filter: brightness(1.05); }

/* voice-settings popover (portal on <body>, anchored to the gear) */
.voice-pop {
  position: fixed;
  z-index: 1002;
  width: min(300px, 88vw);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--ink-2);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 0.85rem;
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.8);
}
.voice-pop[hidden] { display: none; }
.voice-pop__title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1rem;
  color: var(--fg);
}
.voice-pop__label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.voice-pop__select {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--fg);
  background: var(--ink-inset);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  padding: 0.4rem 0.5rem;
  cursor: pointer;
}
.voice-pop__select:focus-visible { outline: none; border-color: var(--brass); }
.voice-pop__select:disabled { opacity: 0.5; cursor: not-allowed; }
.voice-pop__status {
  margin: 0;
  min-height: 1em;
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--muted);
}

/* portal tooltip — lives on <body> so the rail's overflow can't clip it */
.floating-tip {
  position: fixed;
  z-index: 1000;
  max-width: min(320px, 80vw);
  background: var(--ink);
  color: var(--fg);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  padding: 0.45rem 0.65rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  line-height: 1.4;
  box-shadow: 0 14px 34px -14px rgba(0, 0, 0, 0.75);
  pointer-events: none;
}
.floating-tip[hidden] { display: none; }
.floating-tip::before {
  content: "context";
  display: block;
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 0.2rem;
}

/* the source turn, briefly lit when you jump to it from the ledger */
.turn--flash .turn__bubble {
  animation: turnflash 1.5s ease-out;
}
@keyframes turnflash {
  0%, 20% { background: color-mix(in srgb, var(--brass) 42%, var(--paper-2)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brass) 45%, transparent); }
  100% { background: var(--paper-2); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset; }
}
.empty {
  color: var(--muted-2);
  background: transparent !important;
  border: none !important;
  padding-left: 0 !important;
  font-family: var(--mono);
  font-size: 0.74rem;
}

/* ── sessions (history) ──────────────────────────────────────────── */
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.history-item {
  padding: 0.55rem 0.7rem;
  background: var(--ink-inset);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s, background 0.15s;
}
.history-item:hover {
  border-color: var(--brass);
  background: color-mix(in srgb, var(--brass) 8%, var(--ink-inset));
  transform: translateX(2px);
}
.history-item__main { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.history-item__who { font-weight: 600; font-size: 0.9rem; }
.history-item__when { font-family: var(--mono); font-size: 0.66rem; color: var(--muted); }
.history-item__meta { font-family: var(--mono); font-size: 0.68rem; color: var(--muted-2); margin-top: 0.2rem; }

/* ── sessions: collapsible header + pagination ───────────────────── */
.rail-head--toggle {
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.1rem 0;
  color: inherit;
  font: inherit;
}
.rail-head--toggle .chevron {
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--muted-2);
  transition: transform 0.18s ease;
}
.rail-head--toggle[aria-expanded="true"] .chevron { transform: rotate(-180deg); }
.rail-head--toggle:hover .chevron { border-top-color: var(--fg); }
.count-badge {
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--brass);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  vertical-align: middle;
  margin-left: 0.25rem;
}
.count-badge[hidden] { display: none; }
.past__body[hidden] { display: none; }
.past__foot { margin-top: 0.6rem; display: flex; justify-content: flex-end; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.6rem;
}
.pager[hidden] { display: none; }
.pager__range {
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--muted);
  white-space: nowrap;
}
.ghost:disabled { opacity: 0.4; cursor: not-allowed; }

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  padding: 0.28rem 0.6rem;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: color 0.15s, border-color 0.15s;
}
.ghost:hover { color: var(--fg); border-color: var(--muted-2); }

/* ── stage: the dictation sheet ──────────────────────────────────── */
.stage { min-width: 0; }
.sheet {
  background:
    linear-gradient(var(--paper), var(--paper));
  border-radius: var(--r-lg);
  border: 1px solid var(--paper-edge);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5) inset,
    0 30px 60px -30px rgba(0, 0, 0, 0.55);
  padding: clamp(1.2rem, 2.5vw, 2rem);
  color: var(--ink-text);
  position: relative;
  overflow: hidden;
}
/* the brass margin rule of a ruled page */
.sheet::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: clamp(2.4rem, 4vw, 3.4rem);
  width: 1px;
  background: color-mix(in srgb, var(--err-grammar) 30%, transparent);
}
.sheet__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--paper-line);
  margin-bottom: 0.4rem;
}
.sheet__eyebrow {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--err-grammar);
  margin: 0 0 0.15rem;
}
.sheet__title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: -0.015em;
  margin: 0;
  color: var(--ink-text);
}
.sheet__legend { font-size: 0.78rem; color: var(--ink-muted); max-width: 30ch; text-align: right; }
.err-legend {
  color: var(--err-grammar);
  text-decoration: underline wavy var(--err-grammar) 1.2px;
  text-underline-offset: 2px;
}

.convo-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin: 0.9rem 0 0.2rem;
  padding: 0.55rem 0.85rem;
  border-radius: var(--r-md);
  background: var(--paper-2);
  border: 1px solid var(--paper-edge);
  border-left: 3px solid var(--brass);
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--ink-muted);
}
.convo-banner[hidden] { display: none; }
.convo-banner .ghost {
  color: var(--brass-deep);
  border-color: var(--paper-edge);
}
.convo-banner .ghost:hover { color: var(--ink-text); border-color: var(--brass-deep); }

/* ── transcript: script-style lines ──────────────────────────────── */
.transcript {
  margin-top: 1rem;
  max-height: min(62vh, 640px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  padding-right: 0.4rem;
  scroll-behavior: smooth;
}
.transcript__empty {
  color: var(--ink-muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  text-align: center;
  padding: 2.5rem 1rem;
  margin: 0;
}

.turn { display: flex; flex-direction: column; gap: 0.3rem; max-width: 100%; }
.turn__who {
  font-family: var(--mono);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.turn--bot .turn__who { color: var(--err-pronunciation); }
.turn--user .turn__who { color: var(--brass-deep); }

.turn__bubble {
  font-size: 1.02rem;
  line-height: 1.62;
  color: var(--ink-text);
}
/* the tutor speaks in the running body voice; the learner's line is set off
   as the marked-up specimen — a card clipped to the page. */
.turn--bot .turn__bubble {
  padding-left: 0.9rem;
  border-left: 2px solid color-mix(in srgb, var(--err-pronunciation) 40%, transparent);
}
.turn--user .turn__bubble {
  background: var(--paper-2);
  border: 1px solid var(--paper-edge);
  border-radius: 4px 12px 12px 12px;
  padding: 0.6rem 0.85rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset;
}
/* native rewrite — its own line under the learner's original text */
.turn__native {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.55rem 0.85rem;
  border-radius: 4px 12px 12px 12px;
  background: color-mix(in srgb, var(--live) 14%, var(--paper-2));
  border: 1px solid color-mix(in srgb, var(--live) 45%, var(--paper-edge));
}
.turn__native-cue {
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--live) 55%, var(--ink-text));
}
.turn__native-text { font-size: 1.02rem; line-height: 1.55; color: var(--ink-text); }

/* ── proofreader marks (inline errors) ───────────────────────────── */
.err {
  position: relative;
  cursor: help;
  border-radius: 2px;
  padding: 0 1px;
  font-weight: 500;
  text-decoration: underline wavy var(--err-grammar) 1.5px;
  text-underline-offset: 3px;
}
.err--grammar { text-decoration-color: var(--err-grammar); color: var(--err-grammar); }
.err--vocabulary { text-decoration-color: var(--err-vocabulary); color: var(--err-vocabulary); }
.err--pronunciation { text-decoration-color: var(--err-pronunciation); color: var(--err-pronunciation); }
.err:hover, .err--open { background: color-mix(in srgb, currentColor 14%, transparent); }
.err:hover::after, .err--open::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 7px);
  transform: translateX(-50%);
  white-space: normal;
  width: max-content;
  max-width: min(260px, 72vw);
  background: var(--ink);
  color: var(--fg);
  border: 1px solid var(--rule);
  padding: 0.35rem 0.6rem;
  border-radius: var(--r-sm);
  font-family: var(--mono);
  font-size: 0.76rem;
  font-weight: 400;
  line-height: 1.35;
  text-align: center;
  text-decoration: none;
  box-shadow: 0 10px 26px -12px rgba(0, 0, 0, 0.7);
  z-index: 5;
  pointer-events: none;
}
.err:hover::before, .err--open::before {
  content: "";
  position: absolute;
  left: 50%; bottom: calc(100% + 2px);
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--rule);
  z-index: 5;
}

/* ── margin notes (corrections whose fragment got normalized away) ─ */
.turn__notes { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.1rem; }
.turn__notes:empty { display: none; }
.note {
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--r-sm);
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-left: 3px solid var(--err-grammar);
  color: var(--ink-muted);
}
.note--vocabulary { border-left-color: var(--err-vocabulary); }
.note--pronunciation { border-left-color: var(--err-pronunciation); }

/* ── native-rewrite action ───────────────────────────────────────── */
.turn__actions { margin-top: 0.1rem; }
.native-btn {
  background: transparent;
  color: var(--brass-deep);
  border: 1px solid var(--paper-edge);
  border-radius: 999px;
  padding: 0.26rem 0.7rem;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.native-btn:hover {
  border-color: var(--brass-deep);
  background: color-mix(in srgb, var(--brass) 12%, transparent);
}
.native-btn:disabled { opacity: 0.6; cursor: wait; }

/* ── focus + scrollbar + motion ──────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
  border-radius: 4px;
}
.transcript { scrollbar-width: thin; scrollbar-color: var(--paper-edge) transparent; }
.transcript::-webkit-scrollbar { width: 8px; }
.transcript::-webkit-scrollbar-thumb { background: var(--paper-edge); border-radius: 999px; }
.transcript::-webkit-scrollbar-track { background: transparent; }

/* ── end-of-call recap card ──────────────────────────────────────── */
.recap-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 4vw, 2rem);
  background: rgba(6, 14, 15, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: recapfade 0.2s ease-out;
}
@keyframes recapfade { from { opacity: 0; } to { opacity: 1; } }
.recap-card {
  width: min(460px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--paper);
  color: var(--ink-text);
  border: 1px solid var(--paper-edge);
  border-radius: var(--r-lg);
  box-shadow: 0 40px 80px -30px rgba(0, 0, 0, 0.7);
  padding: clamp(1.2rem, 3vw, 1.8rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.recap-eyebrow {
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--err-grammar);
  margin: 0 0 0.15rem;
}
.recap-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.3rem, 3.5vw, 1.7rem);
  letter-spacing: -0.015em;
  margin: 0;
}
.recap-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}
.recap-stat {
  background: var(--paper-2);
  border: 1px solid var(--paper-edge);
  border-radius: var(--r-md);
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.recap-stat b { font-family: var(--serif); font-size: 1.4rem; font-weight: 600; color: var(--ink-text); }
.recap-stat i {
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.recap-balance { display: flex; flex-direction: column; gap: 0.35rem; }
.recap-balance__bar {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in srgb, var(--err-pronunciation) 30%, var(--paper-2));
}
.recap-balance__you {
  display: block;
  height: 100%;
  background: var(--live);
  transition: width 0.4s ease;
}
.recap-balance__legend {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--ink-muted);
}
.recap-section h3 {
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 0.45rem;
}
.recap-groups { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.recap-groups li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  background: var(--paper-2);
  border: 1px solid var(--paper-edge);
  border-radius: var(--r-sm);
  font-size: 0.88rem;
}
.recap-groups b { color: var(--err-grammar); font-family: var(--mono); }
.recap-words { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.recap-word {
  font-size: 0.82rem;
  padding: 0.25rem 0.55rem;
  background: color-mix(in srgb, var(--live) 14%, var(--paper-2));
  border: 1px solid color-mix(in srgb, var(--live) 40%, var(--paper-edge));
  border-radius: 999px;
}
.recap-close { margin-top: 0.3rem; }

/* ── mobile chrome (hidden on desktop by default) ─────────────────── */
.tabbar { display: none; }
.scrim { display: none; }
.panel__grip { display: none; }

/* ══════════════════════════════════════════════════════════════════
   MOBILE / TABLET  (< 900px)
   The transcript is the app. Console sections become slide-up sheets
   summoned from a bottom tab bar; the mic lives in a fixed call bar.
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  :root {
    --callbar-h: 68px;
    --tabbar-h: 60px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
  }

  .shell {
    display: block;
    padding: 0;
    max-width: 100%;
  }

  /* console stops being a column; its children reflow / reposition */
  .console {
    display: contents;
  }

  /* masthead → sticky top app bar */
  .masthead {
    position: sticky;
    top: 0;
    z-index: 40;
    padding: calc(0.7rem + var(--safe-t)) clamp(0.9rem, 4vw, 1.2rem) 0.7rem;
    background: color-mix(in srgb, var(--ink) 88%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--rule);
  }
  .brand__name { font-size: 1.15rem; }

  /* stage fills the screen; reserve room for the fixed call bar + tab bar */
  .stage {
    padding: 0.8rem clamp(0.7rem, 3vw, 1rem);
    padding-bottom: calc(var(--callbar-h) + var(--tabbar-h) + var(--safe-b) + 1rem);
  }
  .sheet {
    padding: 1rem 0.95rem;
    border-radius: var(--r-md);
  }
  .sheet::before { left: 1.6rem; }
  .sheet__head { padding-bottom: 0.7rem; }
  .sheet__legend { text-align: left; max-width: 100%; font-size: 0.74rem; }
  .transcript { max-height: none; }

  /* ── mic → fixed bottom call bar, above the tab bar ─────────────── */
  .mic {
    position: fixed;
    left: 0; right: 0;
    bottom: calc(var(--tabbar-h) + var(--safe-b));
    z-index: 45;
    height: var(--callbar-h);
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem clamp(0.8rem, 4vw, 1.1rem);
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    background: color-mix(in srgb, var(--ink-2) 96%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
  .call-btn {
    flex: none;
    min-height: 46px;
    padding: 0.7rem 1.15rem;
    font-size: 0.98rem;
  }
  .mic__gauge {
    flex: 1;
    order: -1;               /* level to the left, big button on the right */
  }
  .now {
    order: 0;
    position: absolute;      /* status rides just above the bar, unobtrusive */
    left: clamp(0.8rem, 4vw, 1.1rem);
    right: 96px;
    bottom: calc(100% + 0.35rem);
    margin: 0;
    font-size: 0.72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: color-mix(in srgb, var(--ink) 80%, transparent);
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    pointer-events: none;
  }

  /* ── console sections → slide-up sheets ─────────────────────────── */
  .panel {
    position: fixed;
    left: 0; right: 0;
    bottom: 0;
    z-index: 60;
    max-height: 78dvh;
    overflow-y: auto;
    margin: 0;
    padding: 0.4rem clamp(0.9rem, 4vw, 1.2rem)
             calc(1.2rem + var(--safe-b));
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border: 1px solid var(--rule);
    border-bottom: none;
    box-shadow: 0 -24px 50px -24px rgba(0, 0, 0, 0.7);
    transform: translateY(102%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    -webkit-overflow-scrolling: touch;
  }
  .panel--open { transform: translateY(0); }
  .panel__grip {
    display: block;
    width: 40px; height: 4px;
    margin: 0.5rem auto 0.7rem;
    border-radius: 999px;
    background: var(--rule);
  }
  /* comfy touch targets inside sheets */
  .persona { padding: 0.8rem 0.9rem; }
  .persona:hover { transform: none; }        /* no hover-nudge on touch */
  .ghost { min-height: 40px; padding: 0.4rem 0.75rem; }
  .native-btn { min-height: 40px; padding: 0.4rem 0.9rem; font-size: 0.76rem; }
  .history-item { padding: 0.75rem 0.85rem; }
  .history-item:hover { transform: none; }

  /* the sessions sheet always shows its list — collapse is a desktop affordance */
  .past__body[hidden] { display: block; }
  .rail-head--toggle { pointer-events: none; }
  .rail-head--toggle .chevron { display: none; }
  .hist-prev, .hist-next { min-height: 44px; }

  /* ── scrim ──────────────────────────────────────────────────────── */
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(6, 14, 15, 0.55);
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
  }
  .scrim--on { opacity: 1; pointer-events: auto; }

  /* ── bottom tab bar ─────────────────────────────────────────────── */
  .tabbar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    height: calc(var(--tabbar-h) + var(--safe-b));
    padding-bottom: var(--safe-b);
    background: color-mix(in srgb, var(--ink) 94%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--rule);
  }
  .tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 44px;
    background: none;
    border: none;
    color: var(--muted-2);
    font-family: var(--mono);
    font-size: 0.6rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s;
  }
  .tab svg {
    width: 22px; height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .tab--active { color: var(--brass); }
}

/* very small phones — tighten type so the call bar never crowds */
@media (max-width: 380px) {
  .call-btn { padding: 0.65rem 0.9rem; font-size: 0.9rem; }
  .tab span { font-size: 0.56rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; scroll-behavior: auto !important; transition: none !important; }
}
/* ---- private Telegram sign-in ---- */
.login-page {
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #0f1c1e;
  color: #eef1e8;
  font-family: "Instrument Sans", sans-serif;
}

.login-card {
  width: min(100%, 430px);
  padding: clamp(30px, 8vw, 52px);
  border: 1px solid rgba(238, 241, 232, .18);
  border-radius: 24px;
  background: #17282a;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .32);
  text-align: center;
}

.login-card__mark { display: inline-grid; margin-bottom: 24px; }
.login-card__eyebrow { margin: 0 0 8px; color: #9bad9f; letter-spacing: .12em; text-transform: uppercase; font-size: 12px; }
.login-card h1 { margin: 0; font: 900 clamp(36px, 10vw, 56px)/1 "Fraunces", serif; }
.login-card__message { min-height: 48px; margin: 24px 0 18px; color: #cbd4cc; line-height: 1.5; }
.login-card__button { min-height: 44px; }
.login-card__button iframe { color-scheme: light; }
.login-card__retry { margin: 0 auto; width: auto; padding-inline: 24px; }
