:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #1b2333;
  --muted: #5d6779;
  --border: #dde2ec;
  --accent: #1f5fbf;
  --accent-2: #d52b1e;
  --accent-soft: #e3ecfb;
  --ok: #1e8e4e;
  --ok-soft: #dcf3e5;
  --warn: #b26a00;
  --warn-soft: #fbefd9;
  --bad: #c62828;
  --bad-soft: #fbe2e2;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .06);
  --radius: 14px;
  --ru-font: "Noto Sans", "PT Sans", "Segoe UI", "Ubuntu", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141c; --surface: #171e29; --surface-2: #202938; --text: #e8edf5; --muted: #9aa6ba;
    --border: #2b3546; --accent: #6ea8ff; --accent-2: #ff6b5e; --accent-soft: #1d2d47;
    --ok: #4cc77f; --ok-soft: #173826; --warn: #f0b04a; --warn-soft: #3a2c12; --bad: #ff7272; --bad-soft: #3d1c1c;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141c; --surface: #171e29; --surface-2: #202938; --text: #e8edf5; --muted: #9aa6ba;
  --border: #2b3546; --accent: #6ea8ff; --accent-2: #ff6b5e; --accent-soft: #1d2d47;
  --ok: #4cc77f; --ok-soft: #173826; --warn: #f0b04a; --warn-soft: #3a2c12; --bad: #ff7272; --bad-soft: #3d1c1c;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Ubuntu, sans-serif;
  min-height: 100vh; -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; text-decoration: none; color: var(--text); font-weight: 700; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-family: var(--ru-font);
}
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a {
  padding: .45rem .7rem; border-radius: 10px; text-decoration: none; color: var(--muted); white-space: nowrap; font-size: .95rem;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.pill { padding: .2rem .6rem; border-radius: 999px; background: var(--surface-2); font-size: .9rem; white-space: nowrap; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; display: inline-grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--surface-2); }

@media (max-width: 760px) {
  .topbar { padding: .4rem .6rem; }
  .brand-text { display: none; }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border);
    justify-content: space-around; padding: .3rem .2rem calc(.3rem + env(safe-area-inset-bottom)); z-index: 30;
  }
  .nav a { display: flex; flex-direction: column; align-items: center; font-size: 1.15rem; padding: .25rem .4rem; }
  .nav a span { font-size: .65rem; }
  .nav a[data-route="settings"], .nav a[data-route="vocab"] { display: none; }
  .view { padding-bottom: 90px !important; }
}

/* ---------- layout ---------- */
.view { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 3rem; outline: none; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; }
.card h2 { margin-bottom: .6rem; }
.section-title { margin: 1.6rem 0 .7rem; display: flex; align-items: center; gap: .5rem; }

