/* ============================================================
   SQLpedia — app shell, problem workspace, handbook reading layout
   One accent (blue), neutral surfaces, difficulty colours only on pills.
   ============================================================ */

:root{
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-read: Georgia, "Linux Libertine", "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, "Liberation Mono", monospace;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-3: #e9ecf1;
  --border: #e2e5ea;
  --border-strong: #c9ced6;
  --text: #16181d;
  --text-2: #4a5160;
  --muted: #6b7280;
  --accent: #2f5fd0;
  --accent-2: #2450b8;
  --accent-soft: #e8eefc;
  --on-accent: #ffffff;
  --easy: #12805c;   --easy-soft: #e3f5ee;
  --medium: #a15c07; --medium-soft: #fdf1df;
  --hard: #c0362c;   --hard-soft: #fde8e6;
  --ok: #12805c;  --ok-soft: #e3f5ee;
  --bad: #c0362c; --bad-soft: #fde8e6;
  --warn: #a15c07; --warn-soft: #fdf3e2;
  --null-bg: #f1eefc; --null-fg: #6b5fb0;
  --code-bg: #f6f8fa;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --shadow-pop: 0 8px 24px rgba(16,24,40,.12);
  --radius: 8px;
  --radius-sm: 6px;
  --top: 56px;

  --tok-kw:#9a1d8c; --tok-str:#0f6b38; --tok-com:#6b7280; --tok-num:#b04a00; --tok-fn:#2450b8;
  --hm-0:#eceff3; --hm-1:#c7d6f6; --hm-2:#8fadeb; --hm-3:#4f7fd9; --hm-4:#2450b8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#0e1014; --surface:#15181e; --surface-2:#1b1f27; --surface-3:#232833;
    --border:#272c36; --border-strong:#39404d; --text:#e7e9ee; --text-2:#b8bfcc; --muted:#8c94a3;
    --accent:#7aa2ff; --accent-2:#9db9ff; --accent-soft:#1c2740; --on-accent:#0b1020;
    --easy:#4fd1a1; --easy-soft:#123127; --medium:#f0b45a; --medium-soft:#33270f; --hard:#ff8a7a; --hard-soft:#3a1714;
    --ok:#4fd1a1; --ok-soft:#123127; --bad:#ff8a7a; --bad-soft:#3a1714; --warn:#f0b45a; --warn-soft:#33270f;
    --null-bg:#241f3a; --null-fg:#b3a8f0; --code-bg:#11141a;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-pop: 0 8px 24px rgba(0,0,0,.5);
    --tok-kw:#f2a0e6; --tok-str:#8fd9a8; --tok-com:#8c94a3; --tok-num:#ffb37a; --tok-fn:#9db9ff;
    --hm-0:#1f242d; --hm-1:#22406f; --hm-2:#2f5bb0; --hm-3:#4f7fd9; --hm-4:#9db9ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"]{
  --bg:#0e1014; --surface:#15181e; --surface-2:#1b1f27; --surface-3:#232833;
  --border:#272c36; --border-strong:#39404d; --text:#e7e9ee; --text-2:#b8bfcc; --muted:#8c94a3;
  --accent:#7aa2ff; --accent-2:#9db9ff; --accent-soft:#1c2740; --on-accent:#0b1020;
  --easy:#4fd1a1; --easy-soft:#123127; --medium:#f0b45a; --medium-soft:#33270f; --hard:#ff8a7a; --hard-soft:#3a1714;
  --ok:#4fd1a1; --ok-soft:#123127; --bad:#ff8a7a; --bad-soft:#3a1714; --warn:#f0b45a; --warn-soft:#33270f;
  --null-bg:#241f3a; --null-fg:#b3a8f0; --code-bg:#11141a;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-pop: 0 8px 24px rgba(0,0,0,.5);
  --tok-kw:#f2a0e6; --tok-str:#8fd9a8; --tok-com:#8c94a3; --tok-num:#ffb37a; --tok-fn:#9db9ff;
  --hm-0:#1f242d; --hm-1:#22406f; --hm-2:#2f5bb0; --hm-3:#4f7fd9; --hm-4:#9db9ff;
  color-scheme: dark;
}

