/* NetHack+ — page styles. Tokens first; everything else reads roles. */
:root {
  color-scheme: light;
  --paper: #f5f6f8;
  --paper-2: #eceef2;
  --ink: #1b1e2b;
  --muted: #5a6074;
  --rule: #d9dce4;
  --link: #2446c4;
  --code-bg: #e8eaf0;
  --dungeon: #15172e;
  --dungeon-2: #1d2040;
  --dungeon-ink: #d8dbea;
  --dungeon-muted: #8a90ab;
  --dungeon-rule: #2c3058;
  --gold: #f2c14e;
  --chart-bg: #ffffff;
  --chart-ink: #1b1e2b;
  --chart-muted: #5a6074;
  --chart-rule: #e4e7ee;
  --human: #a87600;
  --chart-tip-bg: #1b1e2b;
  --chart-tip-ink: #ffffff;
  /* memory categories: validated categorical order on the dungeon surface */
  --c-map: #3987e5;
  --c-rng: #d95926;
  --c-obj: #199e70;
  --c-hero: #c98500;
  --c-disp: #d55181;
  --c-dgn: #008300;
  --c-vis: #9085e9;
  --c-mon: #e66767;
  --c-other: #4a4f6e;
  --serif: "Literata", "Iowan Old Style", Georgia, serif;
  --mono: "Martian Mono", "SFMono-Regular", Menlo, monospace;
  --col: 680px;
  --wide: 1080px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #0e1016;
    --paper-2: #161925;
    --ink: #e4e6ee;
    --muted: #9aa0b4;
    --rule: #262a3d;
    --link: #93a9ff;
    --code-bg: #1b1e2e;
    --dungeon: #181b34;
    --dungeon-2: #20244a;
    --dungeon-rule: #2e3366;
    --chart-bg: #141724;
    --chart-ink: #e4e6ee;
    --chart-muted: #9aa0b4;
    --chart-rule: #262a3d;
    --human: #f2c14e;
    --chart-tip-bg: #ffffff;
    --chart-tip-ink: #15172e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0e1016;
  --paper-2: #161925;
  --ink: #e4e6ee;
  --muted: #9aa0b4;
  --rule: #262a3d;
  --link: #93a9ff;
  --code-bg: #1b1e2e;
  --dungeon: #181b34;
  --dungeon-2: #20244a;
  --dungeon-rule: #2e3366;
  --chart-bg: #141724;
  --chart-ink: #e4e6ee;
  --chart-muted: #9aa0b4;
  --chart-rule: #262a3d;
  --human: #f2c14e;
  --chart-tip-bg: #ffffff;
  --chart-tip-ink: #15172e;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.68;
  font-optical-sizing: auto;
  overflow-x: hidden;
}
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; border-radius: 2px; }

/* ---------- reading column ---------- */
.page { padding: 0 16px; }
.col { max-width: var(--col); margin: 0 auto; }
.wide { max-width: var(--wide); margin-left: auto; margin-right: auto; }
p { margin: 0 0 1.1em; }
h1, h2, h3 { font-family: var(--mono); font-weight: 500; letter-spacing: -0.01em; line-height: 1.25; }
h2 { font-size: 1.3rem; margin: 3.2em 0 0.9em; }
h3 { font-size: 1.08rem; margin: 2.2em 0 0.6em; color: var(--ink); text-wrap: balance; }
h2 .n { color: var(--muted); font-weight: 400; margin-right: 0.6em; }
strong { font-weight: 600; }
em { font-style: italic; }
code, kbd { font-family: var(--mono); font-size: 0.78em; background: var(--code-bg); padding: 0.12em 0.38em; border-radius: 4px; }
pre { font-family: var(--mono); font-size: 13px; line-height: 1.6; background: var(--dungeon); color: var(--dungeon-ink); padding: 18px 20px; border-radius: 10px; overflow-x: auto; margin: 1.4em 0; }
pre code { background: none; padding: 0; font-size: inherit; }
ul, ol { padding-left: 1.3em; margin: 0 0 1.2em; }
li { margin: 0.35em 0; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 3em 0; }
.muted { color: var(--muted); }

