:root {
  --bg: #0e1116; --panel: #161b22; --panel2: #1b2230; --border: #232a33;
  --text: #e6edf3; --muted: #8b949e; --accent: #3fb950; --accent2: #58a6ff;
  --gradeA: #3fb950; --gradeB: #58a6ff; --gradeC: #8b949e; --gradeD: #d29922;
  --radius: 10px; --maxw: 880px; --sidew: 300px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
[data-theme="light"] {
  --bg: #ffffff; --panel: #f6f8fa; --panel2: #eef1f4; --border: #d8dee4;
  --text: #1f2328; --muted: #636c76; --accent: #1a7f37; --accent2: #0969da;
  --gradeC: #6e7781;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--sans); line-height: 1.6; font-size: 16px; }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 17px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: #06210f; font-weight: 800; font-size: 13px; }
.search-wrap { position: relative; flex: 1; max-width: 460px; }
#search { width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; }
#search:focus { outline: none; border-color: var(--accent2); }
.search-results { position: absolute; top: 110%; left: 0; right: 0; max-height: 60vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 12px 32px rgba(0,0,0,.4); z-index: 50; }
.search-results .sr { display: block; padding: 9px 12px; border-bottom: 1px solid var(--border); color: var(--text); }
.search-results .sr:hover { background: var(--panel2); text-decoration: none; }
.search-results .sr small { color: var(--muted); }
.top-links { display: flex; gap: 14px; margin-left: auto; }
.top-links a { color: var(--muted); font-size: 14px; font-weight: 500; }
.top-links a:hover { color: var(--text); text-decoration: none; }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--text); width: 36px; height: 34px;
  border-radius: 8px; cursor: pointer; font-size: 16px; }
.icon-btn:hover { background: var(--panel2); }
#menuBtn { display: none; }

/* Layout */
.layout { display: grid; grid-template-columns: var(--sidew) 1fr; align-items: start; }
.sidebar { position: sticky; top: 55px; height: calc(100vh - 55px); overflow-y: auto;
  border-right: 1px solid var(--border); padding: 14px 8px 40px; background: var(--bg); }
.nav-loading { color: var(--muted); padding: 12px; }
.nav .sec { margin-bottom: 2px; }
.nav .sec > .sec-h { display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
  background: none; border: 0; color: var(--text); font-weight: 600; font-size: 13.5px; padding: 7px 10px;
  border-radius: 7px; cursor: pointer; }
.nav .sec > .sec-h:hover { background: var(--panel2); }
.nav .sec-h .ord { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.nav .sec-items { display: none; padding: 2px 0 6px 14px; }
.nav .sec.open .sec-items { display: block; }
.nav .sec-items a { display: block; padding: 5px 10px; border-radius: 6px; color: var(--muted); font-size: 13.5px; }
.nav .sec-items a:hover { background: var(--panel2); color: var(--text); text-decoration: none; }
.nav .sec-items a.active { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--text); font-weight: 600; }
.nav .nav-top { display: block; padding: 7px 10px; border-radius: 7px; color: var(--text); font-weight: 600; font-size: 13.5px; }
.nav .nav-top:hover { background: var(--panel2); text-decoration: none; }
.nav hr { border: 0; border-top: 1px solid var(--border); margin: 10px 6px; }

/* Main */
.main { padding: 28px 32px 80px; min-width: 0; }
.loading { color: var(--muted); padding: 40px 0; }
.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.crumbs a { color: var(--muted); }
.page-head { max-width: var(--maxw); margin-bottom: 18px; }
.page-head h1 { font-size: 30px; line-height: 1.2; margin: 0 0 8px; }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }

/* Pills & badges */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--border); background: var(--panel); color: var(--muted); }
.pill.type { color: var(--accent2); border-color: color-mix(in srgb, var(--accent2) 35%, var(--border)); }
.pill.diff-beginner { color: var(--gradeA); }
.pill.diff-intermediate { color: var(--gradeB); }
.pill.diff-advanced { color: var(--gradeD); }
.tag { font-size: 11.5px; padding: 1px 8px; border-radius: 6px; background: var(--panel2); color: var(--muted); }
.ev { font-family: var(--mono); font-size: 12px; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border); white-space: normal; }
.ev-A { background: color-mix(in srgb, var(--gradeA) 16%, transparent); border-color: var(--gradeA); color: var(--gradeA); }
.ev-B { background: color-mix(in srgb, var(--gradeB) 16%, transparent); border-color: var(--gradeB); color: var(--gradeB); }
.ev-C { background: color-mix(in srgb, var(--gradeC) 16%, transparent); border-color: var(--gradeC); color: var(--text); }
.ev-D { background: color-mix(in srgb, var(--gradeD) 16%, transparent); border-color: var(--gradeD); color: var(--gradeD); }

