/* Phrazo — frontend typing styles.
   Theme/layout/font-size toggle via data-* attributes on <html>. */

:root {
  color-scheme: light;

  --bg:        #f3f5f9;
  --surface:   #ffffff;
  --surface-2: #fbfcfe;
  --ink:       #121826;
  --ink-soft:  #1f2937;
  --muted:     #5b6678;
  --line:      #dfe5ee;
  --line-soft: #ecf0f6;

  --pending:   #aab3c2;
  --current:   #101524;
  --correct:   #0e7c4f;
  --correct-bg:#dff5e8;
  --wrong:     #b42318;
  --wrong-bg:  #fde2dd;
  --fixed:     #1c6a8a;
  --fixed-bg:  #e0f0f7;

  --accent:    #0f7a73;
  --accent-soft:#e3f2f0;
  --accent-ink:#0a5853;

  --shadow-card: 0 14px 40px rgba(15, 23, 42, 0.06);
  --shadow-pop:  0 18px 50px rgba(15, 23, 42, 0.14);

  --radius-card: 10px;
  --radius-inner: 8px;
  --radius-pill: 999px;

  --heat-0: #ecf0f6;
  --heat-1: #b6e0cc;
  --heat-2: #5cc198;
  --heat-3: #1f9469;
  --heat-4: #0e6748;
  --gold:   #d29b16;

  --phrase-size: clamp(28px, 4vw, 46px);
  --phrase-line: 1.5;
}

html[data-fontsize="large"]  { --phrase-size: clamp(34px, 5vw, 56px); }
html[data-fontsize="huge"]   { --phrase-size: clamp(40px, 6.4vw, 72px); }

html[data-theme="minimal"] {
  --bg:        #ffffff;
  --surface:   #ffffff;
  --surface-2: #fafafa;
  --line:      #e5e7eb;
  --line-soft: #f1f3f5;
  --accent:    #111827;
  --accent-soft:#f1f3f5;
  --accent-ink:#111827;
  --correct:   #111827;
  --correct-bg:transparent;
  --pending:   #b9bfc7;
  --current:   #000000;
  --shadow-card: none;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg:        #0d1117;
  --surface:   #131a24;
  --surface-2: #181f2b;
  --ink:       #e8edf5;
  --ink-soft:  #c5cde0;
  --muted:     #8a94a9;
  --line:      #232c3a;
  --line-soft: #1c2331;
  --pending:   #5d6779;
  --current:   #ffffff;
  --correct:   #4ade80;
  --correct-bg:#0e2a1d;
  --wrong:     #ff6b6b;
  --wrong-bg:  #2c1414;
  --fixed:     #7ec8e3;
  --fixed-bg:  #122230;
  --accent:    #5eead4;
  --accent-soft:#0f2f2c;
  --accent-ink:#5eead4;
  --shadow-card: 0 14px 40px rgba(0, 0, 0, 0.5);
  --shadow-pop:  0 18px 50px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", system-ui, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: relative;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand-mark {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.brand-sub {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.scenario-tabs {
  display: flex;
  flex: 1;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
}

.tab {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  letter-spacing: 0.02em;
}

.tab:hover:not(.tab-disabled) {
  color: var(--ink);
  background: var(--surface-2);
}

.tab.tab-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-color: var(--accent-soft);
}

.tab.tab-disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.ghost-btn,
.primary-btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  min-height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-inner);
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.12s, background 0.12s;
}

.ghost-btn:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.primary-btn:hover {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
}