*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0;background:var(--bg);color:var(--text);font:14px/1.55 var(--font)}
a{color:var(--accent);text-decoration:none}
a:hover{text-decoration:underline}
button{font:inherit;color:inherit}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:4px}
.visually-hidden{position:absolute!important;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.skip-link{position:absolute;left:-999px;top:8px;z-index:100;background:var(--surface);padding:6px 10px;border:1px solid var(--border)}
.skip-link:focus{left:8px}
code,kbd{font-family:var(--mono);font-size:.88em;background:var(--surface-2);border:1px solid var(--border);border-radius:4px;padding:.05em .35em}
kbd{font-size:.8em}
p{margin:.5em 0 .85em}
ul,ol{margin:.4em 0 .9em;padding-left:1.4em}
li{margin:.15em 0}
hr{border:0;border-top:1px solid var(--border);margin:1.5em 0}
h1,h2,h3,h4{line-height:1.3;margin:0}

/* ------------------------------------------------------------ top bar */
.topbar{
  position:sticky;top:0;z-index:50;height:var(--top);
  display:flex;align-items:center;gap:16px;padding:0 20px;
  background:color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter:saturate(1.4) blur(8px);
  border-bottom:1px solid var(--border);
}
.brand{display:flex;align-items:center;gap:9px;color:var(--text);font-weight:650;font-size:16px;letter-spacing:-.01em}
.brand:hover{text-decoration:none}
.brand svg{width:26px;height:26px;color:var(--accent)}
.brand .serif{font-family:var(--font-read);font-weight:400;font-size:19px}
.nav{display:flex;gap:2px}
.nav a{padding:7px 12px;border-radius:var(--radius-sm);color:var(--text-2);font-weight:500}
.nav a:hover{background:var(--surface-2);text-decoration:none;color:var(--text)}
.nav a[aria-current="page"]{color:var(--text);background:var(--surface-2)}
.topbar .spacer{flex:1}
.search{position:relative;width:min(340px,32vw)}
.search input{
  width:100%;height:34px;padding:0 64px 0 32px;border-radius:var(--radius-sm);
  border:1px solid var(--border);background:var(--surface-2);color:var(--text);font:inherit;outline:none;
}
.search input:focus{border-color:var(--accent);background:var(--surface);box-shadow:0 0 0 3px var(--accent-soft)}
.search svg{position:absolute;left:10px;top:9px;width:16px;height:16px;color:var(--muted);pointer-events:none}
.search kbd{position:absolute;right:8px;top:7px;color:var(--muted)}
.search-pop{
  position:absolute;top:40px;left:0;right:0;background:var(--surface);border:1px solid var(--border);
  border-radius:var(--radius);box-shadow:var(--shadow-pop);max-height:420px;overflow:auto;display:none;padding:4px;
}
.search-pop.open{display:block}
.search-pop a{display:flex;flex-direction:column;padding:8px 10px;border-radius:var(--radius-sm);color:var(--text)}
.search-pop a:hover,.search-pop a.active{background:var(--surface-2);text-decoration:none}
.search-pop .sub{font-size:12px;color:var(--muted)}
.search-pop .group{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);padding:8px 10px 4px}
.search-pop .empty{padding:12px;color:var(--muted)}
.icon-btn{
  width:34px;height:34px;display:inline-flex;align-items:center;justify-content:center;border-radius:var(--radius-sm);
  border:1px solid transparent;background:transparent;cursor:pointer;color:var(--text-2);
}
.icon-btn:hover{background:var(--surface-2);color:var(--text)}
.icon-btn svg{width:18px;height:18px}
.streak{display:inline-flex;align-items:center;gap:6px;font-size:13px;color:var(--text-2);padding:5px 10px;border-radius:999px;background:var(--surface-2)}
.streak b{color:var(--text)}
.streak:hover{text-decoration:none;background:var(--surface-3)}
.menu-btn{display:none}

/* ------------------------------------------------------------ generic pieces */
.page{max-width:1240px;margin:0 auto;padding:28px 24px 64px}
.page.narrow{max-width:960px}
.eyebrow{font-size:12px;font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--muted)}
.page-title{font-size:26px;font-weight:650;letter-spacing:-.015em;margin:4px 0 6px}
.lede{color:var(--text-2);font-size:15px;max-width:68ch;margin:0 0 18px}
.card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow)}
.card-pad{padding:18px 20px}
.muted{color:var(--muted)}
.small{font-size:12.5px}
.row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.grow{flex:1}
.grid{display:grid;gap:16px}
.g2{grid-template-columns:repeat(2,minmax(0,1fr))}
.g3{grid-template-columns:repeat(3,minmax(0,1fr))}
.g4{grid-template-columns:repeat(4,minmax(0,1fr))}
.section-title{font-size:16px;font-weight:650;margin:28px 0 12px;display:flex;align-items:baseline;gap:10px}
.section-title a{font-size:13px;font-weight:500}

