/* Layout: single phone column (max 640px), sticky screen header, fixed bottom tab bar. */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #e9edf3;
  --line: #d8dee7;
  --fg: #142032;
  --muted: #5a6779;
  --ink: #1f3a5f;
  --ink-fg: #ffffff;
  --accent: #c98a0b;
  --accent-soft: #fbf0d6;
  --good: #2c7a4b;
  --good-soft: #e3f2e8;
  --warn: #a8650c;
  --warn-soft: #fbeedb;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --info: #3d5a8a;
  --info-soft: #e5ecf7;
  --font-display: 'Literata', 'Georgia', 'Times New Roman', serif;
  --font-body: 'Golos Text', -apple-system, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-ipa: 'Noto Sans', 'Lucida Grande', 'Arial Unicode MS', sans-serif;
  --radius: 14px;
  --tabbar-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d131b; --surface: #151e29; --surface-2: #1d2835; --line: #2a3747; --fg: #e5ebf2; --muted: #93a1b4;
    --ink: #8db3e6; --ink-fg: #0d131b; --accent: #e7b13f; --accent-soft: #3a2e12;
    --good: #6cc391; --good-soft: #15301f; --warn: #e5a54a; --warn-soft: #3a2a12; --bad: #f08a80; --bad-soft: #3b1714;
    --info: #9db7e3; --info-soft: #1c2a40; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d131b; --surface: #151e29; --surface-2: #1d2835; --line: #2a3747; --fg: #e5ebf2; --muted: #93a1b4;
  --ink: #8db3e6; --ink-fg: #0d131b; --accent: #e7b13f; --accent-soft: #3a2e12;
  --good: #6cc391; --good-soft: #15301f; --warn: #e5a54a; --warn-soft: #3a2a12; --bad: #f08a80; --bad-soft: #3b1714;
  --info: #9db7e3; --info-soft: #1c2a40; color-scheme: dark;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
* { box-sizing: border-box; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
p { margin: 0; }
button { font: inherit; color: inherit; }
s { text-decoration-thickness: 1.5px; }

.app { max-width: 640px; margin: 0 auto; min-height: 100%; }
.main, .screen-body {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.main { padding-block: 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px); }
.page { display: flex; flex-direction: column; gap: 16px; }

.display { font-family: var(--font-display); font-weight: 600; font-size: 1.6rem; line-height: 1.2; letter-spacing: -0.01em; }
h3 { font-size: 1.05rem; margin-top: 8px; }
.eyebrow { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.en { font-feature-settings: "kern"; }
.ipa { font-family: var(--font-ipa); color: var(--info); letter-spacing: 0.01em; }
.pre { white-space: pre-wrap; }
.min0 { min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.mt-s { margin-top: 8px; }
.big-number { font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }

.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.between { justify-content: space-between; }
.gap-s { gap: 8px; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.section { display: flex; flex-direction: column; gap: 10px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; }
.section-head h2 { font-size: 1.05rem; font-weight: 650; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 6px; text-align: left; width: 100%; min-width: 0; }
.card-tap { cursor: pointer; transition: transform 0.12s ease, border-color 0.12s ease; }
.card-tap:active { transform: scale(0.985); }
.card-tap:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.module-lessons { display: flex; flex-direction: column; margin-top: 4px; }
.lesson-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--line); padding: 10px 0; cursor: pointer; }
.lesson-num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 0.8rem; font-weight: 650; color: var(--muted); }
.lesson-row-main { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.lesson-row-title { font-size: 0.95rem; }
.card-muted { background: var(--surface-2); border-style: dashed; }
.callout { border-color: var(--accent); background: var(--accent-soft); }
.checkpoint-card { border-left: 4px solid var(--ink); }
.daily-card { border-left: 4px solid var(--accent); }
.daily-check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: inline-flex; align-items: center; justify-content: center; flex: none; font-size: 14px; }
.daily-check.on { background: var(--good); border-color: var(--good); color: var(--ink-fg); }
.good-text { color: var(--good); }
.scenario-goal { background: var(--info-soft); border-color: transparent; }
.debrief { border-left: 4px solid var(--info); }
.packs > summary { font-weight: 600; cursor: pointer; padding: 6px 0; }
.resume-slot:not(:empty) { margin-bottom: 16px; }

/* Buttons */
.btn { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; font-size: 1rem; min-height: 46px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:focus-visible, .option:focus-visible, .tile:focus-visible, .chip:focus-visible, .tab:focus-visible, .speak:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--ink); color: var(--ink-fg); }
.btn-secondary { background: var(--surface-2); color: var(--fg); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-block { width: 100%; }
.btn-small { min-height: 38px; padding: 8px 14px; font-size: 0.9rem; }
.link { background: none; border: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; padding: 4px 0; cursor: pointer; align-self: flex-start; }

.pill { width: fit-content; display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 10px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.pill-neutral { background: var(--surface-2); color: var(--muted); }
.pill-good { background: var(--good-soft); color: var(--good); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
.pill-info { background: var(--info-soft); color: var(--info); }
.pill-accent { background: var(--accent-soft); color: var(--warn); }

.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: 0.9rem; cursor: pointer; }
.chip-on { background: var(--ink); color: var(--ink-fg); border-color: var(--ink); }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; transition: width 0.3s ease; }
.bar-ink { background: var(--ink); }
.bar-good { background: var(--good); }
.bar-accent { background: var(--accent); }

.ring { position: relative; flex: none; }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; font-variant-numeric: tabular-nums; }
.ring-label b { font-size: 1.4rem; font-family: var(--font-display); }

