:root {
  color-scheme: light;
  --plane:#f6f3ec; --surface-1:#fffdf8;
  --text-primary:#1c2833; --text-secondary:#4a5765; --muted:#7f8c9b;
  --border:#e2dac9; --hair:#ece4d6; --grid:#ece4d6; --axis:#d9d0be;
  --gold:#9a8535; --navy:#1a2a5e;
  --series-1:#1a2a5e; --series-2:#b2544a; --series-3:#9a8535;
  --accent-wash:#efe6d2;
  --shadow:0 1px 2px rgba(27,58,92,.06), 0 2px 10px rgba(27,58,92,.07);
  --shadow-lift:0 6px 22px rgba(27,58,92,.14);
  --display:"Space Grotesk",Inter,-apple-system,sans-serif;
  --body:Inter,-apple-system,system-ui,"Segoe UI",sans-serif;
  --serif:"Newsreader","Iowan Old Style",Palatino,Georgia,serif;
  --mono:"JetBrains Mono",ui-monospace,"SF Mono",Menlo,monospace;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:#14161a; --surface-1:#1b1e24;
  --text-primary:#e7e3da; --text-secondary:#b3aea3; --muted:#8b8579;
  --border:#2c3037; --hair:#24272d; --grid:#2a2e35; --axis:#3a3f47;
  --gold:#c2a54e; --navy:#7ea3d8;
  --series-1:#7ea3d8; --series-2:#d1786c; --series-3:#c2a54e;
  --accent-wash:#2b3a4a;
  --shadow:0 1px 2px rgba(0,0,0,.3), 0 2px 10px rgba(0,0,0,.25);
  --shadow-lift:0 6px 22px rgba(0,0,0,.4);
}

* { box-sizing:border-box; }
html { -webkit-text-size-adjust:100%; }
body {
  margin:0; background:var(--plane); color:var(--text-primary);
  font-family:var(--body); font-size:16px; line-height:1.62;
  -webkit-font-smoothing:antialiased;
}
.wrap { max-width:1080px; margin:0 auto; padding:0 26px; }
a { color:var(--navy); text-decoration:none; border-bottom:1px solid transparent; }
a:hover { border-bottom-color:currentColor; }

/* ---------- signature elements ---------- */
.rule::before {
  content:""; display:block; width:46px; height:3px;
  background:var(--gold); margin-bottom:11px; border-radius:1px;
}
.eyebrow {
  font-family:var(--display); font-size:11px; font-weight:600;
  letter-spacing:.09em; text-transform:uppercase; color:var(--gold);
  margin:0 0 5px;
}
blockquote {
  border-left:3px solid var(--gold); padding-left:16px; margin:0 0 18px;
  font-family:var(--serif); font-size:16.5px; line-height:1.55;
  color:var(--text-primary);
}

/* ---------- masthead ---------- */
header.masthead { padding:34px 0 0; }
.topbar { display:flex; justify-content:space-between; align-items:flex-start; gap:18px; }
h1 { font-family:var(--display); font-size:34px; line-height:1.14; font-weight:600;
     margin:0 0 8px; letter-spacing:-.01em; }
h1 a { color:inherit; border:none; }
.byline { margin:0 0 14px; font-size:13.5px; color:var(--text-secondary); max-width:70ch; }
.statline {
  font-family:var(--mono); font-size:12px; color:var(--text-secondary);
  background:var(--surface-1); border:1px solid var(--hair); border-radius:7px;
  padding:9px 13px; display:inline-block; margin:0 0 16px;
}
.tools { display:flex; gap:7px; flex:0 0 auto; }
.tool {
  width:32px; height:32px; display:grid; place-items:center; cursor:pointer;
  background:var(--surface-1); border:1px solid var(--hair); border-radius:8px;
  color:var(--text-secondary); font-size:13px; padding:0; font-family:var(--body);
}
.tool:hover { color:var(--navy); border-color:var(--border); }

/* ---------- nav ---------- */
nav.main { border-top:1px solid var(--hair); border-bottom:1px solid var(--hair);
           margin-top:8px; }
nav.main ul { list-style:none; margin:0; padding:0; display:flex; flex-wrap:wrap; gap:2px; }
nav.main a, nav.main span.here {
  display:block; padding:11px 15px; font-family:var(--display); font-size:13px;
  font-weight:500; color:var(--text-secondary); border:none;
}
nav.main a:hover { color:var(--navy); background:var(--surface-1); }
nav.main span.here { color:var(--gold); box-shadow:inset 0 -2px 0 var(--gold); }