.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:6px;height:34px;padding:0 14px;border-radius:var(--radius-sm);
  border:1px solid var(--border-strong);background:var(--surface);color:var(--text);font-weight:550;cursor:pointer;white-space:nowrap;
}
.btn:hover{background:var(--surface-2);text-decoration:none}
.btn svg{width:16px;height:16px}
.btn.primary{background:var(--accent);border-color:var(--accent);color:var(--on-accent)}
.btn.primary:hover{background:var(--accent-2);border-color:var(--accent-2)}
.btn.ghost{border-color:transparent;background:transparent;color:var(--text-2)}
.btn.ghost:hover{background:var(--surface-2);color:var(--text)}
.btn.sm{height:28px;padding:0 10px;font-size:12.5px}
.btn[disabled]{opacity:.55;cursor:default}
.seg{display:inline-flex;border:1px solid var(--border);border-radius:var(--radius-sm);background:var(--surface-2);padding:2px;gap:2px}
.seg button{border:0;background:transparent;padding:4px 10px;border-radius:4px;cursor:pointer;color:var(--text-2);font-size:12.5px;font-weight:550}
.seg button[aria-pressed="true"]{background:var(--surface);color:var(--text);box-shadow:var(--shadow)}

.pill{display:inline-flex;align-items:center;height:22px;padding:0 8px;border-radius:999px;font-size:12px;font-weight:600;white-space:nowrap}
.pill.easy{color:var(--easy);background:var(--easy-soft)}
.pill.medium{color:var(--medium);background:var(--medium-soft)}
.pill.hard{color:var(--hard);background:var(--hard-soft)}
.chip{display:inline-flex;align-items:center;height:22px;padding:0 8px;border-radius:999px;font-size:12px;color:var(--text-2);background:var(--surface-2);border:1px solid var(--border);white-space:nowrap}
a.chip:hover{text-decoration:none;border-color:var(--border-strong);color:var(--text)}
.status-ic{width:18px;height:18px;display:inline-flex;align-items:center;justify-content:center;flex:0 0 18px}
.status-ic svg{width:16px;height:16px}
.status-ic.solved{color:var(--ok)}
.status-ic.attempted{color:var(--warn)}
.status-ic.new{color:var(--border-strong)}

.callout{border:1px solid var(--border);border-left:3px solid var(--accent);background:var(--surface-2);border-radius:var(--radius-sm);padding:10px 14px;margin:12px 0}
.callout p:first-child{margin-top:0} .callout p:last-child{margin-bottom:0}
.callout.warn{border-left-color:var(--warn);background:var(--warn-soft)}
.callout.bad{border-left-color:var(--bad);background:var(--bad-soft)}
.callout.ok{border-left-color:var(--ok);background:var(--ok-soft)}
.callout .title{font-weight:650;display:block;margin-bottom:2px}

details.fold{border:1px solid var(--border);border-radius:var(--radius-sm);background:var(--surface);margin:10px 0}
details.fold > summary{cursor:pointer;list-style:none;padding:9px 12px;font-weight:550;display:flex;align-items:center;gap:8px}
details.fold > summary::-webkit-details-marker{display:none}
details.fold > summary::before{content:"";width:6px;height:6px;border-right:2px solid var(--muted);border-bottom:2px solid var(--muted);transform:rotate(-45deg);transition:transform .12s ease-out;margin-right:2px}
details.fold[open] > summary::before{transform:rotate(45deg)}
details.fold > .fold-body{padding:2px 14px 12px}
@media (prefers-reduced-motion: reduce){ details.fold > summary::before{transition:none} }

/* data tables */
.tbl-wrap{overflow:auto;border:1px solid var(--border);border-radius:var(--radius-sm);background:var(--surface);max-width:100%}
.tbl-wrap.tall{max-height:360px}
table.data{border-collapse:separate;border-spacing:0;font-size:13px;width:max-content;min-width:100%}
table.data th,table.data td{padding:6px 12px;border-bottom:1px solid var(--border);text-align:left;white-space:nowrap;vertical-align:top}
table.data th{position:sticky;top:0;background:var(--surface-2);font-weight:600;color:var(--text-2);font-size:12.5px;z-index:1}
table.data tr:last-child td{border-bottom:0}
table.data td.num{text-align:right;font-variant-numeric:tabular-nums}
table.data td.null{color:var(--null-fg);background:var(--null-bg);font-style:italic;font-size:12px}
table.data tr.miss td{background:var(--bad-soft)}
table.data tr.extra td{background:var(--warn-soft)}
table.data .mono,table.schema td:first-child{font-family:var(--mono);font-size:12.5px}
.tbl-caption{display:flex;align-items:baseline;gap:8px;margin:14px 0 6px}
.tbl-caption .name{font-family:var(--mono);font-weight:600;font-size:13px}

