:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1a1d23;
  --muted: #5d6573;
  --border: #e2dfd6;
  --accent: #f2b705;
  --accent-strong: #d99e00;
  --accent-ink: #1a1d23;
  --accent-soft: #fff4cc;
  --navy: #14213d;
  --ok: #138a4a;
  --ok-soft: #e3f5ea;
  --bad: #c62828;
  --bad-soft: #fdeaea;
  --warn-soft: #fff6dc;
  --warn-border: #f0d27a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 4px 16px rgba(20, 33, 61, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1f2430;
    --text: #e9ebef;
    --muted: #9aa3b2;
    --border: #2a3040;
    --accent-soft: #3a3014;
    --navy: #0b0f17;
    --ok: #4ccb84;
    --ok-soft: #153325;
    --bad: #ff6b6b;
    --bad-soft: #3a1a1c;
    --warn-soft: #2e2715;
    --warn-border: #6b5a22;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218; --surface: #171b23; --surface-2: #1f2430; --text: #e9ebef; --muted: #9aa3b2;
  --border: #2a3040; --accent-soft: #3a3014; --navy: #0b0f17; --ok: #4ccb84; --ok-soft: #153325;
  --bad: #ff6b6b; --bad-soft: #3a1a1c; --warn-soft: #2e2715; --warn-border: #6b5a22;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Heebo", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 17px;
}
a { color: inherit; }
img, iframe { max-width: 100%; }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.skip { position: absolute; right: -9999px; }
.skip:focus { right: 16px; top: 8px; background: var(--accent); padding: 6px 12px; z-index: 10; border-radius: 8px; }

/* ── Topbar ── */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 1.2rem; text-decoration: none; display: flex; align-items: center; gap: 6px; }
.bolt { color: var(--accent); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { text-decoration: none; padding: 6px 12px; border-radius: 999px; font-weight: 500; font-size: .95rem; opacity: .85; }
.nav a:hover { opacity: 1; background: rgba(255,255,255,.08); }
.nav a.active { background: var(--accent); color: var(--accent-ink); opacity: 1; }

main { padding: 28px 16px 48px; min-height: 60vh; outline: none; }

/* ── Hero ── */
.hero {
  background: linear-gradient(135deg, var(--navy), #22335c);
  color: #fff; border-radius: 20px; padding: 32px 28px;
  display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center;
  box-shadow: var(--shadow);
}
.hero h1 { margin: 0 0 8px; font-size: clamp(1.6rem, 4vw, 2.3rem); line-height: 1.25; }
.hero p { margin: 0 0 18px; opacity: .9; max-width: 52ch; }
.hero .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.ring { --p: 0; width: 132px; height: 132px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), rgba(255,255,255,.15) 0);
  display: grid; place-items: center; }
.ring > div { width: 104px; height: 104px; border-radius: 50%; background: #1b2a4c; display: grid; place-items: center; text-align: center; line-height: 1.2; }
.ring strong { font-size: 1.7rem; display: block; }
.ring span { font-size: .8rem; opacity: .8; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; font-size: .98rem;
  padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; transition: transform .05s, background .15s;
  background: var(--accent); color: var(--accent-ink);
}
.btn:hover { background: var(--accent-strong); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; border-color: currentColor; color: inherit; }
.btn.ghost:hover { background: rgba(127,127,127,.1); }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--border); }
.btn.ok { background: var(--ok); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Section headings ── */
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 36px 0 14px; flex-wrap: wrap; }
.section-title h2 { margin: 0; font-size: 1.4rem; }

/* ── Cards / grid ── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); text-decoration: none; display: block;
}
a.card:hover { border-color: var(--accent); }
.card h3 { margin: 6px 0 4px; font-size: 1.12rem; line-height: 1.35; }
.card p { margin: 0 0 12px; color: var(--muted); font-size: .94rem; }
.card .icon { font-size: 1.6rem; }
.card .meta { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-top: 6px; }
.num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); font-size: .82rem; font-weight: 700; margin-left: 6px; }

.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar.ok > i { background: var(--ok); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat strong { font-size: 1.5rem; display: block; line-height: 1.2; }
.stat span { color: var(--muted); font-size: .88rem; }

/* ── Breadcrumbs ── */
.crumbs { font-size: .9rem; color: var(--muted); margin-bottom: 10px; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

/* ── Module page ── */
.page-head h1 { margin: 0 0 6px; font-size: clamp(1.5rem, 3.6vw, 2rem); line-height: 1.3; }
.page-head p { margin: 0; color: var(--muted); }
.lesson-list { list-style: none; padding: 0; margin: 20px 0; display: grid; gap: 10px; }
.lesson-list a {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); text-decoration: none;
}
.lesson-list a:hover { border-color: var(--accent); }
.lesson-list .t { flex: 1; font-weight: 500; }
.lesson-list .m { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; font-size: .8rem; flex-shrink: 0; }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.quiz-cta { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: var(--accent-soft); border: 1px solid var(--warn-border); border-radius: var(--radius); padding: 18px; }
.quiz-cta h3 { margin: 0; }
.quiz-cta p { margin: 2px 0 0; color: var(--muted); font-size: .92rem; }

