/* ──────────── TOKENS (light default, dark via data-theme or OS) ──────────── */
:root {
  --bg: #f5f7f8; --bg2: #ffffff; --bg3: #eef3f3; --bg4: #dfe8e8;
  --text: #14202b; --text2: #4a5866; --text3: #7a8792;
  --navy: #14304f; --accent: #1f7a7a; --accent-ink: #ffffff; --accent-soft: #e6f2f2;
  --green: #1b8a4b; --green-soft: #e3f4ea; --red: #c23b3b; --red-soft: #fbe9e9;
  --amber: #b26b00; --amber-soft: #fff3df; --blue: #2a78d6; --blue-soft: #e7f0fb;
  --border: #d8e0e3; --card: #ffffff;
  --r: 8px; --r2: 12px; --shadow: 0 1px 2px rgba(20, 48, 79, .06), 0 4px 16px rgba(20, 48, 79, .06);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1418; --bg2: #161d22; --bg3: #1d262d; --bg4: #27323a;
    --text: #e8edf0; --text2: #a9b5bd; --text3: #75838c;
    --navy: #cfe0f0; --accent: #3fa9a9; --accent-ink: #06191a; --accent-soft: #15302f;
    --green: #4cc27f; --green-soft: #143222; --red: #ef7070; --red-soft: #3a1b1b;
    --amber: #f0ad3c; --amber-soft: #3a2a10; --blue: #6aa8f0; --blue-soft: #162a42;
    --border: #2a353d; --card: #161d22; --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1418; --bg2: #161d22; --bg3: #1d262d; --bg4: #27323a;
  --text: #e8edf0; --text2: #a9b5bd; --text3: #75838c;
  --navy: #cfe0f0; --accent: #3fa9a9; --accent-ink: #06191a; --accent-soft: #15302f;
  --green: #4cc27f; --green-soft: #143222; --red: #ef7070; --red-soft: #3a1b1b;
  --amber: #f0ad3c; --amber-soft: #3a2a10; --blue: #6aa8f0; --blue-soft: #162a42;
  --border: #2a353d; --card: #161d22; --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

/* ──────────── BASE ──────────── */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.5; min-height: 100vh; }
a { color: var(--accent); }
h1, h2, h3, h4 { color: var(--navy); font-weight: 600; line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.1rem; } h4 { font-size: 1rem; }
p { margin: 0 0 .75em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--text2); } .small { font-size: .87rem; } .tiny { font-size: .78rem; color: var(--text3); }
.mono { font-family: var(--mono); font-size: .85em; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 1rem; }
.hidden { display: none !important; }

/* ──────────── TOP BAR ──────────── */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--navy); color: #fff; }
:root[data-theme="dark"] .topbar { background: #0b1e33; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .topbar { background: #0b1e33; } }
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: .6rem 16px; display: flex; align-items: center; gap: 1rem; }
.brand { color: #fff; text-decoration: none; font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
.brand span { color: #8fd3d3; font-weight: 400; }
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav a { color: #d6e2ec; text-decoration: none; padding: .35rem .65rem; border-radius: 6px; white-space: nowrap; font-size: .93rem; }
.nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav a.active { background: rgba(255, 255, 255, .14); color: #fff; }
.topbar .icon-btn { background: none; border: 1px solid rgba(255, 255, 255, .25); color: #fff; border-radius: 6px; padding: .3rem .55rem; cursor: pointer; }
.user-menu { position: relative; }
.user-menu .menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow); min-width: 180px; padding: .35rem; }
.user-menu .menu a, .user-menu .menu button { display: block; width: 100%; text-align: left; padding: .45rem .6rem; border-radius: 6px;
  color: var(--text); text-decoration: none; background: none; border: 0; cursor: pointer; }
.user-menu .menu a:hover, .user-menu .menu button:hover { background: var(--bg3); }

/* ──────────── LAYOUT ──────────── */
.view { max-width: 1120px; margin: 0 auto; padding: 1.5rem 16px 4rem; outline: none; }
.narrow { max-width: 760px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r2); padding: 1.25rem; box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }
.grid > .card { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.kicker { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; color: var(--accent); font-weight: 600; margin-bottom: .2rem; }
.crumbs { font-size: .87rem; margin-bottom: .75rem; } .crumbs a { text-decoration: none; }

/* ──────────── CONTROLS ──────────── */
.btn { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--border); background: var(--bg2); color: var(--text);
  padding: .5rem .95rem; border-radius: var(--r); cursor: pointer; text-decoration: none; font-weight: 500; line-height: 1.2; }
.btn:hover { background: var(--bg3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--red); border-color: var(--red); background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: .3rem .6rem; font-size: .87rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
label.field { display: block; margin-bottom: .9rem; }
label.field > span { display: block; font-size: .85rem; font-weight: 600; color: var(--text2); margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: var(--r); background: var(--bg2); }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.inline-input { width: auto; }

/* ──────────── CHIPS, BARS, TABLES ──────────── */
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--bg3); color: var(--text2); white-space: nowrap; }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.blue { background: var(--blue-soft); color: var(--blue); }
.chip.teal { background: var(--accent-soft); color: var(--accent); }
.bar { height: 8px; background: var(--bg4); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar.green > i { background: var(--green); } .bar.amber > i { background: var(--amber); } .bar.red > i { background: var(--red); }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text3); font-weight: 600;
  padding: .55rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tr.clickable { cursor: pointer; } table.data tr.clickable:hover td { background: var(--bg3); }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; color: var(--text2); padding: 2.5rem 1rem; }