html[data-theme="dark"] .primary-btn { color: #06231f; }
html[data-theme="dark"] .primary-btn:hover { color: #06231f; }

/* ---------- auth pill + popover ---------- */

.auth-slot {
  position: relative;
}

.auth-pill {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  min-height: 38px;
  padding: 0 4px 0 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  max-width: 260px;
}

.auth-pill:hover {
  border-color: var(--accent);
}

.auth-pill-email {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-pill-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.auth-pill-badge[data-plan="guest"] {
  background: var(--line-soft);
  color: var(--muted);
}

.auth-pill-badge[data-plan="trial"] {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.auth-pill-badge[data-plan="expired_trial"] {
  background: #fde2dd;
  color: #b42318;
}

html[data-theme="dark"] .auth-pill-badge[data-plan="expired_trial"] {
  background: #3c1717;
  color: #ffb4a8;
}

.auth-pill-badge[data-plan="paid"] {
  background: #0b3a36;
  color: #5eead4;
}

/* F1: cold-load shimmer. While viewerStore.isLoaded() === false the pill
   carries data-state="loading" so the rendered email/badge spans are
   replaced with a single non-breaking space — see auth-ui.js renderPill.
   The pill itself is sized to its max-width during loading so a cookied
   refresh (the case F1 protects against) resolves to a real authenticated
   pill of the same width — zero layout shift. The inner spans get a
   subtle animated gradient sourced from the theme palette so the user
   never sees a misleading "Гость" label flash. */
.auth-pill[data-state="loading"] {
  min-width: 260px;
  justify-content: space-between;
}

.auth-pill[data-state="loading"] .auth-pill-email,
.auth-pill[data-state="loading"] .auth-pill-badge {
  min-width: 6ch;
  display: inline-block;
  color: transparent;
  background-image: linear-gradient(
    90deg,
    var(--line-soft) 0%,
    var(--surface-2) 50%,
    var(--line-soft) 100%
  );
  background-size: 200% 100%;
  background-position: 0 0;
  animation: auth-pill-shimmer 1.4s ease-in-out infinite;
  border-radius: 4px;
}

.auth-pill[data-state="loading"] .auth-pill-email {
  flex: 1 1 auto;
  max-width: 160px;
}

@keyframes auth-pill-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .auth-pill[data-state="loading"] .auth-pill-email,
  .auth-pill[data-state="loading"] .auth-pill-badge {
    animation: none;
  }
}

.auth-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  /* Widened 25% (260 -> 325) so the auth forms — incl. the new confirm-
     password field + eye toggles — have more breathing room. */
  min-width: 325px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  padding: 16px;
  display: grid;
  gap: 12px;
  z-index: 40;
}

.auth-popover[hidden] { display: none; }

.auth-login,
.auth-account {
  display: grid;
  gap: 10px;
}

.auth-login-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.auth-login-hint,
.auth-account-plan {
  font-size: 13px;
  color: var(--muted);
}

.auth-login-error {
  font-size: 12px;
  color: var(--wrong);
  background: var(--wrong-bg);
  border-radius: 6px;
  padding: 6px 10px;
}

.auth-input {
  appearance: none;
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--surface-2);
  color: var(--ink);
}

.auth-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Password field with a show/hide "eye" toggle. The input is wrapped in a
   relative container so the eye button sits inside the field's right edge;
   the input gets extra right padding so typed text never slides under it. */
.auth-pwd-field {
  position: relative;
  display: block;
  width: 100%;
}

.auth-pwd-field .auth-input {
  width: 100%;
  box-sizing: border-box;
  padding-right: 40px;
}

.auth-pwd-eye {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
}

.auth-pwd-eye:hover { color: var(--ink); }

.auth-pwd-eye:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* When the password is revealed, tint the eye and overlay a diagonal slash
   so it reads as "hide" (the standard eye / eye-off metaphor). */
.auth-pwd-eye.is-visible { color: var(--accent-ink); }

.auth-pwd-eye.is-visible::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 2px;
  background: currentColor;
  transform: translate(-50%, -50%) rotate(-45deg);
  border-radius: 2px;
}

.auth-dev-btn,
.auth-back {
  font-size: 12px;
  min-height: 32px;
}

.auth-upgrade {
  opacity: 0.6;
}

.auth-account-email {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- practice slot + popover ---------- */

.practice-slot {
  position: relative;
}

#practiceBtn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
}

.practice-summary {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.practice-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 280px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  padding: 14px;
  display: grid;
  gap: 10px;
  z-index: 40;
}

.practice-panel[hidden] { display: none; }

.practice-panel select {
  appearance: none;
  font: inherit;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  min-width: 140px;
}

/* ---------- phrase meta row ---------- */

.phrase-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.phrase-meta[hidden] { display: none; }

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line-soft);
}

.meta-chip[data-kind="level"] {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-color: transparent;
}

.meta-chip[data-kind="topic"] {
  background: var(--line-soft);
  color: var(--ink-soft);
}