/* ---------- title block ---------- */
.titleblock { padding: 56px 0 8px; }
.titleblock h1 { font-size: clamp(2rem, 5.4vw, 3.1rem); font-weight: 600; margin: 0 0 18px; letter-spacing: -0.035em; }
.titleblock h1 .plus { color: var(--gold); -webkit-text-stroke: 0; }
.dek { font-size: 1.22rem; line-height: 1.55; color: var(--ink); margin: 0 0 22px; max-width: 34em; }
.byline { font-family: var(--mono); font-size: 13px; color: var(--muted); margin: 0; }
.byline span + span::before { content: ""; display: inline-block; width: 16px; }

/* ---------- table of contents ---------- */
.toc { display: none; }
.toc.hidden { opacity: 0; pointer-events: none; visibility: hidden; }
@media (min-width: 1600px) {
  .toc {
    display: block; position: fixed; top: 96px; left: max(20px, calc(50% - 540px - 250px));
    width: 220px; font-family: var(--mono); font-size: 12px; line-height: 1.5;
  }
  .toc a { display: block; color: var(--muted); text-decoration: none; padding: 5px 0 5px 12px; border-left: 2px solid var(--rule); }
  .toc a:hover { color: var(--ink); }
  .toc a.on { color: var(--ink); border-left-color: var(--gold); }
  .toc { transition: opacity .3s, visibility .3s; }
}