.stat { font-size: 1.8rem; font-weight: 600; color: var(--navy); line-height: 1.1; }
.stat-label { font-size: .8rem; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; }

/* ──────────── DASHBOARD ──────────── */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 1.5rem; align-items: center; }
.ring { --p: 0; width: 112px; height: 112px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--bg4) 0); }
.ring > div { width: 88px; height: 88px; border-radius: 50%; background: var(--card); display: grid; place-items: center; text-align: center; }
.ring b { font-size: 1.5rem; color: var(--navy); display: block; line-height: 1; } .ring small { font-size: .72rem; color: var(--text2); }
.module h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); margin: 1.75rem 0 .75rem; }
.ch-card { display: flex; flex-direction: column; gap: .6rem; text-decoration: none; color: var(--text); position: relative; }
a.ch-card:hover { border-color: var(--accent); }
.ch-card .num { font-size: .78rem; color: var(--text3); font-weight: 600; }
.ch-card h3 { font-size: 1.02rem; margin: 0; }
.ch-card.locked { opacity: .6; }
.ch-card .foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; font-size: .85rem; color: var(--text2); }
.banner { border-radius: var(--r2); padding: 1rem 1.25rem; border: 1px solid; display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.banner.amber { background: var(--amber-soft); border-color: var(--amber); }
.banner.green { background: var(--green-soft); border-color: var(--green); }
.banner.red { background: var(--red-soft); border-color: var(--red); }
.banner.teal { background: var(--accent-soft); border-color: var(--accent); }

/* ──────────── LESSON ──────────── */
.lesson { display: grid; grid-template-columns: 220px 1fr; gap: 2rem; align-items: start; }
.toc { position: sticky; top: 72px; font-size: .9rem; }
.toc a { display: flex; gap: .4rem; align-items: baseline; padding: .3rem .5rem; border-radius: 6px; color: var(--text2); text-decoration: none; }
.toc a:hover { background: var(--bg3); color: var(--text); }
.toc a .dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--text3); flex: none; transform: translateY(-1px); }
.toc a.read .dot { background: var(--green); border-color: var(--green); }
.prose { font-size: 1.02rem; max-width: 760px; }
.prose ul { padding-left: 1.2rem; margin: 0 0 1rem; } .prose li { margin: .25rem 0; } .prose li ul { margin: .25rem 0; }
.prose li ul li { list-style: '– '; color: var(--text2); }
.prose section { scroll-margin-top: 80px; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); margin-bottom: 1.75rem; }
.prose section:last-of-type { border-bottom: 0; }
.prose h2.sec { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; }
.why { background: var(--accent-soft); border-left: 4px solid var(--accent); border-radius: var(--r); padding: .9rem 1.1rem; margin: 1rem 0 1.5rem; }
.why b { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); margin-bottom: .2rem; }
.callout { background: var(--bg3); border-radius: var(--r); padding: .9rem 1.1rem; margin: 1rem 0; }
.callout.accent { border-left: 4px solid var(--accent); background: var(--accent-soft); }
.callout b { display: block; margin-bottom: .25rem; color: var(--navy); }
.callout p { margin: 0 0 .6em; } .callout p:last-child { margin-bottom: 0; }
.callout.example { background: var(--blue-soft); border-left: 4px solid var(--blue); }
.callout.say { background: var(--amber-soft); border-left: 4px solid var(--amber); }
.callout-label { display: block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); margin-bottom: .15rem; }
.callout.example .callout-label { color: var(--blue); } .callout.say .callout-label { color: var(--amber); }
.prose > section > p, .prose section > p { line-height: 1.65; }
.placeholder { border: 1.5px dashed var(--text3); border-radius: var(--r); padding: 1.25rem; text-align: center; color: var(--text2); margin: 1rem 0; background: var(--bg3); }
figure { margin: 1.25rem 0; } figure img { max-width: 100%; border: 1px solid var(--border); border-radius: var(--r); background: #fff; }
figcaption { font-size: .85rem; color: var(--text2); margin-top: .4rem; }
.fig-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.prose table.data { margin: .5rem 0 1.25rem; font-size: .88rem; }
.prose .table-title { font-weight: 600; color: var(--navy); margin-top: 1rem; }
.terms { display: flex; flex-wrap: wrap; gap: .35rem; }
.terms span { background: var(--bg3); border-radius: 6px; padding: .15rem .5rem; font-size: .85rem; }
.objectives li::marker { color: var(--accent); }

/* ──────────── QUIZ ──────────── */
.quiz { display: grid; grid-template-columns: 1fr 230px; gap: 1.5rem; align-items: start; }
.qnav { position: sticky; top: 72px; }
.qnav .dots { display: grid; grid-template-columns: repeat(6, 1fr); gap: .35rem; margin: .75rem 0 1rem; }
.qnav .dots a { display: grid; place-items: center; height: 30px; border-radius: 6px; background: var(--bg3); color: var(--text2); text-decoration: none; font-size: .8rem; font-weight: 600; }
.qnav .dots a.answered { background: var(--accent-soft); color: var(--accent); }
.qnav .dots a.right { background: var(--green-soft); color: var(--green); }
.qnav .dots a.wrong { background: var(--red-soft); color: var(--red); }
.qnav .dots a.partial, .qnav .dots a.pending { background: var(--amber-soft); color: var(--amber); }
.question { scroll-margin-top: 80px; }
.question .qhead { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; }
.question .prompt { font-size: 1.05rem; font-weight: 500; margin-bottom: .9rem; white-space: pre-line; }
.opt { display: flex; gap: .7rem; align-items: flex-start; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: var(--r); margin-bottom: .45rem; cursor: pointer; background: var(--bg2); }
.opt:hover { border-color: var(--accent); }
.opt input { margin-top: .25rem; accent-color: var(--accent); }
.opt.picked { border-color: var(--accent); background: var(--accent-soft); }
.opt.correct { border-color: var(--green); background: var(--green-soft); }
.opt.incorrect { border-color: var(--red); background: var(--red-soft); }
.pairs { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .45rem .8rem; align-items: center; }
.pairs .item { padding: .45rem .6rem; background: var(--bg3); border-radius: 6px; }
.explain { margin-top: .9rem; padding: .75rem .9rem; border-radius: var(--r); background: var(--bg3); font-size: .93rem; }
.explain b { color: var(--navy); }
.result { text-align: center; padding: 2rem 1rem; }
.result .score { font-size: 3rem; font-weight: 700; line-height: 1; }
.result.pass .score { color: var(--green); } .result.fail .score { color: var(--red); } .result.pending .score { color: var(--amber); }

/* ──────────── MISC ──────────── */
.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast { background: var(--navy); color: #fff; padding: .7rem 1rem; border-radius: var(--r); box-shadow: var(--shadow); max-width: 360px; font-size: .93rem; }
:root[data-theme="dark"] .toast { background: #263544; }
.toast.error { background: var(--red); color: #fff; }
.modal-back { position: fixed; inset: 0; background: rgba(10, 20, 30, .45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: var(--card); border-radius: var(--r2); max-width: 720px; width: 100%; max-height: 90vh; overflow: auto; padding: 1.5rem; box-shadow: var(--shadow); }
.auth-wrap { min-height: calc(100vh - 160px); display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 400px; }
.cert { max-width: 880px; margin: 0 auto; background: #fff; color: #14304f; border: 10px double #1f7a7a; padding: 3rem; text-align: center; }
.cert h1 { color: #14304f; font-size: 2.1rem; font-weight: 400; } .cert .name { font-size: 2.2rem; margin: 1rem 0; border-bottom: 1px solid #c8d6d6; display: inline-block; padding: 0 2rem .3rem; }
.cert .meta { display: flex; justify-content: center; gap: 2.5rem; margin-top: 2rem; color: #4a5866; font-size: .95rem; }
.skill-row { display: grid; grid-template-columns: 1fr 90px; gap: .75rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--bg4); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 3rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .lesson, .quiz { grid-template-columns: 1fr; }
  .toc, .qnav { position: static; }
  .hero { grid-template-columns: 1fr; }
  .fig-row, .pairs { grid-template-columns: 1fr; }
  .nav { display: none; }
  .nav.open { display: flex; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; background: var(--navy); padding: .5rem 16px 1rem; }
}
@media (min-width: 861px) { .nav-toggle { display: none; } }
@media print {
  .topbar, .no-print, .toasts { display: none !important; }
  body { background: #fff; } .view { padding: 0; }
}
