:root {
  --bg: #f3f5f1;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --ink: #1a201c;
  --muted: #5b655f;
  --line: #dce2db;
  --accent: #1d7555;
  --accent-ink: #ffffff;
  --accent-soft: #dff0e7;
  --warn: #a8690f;
  --warn-soft: #fbefd9;
  --bad: #b83a33;
  --bad-soft: #f8e1df;
  --code-bg: #f6f8f4;
  --code-line: #e3e8e1;
  --tok-kw: #7a3fb0;
  --tok-str: #1d7555;
  --tok-num: #b0521b;
  --tok-com: #7d887f;
  --tok-def: #1f5fbf;
  --tok-builtin: #a1398a;
  --shadow: 0 1px 2px rgba(20, 30, 24, .06), 0 4px 16px rgba(20, 30, 24, .05);
  --radius: 10px;
  --f-ui: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-code: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --f-display: "Unbounded", "Onest", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111412; --surface: #191d1a; --surface-2: #20251f; --ink: #e4eae5; --muted: #98a39b;
    --line: #2b322d; --accent: #4cc08c; --accent-ink: #0c1a13; --accent-soft: #1b3428;
    --warn: #e0a64a; --warn-soft: #3a2c14; --bad: #ef7a70; --bad-soft: #3d1d1a;
    --code-bg: #151916; --code-line: #262c27;
    --tok-kw: #c79bf2; --tok-str: #7fd6a8; --tok-num: #f0a36b; --tok-com: #6f7b72; --tok-def: #7fb2ff; --tok-builtin: #e88ad0;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111412; --surface: #191d1a; --surface-2: #20251f; --ink: #e4eae5; --muted: #98a39b;
  --line: #2b322d; --accent: #4cc08c; --accent-ink: #0c1a13; --accent-soft: #1b3428;
  --warn: #e0a64a; --warn-soft: #3a2c14; --bad: #ef7a70; --bad-soft: #3d1d1a;
  --code-bg: #151916; --code-line: #262c27;
  --tok-kw: #c79bf2; --tok-str: #7fd6a8; --tok-num: #f0a36b; --tok-com: #6f7b72; --tok-def: #7fb2ff; --tok-builtin: #e88ad0;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.6 var(--f-ui);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- верхняя панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--f-code); font-weight: 600; font-size: 15px; color: var(--ink); text-decoration: none; }
.brand span { color: var(--accent); }
.topnav { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.topnav a, .linkish {
  padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 14px;
  background: none; border: 0; cursor: pointer;
}
.topnav a:hover, .linkish:hover, .topnav a.on { background: var(--surface-2); color: var(--ink); }
#review-badge {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; text-align: center; line-height: 20px;
}

main { max-width: 1180px; margin: 0 auto; padding-inline: 20px; padding-block: 24px 80px; }
.loading { color: var(--muted); padding: 40px 0; }

h1, h2, h3 { text-wrap: balance; line-height: 1.25; }
h1 { font-family: var(--f-display); font-weight: 700; font-size: 26px; margin: 0 0 8px; letter-spacing: -.01em; }
h2 { font-size: 21px; margin: 0 0 12px; }
h3 { font-size: 17px; margin: 18px 0 8px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 500; font-size: 15px; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- вход ---------- */
.login { max-width: 360px; margin: 12vh auto 0; }
.login form { display: grid; gap: 12px; margin-top: 20px; }
.login input {
  padding: 11px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit;
}
.err { color: var(--bad); font-size: 14px; min-height: 1.4em; }

/* ---------- главная ---------- */
.home-head { display: grid; gap: 16px; grid-template-columns: 1fr; margin-bottom: 28px; }
.review-panel {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-radius: var(--radius); background: var(--accent-soft);
}
.review-panel b { font-size: 18px; }
.level { margin-bottom: 36px; }
.level-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.level-head h2 { font-family: var(--f-display); font-weight: 500; font-size: 19px; margin: 0; }
.topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.topic-card {
  display: grid; gap: 10px; padding: 16px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); text-decoration: none; color: var(--ink);
}
.topic-card:hover { border-color: var(--accent); }
.topic-card .t { font-weight: 600; }
.topic-card .s { font-size: 14px; color: var(--muted); line-height: 1.45; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }
.planned { padding: 14px 16px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); font-size: 14px; }
.planned ul { margin: 6px 0 0; padding-left: 20px; }