/* ---------- hero (scrollytelling memory view) ---------- */
.hero { position: relative; background: var(--dungeon); color: var(--dungeon-ink); border-bottom: 1px solid var(--dungeon-rule); margin-top: 8px; }
.hero-stage { position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden; }
.hero-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hero-steps { position: relative; z-index: 2; margin-top: -100vh; margin-top: -100svh; pointer-events: none; }
.hero-step { min-height: 100vh; min-height: 100svh; display: flex; align-items: flex-end; padding: 0 16px 9vh; }
.hero-step .card {
  pointer-events: auto; max-width: 430px; background: color-mix(in srgb, var(--dungeon) 86%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--dungeon-rule); border-radius: 12px; padding: 18px 20px;
  font-size: 16px; line-height: 1.55; color: var(--dungeon-ink);
}
.hero-step .card b { color: #fff; font-weight: 600; }
.hero-step .card .k { font-family: var(--mono); font-size: 12px; color: var(--dungeon-muted); display: block; margin-bottom: 6px; }
@media (min-width: 900px) { .hero-step { padding-left: max(32px, calc(50% - 540px)); } }
.hero-legend {
  position: absolute; z-index: 3; top: 16px; right: 16px; display: flex; flex-wrap: wrap; gap: 6px 12px;
  justify-content: flex-end; max-width: 520px; font-family: var(--mono); font-size: 11px; color: var(--dungeon-muted);
}
.hero-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.hero-hud { position: absolute; z-index: 3; left: 16px; top: 16px; font-family: var(--mono); font-size: 11px; color: var(--dungeon-muted); line-height: 1.6; }
.hero-hud b { color: var(--gold); font-weight: 500; }
.hero-tip {
  position: absolute; z-index: 4; pointer-events: none; font-family: var(--mono); font-size: 11.5px; line-height: 1.5;
  background: #fff; color: #15172e; padding: 7px 10px; border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.35);
  opacity: 0; transform: translate(-50%, calc(-100% - 12px)); transition: opacity .12s; white-space: nowrap;
}
.hero-skip { position: absolute; z-index: 5; right: 16px; bottom: 16px; font-family: var(--mono); font-size: 12px; color: var(--dungeon-muted); background: none; border: 1px solid var(--dungeon-rule); border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.hero-skip:hover { color: #fff; border-color: var(--dungeon-muted); }

/* ---------- figures ---------- */
figure { margin: 2.4em auto 2.8em; }
figure.wide { max-width: var(--wide); }
.window {
  background: var(--dungeon); color: var(--dungeon-ink); border-radius: 14px; padding: 20px;
  border: 1px solid var(--dungeon-rule); position: relative; overflow: hidden;
}
figcaption { font-family: var(--serif); font-size: 15px; line-height: 1.55; color: var(--muted); margin-top: 12px; max-width: var(--col); }
figure.wide figcaption { margin-left: auto; margin-right: auto; }
figcaption b { color: var(--ink); font-weight: 600; font-family: var(--mono); font-size: 12.5px; margin-right: 4px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; align-items: center; font-family: var(--mono); font-size: 12px; color: var(--dungeon-muted); }
.controls .label { margin-right: 4px; }
.seg { display: inline-flex; border: 1px solid var(--dungeon-rule); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; color: var(--dungeon-muted); background: transparent; border: 0; padding: 6px 11px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--dungeon-rule); }
.seg button[aria-pressed="true"] { background: var(--dungeon-2); color: #fff; }
.seg button:hover { color: #fff; }

/* terminal map */
.tty { font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace; font-size: clamp(5.6px, 1.42vw, 15.5px); line-height: 1.2; white-space: pre; color: #c9cbd9; overflow: hidden; letter-spacing: 0; }
.tty .g-wall { color: #8d93b5; } .tty .g-floor { color: #4b5078; } .tty .g-door { color: #c98500; }
.tty .g-corr { color: #6c7299; } .tty .g-hero { color: #fff; background: #3987e5; border-radius: 2px; }
.tty .g-mon { color: #e66767; } .tty .g-obj { color: #3ed1a0; } .tty .g-stair { color: #f2c14e; }
.tty .g-trap { color: #d55181; } .tty .g-water { color: #3987e5; } .tty .g-dark { color: #2a2e52; }

/* tables */
.tablewrap { overflow-x: auto; margin: 1.6em 0; }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-family: var(--mono); font-weight: 500; font-size: 12px; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.hl td { background: color-mix(in srgb, var(--gold) 14%, transparent); }
tr.ref td { color: var(--muted); }

/* asides and notes */
.note { border-left: 3px solid var(--rule); padding: 2px 0 2px 16px; color: var(--muted); font-size: 16px; margin: 1.4em 0; }
.pending { font-family: var(--mono); font-size: 12px; color: var(--muted); border: 1px dashed var(--rule); border-radius: 8px; padding: 10px 12px; margin: 1em 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; margin: 1.8em 0; }
.stats div { background: var(--paper); padding: 14px 16px; }
.stats b { display: block; font-family: var(--mono); font-weight: 500; font-size: 1.35rem; letter-spacing: -0.02em; }
.stats span { font-size: 14px; color: var(--muted); line-height: 1.4; display: block; margin-top: 2px; }

/* code comparison */
.diff { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 860px) { .diff { grid-template-columns: 1fr 1fr; } }
.diff pre { margin: 0; height: 100%; }
.diff .tag { font-family: var(--mono); font-size: 11px; color: var(--dungeon-muted); display: block; margin-bottom: 8px; }
.tok-k { color: #9085e9; } .tok-c { color: #6c7299; font-style: italic; } .tok-s { color: #3ed1a0; } .tok-n { color: #f2c14e; } .tok-hl { background: rgba(242,193,78,.16); border-radius: 3px; }

/* svg charts */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.window.chart { background: var(--chart-bg); color: var(--chart-ink); border: 1px solid var(--rule); }
.chart .axis text, .chart .lbl { font-family: var(--mono); font-size: 11px; fill: var(--chart-muted); }
.chart .grid line { stroke: var(--chart-rule); stroke-width: 1; }
.chart .dl { font-family: var(--mono); font-size: 11.5px; fill: var(--chart-ink); }
.chart .legend { color: var(--chart-muted); }
@media (max-width: 700px) { .window.chart { overflow-x: auto; } .window.chart svg { min-width: 640px; } }
.chart-tip { position: absolute; pointer-events: none; z-index: 5; font-family: var(--mono); font-size: 11.5px; line-height: 1.5; background: var(--chart-tip-bg); color: var(--chart-tip-ink); padding: 7px 10px; border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.25); opacity: 0; transition: opacity .1s; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-family: var(--mono); font-size: 11.5px; color: var(--dungeon-muted); margin-bottom: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* footer */
.foot { font-size: 15px; color: var(--muted); padding: 40px 0 80px; }
.cite { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; }

@media (max-width: 600px) {
  body { font-size: 17px; }
  .window { padding: 14px; border-radius: 10px; }
  .hero-step .card { font-size: 15px; }
  .hero-legend { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* knob gallery */
.knob-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-family: var(--mono); font-size: 12px; color: var(--dungeon-ink); margin-top: 12px; }
#knob-frame { color: var(--dungeon-muted); }
.controls .group { color: var(--dungeon-muted); margin: 0 4px 0 2px; }
.tty .hl { background: rgba(242,193,78,.28); border-radius: 2px; color: #fff; }
.tty .me { background: #3987e5; color: #fff; border-radius: 2px; }
.tty-status { font-family: var(--mono); font-size: 12px; color: var(--dungeon-muted); margin-top: 8px; white-space: pre-wrap; }
.knob-play { font: inherit; color: var(--dungeon-muted); background: transparent; border: 1px solid var(--dungeon-rule); border-radius: 8px; padding: 6px 11px; cursor: pointer; }
.knob-play:hover { color: #fff; }

.hero-steps-nav { position: absolute; z-index: 5; left: 50%; transform: translateX(-50%); bottom: 16px; display: inline-flex; border: 1px solid var(--dungeon-rule); border-radius: 999px; overflow: hidden; background: color-mix(in srgb, var(--dungeon) 80%, transparent); }
.hero-steps-nav button { font-family: var(--mono); font-size: 11.5px; color: var(--dungeon-muted); background: transparent; border: 0; padding: 7px 13px; cursor: pointer; }
.hero-steps-nav button + button { border-left: 1px solid var(--dungeon-rule); }
.hero-steps-nav button[aria-current="step"] { color: #15172e; background: var(--gold); }
.hero-steps-nav button:hover { color: #fff; }
.hero-steps-nav button[aria-current="step"]:hover { color: #15172e; }
@media (max-width: 600px) { .hero-steps-nav { bottom: auto; top: 58px; } .hero-steps-nav button { padding: 6px 9px; font-size: 10.5px; } }
@media (max-width: 700px) { .controls .seg { flex-wrap: wrap; } .controls .seg button { border-left: 0 !important; border-right: 1px solid var(--dungeon-rule); border-bottom: 1px solid var(--dungeon-rule); } }

/* inline contents for screens without the side TOC */
.contents { font-family: var(--mono); font-size: 13px; line-height: 1.9; margin: 1.6em 0 0; padding: 14px 18px; border: 1px solid var(--rule); border-radius: 10px; }
.contents ol { margin: 0; padding-left: 1.4em; }
.contents a { text-decoration: none; }
@media (min-width: 1600px) { .contents { display: none; } }

/* trace excerpts */
h4 { font-family: var(--mono); font-weight: 500; font-size: 0.98rem; margin: 1.8em 0 0.5em; }
pre.trace { font-size: 12.5px; margin: 0.8em 0 1.2em; }
blockquote.trace { margin: 0.8em 0 1.2em; padding: 10px 16px; border-left: 3px solid var(--human); background: var(--paper-2); font-style: italic; border-radius: 0 8px 8px 0; }

/* scrolly figure: sticky diagram on one side, steps on the other */
.scrolly .scrolly-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 36px; align-items: start; }
.scrolly .scrolly-fig { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 50vh - 190px); padding: 14px; }
.scrolly .scrolly-step { min-height: 72vh; display: flex; align-items: center; }
.scrolly .scrolly-step:first-child { min-height: 50vh; }
.scrolly .scrolly-step > div { background: var(--paper); border: 1px solid var(--rule); border-radius: 10px; padding: 16px 20px; font-size: 17px; line-height: 1.6; opacity: 0.4; transition: opacity 0.3s; }
.scrolly .scrolly-step > div p { margin: 0; }
.scrolly .scrolly-step.on > div { opacity: 1; border-color: var(--muted); }
@media (max-width: 860px) {
  .scrolly .scrolly-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .scrolly .scrolly-fig { position: relative; top: auto; padding: 8px; }
  .scrolly .scrolly-step, .scrolly .scrolly-step:first-child, #fig-history .scrolly-step, #fig-history .scrolly-step:first-child { min-height: 0; display: block; margin: 0 0 12px; }
  .scrolly .scrolly-step > div { opacity: 1; font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) { .scrolly .scrolly-step > div { transition: none; } }
.scrolly .when { font-family: var(--mono); font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
#fig-history .scrolly-step { min-height: 46vh; }
#fig-history .scrolly-step:first-child { min-height: 40vh; }
table.compare td, table.compare th { vertical-align: top; font-size: 13.5px; line-height: 1.45; }
table.compare td .yes, table.compare td .no, table.compare td .part { font-size: 15px; margin-right: 2px; }
table.compare td:first-child { white-space: nowrap; }
table.compare .yes { color: var(--ok); font-weight: 600; }
table.compare .no { color: var(--bad); font-weight: 600; }
table.compare .part { color: var(--warn); font-weight: 600; }
table.compare tr.ours td { background: color-mix(in srgb, var(--gold) 14%, transparent); }
:root { --ok: #1f7a45; --bad: #b3261e; --warn: #8a5a00; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --ok: #6fdc9b; --bad: #ff8a80; --warn: #f2c14e; } }
:root[data-theme="dark"] { --ok: #6fdc9b; --bad: #ff8a80; --warn: #f2c14e; }
table.compare code { white-space: nowrap; }

/* ---------- series: hub entries, part line, next link ---------- */
.series { display: flex; flex-wrap: wrap; gap: 6px 18px; font-family: var(--mono); font-size: 13px; color: var(--muted); margin: 0 0 22px; }
.series a { text-decoration: none; }
.series .plus, .parts .plus { color: var(--human); }
.series > :last-child { margin-left: auto; }
.parts { list-style: none; padding: 0; margin: 2.4em 0 1em; display: grid; gap: 18px; }
.parts li { margin: 0; padding: 22px 24px; border: 1px solid var(--rule); border-radius: 10px; background: var(--paper-2); }
.parts a { display: grid; gap: 6px; text-decoration: none; color: var(--ink); }
.parts a:hover .part-t { color: var(--link); }
.part-n { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.part-t { font-family: var(--mono); font-size: 1.15rem; font-weight: 500; line-height: 1.3; text-wrap: balance; }
.parts p { margin: 10px 0 0; color: var(--muted); }
.next { margin-top: 2.4em; padding-top: 1.2em; border-top: 1px solid var(--rule); }

/* ---------- footnotes ---------- */
sup.fn { font-size: 0.7em; line-height: 0; }
sup.fn a { text-decoration: none; padding: 0 1px; }
.footnotes { margin-top: 2.4em; padding-top: 1em; border-top: 1px solid var(--rule); font-size: 0.9em; color: var(--muted); }
.footnotes ol { padding-left: 1.4em; margin: 0; }
.footnotes li { margin: 0 0 0.5em; }
.footnotes li a[href^="#fnref"] { text-decoration: none; }
