:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #1b2433;
  --muted: #5d6b80;
  --border: #dbe2ec;
  --accent: #2a6fdb;
  --accent-soft: #e3edfc;
  --ok: #1f8a4c;
  --ok-soft: #e1f4e8;
  --bad: #c43b3b;
  --bad-soft: #fbe5e5;
  --warn: #b7791f;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .05);
  --radius: 12px;
  --sidebar-w: 290px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141c; --surface: #171e29; --surface-2: #1e2734; --text: #e4e9f1; --muted: #93a1b5;
    --border: #2a3545; --accent: #6aa2ff; --accent-soft: #1d2d48; --ok: #4cc27f; --ok-soft: #173325;
    --bad: #f07070; --bad-soft: #3a1e22; --warn: #e3b05a; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141c; --surface: #171e29; --surface-2: #1e2734; --text: #e4e9f1; --muted: #93a1b5;
  --border: #2a3545; --accent: #6aa2ff; --accent-soft: #1d2d48; --ok: #4cc27f; --ok-soft: #173325;
  --bad: #f07070; --bad-soft: #3a1e22; --warn: #e3b05a; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; text-wrap: balance; }
.muted { color: var(--muted); }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; height: 56px;
  display: flex; align-items: center; gap: 8px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo { width: 40px; height: 16px; fill: var(--accent); }
.spacer { flex: 1; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  width: 36px; height: 36px; border-radius: 8px; font-size: 18px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
#menuBtn { display: none; }

/* layout */
.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar {
  width: var(--sidebar-w); flex: none; border-right: 1px solid var(--border);
  background: var(--surface); padding: 16px 10px 40px;
  position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto;
}
.main { flex: 1; min-width: 0; padding: 28px 40px 80px; max-width: 980px; }

.side-chapter { margin-bottom: 18px; }
.side-chapter > a {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px;
  font-weight: 700; color: var(--text);
}
.side-topics { list-style: none; margin: 4px 0 0; padding: 0; }
.side-topics a {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 14px; border-radius: 8px;
  color: var(--text); font-size: .93rem; line-height: 1.35;
}
.side-topics a:hover, .side-chapter > a:hover { background: var(--surface-2); text-decoration: none; }
.side-topics a.active, .side-chapter > a.active { background: var(--accent-soft); color: var(--accent); }
.side-topics .num { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 1.6em; font-size: .85em; }
.side-topics .title { flex: 1; }
.badge { font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.mid { background: #fff3dc; color: var(--warn); }
:root[data-theme="dark"] .badge.mid { background: #3a2f17; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.mid { background: #3a2f17; } }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px;
}
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.topic-card { display: flex; flex-direction: column; gap: 8px; color: var(--text); }
.topic-card:hover { border-color: var(--accent); text-decoration: none; }
.topic-card h3 { margin: 0; font-size: 1.05rem; }
.topic-card p { margin: 0; color: var(--muted); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.topic-card .foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; font-size: .85rem; color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 700; color: var(--accent); }
.hero h1 { margin: 4px 0 8px; font-size: 2rem; }
.hero p { margin: 0 0 20px; color: var(--muted); max-width: 70ch; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 28px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 8px 16px; border-radius: 8px;
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ok); }

/* topic page */
.crumbs { font-size: .88rem; color: var(--muted); margin-bottom: 6px; }
.topic-head h1 { margin: 0 0 16px; font-size: 1.8rem; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 24px; overflow-x: auto; }
.tabs a {
  padding: 10px 16px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent;
  margin-bottom: -1px; white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

.abstract { font-size: 1.12rem; line-height: 1.7; }
.abstract-box { border-left: 4px solid var(--accent); }
.next-steps { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); margin-top: 24px; }
.next-steps a { color: var(--text); }
.next-steps a:hover { border-color: var(--accent); text-decoration: none; }
.next-steps strong { display: block; }
.next-steps span { color: var(--muted); font-size: .9rem; }

.reading { max-width: 72ch; }
.reading p { margin: 0 0 1.05em; }
.reading h2 { font-size: 1.3rem; margin: 1.6em 0 .6em; }
.reading h2:first-child { margin-top: 0; }
.reading figure { margin: 1.4em 0 1.8em; }
.reading figure img {
  display: block; max-width: 100%; max-height: 520px; margin: 0 auto; border-radius: 8px;
  cursor: zoom-in; background: #fff;
}
.reading figcaption { text-align: center; color: var(--muted); font-size: .9rem; margin-top: 8px; }
a.figref { border-bottom: 1px dashed var(--accent); }
a.figref:hover { text-decoration: none; }

/* quiz */
.quiz-q { margin-bottom: 16px; }
.quiz-q h3 { margin: 0 0 12px; font-size: 1.02rem; font-weight: 600; display: flex; gap: 10px; }
.quiz-q h3 .qn { color: var(--muted); font-variant-numeric: tabular-nums; }
.opts { display: grid; gap: 8px; }
.opt {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--border); cursor: pointer; background: var(--surface);
}
.opt:hover { background: var(--surface-2); }
.opt input { margin-top: 5px; accent-color: var(--accent); }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.checked .opt { cursor: default; }
.explain { margin-top: 10px; font-size: .92rem; color: var(--muted); }
.explain b.ok { color: var(--ok); } .explain b.bad { color: var(--bad); }
.quiz-bar {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 0; background: linear-gradient(transparent, var(--bg) 30%);
}
.score { font-size: 1.15rem; font-weight: 700; }
.score.ok { color: var(--ok); } .score.bad { color: var(--bad); }

/* cheatsheet */
.cs-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.cs { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--border); }
.cs th, .cs td { text-align: left; vertical-align: top; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.cs tr:last-child td { border-bottom: 0; }
.cs td.k { font-weight: 600; width: 34%; }
.cs-title { margin: 28px 0 10px; font-size: 1.15rem; }
.selfcheck .cs td.v { cursor: pointer; }
.selfcheck .cs td.v:not(.shown) { color: transparent; background: var(--surface-2); user-select: none; position: relative; }
.selfcheck .cs td.v:not(.shown)::after { content: "tap to reveal"; color: var(--muted); position: absolute; left: 14px; top: 10px; font-size: .85rem; font-style: italic; }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; }
.pager a { max-width: 48%; }
.pager .lbl { display: block; font-size: .78rem; color: var(--muted); }

/* lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(5, 10, 18, .88);
  display: flex; align-items: center; justify-content: center; padding: 20px; cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox figure { margin: 0; max-width: 100%; max-height: 100%; text-align: center; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 100px); border-radius: 8px; background: #fff; }
.lightbox figcaption { color: #dfe6f0; margin-top: 10px; font-size: .95rem; }

/* responsive */
@media (max-width: 860px) {
  #menuBtn { display: inline-block; }
  .sidebar {
    position: fixed; left: 0; top: 56px; z-index: 30; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: var(--shadow); width: min(85vw, 320px);
  }
  body.menu-open .sidebar { transform: none; }
  .main { padding: 20px 16px 80px; }
  .hero h1 { font-size: 1.6rem; }
  .topic-head h1 { font-size: 1.45rem; }
  .cs td.k { width: 40%; }
  .cs th, .cs td { padding: 8px 10px; }
}

@media print {
  .topbar, .sidebar, .tabs, .cs-toolbar, .pager, .crumbs, .quiz-bar { display: none !important; }
  .main { padding: 0; max-width: none; }
  body { background: #fff; color: #000; }
  .cs { box-shadow: none; }
  .cs tr { break-inside: avoid; }
}

/* ---- sections, exam, practice (v2) ---- */
.small { font-size: .85rem; }
.grid.three { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.section-card h3 { font-size: 1.25rem; }
.side-section {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; margin-top: 2px; border-radius: 8px;
  color: var(--text); font-weight: 600; font-size: .95rem;
}
.side-section:hover { background: var(--surface-2); text-decoration: none; }
.side-section.active { background: var(--accent-soft); color: var(--accent); }
.side-section .badge, .side-section .small { margin-left: auto; }
.side-topics.collapsed { display: none; }
.side-topics a { padding-left: 22px; }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

.src-divider {
  display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; margin: 2.2em 0 1.2em; padding: 10px 14px;
  border-radius: 8px; background: var(--surface-2); font-size: .88rem;
}
.reading .src-divider:first-child { margin-top: 0; }
.src-divider span { text-transform: uppercase; letter-spacing: .08em; font-weight: 700; font-size: .72rem; color: var(--muted); }
.list-box { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin: 0 0 1.1em; }
.list-box ul { margin: 6px 0 0; padding-left: 20px; }

.exam-intro .facts { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.exam-intro .facts li { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; }
.exam-intro .facts b { display: block; font-size: 1.5rem; color: var(--accent); }
.exam-intro .facts span { color: var(--muted); font-size: .9rem; }
.btn.big { font-size: 1.05rem; padding: 12px 26px; }
.timer-bar {
  position: sticky; top: 56px; z-index: 10; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 14px; margin: 0 0 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.timer { font: 700 1.4rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums; min-width: 4.2ch; }
.timer-progress { flex: 1; min-width: 80px; }
.timer-progress span { background: var(--accent); transition: width .5s linear; }
.timer-bar.low .timer { color: var(--bad); }
.timer-bar.low .timer-progress span { background: var(--bad); }
.qnav { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; }
.qnav a {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; font-size: .85rem; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
}
.qnav a.done { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.qnav a:hover { text-decoration: none; border-color: var(--accent); }
.result { display: flex; align-items: center; gap: 20px; margin-bottom: 16px; border-left: 6px solid var(--muted); }
.result.pass { border-left-color: var(--ok); } .result.fail { border-left-color: var(--bad); } .result.meh { border-left-color: var(--warn); }
.big-score { font-size: 2.6rem; font-weight: 800; }
.result.pass .big-score { color: var(--ok); } .result.fail .big-score { color: var(--bad); }
.weak { margin: 8px 0 0; padding-left: 20px; }
.card + .card, .card + .actions { margin-top: 14px; }

.case p { font-size: 1.04rem; }
.cs.data { margin: 4px 0 8px; }
.case-opts { display: grid; gap: 10px; }
.case-opt { padding: 14px 16px; }
.case-opt .opt-text { display: block; }
.case-opt.chosen { border-color: var(--accent); }
.case-opt.v-ok { border-color: var(--ok); background: var(--ok-soft); }
.case-opt.v-mid { border-color: var(--warn); }
.case-opt.v-bad { border-color: var(--bad); }
.case-opt.v-bad.chosen { background: var(--bad-soft); }
.verdict { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.verdict p { margin: 6px 0 0; font-size: .93rem; color: var(--text); }
.debrief ul { margin: 8px 0 10px; padding-left: 20px; }
.debrief li { margin-bottom: 4px; }

/* ---- tables & decoders (METAR/TAF) ---- */
.table-box { margin: 0 0 1.2em; }
.table-box > strong, .decode > strong { display: block; margin-bottom: 8px; }
.table-scroll { overflow-x: auto; border-radius: var(--radius); }
.table-box .cs th { background: var(--surface-2); font-size: .85rem; }
.cs td.code, .decode td.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; white-space: nowrap; }
.decode {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin: 0 0 1.4em; box-shadow: var(--shadow);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: 600 .95rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 6px 9px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.decode-out { margin-top: 12px; min-height: 2.6em; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); }
.decode-out code { font-weight: 700; }
.decode details { margin-top: 10px; }
.decode summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: .92rem; }
.decode details .cs { margin-top: 8px; box-shadow: none; }