/* code */
.code{position:relative;margin:10px 0}
.code pre{margin:0;background:var(--code-bg);border:1px solid var(--border);border-radius:var(--radius-sm);padding:12px 14px;overflow:auto;font:12.5px/1.6 var(--mono);color:var(--text)}
.code .code-actions{position:absolute;top:6px;right:6px;display:flex;gap:4px;opacity:.85}
.code:hover .code-actions{opacity:1}
.tok-kw{color:var(--tok-kw)} .tok-str{color:var(--tok-str)} .tok-com{color:var(--tok-com);font-style:italic}
.tok-num{color:var(--tok-num)} .tok-fn{color:var(--tok-fn)}

.empty-state{text-align:center;padding:40px 20px;color:var(--muted)}
.empty-state b{display:block;color:var(--text);font-size:15px;margin-bottom:4px}

.toast{
  position:fixed;left:50%;bottom:24px;transform:translate(-50%,8px);z-index:90;max-width:min(92vw,520px);
  background:var(--text);color:var(--bg);padding:9px 14px;border-radius:var(--radius-sm);font-size:13px;
  opacity:0;pointer-events:none;transition:opacity .15s ease-out,transform .15s ease-out;
}
.toast.show{opacity:1;transform:translate(-50%,0)}
@media (prefers-reduced-motion: reduce){ .toast{transition:none} }

/* ------------------------------------------------------------ home */
.hero{display:grid;grid-template-columns:minmax(0,1.4fr) minmax(0,1fr);gap:16px;margin-bottom:8px}
.hero h1{font-size:28px;font-weight:650;letter-spacing:-.02em;margin:0 0 6px}
.hero .serif{font-family:var(--font-read);font-weight:400}
.continue{display:flex;flex-direction:column;gap:10px}
.continue .title{font-size:17px;font-weight:600;color:var(--text)}
.stats{display:flex;gap:10px;flex-wrap:wrap}
.stat{flex:1 1 0;min-width:96px;background:var(--surface-2);border:1px solid var(--border);border-radius:var(--radius-sm);padding:10px 12px}
.stat .v{font-size:22px;font-weight:650;line-height:1.1}
.stat .k{font-size:12px;color:var(--muted)}
.coll-card{display:flex;flex-direction:column;gap:8px;color:var(--text);height:100%}
.coll-card:hover{text-decoration:none;border-color:var(--border-strong)}
.coll-card .name{font-weight:650;font-size:15px}
.coll-card .desc{color:var(--text-2);font-size:13px;flex:1}
.bar3{display:flex;height:6px;border-radius:999px;overflow:hidden;background:var(--surface-3)}
.bar3 span:nth-child(1){background:var(--easy)} .bar3 span:nth-child(2){background:var(--medium)} .bar3 span:nth-child(3){background:var(--hard)}
.hb-group h3{font-size:12px;font-weight:650;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin:0 0 8px}
.hb-group ul{list-style:none;padding:0;margin:0;display:grid;gap:2px}
.hb-group a{display:block;padding:5px 8px;margin:0 -8px;border-radius:var(--radius-sm);color:var(--text)}
.hb-group a:hover{background:var(--surface-2);text-decoration:none}