.banner { max-width: 1100px; margin: .75rem auto 0; padding: .65rem 1rem; border-radius: 12px; background: var(--warn-soft); color: var(--text); border: 1px solid var(--border); }
.banner.info { background: var(--accent-soft); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .6rem 1.05rem;
  border-radius: 11px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600;
  text-decoration: none; color: var(--text); min-height: 42px; transition: background .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.small { padding: .3rem .65rem; min-height: 32px; font-size: .875rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.kbd, kbd {
  font: 600 .75rem/1 ui-monospace, monospace; padding: .2rem .4rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--muted);
}

/* ---------- refresh screen ---------- */
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.hero .greet { font-family: var(--ru-font); font-size: 2rem; font-weight: 700; margin: 0; }
.stats { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: .1rem; }
.stat .sub { color: var(--muted); font-size: .85rem; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: .45rem; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.bar.ok > span { background: var(--ok); }
.options { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.option {
  display: flex; gap: .8rem; align-items: flex-start; text-align: left; padding: 1rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; box-shadow: var(--shadow); color: var(--text);
  text-decoration: none;
}
.option:hover { border-color: var(--accent); }
.option.primary { border: 2px solid var(--accent); }
.option .num {
  flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft);
  color: var(--accent); font-weight: 700;
}
.option .t { font-weight: 700; }
.option .d { color: var(--muted); font-size: .88rem; }
.recap { border-left: 4px solid var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem; padding: .25rem .6rem; border-radius: 99px; background: var(--surface-2);
  font-family: var(--ru-font); font-size: .95rem; border: 1px solid transparent; cursor: default;
}
.chip.play { cursor: pointer; }
.chip.play:hover { border-color: var(--accent); }
.chip.ok { background: var(--ok-soft); } .chip.close { background: var(--warn-soft); }
.chip.wrong, .chip.missing { background: var(--bad-soft); }
.chip.missing { text-decoration: line-through; }
.correction { font-size: .92rem; padding: .35rem 0; border-bottom: 1px dashed var(--border); }
.correction:last-child { border-bottom: 0; }
.strike { text-decoration: line-through; color: var(--bad); }
.fix { color: var(--ok); font-weight: 600; font-family: var(--ru-font); }

/* ---------- russian text ---------- */
.ru { font-family: var(--ru-font); }
.ru-big { font-family: var(--ru-font); font-size: clamp(2rem, 6vw, 3.2rem); font-weight: 700; line-height: 1.15; }
.ru-mid { font-family: var(--ru-font); font-size: clamp(1.35rem, 3.6vw, 1.9rem); font-weight: 600; line-height: 1.3; }
.tr { color: var(--muted); font-family: ui-monospace, "Ubuntu Mono", monospace; font-size: .95rem; }
.en { color: var(--muted); font-size: 1.05rem; }
.emoji { font-size: 2.2rem; }

/* ---------- audio / speech ---------- */
.audio-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.play-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--accent-soft); color: var(--accent); cursor: pointer; font-size: 1.1rem; flex: none;
}
.play-btn.sm { width: 32px; height: 32px; font-size: .85rem; }
.play-btn:hover { filter: brightness(1.05); border-color: var(--accent); }
.play-btn.playing { animation: pulse 1s infinite; }
.mic-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; height: 44px; padding: 0 1rem; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; user-select: none; touch-action: none;
}
.mic-btn.recording { background: var(--accent-2); color: #fff; border-color: var(--accent-2); animation: pulse 1.2s infinite; }
.mic-btn.busy { opacity: .7; }
.mic-btn.listening { border-color: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(213, 43, 30, .35); } 50% { box-shadow: 0 0 0 8px rgba(213, 43, 30, 0); } }
.level-meter { width: 80px; height: 6px; background: var(--surface-2); border-radius: 9px; overflow: hidden; }
.level-meter span { display: block; height: 100%; width: 0; background: var(--ok); transition: width .05s; }
.speech-result { margin-top: .7rem; padding: .75rem .9rem; border-radius: 12px; background: var(--surface-2); }
.score-badge { display: inline-grid; place-items: center; min-width: 54px; height: 54px; border-radius: 50%; font-weight: 800; font-size: 1.15rem; color: #fff; background: var(--muted); flex: none; }
.score-badge.good { background: var(--ok); } .score-badge.mid { background: var(--warn); } .score-badge.bad { background: var(--bad); }

/* ---------- lesson ---------- */
.lesson-head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: .8rem; }
.steps { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: 1rem; }
.step-dot { padding: .25rem .65rem; border-radius: 99px; background: var(--surface-2); font-size: .82rem; color: var(--muted); cursor: pointer; border: 0; }
.step-dot.done { background: var(--ok-soft); color: var(--ok); }
.step-dot.cur { background: var(--accent); color: #fff; }
.word-card { text-align: center; padding: 2rem 1.2rem; }
.word-card .audio-row { justify-content: center; margin: 1rem 0; }
.word-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; gap: .5rem; }
.dots { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.dots span.on { background: var(--accent); }
.grammar-box table { border-collapse: collapse; width: 100%; margin: .8rem 0; font-family: var(--ru-font); }
.grammar-box th, .grammar-box td { border: 1px solid var(--border); padding: .45rem .6rem; text-align: left; }
.grammar-box th { background: var(--surface-2); font-family: system-ui, sans-serif; font-size: .9rem; }
.table-wrap { overflow-x: auto; }
.dialogue .line { display: flex; gap: .7rem; align-items: flex-start; padding: .65rem 0; border-bottom: 1px solid var(--border); }
.dialogue .line:last-child { border-bottom: 0; }
.dialogue .speaker { font-weight: 700; min-width: 80px; font-family: var(--ru-font); color: var(--accent); }
.dialogue .line.active { background: var(--accent-soft); border-radius: 10px; }
.blur { filter: blur(6px); user-select: none; }
.drill { min-height: 300px; }
.drill .prompt { margin: .4rem 0 1rem; }
.choice-list { display: grid; gap: .55rem; }
.choice {
  text-align: left; padding: .8rem 1rem; border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-family: var(--ru-font); font-size: 1.1rem; display: flex; gap: .7rem; align-items: center;
}
.choice:hover { border-color: var(--accent); }
.choice.correct { background: var(--ok-soft); border-color: var(--ok); }
.choice.wrong { background: var(--bad-soft); border-color: var(--bad); }
.choice .k { color: var(--muted); font: 600 .8rem ui-monospace, monospace; }
.text-input {
  width: 100%; padding: .75rem .9rem; border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  font-family: var(--ru-font); font-size: 1.2rem;
}
.text-input:focus, textarea:focus, select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea.text-input { min-height: 110px; resize: vertical; }
.feedback { margin-top: .9rem; padding: .7rem .9rem; border-radius: 12px; }
.feedback.correct { background: var(--ok-soft); } .feedback.close { background: var(--warn-soft); } .feedback.wrong { background: var(--bad-soft); }
.tiles { display: flex; flex-wrap: wrap; gap: .45rem; min-height: 50px; padding: .5rem; border-radius: 12px; border: 1px dashed var(--border); }
.tile { padding: .45rem .75rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-family: var(--ru-font); font-size: 1.1rem; }
.tile.used { opacity: .3; pointer-events: none; }
.gap { display: inline-block; min-width: 70px; border-bottom: 2px solid var(--accent); text-align: center; color: var(--accent); }
.drill-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 1.2rem; gap: .5rem; flex-wrap: wrap; }
.tag { font-size: .75rem; padding: .15rem .5rem; border-radius: 99px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }

/* virtual keyboard */
.vkbd { margin-top: .5rem; display: grid; gap: 4px; }
.vkbd .krow { display: flex; gap: 4px; justify-content: center; }
.vkbd button { flex: 1; max-width: 42px; padding: .45rem 0; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-family: var(--ru-font); }
.vkbd button.wide { max-width: 140px; flex: 3; }

/* ---------- review ---------- */
.flash { text-align: center; padding: 2.2rem 1rem; min-height: 320px; display: flex; flex-direction: column; justify-content: center; gap: .6rem; }
.grade-row { display: grid; gap: .5rem; grid-template-columns: repeat(4, 1fr); margin-top: 1rem; }
.grade-row .btn { flex-direction: column; gap: 0; }
.grade-row .btn small { font-weight: 400; color: var(--muted); font-size: .75rem; }

/* ---------- chat ---------- */
.chat-wrap { display: grid; grid-template-columns: 230px 1fr; gap: 1rem; }
@media (max-width: 860px) { .chat-wrap { grid-template-columns: 1fr; } .chat-side { display: none; } }
.chat-log { height: calc(100vh - 330px); min-height: 300px; overflow-y: auto; padding: .5rem; display: flex; flex-direction: column; gap: .7rem; }
.msg { max-width: 82%; padding: .7rem .9rem; border-radius: 14px; }
.msg.tutor { background: var(--surface-2); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.user { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .ru { font-size: 1.15rem; }
.msg .en { font-size: .9rem; }
.msg .corr { margin-top: .5rem; padding: .5rem .6rem; border-radius: 10px; background: var(--warn-soft); color: var(--text); font-size: .9rem; }
.chat-input { display: flex; gap: .5rem; align-items: flex-end; margin-top: .7rem; }
.chat-input .text-input { flex: 1; }
.conv { display: block; width: 100%; text-align: left; padding: .5rem .6rem; border-radius: 9px; border: 0; background: transparent; cursor: pointer; }
.conv:hover, .conv.cur { background: var(--surface-2); }

/* ---------- tables / forms ---------- */
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: .5rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.list th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
label.field { display: block; margin-bottom: .8rem; }
label.field > span { display: block; font-size: .88rem; color: var(--muted); margin-bottom: .25rem; }
input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: .55rem .7rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
}
input[type=range] { width: 100%; }
.switch { display: flex; align-items: center; gap: .5rem; cursor: pointer; margin-bottom: .6rem; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); margin-right: .35rem; }
.status-dot.on { background: var(--ok); } .status-dot.partial { background: var(--warn); }

/* ---------- charts ---------- */
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heatmap span { width: 13px; height: 13px; border-radius: 3px; background: var(--surface-2); }
.heatmap span.l1 { background: color-mix(in srgb, var(--ok) 35%, var(--surface-2)); }
.heatmap span.l2 { background: color-mix(in srgb, var(--ok) 60%, var(--surface-2)); }
.heatmap span.l3 { background: var(--ok); }
.hbar { display: grid; grid-template-columns: 110px 1fr 44px; gap: .6rem; align-items: center; margin: .35rem 0; font-size: .92rem; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(10, 15, 25, .55); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal-card { background: var(--surface); border-radius: var(--radius); padding: 1.4rem; max-width: 560px; width: 100%; max-height: 85vh; overflow: auto; position: relative; }
.modal-close { position: absolute; top: .7rem; right: .7rem; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: .6rem 1rem; border-radius: 10px; z-index: 60; max-width: 90vw; box-shadow: var(--shadow);
}
@media (max-width: 760px) { .toast { bottom: 84px; } }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

/* ---------- phone: keep the exercise above the fold ---------- */
@media (max-width: 760px) {
  .view { padding-top: .8rem; }
  h1 { font-size: 1.3rem; }
  .lesson-head { margin-bottom: .4rem; }
  .steps { gap: .25rem; margin-bottom: .6rem; }
  .step-dot { font-size: .72rem; padding: .2rem .5rem; }
  .card { padding: .9rem .9rem; }
  .drill { min-height: 0; }
  .choice { padding: .65rem .8rem; }
  .hero .greet { font-size: 1.6rem; }
}

/* ---------- language switcher ---------- */
.lang-pill { border: 1px solid var(--border); cursor: pointer; font-size: 1rem; }
.lang-pill:hover { background: var(--accent-soft); }
.lang-choice { display: flex; align-items: center; gap: .8rem; width: 100%; text-align: left; padding: .9rem 1rem;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; margin-bottom: .6rem; }
.lang-choice.cur { border: 2px solid var(--accent); }
.lang-choice .flag { font-size: 2rem; }