.hero { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* Segmented control */
.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.segmented button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 10px; font-size: 0.9rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented button.on { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.small-seg { flex: 1; }
.small-seg button { font-size: 0.82rem; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
}
.tab { position: relative; flex: 1; max-width: 128px; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; font-size: 0.7rem; color: var(--muted); cursor: pointer; min-height: 50px; }
.tab-on { color: var(--ink); font-weight: 650; }
.tab-dot { position: absolute; top: 4px; right: calc(50% - 16px); width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }

/* Screens (overlays) */
.screen { min-height: 100%; }
.screen-head {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 15; background: var(--bg);
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 4px;
  padding: 6px max(8px, env(safe-area-inset-right, 0px)) 8px max(8px, env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--line);
}
.screen-title { font-size: 1rem; font-weight: 650; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.screen-right { min-width: 44px; display: flex; justify-content: flex-end; }
.screen-progress { grid-column: 1 / -1; }
.back { width: 44px; height: 44px; border: 0; background: none; display: grid; place-items: center; color: var(--ink); cursor: pointer; border-radius: 10px; }
.screen-body { padding-block: 16px calc(32px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 14px; }
.lesson-step { display: flex; flex-direction: column; gap: 14px; }
.step-nav { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
.step-nav .btn { flex: 1; min-width: 120px; }

/* Exercises */
.ex { display: flex; flex-direction: column; gap: 14px; }
.ex-task { color: var(--muted); font-size: 0.9rem; font-weight: 600; }
.ex-prompt { font-size: 1.2rem; line-height: 1.45; }
.ex-hint { font-size: 0.85rem; color: var(--muted); }
.ex-audio { display: flex; gap: 10px; flex-wrap: wrap; }
.ex-form { display: flex; flex-direction: column; gap: 10px; }
.gap { display: inline-block; min-width: 3em; border-bottom: 2px solid var(--ink); padding: 0 4px; }
.gap-filled { color: var(--ink); font-weight: 600; }
.input {
  width: 100%; font: inherit; font-size: 16px; color: var(--fg); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 48px;
}
.input:focus { outline: none; border-color: var(--ink); }
textarea.input { resize: vertical; line-height: 1.45; }
.options { display: flex; flex-direction: column; gap: 10px; }
.options.two { flex-direction: row; }
.options.two .option { flex: 1; text-align: center; }
.option {
  text-align: left; border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 13px 14px; font-size: 1.02rem; cursor: pointer; min-height: 50px;
}
.option:not(:disabled):active { border-color: var(--ink); }
.option-good { border-color: var(--good); background: var(--good-soft); }
.option-bad { border-color: var(--bad); background: var(--bad-soft); }
.option:disabled { cursor: default; color: var(--fg); }

.order-answer { min-height: 58px; border: 1.5px dashed var(--line); border-radius: 12px; padding: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.order-pool { display: flex; flex-wrap: wrap; gap: 8px; }
.tile { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 12px; font-size: 1rem; cursor: pointer; min-height: 42px; }
.tile:disabled { opacity: 0.25; }
.tile-in { background: var(--info-soft); border-color: transparent; }

.feedback { border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; border: 1px solid transparent; }
.feedback-good { background: var(--good-soft); }
.feedback-warn { background: var(--warn-soft); }
.feedback-bad { background: var(--bad-soft); }
.feedback-info { background: var(--info-soft); }
.feedback-expected { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ai-note { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 0.92rem; }
.dispute { display: flex; flex-direction: column; gap: 8px; }
.note { background: var(--surface-2); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.file { font-size: 0.9rem; }
.passage { display: flex; flex-direction: column; gap: 8px; }
.reading-text { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; line-height: 1.6; max-width: 65ch; }
.reading-ref .reading-text { max-height: 40vh; overflow-y: auto; }
.passage-text { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }

.speak { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 8px 14px; min-height: 40px; cursor: pointer; font-weight: 600; font-size: 0.92rem; flex: none; }
.speak-small { padding: 4px; min-height: 32px; width: 32px; justify-content: center; vertical-align: middle; }
.speak-compact { padding: 5px 12px; min-height: 34px; font-size: 0.85rem; }
.speak-on { background: var(--ink); color: var(--ink-fg); border-color: var(--ink); }

/* Lesson content */
.goals { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { background: var(--surface-2); font-weight: 650; }
.table tr:last-child td { border-bottom: 0; }
.pitfall { border-left: 3px solid var(--line); padding: 2px 0 2px 12px; display: flex; flex-direction: column; gap: 2px; }
.word-card .word-en { font-size: 1.15rem; }
.details summary { cursor: pointer; color: var(--ink); padding: 6px 0; }
.details[open] { display: flex; flex-direction: column; gap: 8px; }
.summary-card { align-items: flex-start; }
.err-row { border-bottom: 1px solid var(--line); padding: 8px 0; display: flex; flex-direction: column; gap: 4px; }

.speak-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.speak-text { font-size: 1.15rem; font-weight: 600; }
.asr { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.asr-result { background: var(--info-soft); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.asr-words { display: flex; flex-wrap: wrap; gap: 6px; }
.asr-w { padding: 2px 8px; border-radius: 8px; }
.asr-ok { background: var(--good-soft); color: var(--good); }
.asr-miss { background: var(--surface-2); color: var(--muted); text-decoration: underline dotted; }
.compare { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.compare audio { width: 100%; }

.writing { display: flex; flex-direction: column; gap: 12px; }
.checks { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.checks .ok { color: var(--good); }
.checks .no { color: var(--muted); }
.model { border-left: 3px solid var(--accent); padding-left: 12px; }
.self { display: flex; flex-direction: column; gap: 8px; }
.self ul { margin: 0; padding-left: 18px; }
.ai-review { background: var(--info-soft); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.scores { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.score { background: var(--surface); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; font-size: 0.78rem; text-align: center; }
.score b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }

/* Home */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 110px; }
.week-col { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; }
.week-bar { flex: 1; width: 100%; max-width: 30px; background: var(--surface-2); border-radius: 8px; display: flex; align-items: flex-end; overflow: hidden; }
.week-bar div { width: 100%; background: var(--ink); border-radius: 8px; min-height: 2px; }
.week-bar div.met { background: var(--accent); }

/* Vocabulary */
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer; width: 100%; }
.list-row:last-child { border-bottom: 0; }
.dots { display: flex; gap: 4px; flex: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); }
.dot-learning { background: var(--info); border-color: var(--info); }
.dot-known { background: var(--good); border-color: var(--good); }
.dot-solid { background: var(--accent); border-color: var(--accent); }
.review { display: flex; flex-direction: column; gap: 14px; }
.review-word { font-size: 1.6rem; font-family: var(--font-display); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 56px; }
.form { display: flex; flex-direction: column; gap: 8px; }
.form label { font-size: 0.88rem; color: var(--muted); margin-top: 6px; }

/* Speak */
.status-card .row { min-height: 28px; }
.sound-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.sound-tile { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.sound-sym { font-size: 1.4rem; }
.how { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.word-line { padding: 4px 0; border-bottom: 1px solid var(--line); }
.pair-line { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.syllables { display: flex; gap: 8px; flex-wrap: wrap; }
.syl { border: 1.5px solid var(--line); background: var(--surface); border-radius: 10px; padding: 12px 16px; font-size: 1.15rem; cursor: pointer; min-width: 56px; }
.chat { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 88%; border-radius: 16px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.bubble.them { background: var(--surface); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.me { background: var(--info-soft); align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.q-best { background: var(--good-soft); }
.bubble.q-ok { background: var(--warn-soft); }
.bubble.q-wrong { background: var(--bad-soft); }
.voice-bar { position: sticky; bottom: calc(env(safe-area-inset-bottom, 0px) + 64px); z-index: 2; }
.chat-input { position: sticky; bottom: env(safe-area-inset-bottom, 0px); display: flex; gap: 8px; background: var(--bg); padding: 8px 0; }

/* Profile */
.sync-card { gap: 4px; }
.skill-line { display: flex; flex-direction: column; gap: 4px; }
.achievements { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.ach { border: 1px dashed var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 2px; opacity: 0.7; }
.ach-on { border-style: solid; border-color: var(--accent); background: var(--accent-soft); opacity: 1; }
.limits { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
input[type="range"] { width: 100%; accent-color: var(--ink); }

.empty { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; padding: 24px 0; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px);
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 0.9rem;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

@media (max-width: 360px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .scores { grid-template-columns: repeat(2, 1fr); }
  .display { font-size: 1.4rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