.meta-chip[data-kind="grammar"] {
  background: var(--surface-2);
  color: var(--ink-soft);
}

.meta-chip[data-kind="source"] {
  background: transparent;
  border-color: var(--line);
}

.meta-chip[data-kind="audio"] {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: none;
}

.meta-chip[data-kind="audio-live"],
.meta-chip[data-kind="audio-ai"],
.meta-chip[data-kind="audio-tts"] {
  font-weight: 800;
  letter-spacing: 0.04em;
}

.meta-chip[data-kind="audio-live"] {
  background: #e4f6ed;
  color: #0e6748;
  border-color: #b9e6cf;
}

.meta-chip[data-kind="audio-ai"] {
  background: #edf2ff;
  color: #3154a3;
  border-color: #cbd7ff;
}

.meta-chip[data-kind="audio-tts"] {
  background: var(--surface-2);
  color: var(--muted);
  border-style: dashed;
}

html[data-theme="dark"] .meta-chip[data-kind="audio-live"] {
  background: #0e2a1d;
  color: #86efac;
  border-color: #1f6f4b;
}

html[data-theme="dark"] .meta-chip[data-kind="audio-ai"] {
  background: #17203a;
  color: #a9bcff;
  border-color: #32477f;
}

.phrase-source {
  font-size: 12px;
  color: var(--muted);
}

.phrase-source[hidden] { display: none; }

.phrase-source a {
  color: var(--accent-ink);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent-ink);
}

.phrase-source a:hover { border-bottom-style: solid; }

/* ---------- settings popover ---------- */

.settings-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  padding: 14px;
  display: grid;
  gap: 10px;
  z-index: 40;
}

.settings-panel[hidden] { display: none; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

.settings-row select {
  appearance: none;
  font: inherit;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  min-width: 120px;
}

.settings-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
  user-select: none;
  cursor: pointer;
}

.settings-check input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}

/* ---------- shell ---------- */

.shell {
  flex: 1;
  width: min(1180px, calc(100vw - 32px));
  margin: 28px auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 24px;
  align-items: start;
}

html[data-layout="focus"] .shell,
html[data-motivation="off"] .shell {
  grid-template-columns: minmax(0, 1fr);
}

html[data-layout="focus"] .motivation,
html[data-motivation="off"] .motivation { display: none; }

html[data-layout="compact"] .shell { gap: 16px; margin: 16px auto; }
html[data-layout="compact"] .stage { padding: 18px; }

/* ---------- stage ---------- */

.stage {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 28px;
  display: grid;
  gap: 20px;
  min-width: 0;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-inner);
  min-width: 0;
}