/* ── Lesson ── */
.lesson { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 26px; box-shadow: var(--shadow); }
.lesson h3 { margin: 26px 0 8px; font-size: 1.18rem; }
.lesson p, .lesson li { max-width: 72ch; }
.lesson ul, .lesson ol { padding-inline-start: 22px; }
.lesson li { margin: 4px 0; }
.videos { display: grid; gap: 14px; margin: 18px 0 8px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.video { border-radius: 12px; overflow: hidden; background: #000; position: relative; }
.video .ratio { position: relative; padding-top: 56.25%; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-cap { display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: .88rem; color: var(--muted); padding: 6px 2px 0; flex-wrap: wrap; }
.video-cap a { color: var(--muted); }
.no-video { background: var(--surface-2); border: 1px dashed var(--border); border-radius: 12px; padding: 16px; color: var(--muted); }

.formula {
  direction: ltr; text-align: center; font-family: "SF Mono", Menlo, Consolas, monospace;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin: 12px 0; font-size: 1.05rem; font-weight: 600; overflow-x: auto;
}
.example { background: var(--ok-soft); border-inline-start: 4px solid var(--ok); border-radius: 8px; padding: 12px 14px; margin: 12px 0; }
.note { background: var(--warn-soft); border: 1px solid var(--warn-border); border-radius: 10px; padding: 12px 14px; margin: 14px 0; font-size: .95rem; }
.tbl { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: .95rem; display: block; overflow-x: auto; }
.tbl th, .tbl td { border: 1px solid var(--border); padding: 8px 10px; text-align: right; vertical-align: top; }
.tbl th { background: var(--surface-2); font-weight: 700; }
.tbl tr.hl td { background: var(--accent-soft); }
.wire { display: inline-block; width: 26px; height: 10px; border-radius: 5px; vertical-align: middle; margin-left: 6px; border: 1px solid rgba(127,127,127,.4); }
.wire-pe { background: repeating-linear-gradient(90deg, #1f9d3a 0 6px, #f2d200 6px 12px); }

.keypoints { background: var(--accent-soft); border: 1px solid var(--warn-border); border-radius: 14px; padding: 16px 18px; margin-top: 26px; }
.keypoints h3 { margin: 0 0 8px !important; }
.keypoints ul { margin: 0; }
.lesson-actions { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.lesson-actions .nav-btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Quiz ── */
.quiz { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 24px; box-shadow: var(--shadow); }
.quiz-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; color: var(--muted); font-size: .92rem; flex-wrap: wrap; }
.quiz .q { font-size: 1.15rem; font-weight: 700; margin: 6px 0 16px; line-height: 1.5; }
.opts { display: grid; gap: 10px; }
.opt {
  text-align: right; font: inherit; padding: 12px 14px; border-radius: 12px; cursor: pointer;
  background: var(--surface); color: var(--text); border: 2px solid var(--border); display: flex; gap: 10px; align-items: flex-start;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt .letter { font-weight: 800; color: var(--muted); min-width: 1.2em; }
.opt.sel { border-color: var(--navy); background: var(--surface-2); }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt:disabled { cursor: default; }
.feedback { margin-top: 14px; padding: 12px 14px; border-radius: 10px; }
.feedback.ok { background: var(--ok-soft); }
.feedback.bad { background: var(--bad-soft); }
.quiz-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

.result { text-align: center; padding: 10px 0; }
.result .score { font-size: 3rem; font-weight: 800; line-height: 1.1; }
.result .score.pass { color: var(--ok); }
.result .score.fail { color: var(--bad); }

.timer { font-variant-numeric: tabular-nums; font-weight: 800; background: var(--surface-2); padding: 4px 12px; border-radius: 999px; color: var(--text); }
.timer.low { background: var(--bad-soft); color: var(--bad); }
.qnav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.qnav button { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: .85rem; cursor: pointer; }
.qnav button.ans { background: var(--accent-soft); border-color: var(--warn-border); }
.qnav button.cur { outline: 2px solid var(--navy); }
.qnav button.r-ok { background: var(--ok-soft); border-color: var(--ok); }
.qnav button.r-bad { background: var(--bad-soft); border-color: var(--bad); }

.review { display: grid; gap: 12px; margin-top: 20px; text-align: right; }
.review .item { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--surface); }
.review .item.bad { border-inline-start: 4px solid var(--bad); }
.review .item.ok { border-inline-start: 4px solid var(--ok); }
.review .item p { margin: 4px 0; }

/* ── Formulas page ── */
.f-group { margin-bottom: 18px; }
.f-group h2 { font-size: 1.2rem; margin: 0 0 10px; }
.f-row { display: grid; grid-template-columns: minmax(140px, 1fr) 2fr; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.f-row:last-child { border-bottom: 0; }
.f-row .formula { margin: 0; text-align: left; }

.footer { border-top: 1px solid var(--border); padding: 22px 0; font-size: .88rem; color: var(--muted); }
.footer p { margin: 4px 0; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .hero { grid-template-columns: 1fr; padding: 24px 20px; }
  .ring { justify-self: start; }
  .lesson, .quiz { padding: 18px; }
  .f-row { grid-template-columns: 1fr; gap: 4px; }
  .topbar-inner { padding: 8px 0; }
  .nav a { padding: 4px 10px; font-size: .9rem; }
}
