:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #f1f2f8;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e6e8ef;
  --accent: #5b53f0;
  --accent-ink: #ffffff;
  --accent-soft: #eeecff;
  --ok: #12855f;
  --ok-soft: #e6f6ef;
  --warn: #b4541b;
  --warn-soft: #fdf0e6;
  --bad: #d23f4f;
  --bad-soft: #fdeaec;
  --violet: #6c5ce7;
  --amber: #e69a3c;
  --teal: #2fb39a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 18, 30, .05), 0 10px 30px rgba(16, 18, 30, .07);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --panel: #171a22;
    --panel-2: #1d2029;
    --ink: #e9eaf0;
    --muted: #9aa1b1;
    --line: #262a35;
    --accent: #8b84ff;
    --accent-ink: #0f1117;
    --accent-soft: #21203a;
    --ok: #4ade9e;
    --ok-soft: #172a24;
    --warn: #f0a373;
    --warn-soft: #2b2018;
    --bad: #ff6b7a;
    --bad-soft: #2f1a1e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117;
  --panel: #171a22;
  --panel-2: #1d2029;
  --ink: #e9eaf0;
  --muted: #9aa1b1;
  --line: #262a35;
  --accent: #8b84ff;
  --accent-ink: #0f1117;
  --accent-soft: #21203a;
  --ok: #4ade9e;
  --ok-soft: #172a24;
  --warn: #f0a373;
  --warn-soft: #2b2018;
  --bad: #ff6b7a;
  --bad-soft: #2f1a1e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 "Manrope", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; color: inherit; }
button:disabled { cursor: default; opacity: .45; }
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  line-height: 16px;
  font-weight: 600;
  text-align: center;
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

/* ─── шапка ─── */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 2px 8px;
}
html.embed .top { display: none; }
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.logo { font-weight: 800; letter-spacing: -.02em; color: var(--accent); }
.sep { color: var(--line); }
.course { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; flex: none; }