.metric span {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.metric strong {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.metric-level strong {
  color: var(--accent-ink);
}

/* ---------- phrase ---------- */

.phrase-frame {
  border: 1px solid var(--line);
  border-radius: var(--radius-inner);
  background: var(--surface-2);
  padding: clamp(20px, 3vw, 40px);
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.phrase {
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: var(--phrase-size);
  line-height: var(--phrase-line);
  font-weight: 600;
  letter-spacing: 0;
  color: var(--pending);
  text-align: left;
  word-break: normal;
  overflow-wrap: break-word;
  width: 100%;
}

.char {
  color: var(--pending);
  border-radius: 4px;
  padding: 0 1px;
  transition: color 0.06s, background 0.06s, box-shadow 0.06s;
}

.char.correct {
  color: var(--correct);
  background: var(--correct-bg);
}

.char.fixed {
  color: var(--fixed);
  background: var(--fixed-bg);
}

.char.wrong {
  color: var(--wrong);
  background: var(--wrong-bg);
  text-decoration: underline;
  text-decoration-color: var(--wrong);
  text-underline-offset: 4px;
  text-decoration-thickness: 2px;
}

.char.current {
  color: var(--current);
  background: var(--accent-soft);
  box-shadow: inset 0 -3px 0 var(--accent);
}

.char.current.space {
  background: var(--accent-soft);
  box-shadow: inset 0 -3px 0 var(--accent);
  min-width: 0.5ch;
}

/* Minimal theme tones char states down but keeps each state visually
   distinct. Without these overrides:
   - .char.correct in paper has a green wash + green color; in minimal we
     drop the wash but add a faint baseline so "typed correctly" still
     reads as progress and doesn't look identical to surrounding pending
     chars.
   - .char.fixed inherits the paper theme's blue color + blue background
     block; the block dominates the phrase visually (only-fixed chars
     look like the cursor), so we strip the background and use a matching
     baseline. The blue color stays — fixed still reads as "was wrong,
     now correct" without screaming. */
html[data-theme="minimal"] .char.correct {
  color: var(--ink);
  background: transparent;
  box-shadow: inset 0 -1px 0 var(--line);
}

html[data-theme="minimal"] .char.fixed {
  color: var(--fixed);
  background: transparent;
  box-shadow: inset 0 -1px 0 var(--fixed);
}

html[data-theme="minimal"] .char.current {
  background: transparent;
  box-shadow: inset 0 -3px 0 var(--ink);
}

/* ---------- translation ---------- */

.translation {
  font-size: 16px;
  color: var(--muted);
  min-height: 22px;
  text-align: left;
}

html[data-translation="off"] .translation { display: none; }

/* ---------- progress ---------- */

.progress-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.progress-track {
  flex: 1;
  height: 6px;
  background: var(--line-soft);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: inherit;
  transition: width 0.08s linear;
}

.status-hint {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

/* ---------- actions ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

/* ---------- result panel ---------- */

.result-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius-inner);
  color: var(--accent-ink);
}

.result-panel[hidden] { display: none; }

.result-metric {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.result-metric span {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.75;
}

.result-metric strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.result-metric strong[data-rating="again"] { color: var(--wrong); }
.result-metric strong[data-rating="hard"]  { color: #b96d16; }
.result-metric strong[data-rating="good"]  { color: var(--accent-ink); }
.result-metric strong[data-rating="easy"]  { color: var(--correct); }

.result-save {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.result-save[data-state="pending"] { background: var(--line-soft); color: var(--muted); }
.result-save[data-state="saved"]   { background: var(--correct-bg); color: var(--correct); }
.result-save[data-state="guest"]   { background: var(--line-soft); color: var(--muted); }
.result-save[data-state="expired"] { background: var(--wrong-bg); color: var(--wrong); }
.result-save[data-state="unknown"] { background: var(--line-soft); color: var(--muted); }
.result-save[data-state="unavailable"] { background: var(--line-soft); color: var(--muted); }
.result-save[hidden] { display: none; }

.result-hint {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.75;
}

/* ---------- guest nudge ---------- */

.guest-nudge {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: var(--radius-inner);
}

.guest-nudge[hidden] { display: none; }

.guest-nudge-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 200px;
}

.guest-nudge-text strong {
  font-size: 14px;
  color: var(--ink);
}

.guest-nudge-text span {
  font-size: 13px;
  color: var(--muted);
}

.guest-nudge-actions {
  display: flex;
  gap: 8px;
}

/* ---------- motivation locked state ---------- */

.motivation[data-locked="yes"] .motivation-cell strong,
.motivation[data-locked="yes"] .motivation-level-head strong {
  color: var(--muted);
}

.motivation[data-locked="yes"] .motivation-achievement strong {
  font-weight: 600;
  color: var(--muted);
  font-style: italic;
}

/* ---------- motivation aside ---------- */

.motivation {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 18px;
  display: grid;
  gap: 16px;
  position: sticky;
  top: 28px;
}

.aside-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.motivation-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.motivation-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-inner);
  border: 1px solid var(--line-soft);
}

.motivation-cell span {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.motivation-cell strong {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.motivation-level {
  display: grid;
  gap: 6px;
}

.motivation-level-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.motivation-level-head strong {
  color: var(--accent-ink);
  font-size: 14px;
}

.level-track {
  height: 5px;
  background: var(--line-soft);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.level-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s ease-out;
}

.motivation-achievement {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-inner);
  border: 1px solid var(--line-soft);
}

.motivation-achievement-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.motivation-achievement strong {
  font-size: 14px;
  color: var(--ink-soft);
}

/* ---------- hotkeys footer ---------- */

.hotkeys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px;
  padding: 14px 28px 22px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

html[data-hotkeys="off"] .hotkeys { display: none; }

.hotkeys kbd {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  color: var(--ink-soft);
  margin-right: 4px;
}

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .motivation { position: static; }
}

@media (max-width: 720px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .scenario-tabs { justify-content: flex-start; order: 3; flex-basis: 100%; }
  .shell { width: calc(100vw - 20px); margin: 16px auto; gap: 14px; }
  .stage { padding: 18px; gap: 16px; }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .phrase-frame { padding: 18px; min-height: 140px; }
  .progress-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .status-hint { white-space: normal; }
  .actions { justify-content: stretch; }
  .actions > button { flex: 1; }
  .hotkeys { gap: 10px; padding: 12px 16px 18px; }
}

@media (max-width: 430px) {
  :root { --phrase-size: clamp(22px, 7vw, 32px); }
  .brand-sub { display: none; }
  .topbar { gap: 10px; }
  .topbar-actions .ghost-btn { padding: 0 12px; min-height: 34px; font-size: 13px; }
  .practice-summary { display: none; }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .metric { padding: 8px 10px; }
  .metric strong { font-size: 18px; }
  .stage { padding: 14px; }
  .result-panel { padding: 12px 14px; gap: 10px; }
  .result-hint { display: none; }
  .settings-panel,
  .practice-panel { right: 0; left: auto; min-width: 220px; }
}

/* Layout: dashboard expands gaps slightly */
html[data-layout="dashboard"] .stage { padding: 32px; gap: 24px; }
html[data-layout="dashboard"] .phrase-frame { padding: clamp(24px, 4vw, 48px); }

/* ---------- heatmap (shared by motivation aside and dashboard widget) ---------- */
/* Plan §3.3 referred to existing .heatmap / .heatmap-cell tokens; they were
   missing from this file. Added here so the motivation aside and the dashboard
   heatmap widget render correctly under the same selectors. */

.heatmap {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr);
  gap: 3px;
  margin-top: 6px;
}

.heatmap-cell {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 2px;
  background: var(--heat-0);
  display: inline-block;
}

.heatmap-cell[data-level="1"] { background: var(--heat-1); }
.heatmap-cell[data-level="2"] { background: var(--heat-2); }
.heatmap-cell[data-level="3"] { background: var(--heat-3); }
.heatmap-cell[data-level="4"] { background: var(--heat-4); }

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 10px;
  color: var(--muted);
}