/* ---------- страница темы ---------- */
.topic-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 28px; }
.side { position: sticky; top: 70px; align-self: start; max-height: calc(100vh - 90px); overflow: auto; font-size: 14px; }
.side a { display: block; padding: 6px 10px; border-radius: 7px; color: var(--muted); text-decoration: none; line-height: 1.35; }
.side a.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.side a:hover { color: var(--ink); }
.side .lvl { font-weight: 600; color: var(--ink); padding: 0 10px 8px; }
@media (max-width: 860px) {
  .topic-layout { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
  .side details:not([open]) { margin-bottom: 0; }
}
.side summary { cursor: pointer; padding: 6px 10px; color: var(--muted); }
@media (min-width: 861px) { .side summary { display: none; } }

.steps { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0 22px; }
.stepdot {
  width: 34px; height: 34px; border-radius: 7px; display: grid; place-items: center;
  font: 600 12px var(--f-code); text-decoration: none; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line);
}
.stepdot.done { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.stepdot.started { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.stepdot.on { outline: 2px solid var(--ink); outline-offset: 1px; }
.legend { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: -12px; margin-bottom: 20px; }
.legend code { font-family: var(--f-code); font-weight: 600; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 24px; box-shadow: var(--shadow);
}
@media (max-width: 600px) { .card { padding: 16px; } main { padding-inline: 16px; } }
.kind { display: inline-block; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding: 3px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.kind.bug { background: var(--bad-soft); color: var(--bad); }
.kind.real, .kind.final { background: var(--warn-soft); color: var(--warn); }
.kind.drill { background: var(--accent-soft); color: var(--accent); }
.based { font-size: 13px; color: var(--muted); margin-left: 8px; }

.md { max-width: 72ch; }
.md p, .md ul, .md ol { margin: 0 0 12px; }
.md li { margin: 3px 0; }
.md table { border-collapse: collapse; margin: 8px 0 14px; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md blockquote { margin: 0 0 12px; padding: 10px 14px; border-left: 3px solid var(--warn); background: var(--warn-soft); border-radius: 0 8px 8px 0; }
.md blockquote p:last-child { margin: 0; }
.md :not(pre) > code, .inline-code {
  font-family: var(--f-code); font-size: .88em; padding: 1px 5px; border-radius: 4px; background: var(--surface-2);
}
pre.code {
  font: 14px/1.55 var(--f-code); background: var(--code-bg); border: 1px solid var(--code-line);
  border-radius: 8px; padding: 12px 14px; overflow-x: auto; margin: 0 0 14px; max-width: 100%;
}
pre.code.numbered { padding-left: 0; }
pre.code .ln { display: inline-block; width: 3.4em; padding-right: 12px; text-align: right; color: var(--tok-com); user-select: none; }
.cm-keyword { color: var(--tok-kw); }
.cm-string, .cm-string-2 { color: var(--tok-str); }
.cm-number { color: var(--tok-num); }
.cm-comment { color: var(--tok-com); font-style: italic; }
.cm-def { color: var(--tok-def); }
.cm-builtin { color: var(--tok-builtin); }
.cm-variable-2, .cm-property { color: inherit; }
.cm-meta { color: var(--tok-num); }

/* редактор */
.CodeMirror {
  height: auto; min-height: 140px; font: 14px/1.55 var(--f-code);
  border: 1px solid var(--code-line); border-radius: 8px; background: var(--code-bg); color: var(--ink);
}
.CodeMirror-scroll { min-height: 140px; max-height: 560px; }
.CodeMirror-gutters { background: var(--code-bg); border-right: 1px solid var(--code-line); }
.CodeMirror-linenumber { color: var(--tok-com); }
.CodeMirror-cursor { border-left-color: var(--ink); }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: var(--accent-soft) !important; }
.CodeMirror-matchingbracket { color: var(--accent) !important; font-weight: 700; }
.editor-wrap { margin: 14px 0 12px; }
.hint-keys { font-size: 12px; color: var(--muted); }

.output {
  font: 13px/1.5 var(--f-code); white-space: pre-wrap; word-break: break-word;
  background: var(--code-bg); border: 1px solid var(--code-line); border-radius: 8px; padding: 10px 12px; margin-top: 10px; max-height: 360px; overflow: auto;
}
.results { margin-top: 16px; display: grid; gap: 6px; }
.verdict { padding: 12px 14px; border-radius: 8px; font-weight: 600; }
.verdict.ok { background: var(--accent-soft); color: var(--accent); }
.verdict.no { background: var(--bad-soft); color: var(--bad); }
.test { display: grid; grid-template-columns: 22px 1fr; gap: 6px; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.test .m { font-weight: 700; }
.test.passed .m { color: var(--accent); }
.test.failed .m, .test.not_run .m { color: var(--bad); }
.test .msg { color: var(--muted); font-size: 13px; }
.test pre { margin: 6px 0 0; font: 12px/1.45 var(--f-code); white-space: pre-wrap; color: var(--muted); }
details.more { margin-top: 10px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 14px; }

/* подтемы в полоске шагов */
.steps { gap: 10px 14px; align-items: flex-start; }
.stepgroup { display: grid; gap: 4px; padding: 6px 8px; border-radius: 8px; border: 1px solid transparent; }
.stepgroup.cur { border-color: var(--line); background: var(--surface); }
.stepgroup-title { font-size: 12px; color: var(--muted); max-width: 26ch; line-height: 1.3; }
.stepgroup.done .stepgroup-title { color: var(--accent); }
.stepgroup-dots { display: flex; flex-wrap: wrap; gap: 5px; }

/* расставь строки */
.parsons { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; }
.pline { display: flex; align-items: center; gap: 8px; padding: 4px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: grab; }
.pline pre.code { margin: 0; flex: 1; white-space: pre; padding: 6px 10px; border: 0; background: transparent; }
.pline.ok { border-color: var(--accent); background: var(--accent-soft); }
.pline.dragging { opacity: .5; }
.pbtns { display: flex; gap: 4px; }
.pbtns .btn { padding: 3px 8px; }
.kind.fill { background: var(--accent-soft); color: var(--accent); }

/* примеры к задаче */
.examples { margin: 14px 0 4px; padding: 12px 14px; border-radius: 8px; background: var(--surface-2); max-width: 100%; }
.examples .eyebrow { margin-bottom: 8px; }
.examples .ex + .ex { border-top: 1px dashed var(--line); margin-top: 10px; padding-top: 10px; }
.examples pre.code { margin: 0 0 6px; }
.ex-row { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; font: 14px/1.5 var(--f-code); padding: 2px 0; overflow-wrap: anywhere; }
.ex-row code { font-family: var(--f-code); }
.ex-arrow { color: var(--muted); }
.ex-err { color: var(--bad); }

/* вопросы */
.check { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 18px; }
.check .qn { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.opts { display: grid; gap: 8px; margin-top: 10px; }
.opt {
  text-align: left; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-size: 15px; line-height: 1.4;
}
.opt code { font-family: var(--f-code); font-size: 14px; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt.right { border-color: var(--accent); background: var(--accent-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt:disabled { cursor: default; }
.feedback { margin-top: 10px; font-size: 15px; }
.feedback.ok { color: var(--accent); }
.feedback.no { color: var(--bad); }
.explain-box { margin-top: 8px; padding: 12px 14px; border-radius: 8px; background: var(--surface-2); }
.explain-box .md { max-width: none; }

.navbtns { display: flex; justify-content: space-between; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.example { margin: 6px 0 16px; }
.example .lbl { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
textarea.explain {
  width: 100%; min-height: 160px; padding: 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 15px/1.5 var(--f-ui); resize: vertical;
}
.source { font-size: 13px; color: var(--muted); font-family: var(--f-code); margin-bottom: 6px; }

/* карточки */
.deck-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 20px; }
.deck-tabs a { padding: 7px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); text-decoration: none; font-size: 14px; }
.deck-tabs a.on { color: var(--ink); border-color: var(--ink); }
.flash { max-width: 760px; }
.flash .front { min-height: 120px; }
.flash .answer { border-top: 1px dashed var(--line); margin-top: 18px; padding-top: 16px; }
.flash .follow { margin-top: 12px; padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); font-size: 15px; }
.rate { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; }
.rate .btn { justify-content: center; flex-direction: column; gap: 0; }
.rate small { font-weight: 400; color: var(--muted); font-size: 12px; }
.rate .again { border-color: var(--bad); }
.rate .good { border-color: var(--accent); }
.meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.topic-select { padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; max-width: 100%; }

/* решения */
.sub-group { margin-bottom: 22px; }
.sub-row { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 14px; text-decoration: none; color: var(--ink); flex-wrap: wrap; }
.sub-row:hover { background: var(--surface); }
.pill { font: 600 12px var(--f-code); padding: 2px 8px; border-radius: 10px; }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.no { background: var(--bad-soft); color: var(--bad); }
.review-tasks { display: grid; gap: 8px; margin-bottom: 24px; }
.review-task { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); flex-wrap: wrap; }
.banner { padding: 12px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--ink); margin-bottom: 16px; font-size: 15px; }
@media (prefers-reduced-motion: no-preference) { .opt, .btn, .topic-card { transition: border-color .15s, background .15s; } }