/* ---------- caveat ---------- */
.caveat {
  background:var(--accent-wash); border-radius:8px; padding:12px 16px;
  font-size:13.5px; color:var(--text-primary); margin:20px 0 0;
  border-left:3px solid var(--gold);
}

/* ---------- sections ---------- */
main { padding:26px 0 60px; }
section { margin:0 0 34px; }
h2 { font-family:var(--display); font-size:21px; font-weight:600; margin:0 0 12px;
     letter-spacing:-.005em; }
h3 { font-family:var(--display); font-size:15.5px; font-weight:600;
     margin:24px 0 7px; }
p { margin:0 0 13px; max-width:78ch; }
.lede { font-size:17px; }
.note { font-size:13px; color:var(--muted); max-width:78ch; }

/* ---------- stat grid ---------- */
.stats { display:grid; grid-template-columns:repeat(auto-fit,minmax(196px,1fr));
         gap:13px; margin:18px 0 8px; }
.stat { background:var(--surface-1); border:1px solid var(--hair); border-radius:10px;
        padding:15px 16px; box-shadow:var(--shadow); }
.stat .v { font-family:var(--mono); font-size:24px; font-weight:500;
           color:var(--navy); line-height:1.12; letter-spacing:-.02em;
           font-variant-numeric:tabular-nums; }
.stat .k { font-size:12.5px; color:var(--text-secondary); margin-top:5px; }
.stat .q { font-family:var(--mono); font-size:10.5px; color:var(--muted); margin-top:6px; }

/* ---------- tables ---------- */
.tablewrap { overflow-x:auto; border:1px solid var(--hair); border-radius:10px;
             background:var(--surface-1); box-shadow:var(--shadow); margin:14px 0; }
table { border-collapse:collapse; width:100%; font-size:13.5px; }
th, td { padding:9px 13px; text-align:left; vertical-align:top;
         border-bottom:1px solid var(--hair); }
thead th { font-family:var(--display); font-size:11.5px; font-weight:600;
           text-transform:uppercase; letter-spacing:.05em; color:var(--text-secondary);
           border-bottom:1.5px solid var(--axis); white-space:nowrap;
           background:var(--surface-1); position:sticky; top:0; z-index:2; }
tbody tr:last-child td { border-bottom:none; }
td.num, th.num { font-family:var(--mono); font-size:12.5px; white-space:nowrap; }
td.rowlab { position:sticky; left:0; background:var(--surface-1); font-weight:500;
            z-index:1; }