.heatmap-legend .heatmap-cell {
  width: 10px;
  height: 10px;
  aspect-ratio: auto;
}

/* ---------- page switching: trainer vs dashboard ---------- */

html[data-page="dashboard"] .shell { display: none; }
html[data-page="trainer"]   .dashboard { display: none; }

/* "Этапы обучения" is a third full-screen page, toggled the same way:
   when it is active the trainer and dashboard are hidden, and on every
   other page the help screen is hidden. */
html[data-page="help"]      .shell,
html[data-page="help"]      .dashboard { display: none; }
html[data-page="trainer"]   .help-screen,
html[data-page="dashboard"] .help-screen { display: none; }

/* [hidden] overrides for new blocks that set their own display.
   CSS class rules win over the UA `[hidden]` selector by source order,
   so authored `display: grid/flex` on `.stage-route`, `.stage-help`,
   `.stage-growth`, `.dashboard` would otherwise show these elements
   even with the `hidden` attribute present. Acceptance #2/#3 require
   these blocks to stay invisible until the integration task wires them. */
.stage-route[hidden],
.stage-help[hidden],
.stage-growth[hidden],
.stage-growth-row[hidden],
.dashboard[hidden],
.dashboard-card[hidden],
.help-screen[hidden] {
  display: none !important;
}

/* ---------- "Этапы обучения" help screen ---------- */

.help-screen {
  flex: 1;
  width: min(820px, calc(100vw - 32px));
  margin: 28px auto;
  display: block;
}

.help-inner {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 24px clamp(16px, 4vw, 32px);
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.help-title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.help-back {
  flex: none;
  white-space: nowrap;
}

.help-intro {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  max-width: 62ch;
}

.help-stage-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.help-stage {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: start;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-inner);
}