/* Markdown article */
.md { max-width: var(--maxw); }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.25; margin: 1.6em 0 .5em; }
.md h1 { font-size: 28px; } .md h2 { font-size: 22px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 18px; } .md h4 { font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.md p, .md li { font-size: 15.5px; }
.md a { color: var(--accent2); }
.md ul, .md ol { padding-left: 22px; }
.md code { font-family: var(--mono); font-size: 13px; background: var(--panel2); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.5; }
.md blockquote { margin: 1em 0; padding: 6px 16px; border-left: 3px solid var(--accent); background: var(--panel); border-radius: 0 8px 8px 0; color: var(--text); }
.md table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; }
.md th { background: var(--panel2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.8em 0; }
.md .mermaid { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }

/* Home */
.hero { max-width: 920px; }
.hero h1 { font-size: 38px; line-height: 1.15; margin: 6px 0 10px; }
.hero p.lede { font-size: 18px; color: var(--muted); max-width: 720px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin: 26px 0; max-width: 920px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 800; color: var(--accent); }
.stat .l { font-size: 12.5px; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; max-width: 1100px; }
.card { display: block; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 16px; color: var(--text); }
.card:hover { border-color: var(--accent2); text-decoration: none; transform: translateY(-1px); transition: .12s; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card p { margin: 0; font-size: 13.5px; color: var(--muted); }
.card .card-meta { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.section-title { max-width: 1100px; margin: 6px 0 14px; }
.section-title h1 { font-size: 26px; margin: 0 0 4px; }
.section-title p { color: var(--muted); margin: 0; }

/* Filter bar */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 18px; max-width: 1100px; }
.filters select, .filters input { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13.5px; }

/* Data table (strategies/sources) */
.dtable { width: 100%; border-collapse: collapse; font-size: 13.5px; max-width: 1200px; display: block; overflow-x: auto; }
.dtable th, .dtable td { border-bottom: 1px solid var(--border); padding: 8px 11px; text-align: left; white-space: nowrap; }
.dtable th { position: sticky; top: 55px; background: var(--panel); cursor: pointer; }
.dtable tr:hover td { background: var(--panel); }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30; }

footer.pagefoot { max-width: var(--maxw); margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px; }

/* Responsive */
@media (max-width: 860px) {
  .top-links { display: none; }
  #menuBtn { display: block; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 55px; width: 84vw; max-width: 320px; z-index: 35;
    transform: translateX(-105%); transition: transform .2s; box-shadow: 4px 0 24px rgba(0,0,0,.4); }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 20px 18px 70px; }
}

/* --- production a11y + risk gate --- */
.visually-hidden{position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
.skip-link{position:absolute;left:8px;top:-48px;z-index:100;background:var(--accent,#3fd07a);color:#06210f;padding:8px 14px;border-radius:8px;text-decoration:none;font-weight:700;transition:top .15s}
.skip-link:focus{top:8px}
a:focus-visible,button:focus-visible,input:focus-visible,.choice:focus-visible,.mod-card:focus-visible,.lesson-row:focus-visible,.sec-h:focus-visible{outline:3px solid var(--accent2,#6aa7ff);outline-offset:2px;border-radius:4px}
@media (prefers-reduced-motion: reduce){*{animation:none!important;transition:none!important;scroll-behavior:auto!important}}
#riskGate{position:fixed;inset:0;z-index:1000;background:rgba(0,0,0,.72);display:grid;place-items:center;padding:20px}
#riskGate .rg-box{background:var(--panel,#181d2e);border:1px solid var(--border,#2a3147);border-radius:16px;max-width:520px;padding:24px;font-family:inherit}
#riskGate h2{margin:0 0 10px;font-size:20px;color:var(--text,#eef1f7)}
#riskGate p{color:var(--muted,#9aa3bd);font-size:15px;line-height:1.55}
#riskGate .rg-warn{color:#f5b945;font-weight:700}
#riskGate b{color:var(--text,#eef1f7)}
#riskGate a{color:var(--accent2,#6aa7ff)}
#riskGate button{margin-top:16px;background:var(--accent,#3fd07a);color:#06210f;border:none;border-radius:999px;padding:13px 22px;font-weight:700;font-size:15px;cursor:pointer;width:100%}
.app-footer{margin-top:auto;padding:18px;text-align:center;color:var(--muted,#9aa3bd);font-size:12.5px;border-top:1px solid var(--border,#2a3147)}
.app-footer a{color:var(--muted,#9aa3bd)}