.pos { color:var(--series-2); }
.neg { color:#2e7d5b; }
:root[data-theme="dark"] .neg { color:#69c79b; }

/* ---------- figures ---------- */
figure { margin:20px 0; background:var(--surface-1); border:1px solid var(--hair);
         border-radius:10px; padding:14px; box-shadow:var(--shadow); }
figure img { width:100%; height:auto; display:block; border-radius:5px; }
figcaption { font-size:13px; color:var(--text-secondary); margin-top:11px; max-width:80ch; }
figcaption b { color:var(--text-primary); }

/* ---------- download list ---------- */
.files { display:grid; gap:11px; margin:16px 0; }
.file { background:var(--surface-1); border:1px solid var(--hair); border-radius:10px;
        padding:14px 16px; box-shadow:var(--shadow); }
.file .fh { display:flex; justify-content:space-between; align-items:baseline;
            gap:14px; flex-wrap:wrap; }
.file .fn { font-family:var(--mono); font-size:13.5px; font-weight:500; }
.file .fm { font-family:var(--mono); font-size:11.5px; color:var(--muted);
            white-space:nowrap; }
.file .fd { font-size:13px; color:var(--text-secondary); margin-top:6px; max-width:80ch; }

/* ---------- terminal panel ---------- */
details.code { margin:18px 0; border:1px solid var(--hair); border-radius:10px;
               overflow:hidden; background:var(--surface-1); box-shadow:var(--shadow); }
details.code > summary { cursor:pointer; padding:13px 16px; font-family:var(--display);
                         font-size:13.5px; font-weight:600; list-style:none; }
details.code > summary::-webkit-details-marker { display:none; }
details.code > summary::before { content:"▸ "; color:var(--gold); }
details.code[open] > summary::before { content:"▾ "; }
.term { background:#10141a; color:#d7dbe0; font-family:var(--mono); font-size:12px;
        line-height:1.65; padding:15px 17px; overflow-x:auto; margin:0; }
.term .p { color:#7ee08a; }
.term .c { color:#7f8c9b; }
.tabs { display:flex; gap:2px; padding:0 12px; background:#0b0e13;
        border-bottom:1px solid #232a33; }
.tabs button { background:none; border:none; color:#8b95a1; font-family:var(--mono);
               font-size:11.5px; padding:9px 12px; cursor:pointer; }
.tabs button[aria-selected="true"] { color:#7ee08a; box-shadow:inset 0 -2px 0 #7ee08a; }

/* ---------- footer ---------- */
footer.credit { border-top:1px solid var(--hair); padding:22px 0 46px;
                font-size:13px; color:var(--text-secondary); }
footer.credit p { max-width:80ch; margin:0 0 9px; }

/* ---------- explorer ---------- */
.dims { display:grid; grid-template-columns:repeat(auto-fit,minmax(258px,1fr));
        gap:13px; margin:16px 0; }
fieldset.dim { border:1px solid var(--hair); border-radius:10px; margin:0;
               padding:13px 15px 14px; background:var(--surface-1);
               box-shadow:var(--shadow); }
fieldset.dim legend { font-family:var(--display); font-size:12.5px; font-weight:600;
                      color:var(--gold); text-transform:uppercase;
                      letter-spacing:.06em; padding:0 6px; }
.dimhelp { font-size:12px; color:var(--muted); margin:0 0 9px; max-width:none; }
.opts { display:flex; flex-direction:column; gap:3px; }
.opts.wardopts { display:grid; grid-template-columns:repeat(auto-fit,minmax(112px,1fr)); }
label.opt { display:flex; align-items:center; gap:8px; padding:6px 9px;
            border-radius:7px; cursor:pointer; font-size:13.5px; }
label.opt:hover { background:var(--accent-wash); }
label.opt.on { background:var(--accent-wash); font-weight:500; }
label.opt input { accent-color:var(--gold); margin:0; flex:0 0 auto; width:15px; height:15px; }
label.opt .ol { flex:1 1 auto; }
label.opt .oc { font-family:var(--mono); font-size:11px; color:var(--muted);
                flex:0 0 auto; }
label.opt.on .oc { color:var(--gold); }

.activebar { display:flex; flex-wrap:wrap; gap:7px; align-items:center;
             margin:14px 0 4px; min-height:32px; }
.chip { font-family:var(--body); font-size:12.5px; background:var(--surface-1);
        border:1px solid var(--border); border-radius:20px; padding:5px 12px;
        cursor:pointer; color:var(--text-primary); }
.chip:hover { border-color:var(--gold); }
.chip .cd { color:var(--gold); font-family:var(--display); font-size:10.5px;
            text-transform:uppercase; letter-spacing:.05em; margin-right:5px; }
.chip .cx { color:var(--muted); margin-left:4px; }
.chip.clearall { background:var(--accent-wash); }
.nofilter { font-size:13px; color:var(--muted); }
th.sortable { cursor:pointer; user-select:none; }
th.sortable:hover { color:var(--gold); }
.actions { display:flex; gap:9px; align-items:center; margin:12px 0 0;
           flex-wrap:wrap; }
button.act { font-family:var(--display); font-size:13px; font-weight:500;
             background:var(--navy); color:#fff; border:none; border-radius:8px;
             padding:9px 16px; cursor:pointer; }
button.act:hover { opacity:.9; }
:root[data-theme="dark"] button.act { color:#10141a; }

/* ---------- live distribution + micro bars ---------- */
.distwrap { background:var(--surface-1); border:1px solid var(--hair);
            border-radius:10px; padding:12px 14px 9px; box-shadow:var(--shadow);
            margin:14px 0;
            background-image:radial-gradient(var(--hair) 1px, transparent 1px);
            background-size:14px 14px; background-position:-1px -1px; }
.disthead { display:flex; justify-content:space-between; align-items:baseline;
            gap:12px; margin-bottom:5px; }
.distmed { font-family:var(--mono); font-size:11.5px; color:var(--gold);
           font-weight:500; }
.distsvg { width:100%; height:132px; display:block; }
.distaxis { display:flex; justify-content:space-between;
            font-family:var(--mono); font-size:10px; color:var(--muted);
            margin-top:2px; }
.micro { display:inline-block; width:34px; height:7px; margin-right:7px;
         vertical-align:middle; background:var(--hair); border-radius:2px;
         position:relative; overflow:hidden; }
.micro i { position:absolute; top:0; height:100%; display:block; }
.micro.l i { right:50%; background:#2e7d5b; }
.micro.r i { left:50%; background:var(--series-2); }
:root[data-theme="dark"] .micro.l i { background:#69c79b; }

/* ---------- in-browser R console ---------- */
.runr { padding:14px 16px 16px; background:var(--surface-1); }
.runrnote { font-size:12.5px; color:var(--text-secondary); margin:0 0 10px;
            max-width:80ch; }
.runrnote code { font-family:var(--mono); font-size:11.5px;
                 background:var(--accent-wash); padding:1px 5px;
                 border-radius:4px; }
#rcode { width:100%; font-family:var(--mono); font-size:12px; line-height:1.6;
         background:#10141a; color:#d7dbe0; border:1px solid #232a33;
         border-radius:8px; padding:12px 14px; resize:vertical;
         tab-size:2; }
#rcode:focus { outline:2px solid var(--gold); outline-offset:1px; }
.runrbar { display:flex; align-items:center; gap:10px; margin:10px 0 10px;
           flex-wrap:wrap; }
button.act.ghost { background:transparent; color:var(--text-secondary);
                   border:1px solid var(--border); }
button.act:disabled { opacity:.5; cursor:progress; }
.runrstatus { font-family:var(--mono); font-size:11.5px; color:var(--gold); }
#rout { max-height:340px; overflow:auto; margin:0; }

/* ---------- mobile: MUST REMAIN LAST ---------- */
@media (max-width:768px) {
  body { font-size:15.5px; }
  .wrap { padding:0 16px; }
  h1 { font-size:25px; }
  h2 { font-size:19px; }
  .topbar { flex-direction:column; }
  .tools { align-self:flex-start; }
  .statline { font-size:11px; white-space:normal; }
  .stats { grid-template-columns:repeat(auto-fit,minmax(140px,1fr)); gap:10px; }
  .stat .v { font-size:22px; }
  nav.main ul { gap:0; }
  nav.main a, nav.main span.here { padding:10px 11px; font-size:12.5px; }
  table { font-size:12.5px; }
  th, td { padding:8px 10px; }
  figure { padding:9px; }
  .dims { grid-template-columns:1fr; gap:10px; }
  .opts.wardopts { grid-template-columns:repeat(auto-fit,minmax(96px,1fr)); }
  label.opt { font-size:13px; padding:7px 8px; }
  .chip { font-size:12px; }
}


/* ---------- print: a readable paper copy of the whole site ----------
   Placed after the mobile block deliberately. Print is a separate medium, so
   it cannot lose the screen cascade, and it must override the dark theme. */
@media print {
  :root, :root[data-theme="dark"] {
    --plane:#ffffff; --surface-1:#ffffff;
    --text-primary:#1c2833; --text-secondary:#3d4a57; --muted:#5f6b78;
    --border:#c9c2b2; --hair:#ddd6c6; --axis:#b9b0a0;
    --gold:#7d6b2a; --navy:#16244f;
    --series-1:#16244f; --series-2:#96453c; --series-3:#7d6b2a;
    --accent-wash:#f2ece0;
    --shadow:none; --shadow-lift:none;
  }
  body { background:#fff; font-size:10.5pt; line-height:1.5; }
  .wrap { max-width:none; padding:0 12mm; }
  .tools, nav.main, .actions, .runrbar, #rcode, .tabs { display:none !important; }
  header.masthead { padding-top:0; }
  h1 { font-size:22pt; }
  h2 { font-size:13pt; }
  a { color:inherit; border:none; }
  .stat, .file, figure, .distwrap, .tablewrap, details.code, blockquote,
  fieldset.dim { break-inside:avoid; page-break-inside:avoid;
                 box-shadow:none; }
  h2, h3 { break-after:avoid; page-break-after:avoid; }
  figure img { max-height:150mm; object-fit:contain; }
  details.code { border:1px solid var(--hair); }
  details.code > summary { display:none; }
  .term { background:#f4f4f2; color:#1c2833; border:1px solid var(--hair); }
  .term .p { color:#2f6b40; }
  .term .c { color:#5f6b78; }
  /* the explorer's live table is 200 rows on screen; a paper copy needs a
     sample, and the note below says so rather than truncating silently. */
  #results tbody tr:nth-child(n+26) { display:none; }
  #results .tablewrap::after {
    content:"Printed copy shows the first 25 rows. The full selection is on the site, and the whole table downloads as CSV.";
    display:block; padding:7px 12px; font-size:9pt; font-style:italic;
    color:var(--muted); border-top:1px solid var(--hair);
  }
  section { break-inside:auto; }
  footer.credit { border-top:1px solid var(--hair); }
}