.help-stage-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.help-stage-text {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.help-stage-name {
  font-weight: 700;
  color: var(--ink);
  font-size: 14px;
}

.help-stage-desc {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

/* Reserved column for future per-stage controls (skip / auto-advance after
   N sec / repeat N times). Holds only a muted, non-interactive marker for
   now so the space reads as intentional rather than as a layout gap. */
.help-stage-controls {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 40px;
  align-self: center;
}

.help-stage-soon {
  color: var(--muted);
  opacity: 0.45;
  font-size: 15px;
  cursor: default;
  user-select: none;
}

@media (max-width: 560px) {
  .help-stage { grid-template-columns: 28px 1fr; }
  .help-stage-controls { display: none; }
}

/* ---------- dashboard shell + cards ---------- */

.dashboard {
  flex: 1;
  width: min(1180px, calc(100vw - 32px));
  margin: 28px auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  align-items: start;
}

.dashboard-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 18px;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.dashboard-card-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.dashboard-card-stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.dashboard-card-stats > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 64px;
}

.dashboard-card-stats span {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.dashboard-card-stats strong {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.dashboard-card-foot {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.dashboard-card-count {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.dashboard-card-count strong {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dashboard-card-count span {
  font-size: 12px;
  color: var(--muted);
}

.memory-curve {
  width: 100%;
  height: 100px;
  color: var(--accent);
  display: block;
}

.dashboard-cefr-mini {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.dashboard-cefr-mini li {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-pill);
  font-size: 12px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.dashboard-cefr-mini .cefr-label {
  font-weight: 700;
  color: var(--accent-ink);
}

.dashboard-cefr-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.dashboard-cefr-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.dashboard-cefr-list .cefr-label {
  font-weight: 700;
  color: var(--accent-ink);
  letter-spacing: 0.04em;
}

.cefr-bar {
  height: 6px;
  background: var(--line-soft);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.cefr-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s ease-out;
}

.dashboard-cefr-list li strong {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--ink);
}

.dashboard-repair-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.dashboard-repair-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-inner);
  font-size: 13px;
  color: var(--ink-soft);
}

.dashboard-repair-list li .repair-key {
  font-weight: 600;
  color: var(--ink);
}

.dashboard-repair-list li .repair-reason {
  font-size: 11px;
  color: var(--muted);
  text-transform: lowercase;
}

.dashboard-card-empty[data-empty="true"] {
  opacity: 0.7;
}

/* ---------- phrase trainer first-screen extensions ---------- */

.stage-route {
  display: grid;
  gap: 6px;
}

.stage-route-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.stage-route-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.2;
  user-select: none;
  cursor: default;
}

.stage-route-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
  flex-shrink: 0;
}

.stage-route-item[data-status="locked"] {
  opacity: 0.55;
  color: var(--muted);
}
.stage-route-item[data-status="locked"] .stage-route-dot {
  border-color: var(--line);
}

.stage-route-item[data-status="available"] .stage-route-dot {
  border-color: var(--accent);
}

.stage-route-item[data-status="current"] {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 700;
}
.stage-route-item[data-status="current"] .stage-route-dot {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: stage-route-pulse 1.6s ease-in-out infinite;
}

@keyframes stage-route-pulse {
  0%, 100% { transform: scale(1);   opacity: 1;   }
  50%      { transform: scale(1.2); opacity: 0.75;}
}

.stage-route-item[data-status="done"] {
  color: var(--ink-soft);
}
.stage-route-item[data-status="done"] .stage-route-dot {
  background: var(--correct);
  border-color: var(--correct);
}

.stage-route-item[data-status="repair"] {
  background: var(--wrong-bg);
  color: var(--wrong);
}
.stage-route-item[data-status="repair"] .stage-route-dot {
  border-color: var(--wrong);
  background: transparent;
}

.stage-route-summary {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  align-items: baseline;
}

.stage-route-summary .stage-route-position {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--ink-soft);
}

.stage-route-summary .stage-route-title {
  color: var(--ink);
}

/* Entry point to the "Этапы обучения" explainer. Lives at the right edge of
   the route summary, so it only appears while a lesson is in progress (the
   whole route is hidden otherwise). A quiet "?" that brightens on hover. */
.stage-route-help-link {
  margin-left: auto;
  align-self: center;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.stage-route-help-link:hover,
.stage-route-help-link:focus-visible {
  background: var(--accent);
  color: var(--surface);
  border-color: var(--accent);
}

.stage-help {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-inner);
  font-size: 12px;
}

.stage-help-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-size: 11px;
}