.icon {
  width: 36px; height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.icon:hover { border-color: var(--accent); color: var(--accent); }
.icon.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.view { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.ghost {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.primary {
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 700;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}
.primary:hover { filter: brightness(1.05); }
.primary kbd { background: color-mix(in srgb, var(--accent-ink) 18%, transparent); border-color: transparent; color: var(--accent-ink); }
.link { border: 0; background: none; color: var(--muted); padding: 6px 4px; font-weight: 600; }
.link:hover { color: var(--accent); }

/* ─── главная ─── */
.home { padding: 18px 0 40px; display: flex; flex-direction: column; gap: 28px; }
.hero { text-align: center; padding: 22px 0 4px; }
.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1.08;
  letter-spacing: -.03em;
  font-weight: 800;
}
.hero h1 .caret { color: var(--accent); animation: blink 1s steps(2) infinite; font-weight: 400; }
@keyframes blink { 50% { opacity: 0; } }
.hero p { margin: 0 auto; max-width: 560px; color: var(--muted); font-size: 17px; }

.settings {
  display: flex; flex-wrap: wrap; gap: 14px 28px; justify-content: center; align-items: flex-start;
}
.setting { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.setting .label { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; border-radius: 999px; padding: 7px 16px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.setting .desc { font-size: 13px; color: var(--muted); max-width: 320px; text-align: center; min-height: 20px; }

.chapters { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.chapter {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px;
  text-align: left;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.chapter:hover { transform: translateY(-2px); border-color: var(--accent); }
.cover {
  height: 150px;
  border-radius: 12px;
  color: #fff;
  position: relative;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 56px; font-weight: 800; letter-spacing: -.04em;
  text-shadow: 0 4px 18px rgba(0, 0, 0, .25);
}
.cover::before { content: ""; position: absolute; inset: 0; background: linear-gradient(135deg, rgba(255,255,255,.28), transparent 60%); }
.cover::after { content: ""; position: absolute; left: 14px; top: 0; bottom: 0; width: 6px; background: rgba(0,0,0,.18); }
.cover .tag { position: absolute; left: 30px; top: 12px; font-size: 11px; font-weight: 700; letter-spacing: .1em; opacity: .9; }
.cover.violet { background: var(--violet); }
.cover.amber { background: var(--amber); }
.cover.teal { background: var(--teal); }
.cover.rose { background: #d65a7c; }
.chapter h3 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.chapter .sub { color: var(--muted); font-size: 14px; }
.chapter .meta { display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); }
.chapter .meta b { color: var(--ink); }
.chapter .bar { height: 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.chapter .bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.chapter .resume { color: var(--accent); font-size: 13px; font-weight: 700; }

.notebooks { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.note {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel);
}
.note h4 { margin: 0 0 2px; font-size: 15px; }
.note p { margin: 0; color: var(--muted); font-size: 13px; }
.note .n { font-size: 22px; font-weight: 800; color: var(--accent); }

.home .foot { text-align: center; color: var(--muted); font-size: 13px; }

/* ─── игра ─── */
.play { display: flex; flex-direction: column; flex: 1; gap: 10px; padding-bottom: 20px; }
.bar-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.bar-title { display: flex; align-items: center; gap: 10px; font-weight: 700; min-width: 0; }
.bar-title span.t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.bar-right { display: flex; gap: 6px; }

.progress-row { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.progress-row b { color: var(--ink); }
.track { flex: 1; position: relative; height: 10px; background: var(--panel-2); border-radius: 999px; border: 1px solid var(--line); overflow: hidden; }
.track .fill { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #fff)); border-radius: 999px; transition: width .3s ease; }
.track .dot { position: absolute; top: 50%; width: 5px; height: 5px; margin: -2.5px 0 0 -2.5px; border-radius: 50%; background: #fff; opacity: .9; }
.track .dot.skip { background: var(--warn); }
.legend { white-space: nowrap; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin: 0 4px 0 0; }
.legend i.skip { background: var(--warn); }

.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; color: var(--muted); }
.hud-left { display: flex; gap: 6px; position: relative; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 5px 10px; font-weight: 700; font-size: 13px; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.hud-right { display: flex; gap: 16px; align-items: center; white-space: nowrap; }
.hud-right b { color: var(--ink); font-variant-numeric: tabular-nums; font-size: 16px; }
.hud-right .combo b { color: var(--accent); }
.hud-right .combo.hot b { animation: pop .3s ease; }
@keyframes pop { 50% { transform: scale(1.3); } }

.popover {
  position: absolute; top: 40px; left: 0; z-index: 5;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  padding: 8px; display: flex; gap: 4px; flex-wrap: wrap; max-width: 280px;
}
.popover button { border: 1px solid transparent; background: none; border-radius: 8px; padding: 6px 10px; font-weight: 600; font-size: 13px; }
.popover button.on { background: var(--accent-soft); color: var(--accent); }
.popover .cap { width: 100%; font-size: 12px; color: var(--muted); padding: 2px 6px 4px; }

.stage {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  padding: 24px 8px;
  min-height: 360px;
  text-align: center;
}
.prompt-ru { font-size: clamp(20px, 3vw, 28px); font-weight: 600; letter-spacing: -.01em; max-width: 760px; }
.cues { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 26px; font-size: clamp(22px, 3.6vw, 34px); font-weight: 700; letter-spacing: .02em; }
.cue { display: inline-flex; align-items: baseline; gap: 1px; }
.cue .ini { color: var(--ink); }
.cue .dots { color: var(--muted); letter-spacing: .12em; font-weight: 400; opacity: .75; }
.cue .punct { color: var(--muted); }
.cue.done .ini, .cue.done .dots { color: var(--ok); opacity: 1; }
.listen { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 18px; font-weight: 600; }
.listen .wave { display: inline-flex; gap: 3px; align-items: flex-end; height: 22px; }
.listen::after { content: "Прослушано · Ctrl+' — ещё раз"; font-size: 14px; font-weight: 500; }
.listen.playing::after { content: "Слушай…"; color: var(--accent); }
.listen.fresh::after { content: "Загружаю озвучку…"; }
.listen .wave i { width: 4px; background: var(--accent); border-radius: 2px; height: 30%; }
.listen.playing .wave i { animation: wave .9s ease-in-out infinite; }
.listen .wave i:nth-child(2) { animation-delay: .15s; }
.listen .wave i:nth-child(3) { animation-delay: .3s; }
.listen .wave i:nth-child(4) { animation-delay: .45s; }
.listen .wave i:nth-child(5) { animation-delay: .6s; }
@keyframes wave { 50% { height: 100%; } }
.instruction { margin: -6px 0 0; color: var(--muted); font-size: 14px; }

.slots { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: 14px 18px; max-width: 900px; }
.slot { display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; }
.slot .wrap { display: inline-flex; align-items: flex-end; }
.slot input {
  font-family: inherit;
  font-size: clamp(22px, 3.6vw, 32px);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: .01em;
  color: var(--ink);
  background: none;
  border: 0;
  border-bottom: 3px solid var(--line);
  border-radius: 0;
  padding: 2px 4px 6px;
  text-align: center;
  min-width: 4ch;
  outline: none;
  transition: border-color .15s ease;
  caret-color: var(--accent);
}
.slot input:focus { border-bottom-color: var(--accent); }
.slot input.ok { color: var(--ok); border-bottom-color: var(--ok); }
.slot input.wrong { color: var(--bad); border-bottom-color: var(--bad); animation: shake .35s ease; }
.slot input.hinted { color: var(--warn); }
.slot .punct { font-size: clamp(22px, 3.6vw, 32px); line-height: 1.3; font-weight: 700; color: var(--muted); padding: 2px 0 9px 2px; }
.slot .ghost { position: absolute; top: 100%; font-size: 13px; color: var(--bad); font-weight: 600; white-space: nowrap; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

.status { margin: 0; color: var(--muted); font-size: 14px; min-height: 22px; }
.status.bad { color: var(--bad); font-weight: 600; }
.status.good { color: var(--ok); font-weight: 600; }

/* карточка результата */
.result { display: flex; flex-direction: column; align-items: center; gap: 14px; animation: rise .3s ease-out; max-width: 860px; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.result .big { font-size: clamp(30px, 5vw, 46px); font-weight: 800; letter-spacing: -.03em; }
.result .big small { color: var(--accent); font-size: .6em; font-weight: 800; }
.result .pts { color: var(--accent); font-weight: 800; font-size: 20px; }
.result .pts span { color: var(--muted); font-weight: 600; font-size: 14px; margin-left: 10px; }
.result .soft { color: var(--muted); font-size: 14px; }
.words { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 4px 0; }
.word {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 72px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
}
.word .ipa { font-size: 12px; color: var(--muted); font-family: "Segoe UI", Arial, sans-serif; }
.word .w { font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.word .w.fixed { color: var(--bad); }
.word .ru { font-size: 12px; color: var(--muted); max-width: 140px; }
.result .sentence { font-size: 22px; font-weight: 700; }
.result .ru-line { font-size: 17px; color: var(--muted); }
.result .done-line { color: var(--ok); font-weight: 700; }
.result .actions-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* панель действий */
.actions { display: flex; align-items: center; justify-content: center; gap: 10px; }
.nav { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-size: 20px; flex: none; }
.nav:hover { border-color: var(--accent); color: var(--accent); }
.pill-bar {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px; box-shadow: var(--shadow);
}
.pill-bar .act { border: 0; background: none; border-radius: 999px; padding: 8px 12px; display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; color: var(--ink); }
.pill-bar .act:hover { background: var(--panel-2); }
.pill-bar .act .keys { display: inline-flex; gap: 3px; }
.pill-bar .act .ico { display: none; }
#replayBtn .ico { display: inline; }
.pill-bar .primary { padding: 9px 18px; display: inline-flex; align-items: center; gap: 8px; }
.rules { margin: 0; text-align: center; color: var(--muted); font-size: 12px; }

/* пауза */
.overlay { position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; z-index: 20; }
.overlay .card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px 32px; text-align: center; box-shadow: var(--shadow); }
.overlay h2 { margin: 0 0 6px; }
.overlay p { margin: 0 0 16px; color: var(--muted); }

/* итог */
.summary { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 30px 0 40px; text-align: center; }
.summary h2 { margin: 0; font-size: clamp(28px, 4vw, 40px); letter-spacing: -.03em; }
.summary .sub { color: var(--muted); margin: -8px 0 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; width: 100%; max-width: 640px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.tile .v { font-size: 26px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .v.acc { color: var(--accent); }
.tile .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.mistakes { width: 100%; max-width: 640px; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.mistake { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.mistake .en { font-weight: 600; }
.mistake .en s { color: var(--bad); text-decoration-thickness: 2px; }
.mistake .en b { color: var(--ok); }
.mistake .ru { font-size: 13px; color: var(--muted); }
.vocab { width: 100%; max-width: 760px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-weight: 600; font-size: 14px; box-shadow: var(--shadow); z-index: 30;
  animation: rise .25s ease-out;
}

@media (max-width: 640px) {
  .app { padding: 0 12px; }
  .hud-right { gap: 10px; font-size: 13px; }
  .legend .txt { display: none; }
  .stage { min-height: 280px; padding: 14px 4px; gap: 14px; }
  .slots { gap: 10px 12px; }
  .pill-bar .act .keys, .primary kbd, .pill-bar .act .lbl, .bar-top .link .lbl { display: none; }
  .pill-bar .act .ico { display: inline; font-size: 18px; }
  .pill-bar { gap: 2px; padding: 4px; flex-wrap: nowrap; }
  .pill-bar .act { padding: 8px 9px; }
  .pill-bar .primary { padding: 9px 14px; font-size: 14px; }
  .bar-top .link { white-space: nowrap; }
  .nav { width: 40px; height: 40px; }
  .rules { display: none; }
  .chapters { grid-template-columns: 1fr 1fr; gap: 12px; }
  .cover { height: 110px; font-size: 40px; }
  .chapter { padding: 10px; }
}
@media (max-width: 420px) {
  .chapters { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
