:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1c2233;
  --muted: #667085;
  --line: #e3e6ee;
  --accent: #b4233c;
  --accent-soft: #fde8ec;
  --good: #16884a;
  --good-soft: #e3f6ea;
  --bad: #c9352b;
  --bad-soft: #fdeceb;
  --warn: #9a6700;
  --warn-soft: #fff5d6;
  --rec: #e0352b;
  --special: #c2410c;
  --shadow: 0 1px 3px rgba(20, 30, 60, .08), 0 4px 14px rgba(20, 30, 60, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11141c;
    --card: #1b2030;
    --text: #e8ebf2;
    --muted: #98a2b8;
    --line: #2c3346;
    --accent: #ff8fa3;
    --accent-soft: #4a1d27;
    --good: #4ccb82;
    --good-soft: #15301f;
    --bad: #ff7b70;
    --bad-soft: #3a1d1c;
    --warn: #f0c050;
    --warn-soft: #3a3115;
    --rec: #ff5a4f;
    --special: #ff9f5a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11141c; --card: #1b2030; --text: #e8ebf2; --muted: #98a2b8; --line: #2c3346;
  --accent: #ff8fa3; --accent-soft: #4a1d27; --good: #4ccb82; --good-soft: #15301f;
  --bad: #ff7b70; --bad-soft: #3a1d1c; --warn: #f0c050; --warn-soft: #3a3115;
  --rec: #ff5a4f; --special: #ff9f5a; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}
.loading { text-align: center; color: var(--muted); margin-top: 40vh; }

h1 { font-size: 26px; margin: 8px 0 2px; }
h2 { font-size: 21px; margin: 4px 0; }
h3 { font-size: 17px; margin: 0 0 6px; }
.sub { color: var(--muted); margin: 0 0 16px; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; min-height: 44px; }
.topbar .title { flex: 1; font-weight: 600; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back {
  border: 0; background: none; color: var(--accent); font-size: 17px; padding: 10px 8px 10px 0;
  cursor: pointer; white-space: nowrap;
}

/* cards & lists */
.card {
  background: var(--card); border-radius: 16px; padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.lesson-item {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px;
  margin-bottom: 10px; box-shadow: var(--shadow); color: var(--text); font: inherit; cursor: pointer;
}
.lesson-num {
  flex: 0 0 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.lesson-num.it { background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.lesson-num.done { background: var(--good-soft); color: var(--good); }
.lesson-body { flex: 1; min-width: 0; }
.lesson-body .t { font-weight: 600; }
.lesson-body .r { color: var(--muted); font-size: 14px; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--good); border-radius: 3px; }

details.card summary { font-weight: 600; cursor: pointer; list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::before { content: "▸ "; color: var(--accent); }
details.card[open] summary::before { content: "▾ "; }
details.card ul { padding-left: 20px; margin: 10px 0 0; }
details.card li { margin-bottom: 6px; }

/* tiles on lesson page */
.tile { display: block; }
.tile .head { display: flex; align-items: center; gap: 12px; }
.tile .icon { font-size: 26px; width: 36px; text-align: center; }
.tile .desc { color: var(--muted); font-size: 14px; }
.tile .btns { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.tile .btns .btn { flex: 1; }
.tile-link { cursor: pointer; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.bad { background: var(--bad-soft); border-color: var(--bad-soft); color: var(--bad); }
.btn.rec { background: var(--rec); border-color: var(--rec); color: #fff; }
.btn.rec.on { animation: pulse 1.2s infinite; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn .count { font-weight: 400; color: var(--muted); font-size: 14px; }
.btn.primary .count, .btn.good .count { color: rgba(255,255,255,.8); }
@keyframes pulse { 50% { opacity: .7; } }
.row { display: flex; gap: 8px; margin-top: 10px; }
.row > .btn { flex: 1; }
.icon-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--accent); border-radius: 50%;
  width: 44px; height: 44px; flex: 0 0 44px; font-size: 18px; cursor: pointer; display: inline-grid; place-items: center;
}

/* segmented control */
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 10px; }
.seg button {
  flex: 1; border: 0; background: none; color: var(--text); font: inherit; font-size: 15px; padding: 8px 4px;
  border-radius: 9px; cursor: pointer; min-height: 38px;
}
.seg button.on { background: var(--card); font-weight: 600; box-shadow: var(--shadow); }
.check { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); margin: 4px 0 10px; }
.check input { width: 20px; height: 20px; }

/* practice card */
.progress-line { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.practice { text-align: center; padding: 22px 16px; }
.big-en { font-size: 30px; font-weight: 700; line-height: 1.2; margin: 4px 0; overflow-wrap: anywhere; }
.big-en.sentence { font-size: 23px; }
.big-ru { font-size: 22px; font-weight: 600; margin: 4px 0; }
.big-ru.sentence { font-size: 20px; }
.cyr { font-size: 22px; letter-spacing: .3px; margin: 6px 0; color: var(--accent); }
.cyr.sentence { font-size: 18px; }
.cyr .sp { color: var(--special); font-weight: 700; }
.ipa { color: var(--muted); font-size: 15px; }
.ru { color: var(--muted); margin-top: 6px; }
.tip {
  background: var(--warn-soft); color: var(--text); border-radius: 12px; padding: 10px 12px; margin: 12px 0 0;
  text-align: left; font-size: 15px;
}
.tip::before { content: "💡 "; }
.example { text-align: left; border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; display: flex; gap: 10px; align-items: center; }
.example .txt { flex: 1; font-size: 15px; }
.done-badge { color: var(--good); font-weight: 600; font-size: 14px; }
.speaker { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.hint { color: var(--muted); font-size: 14px; margin-top: 10px; }

/* answer area */
.answer-input {
  width: 100%; font: inherit; font-size: 18px; padding: 12px 14px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--bg); color: var(--text); margin-top: 14px;
}
.answer-input:focus { outline: none; border-color: var(--accent); }
.result { border-radius: 12px; padding: 12px; margin-top: 14px; text-align: left; }
.result.good { background: var(--good-soft); }
.result.bad { background: var(--bad-soft); }
.result.warn { background: var(--warn-soft); }
.result .verdict { font-weight: 700; margin-bottom: 4px; }
.result .yours { text-decoration: line-through; color: var(--muted); }
.reveal { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }

/* pronunciation score */
.score { margin-top: 14px; border-radius: 14px; padding: 12px; text-align: left; background: var(--bg); border: 1px solid var(--line); }
.score .top { display: flex; align-items: center; gap: 12px; }
.score .thumb { font-size: 38px; line-height: 1; display: inline-block; }
.score .pct { font-size: 22px; font-weight: 700; }
.score .label { color: var(--muted); font-size: 14px; }
.score ul { margin: 8px 0 0; padding-left: 20px; font-size: 15px; }
.score li { margin-bottom: 4px; }
.score .w-bad { color: var(--bad); font-weight: 600; }
.score .w-mid { color: var(--warn); font-weight: 600; }
.score .w-good { color: var(--good); }
.score .words { margin-top: 8px; font-size: 18px; line-height: 1.6; }

/* story */
.bubble {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; margin: 0 0 10px;
  max-width: 88%; cursor: pointer; box-shadow: var(--shadow); text-align: left; display: block; width: fit-content;
  color: var(--text); font: inherit;
}
.bubble.anna { margin-left: auto; background: var(--accent-soft); border-color: var(--accent-soft); }
.bubble.playing { outline: 3px solid var(--accent); }
.bubble .en { font-weight: 600; }
.bubble .cyr { font-size: 15px; margin: 2px 0 0; }
.bubble .ru { font-size: 14px; margin-top: 2px; }
.story-controls { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 6px 0 8px; }

/* vocab list */
.vocab-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.vocab-row:last-child { border-bottom: 0; }
.vocab-row .main { flex: 1; min-width: 0; }
.vocab-row .en { font-weight: 600; }
.vocab-row .cyr { font-size: 15px; margin: 0; }
.vocab-row .ru { font-size: 14px; margin: 0; }

.sound-rule { font-size: 16px; }
.center { text-align: center; }
.end-emoji { font-size: 56px; }
.notice { background: var(--warn-soft); border-radius: 12px; padding: 10px 12px; font-size: 15px; margin-bottom: 12px; }

/* Russian keyboard (PC) */
.kb { margin-top: 12px; user-select: none; -webkit-user-select: none; }
.kb-row { display: flex; gap: 3px; justify-content: center; margin-bottom: 3px; }
.kb-key {
  flex: 1 1 0; min-width: 0; max-width: 40px; height: 44px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; cursor: pointer; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05;
}
.kb-key .ru-l { font-size: 17px; font-weight: 600; }
.kb-key .de-l { font-size: 10px; color: var(--muted); }
.kb-key.wide { max-width: 220px; flex: 6 1 0; font-size: 13px; color: var(--muted); }
.kb-key.hit { background: var(--accent); color: #fff; border-color: var(--accent); }
.kb-key.hit .de-l { color: rgba(255,255,255,.8); }
.kb-hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 4px; }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; font-size: 14px; margin-top: 8px; cursor: pointer; }

/* legend: symbols of the reading aid */
.legend { width: 100%; border-collapse: collapse; font-size: 15px; margin-bottom: 8px; }
.legend th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.legend td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.legend td:nth-child(1), .legend td:nth-child(2) { font-size: 20px; font-weight: 700; text-align: center; width: 3.2em; }
.legend .cyr { display: inline; margin: 0; }

.bubble .play-ico { color: var(--accent); font-size: 12px; }
.bubble.playing .play-ico { animation: pulse 1s infinite; }