.stage-help-level {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-weight: 700;
}

.stage-help-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.help-chip {
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  user-select: none;
}

.help-chip[data-active="true"] {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-color: var(--accent-soft);
  font-weight: 700;
}

.help-chip[data-active="false"] {
  opacity: 0.45;
}

.stage-help[data-assist-level="0"] { opacity: 0.6; }

.stage-growth {
  display: grid;
  gap: 6px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-inner);
  font-size: 12px;
}

.stage-growth-row {
  display: grid;
  grid-template-columns: 70px 1fr;
  align-items: baseline;
  gap: 10px;
}

.stage-growth-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-size: 11px;
}

.stage-growth-metrics {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.stage-growth-message {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.stage-growth[data-has-history="false"] [data-growth-row="then"] {
  display: none;
}

/* Hide growth and dim route while the user is actively typing. The
   data-state-during-input attribute is set by the future controller; until
   then growth/route stay visible as designed. */
.stage[data-state-during-input="typing"] .stage-growth { display: none; }
.stage[data-state-during-input="typing"] .stage-route { opacity: 0.5; }

/* ---------- responsive overrides for new blocks ---------- */

@media (max-width: 720px) {
  .stage-route-list { gap: 6px; }
  .stage-route-item .stage-route-label { display: none; }
  .stage-route-item[data-status="current"] .stage-route-label { display: inline; }
  .stage-help { gap: 6px; padding: 6px 10px; }
  .stage-growth-row { grid-template-columns: 1fr; }
  .dashboard { width: calc(100vw - 20px); gap: 12px; }
  .dashboard-card { padding: 14px; }
}

@media (max-width: 430px) {
  .stage-route-list {
    flex-wrap: nowrap;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
  }
  .stage-route-item { scroll-snap-align: center; flex-shrink: 0; }
  .stage-help-chips { flex-wrap: nowrap; overflow-x: auto; }
}

/* ---------- phrase training settings (mode block in settings popover) ----- */

.phrase-training-settings {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.phrase-training-settings[hidden] { display: none; }

.phrase-training-settings-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.phrase-training-settings-subtitle {
  margin: 6px 0 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.phrase-training-settings input[type="number"] {
  appearance: none;
  font: inherit;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  min-width: 84px;
  text-align: right;
}

.phrase-training-settings input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
}

.phrase-training-settings input[disabled],
.phrase-training-settings select[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.phrase-training-settings .settings-check input[disabled] + span {
  opacity: 0.7;
  cursor: not-allowed;
}

.auth-register-sent {
  margin-top: 4px;
  color: var(--ink-soft);
}
.auth-register-password-hint {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

/* Full-screen overlay for /?verify=<token> landings. Z-index higher than
   any popover so it always wins, but a single <div hidden> root keeps the
   DOM cost zero when there is no deep-link. */
.auth-pages-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-pages-overlay[hidden] { display: none; }
.auth-pages-card {
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  padding: 28px 32px;
  min-width: 320px;
  max-width: 480px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-pages-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.auth-pages-message {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.5;
}
.auth-pages-close {
  align-self: flex-end;
  margin-top: 6px;
}

/* F8: toast/snackbar stack. The slot #toastStack already lives in
   index.html; the toast.js module appends .toast children as the 401
   interceptor (or future producers) need to surface non-modal messages.
   Positioned fixed bottom-right so it doesn't fight the topbar pill or
   the typing stage. Theme-neutral via existing CSS vars. column-reverse
   keeps newer toasts at the bottom while older ones drift upward. */
.toast-stack {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 50;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--surface);
  color: inherit;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  font-size: 14px;
  max-width: 360px;
  animation: toast-enter 200ms ease-out;
}

.toast-message {
  flex: 1 1 auto;
}

.toast-action {
  appearance: none;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.toast-action:hover,
.toast-action:focus-visible {
  background: var(--accent);
  color: var(--accent-ink);
  outline: none;
}

.toast-leaving {
  animation: toast-leave 200ms ease-in forwards;
}

@keyframes toast-enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toast-leave {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(8px); }
}

@media (prefers-reduced-motion: reduce) {
  .toast,
  .toast-leaving {
    animation: none;
  }
}