/* ------------------------------------------------------------ problem library */
.lib{display:grid;grid-template-columns:232px minmax(0,1fr);gap:24px;align-items:start}
.rail{position:sticky;top:calc(var(--top) + 20px);display:flex;flex-direction:column;gap:18px;max-height:calc(100vh - var(--top) - 40px);overflow:auto;padding-right:4px}
.rail h4{font-size:11.5px;font-weight:650;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin:0 0 6px}
.rail .opt{display:flex;align-items:center;justify-content:space-between;gap:8px;width:100%;padding:6px 8px;border-radius:var(--radius-sm);border:0;background:transparent;cursor:pointer;text-align:left;color:var(--text-2)}
.rail .opt:hover{background:var(--surface-2);color:var(--text)}
.rail .opt[aria-pressed="true"]{background:var(--accent-soft);color:var(--accent);font-weight:600}
.rail .opt .n{font-size:12px;color:var(--muted);font-variant-numeric:tabular-nums}
.rail details > summary{cursor:pointer;list-style:none;display:flex;justify-content:space-between;padding:6px 8px;border-radius:var(--radius-sm);color:var(--text-2);font-weight:550}
.rail details > summary::-webkit-details-marker{display:none}
.rail details > summary:hover{background:var(--surface-2)}
.rail details .opt{padding-left:18px}
.lib-head{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-bottom:12px}
.lib-head .filter-input{height:34px;padding:0 10px;border-radius:var(--radius-sm);border:1px solid var(--border);background:var(--surface);color:var(--text);font:inherit;min-width:220px;flex:1;max-width:340px}
.lib-head select{height:34px;border-radius:var(--radius-sm);border:1px solid var(--border);background:var(--surface);color:var(--text);font:inherit;padding:0 8px}
.active-filters{display:flex;gap:6px;flex-wrap:wrap;margin:-4px 0 12px}
.active-filters button{display:inline-flex;align-items:center;gap:6px;height:24px;padding:0 8px;border-radius:999px;border:1px solid var(--border);background:var(--surface);cursor:pointer;font-size:12px;color:var(--text-2)}
.active-filters button:hover{border-color:var(--border-strong)}
/* library filter bar: difficulty toggles, topic dropdown, section headings */
.fbar{padding:10px 12px;margin-bottom:12px}
.fbar-row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.flabel{font-size:11.5px;font-weight:650;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin-right:2px}
.ftogs{display:flex;gap:6px;flex-wrap:wrap;margin-right:auto}
.ftog{display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 10px;border-radius:999px;border:1px solid var(--border);background:var(--surface);color:var(--text-2);font-size:13px;white-space:nowrap}
.ftog:hover{text-decoration:none;border-color:var(--border-strong);color:var(--text)}
.ftog .n{font-size:11.5px;color:var(--muted);font-variant-numeric:tabular-nums}
.ftog[aria-pressed="true"]{background:var(--accent-soft);border-color:var(--accent);color:var(--accent);font-weight:600}
.ftog.easy[aria-pressed="true"]{background:var(--easy-soft);border-color:var(--easy);color:var(--easy)}
.ftog.medium[aria-pressed="true"]{background:var(--medium-soft);border-color:var(--medium);color:var(--medium)}
.ftog.hard[aria-pressed="true"]{background:var(--hard-soft);border-color:var(--hard);color:var(--hard)}
.ftog[aria-pressed="true"] .n{color:inherit}
.ftopics{height:28px;gap:6px}
.ftopics .caret{font-size:11px;transition:transform .15s}
.ftopics[aria-expanded="true"] .caret{transform:rotate(180deg)}
.ftopics .badge{display:inline-flex;align-items:center;justify-content:center;min-width:18px;height:18px;padding:0 5px;border-radius:999px;background:var(--accent);color:var(--on-accent);font-size:11px;font-weight:650}
.tpanel{display:grid;gap:10px;margin-top:10px;padding-top:10px;border-top:1px solid var(--border)}
.tpanel[hidden]{display:none}
.tgroup{display:grid;grid-template-columns:150px minmax(0,1fr);gap:8px;align-items:start}
.tfam{font-size:12px;font-weight:600;color:var(--muted);padding-top:5px}
.tchips{display:flex;gap:6px;flex-wrap:wrap}
.plist-sec{display:flex;justify-content:space-between;gap:12px;padding:8px 16px;border-bottom:1px solid var(--border);background:var(--surface-2);font-size:12.5px;font-weight:650;color:var(--text-2)}
.plist-sec .n{font-weight:500;color:var(--muted);font-size:12px}
.g-coll{grid-template-columns:repeat(auto-fill,minmax(210px,1fr))}
@media (prefers-reduced-motion:reduce){.ftopics .caret{transition:none}}
@media (max-width:760px){.tgroup{grid-template-columns:1fr;gap:4px}.tfam{padding-top:0}.ftogs{margin-right:0}}
.plist{overflow:hidden}
.plist-row{display:grid;grid-template-columns:22px minmax(0,1fr) auto 84px;gap:12px;align-items:center;padding:10px 16px;border-bottom:1px solid var(--border);color:var(--text)}
.plist-row:last-child{border-bottom:0}
.plist-row:hover{background:var(--surface-2);text-decoration:none}
.plist-row .t{font-weight:550;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.plist-row .s{font-size:12px;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.plist-row .tags{display:flex;gap:4px;justify-content:flex-end}
.plist-row .d{text-align:right}
.plist-head{display:grid;grid-template-columns:22px minmax(0,1fr) auto 84px;gap:12px;padding:8px 16px;border-bottom:1px solid var(--border);font-size:12px;font-weight:600;color:var(--muted);background:var(--surface-2)}
.filter-toggle{display:none}

/* ------------------------------------------------------------ problem workspace */
.ws{display:grid;grid-template-columns:minmax(360px, var(--left, 48%)) 6px minmax(360px,1fr);height:calc(100vh - var(--top));background:var(--bg)}
.ws-pane{display:flex;flex-direction:column;min-height:0;min-width:0;background:var(--surface)}
.ws-left{border-right:1px solid var(--border)}
.ws-split{cursor:col-resize;background:var(--bg);position:relative}
.ws-split::after{content:"";position:absolute;top:50%;left:2px;width:2px;height:32px;transform:translateY(-50%);border-radius:2px;background:var(--border-strong)}
.ws-split:hover,.ws-split.drag{background:var(--accent-soft)}
.ws-bar{display:flex;align-items:center;gap:6px;padding:8px 12px;border-bottom:1px solid var(--border);min-height:46px}
.tabs{display:flex;gap:2px}
.tabs button{border:0;background:transparent;padding:7px 11px;border-radius:var(--radius-sm);cursor:pointer;color:var(--text-2);font-weight:550;display:inline-flex;gap:6px;align-items:center}
.tabs button:hover{background:var(--surface-2);color:var(--text)}
.tabs button[aria-selected="true"]{background:var(--surface-2);color:var(--text)}
.tabs svg{width:15px;height:15px}
.ws-scroll{overflow:auto;padding:20px 24px 40px;flex:1;min-height:0}
.ws-scroll h1{font-size:21px;font-weight:650;letter-spacing:-.01em;margin:0 0 8px}
.ws-meta{display:flex;gap:6px;flex-wrap:wrap;align-items:center;margin-bottom:14px}
.ws-scroll h2{font-size:14px;font-weight:650;margin:22px 0 8px;color:var(--text)}
.ws-scroll .statement{font-size:14.5px;color:var(--text)}
.nav-arrows{display:flex;gap:2px;margin-left:auto}

.editor-wrap{display:flex;flex-direction:column;min-height:0;flex:1}
.editor{position:relative;flex:1;min-height:160px;overflow:hidden;background:var(--code-bg)}
.editor pre,.editor textarea{
  margin:0;position:absolute;inset:0;padding:14px 16px 14px 52px;font:13px/1.6 var(--mono);white-space:pre;overflow:auto;
  tab-size:2;border:0;letter-spacing:0;
}
.editor pre{pointer-events:none;color:var(--text)}
.editor textarea{background:transparent;color:transparent;caret-color:var(--text);resize:none;outline:none;z-index:1}
.editor textarea::selection{background:color-mix(in srgb, var(--accent) 28%, transparent);color:transparent}
.editor .gutter{position:absolute;top:0;left:0;bottom:0;width:40px;padding:14px 8px 14px 0;text-align:right;color:var(--muted);font:13px/1.6 var(--mono);background:var(--code-bg);border-right:1px solid var(--border);overflow:hidden;user-select:none}
.editor.small{min-height:0;flex:none}
.out{display:flex;flex-direction:column;border-top:1px solid var(--border);min-height:120px;height:var(--out-h, 42%);background:var(--surface)}
.out-head{display:flex;align-items:center;gap:8px;padding:6px 12px;border-bottom:1px solid var(--border);min-height:40px}
.out-body{overflow:auto;padding:12px;flex:1;min-height:0}
.verdict{font-weight:650;font-size:15px}
.verdict.ok{color:var(--ok)} .verdict.bad{color:var(--bad)} .verdict.err{color:var(--bad)}
.err-box{font-family:var(--mono);font-size:12.5px;white-space:pre-wrap;background:var(--bad-soft);color:var(--text);border:1px solid var(--border);border-left:3px solid var(--bad);border-radius:var(--radius-sm);padding:10px 12px}
.diff-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
.engine-note{font-size:12px;color:var(--muted)}
.spinner{width:14px;height:14px;border-radius:50%;border:2px solid var(--border-strong);border-top-color:var(--accent);animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
@media (prefers-reduced-motion: reduce){ .spinner{animation:none} }
.select{height:30px;border-radius:var(--radius-sm);border:1px solid var(--border);background:var(--surface);color:var(--text);font:inherit;font-size:12.5px;padding:0 6px}
.reveal{display:flex;flex-direction:column;align-items:flex-start;gap:10px;padding:18px;border:1px dashed var(--border-strong);border-radius:var(--radius);background:var(--surface-2)}
.sub-list{list-style:none;padding:0;margin:0}
.sub-list li{display:grid;grid-template-columns:96px minmax(0,1fr) auto;gap:10px;align-items:center;padding:9px 0;border-bottom:1px solid var(--border)}
.sub-list .ok{color:var(--ok);font-weight:600}
.sub-list .bad{color:var(--bad);font-weight:600}
.sub-list .att{color:var(--warn);font-weight:600}
.sub-list code{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;background:none;border:0;padding:0;color:var(--text-2)}

/* ------------------------------------------------------------ handbook (reading layout) */
.hb{display:grid;grid-template-columns:236px minmax(0,1fr) 200px;gap:32px;max-width:1360px;margin:0 auto;padding:24px 24px 80px;align-items:start}
.hb-nav{position:sticky;top:calc(var(--top) + 20px);max-height:calc(100vh - var(--top) - 40px);overflow:auto;font-size:13.5px;padding-right:4px}
.hb-nav h4{font-size:11.5px;font-weight:650;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin:16px 0 4px}
.hb-nav h4:first-child{margin-top:0}
.hb-nav a{display:block;padding:4px 8px;border-radius:var(--radius-sm);color:var(--text-2)}
.hb-nav a:hover{background:var(--surface-2);color:var(--text);text-decoration:none}
.hb-nav a[aria-current="page"]{background:var(--accent-soft);color:var(--accent);font-weight:600}
.hb-toc{position:sticky;top:calc(var(--top) + 20px);font-size:12.5px;max-height:calc(100vh - var(--top) - 40px);overflow:auto}
.hb-toc h4{font-size:11.5px;font-weight:650;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin:0 0 6px}
.hb-toc a{display:block;padding:3px 0 3px 10px;border-left:2px solid var(--border);color:var(--muted)}
.hb-toc a:hover{color:var(--text);text-decoration:none}
.hb-toc a.active{border-left-color:var(--accent);color:var(--text);font-weight:600}
.article{min-width:0;max-width:820px}
.article .crumbs{font-size:12.5px;color:var(--muted);margin-bottom:6px}
.article h1{font-family:var(--font-read);font-weight:400;font-size:34px;letter-spacing:-.01em;margin:0 0 8px;padding-bottom:10px;border-bottom:1px solid var(--border)}
.article .summary{font-size:15.5px;color:var(--text-2);margin:12px 0 18px}
.article h2{font-family:var(--font-read);font-weight:400;font-size:24px;margin:38px 0 10px;padding-bottom:6px;border-bottom:1px solid var(--border);scroll-margin-top:calc(var(--top) + 64px)}
.article h3{font-size:15px;font-weight:650;margin:22px 0 6px}
.article .body{font-size:15px;line-height:1.65}
.article .body table{border-collapse:collapse;margin:10px 0 14px;font-size:13.5px}
.article .body th,.article .body td{border:1px solid var(--border);padding:5px 10px;text-align:left}
.article .body th{background:var(--surface-2)}
.dialect-bar{position:sticky;top:var(--top);z-index:5;display:flex;align-items:center;gap:10px;padding:10px 0;margin:0 0 6px;background:var(--bg);border-bottom:1px solid var(--border)}
.syntax{margin:12px 0}
.syntax .label{font-size:11.5px;font-weight:650;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin-bottom:4px}
table.args{border-collapse:collapse;width:100%;margin:8px 0 14px;font-size:13.5px;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-sm);overflow:hidden}
table.args th,table.args td{padding:7px 12px;border-bottom:1px solid var(--border);text-align:left;vertical-align:top}
table.args th{background:var(--surface-2);font-size:12px;color:var(--muted);font-weight:600}
table.args td:first-child{font-family:var(--mono);font-size:12.5px;white-space:nowrap;color:var(--tok-fn);width:1%}
.example{border:1px solid var(--border);border-radius:var(--radius);background:var(--surface);margin:14px 0 18px;overflow:hidden;box-shadow:var(--shadow)}
.example-head{display:flex;align-items:center;gap:8px;padding:10px 14px;border-bottom:1px solid var(--border)}
.example-head .t{font-weight:650;font-size:14px}
.example-explain{padding:8px 14px 0;font-size:14px;color:var(--text-2)}
.example-explain p{margin:.3em 0}
.example .editor{height:auto;min-height:0;margin:10px 14px;border:1px solid var(--border);border-radius:var(--radius-sm)}
.example-out{padding:0 14px 14px}
.example-out .out-label{font-size:11.5px;font-weight:650;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin:2px 0 6px;display:flex;gap:8px;align-items:center}
.pitfalls{margin:14px 0}
.uses{font-size:12.5px;color:var(--muted)}

/* ------------------------------------------------------------ progress */
.heatmap-wrap{overflow-x:auto;padding:4px 0 8px}
.heatmap{display:grid;grid-template-rows:auto repeat(7,12px);grid-auto-flow:column;grid-auto-columns:12px;gap:3px;width:max-content}
.heatmap .m{grid-row:1;font-size:11px;color:var(--muted);white-space:nowrap;height:16px}
.heatmap .c{width:12px;height:12px;border-radius:3px;background:var(--hm-0);border:0;padding:0;cursor:pointer}
.heatmap .c[data-l="1"]{background:var(--hm-1)} .heatmap .c[data-l="2"]{background:var(--hm-2)}
.heatmap .c[data-l="3"]{background:var(--hm-3)} .heatmap .c[data-l="4"]{background:var(--hm-4)}
.heatmap .c.future{visibility:hidden}
.heatmap .c.today{outline:1.5px solid var(--text);outline-offset:1px}
.legend{display:flex;gap:3px;align-items:center;font-size:12px;color:var(--muted)}
.legend span{display:inline-block;width:12px;height:12px;border-radius:3px}
.meter{height:6px;border-radius:999px;background:var(--surface-3);overflow:hidden}
.meter span{display:block;height:100%;background:var(--accent)}
.log{list-style:none;padding:0;margin:0}
.log li{display:flex;gap:12px;padding:8px 0;border-bottom:1px solid var(--border);font-size:13.5px}
.log .when{color:var(--muted);min-width:150px;font-variant-numeric:tabular-nums}

/* dataset page (shared sets) */
figure.diagram{border:1px solid var(--border);border-radius:var(--radius);background:var(--surface);padding:12px;margin:12px 0;overflow-x:auto}
figure.diagram .mermaid-src{display:none}
figure.diagram svg{max-width:100%;height:auto}
figure.diagram figcaption{font-size:12.5px;color:var(--muted);margin-top:6px}

/* ------------------------------------------------------------ responsive */
@media (max-width:1200px){
  .hb{grid-template-columns:220px minmax(0,1fr)}
  .hb-toc{display:none}
}
@media (max-width:980px){
  .g4{grid-template-columns:repeat(2,minmax(0,1fr))}
  .g3{grid-template-columns:repeat(2,minmax(0,1fr))}
  .hero{grid-template-columns:1fr}
  .lib{grid-template-columns:1fr}
  .rail{position:static;max-height:none;display:none}
  .rail.open{display:flex}
  .filter-toggle{display:inline-flex}
  .ws{display:flex;flex-direction:column;height:auto}
  .ws-split{display:none}
  .ws-left{border-right:0;border-bottom:1px solid var(--border)}
  .ws-scroll{overflow:visible}
  .ws-right .editor{min-height:260px;flex:none;height:300px}
  .out{height:auto;min-height:160px}
  .hb{grid-template-columns:1fr;padding:16px 16px 64px}
  .hb-nav{position:static;max-height:none;display:none;border:1px solid var(--border);border-radius:var(--radius);padding:12px;background:var(--surface)}
  .hb-nav.open{display:block}
}
@media (max-width:760px){
  .topbar{gap:8px;padding:0 12px}
  .nav{display:none}
  .nav.open{display:flex;position:absolute;top:var(--top);left:0;right:0;flex-direction:column;background:var(--surface);border-bottom:1px solid var(--border);padding:8px}
  .menu-btn{display:inline-flex}
  .search{width:auto;flex:1}
  .search kbd{display:none}
  .streak{display:none}
  .brand .serif{display:none}
  .page{padding:20px 16px 56px}
  .g2,.g3,.g4{grid-template-columns:1fr}
  .plist-row,.plist-head{grid-template-columns:22px minmax(0,1fr) 70px}
  .plist-row .tags,.plist-head .tags{display:none}
  .diff-grid{grid-template-columns:1fr}
  .article h1{font-size:28px}
  .sub-list li{grid-template-columns:80px minmax(0,1fr)}
  .sub-list li > :last-child{grid-column:1/-1}
}
.rail .opt:hover{text-decoration:none}
a.opt{text-decoration:none}

/* fixes from the 375px pass */
.plist-row .t,.plist-row .s{display:block}
.ws-bar{overflow-x:auto}
@media (max-width:760px){
  .tabs button span{display:none}
  .tabs button{padding:7px 9px}
  table.args td:first-child{white-space:normal;word-break:break-word;width:38%}
  .article table.args{table-layout:fixed}
  .dialect-bar{flex-wrap:wrap}
}

/* review fixes */
.editor:focus-within{outline:2px solid var(--accent);outline-offset:-2px}
.example .editor:focus-within{outline-offset:0}
