@font-face { font-family: "Excalifont"; src: url("/fonts/Excalifont-Regular.woff2") format("woff2"); font-display: swap; }
:root {
  --ink: #1e1e1e; --paper: #fffdf7; --panel: #ffffff; --line: #d9d4c7; --muted: #6b6b6b; --soft: #f4f1e8;
  --yellow: #ffec99; --red: #ffc9c9; --green: #b2f2bb; --grey: #e9ecef; --cyan: #99e9f2;
  --orange: #ffd8a8; --blue: #a5d8ff; --violet: #d0bfff; --accent: #1971c2;
  --code-bg: #1e1e1e; --code-ink: #f1f3f5;
  --hand: "Excalifont", "Virgil", "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  --body: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --top: 56px; --side: 264px; --toc: 220px; --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --ink: #ecebe6; --paper: #191a1d; --panel: #22242a; --line: #3a3d45; --muted: #a0a3ab; --soft: #2a2d34; --accent: #74c0fc; --code-bg: #121316; }
}
:root[data-theme="dark"] { --ink: #ecebe6; --paper: #191a1d; --panel: #22242a; --line: #3a3d45; --muted: #a0a3ab; --soft: #2a2d34; --accent: #74c0fc; --code-bg: #121316; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--top) + 16px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { transition: none !important; } }
body { margin: 0; font: 16px/1.65 var(--body); color: var(--ink); background: var(--paper); -webkit-font-smoothing: antialiased; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--yellow); color: #1e1e1e; padding: 8px 12px; border: 2px solid var(--ink); border-radius: 10px; z-index: 10; }
.skip:focus { left: 8px; }

/* Top bar */
.top { display: flex; align-items: center; gap: 14px; height: var(--top); padding: 0 20px; border-bottom: 2px solid var(--ink); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.menu { display: none; }
.brand { font-family: var(--hand); font-size: 24px; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand em { font-style: normal; color: var(--accent); }
.mark { width: 22px; height: 22px; border: 2px solid var(--ink); border-radius: 6px; background: var(--blue); display: inline-block; }
.search { position: relative; margin-left: auto; }
#search { font: 14px var(--body); padding: 7px 34px 7px 12px; border: 2px solid var(--ink); border-radius: 10px; background: var(--paper); color: var(--ink); width: 280px; }
.search kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font: 12px var(--mono); border: 1.5px solid var(--line); border-radius: 5px; padding: 0 5px; color: var(--muted); pointer-events: none; }
.version { font: 13px var(--mono); color: var(--muted); white-space: nowrap; border: 1.5px solid var(--line); border-radius: 999px; padding: 2px 10px; cursor: help; }
.theme { width: 36px; height: 36px; border: 2px solid var(--ink); border-radius: 10px; background: var(--panel); color: var(--ink); cursor: pointer; display: grid; place-items: center; padding: 0; }
.theme:hover { background: var(--soft); }
.theme svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme .moon { display: none; }
:root[data-theme="dark"] .theme .sun { display: none; }
:root[data-theme="dark"] .theme .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme .sun { display: none; }
  :root:not([data-theme="light"]) .theme .moon { display: block; }
}

/* Three columns: navigation, page, outline */
.wrap { display: grid; grid-template-columns: var(--side) minmax(0, 1fr) var(--toc); min-height: calc(100vh - var(--top)); }
.wrap.no-toc { grid-template-columns: var(--side) minmax(0, 1fr); }
.side { border-right: 2px solid var(--line); padding: 18px 14px 40px; background: var(--panel); position: sticky; top: var(--top); height: calc(100vh - var(--top)); overflow-y: auto; }
.side h4 { font-family: var(--hand); font-size: 18px; font-weight: normal; margin: 18px 8px 6px; }
.side h4:first-child { margin-top: 4px; }
.side ul { list-style: none; margin: 0; padding: 0; }
.side li a { display: block; padding: 5px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; border-left: 3px solid transparent; }
.side li a:hover { background: var(--soft); }
.side li.active a { background: var(--yellow); color: #1e1e1e; border-left-color: #1e1e1e; font-weight: 600; }
#results { margin-bottom: 12px; }
#results a { display: block; padding: 8px 10px; border: 2px solid var(--ink); border-radius: 10px; margin-bottom: 6px; background: var(--panel); color: var(--ink); text-decoration: none; }
#results a.selected, #results a:hover { background: var(--green); color: #1e1e1e; }
#results a small { display: block; font-size: 12px; opacity: .8; line-height: 1.4; }
#results mark { background: var(--yellow); color: #1e1e1e; border-radius: 3px; padding: 0 2px; }
#results .none { color: var(--muted); font-size: 14px; padding: 6px 8px; }
.page { padding: 24px 44px 64px; min-width: 0; }
.content, .pager, footer { max-width: 860px; }
.crumbs { font-size: 13px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.crumbs a { color: var(--muted); }
.crumbs b { color: var(--ink); font-weight: 600; }
.toc { padding: 24px 18px; position: sticky; top: var(--top); height: calc(100vh - var(--top)); overflow-y: auto; font-size: 13.5px; border-left: 2px solid var(--line); }
.toc h4 { font-family: var(--hand); font-size: 17px; font-weight: normal; margin: 0 0 8px; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li a { display: block; padding: 4px 10px; color: var(--muted); text-decoration: none; border-left: 2px solid var(--line); line-height: 1.4; }
.toc li.h3 a { padding-left: 22px; }
.toc li a:hover, .toc li a.current { color: var(--ink); border-left-color: var(--accent); }

/* Text */
h1, h2, h3, h4 { font-family: var(--hand); font-weight: normal; line-height: 1.2; }
h1 { font-size: 42px; margin: 0 0 16px; }
h2 { font-size: 29px; margin: 40px 0 12px; padding-bottom: 6px; border-bottom: 2px solid var(--line); }
h3 { font-size: 22px; margin: 28px 0 8px; }
.anchor { margin-left: 8px; color: var(--muted); text-decoration: none; opacity: 0; font-family: var(--body); font-size: .75em; }
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }
p, ul, ol { margin: 0 0 14px; }
li { margin: 4px 0; }
a { color: var(--accent); text-decoration-thickness: 1.5px; text-underline-offset: 2px; }
a.ext::after { content: "↗"; font-size: .8em; margin-left: 2px; }
hr { border: 0; border-top: 2px dashed var(--line); margin: 28px 0; }
code { font: 14px var(--mono); background: var(--grey); color: #1e1e1e; padding: 1px 6px; border-radius: 6px; }
.code { position: relative; margin: 16px 0; }
.code .lang { position: absolute; top: 9px; right: 84px; font: 11px var(--mono); color: #adb5bd; text-transform: uppercase; letter-spacing: .06em; }
.copy { position: absolute; top: 8px; right: 10px; font: 12px var(--body); padding: 3px 9px; border: 1.5px solid #868e96; border-radius: 7px; background: #343a40; color: #f1f3f5; cursor: pointer; opacity: 0; transition: opacity .15s; }
.code:hover .copy, .copy:focus, .copy.done { opacity: 1; }
.copy.done { background: var(--green); color: #1e1e1e; border-color: #1e1e1e; }
pre { background: var(--code-bg); color: var(--code-ink); padding: 14px 16px; border-radius: var(--radius); overflow: auto; border: 2px solid var(--ink); margin: 0; }
pre code { background: none; color: inherit; padding: 0; font-size: 13.5px; line-height: 1.55; }
.table-wrap { overflow-x: auto; margin: 14px 0; border: 2px solid var(--ink); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { border-bottom: 1.5px solid var(--line); padding: 8px 12px; text-align: left; vertical-align: top; }
th:not(:last-child), td:not(:last-child) { border-right: 1.5px solid var(--line); }
th { background: var(--blue); color: #1e1e1e; font-family: var(--hand); font-weight: normal; font-size: 17px; }
tbody tr:nth-child(even) td { background: var(--soft); }
tr:last-child td { border-bottom: 0; }
blockquote { margin: 18px 0; padding: 12px 16px; border: 2px solid var(--ink); border-radius: var(--radius); background: var(--yellow); color: #1e1e1e; }
blockquote::before { content: "Note"; display: block; font-family: var(--hand); font-size: 15px; opacity: .7; }
blockquote p:last-child { margin: 0; }
blockquote code { background: rgba(255, 255, 255, .7); }
img { max-width: 100%; height: auto; }

/* Diagrams, cards, pager */
figure.diagram { margin: 18px 0 28px; border: 2px solid var(--ink); border-radius: 14px; background: #fff; padding: 10px; box-shadow: 4px 4px 0 var(--line); }
figure.diagram a.zoom { display: block; cursor: zoom-in; }
figure.diagram img { display: block; width: 100%; height: auto; }
figure.diagram figcaption { font-family: var(--hand); text-align: center; color: #1e1e1e; font-size: 15px; margin-top: 8px; }
figure.diagram figcaption::after { content: " · click to enlarge"; color: #868e96; font-family: var(--body); font-size: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; margin: 28px 0; }
.card { border: 2px solid var(--ink); border-radius: 14px; padding: 14px 16px 10px; background: var(--fill, var(--panel)); color: #1e1e1e; box-shadow: 4px 4px 0 var(--line); }
.card h2 { font-size: 22px; margin: 0 0 8px; border: 0; padding: 0; }
.card ul { list-style: none; padding: 0; margin: 0; }
.card li { margin: 0 0 8px; }
.card a { color: #1e1e1e; font-weight: 600; text-decoration: none; }
.card a:hover { text-decoration: underline; }
.card small { display: block; color: #495057; font-size: 12.5px; line-height: 1.4; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 44px 0 0; }
.pager a { display: block; padding: 12px 16px; border: 2px solid var(--ink); border-radius: var(--radius); text-decoration: none; color: var(--ink); background: var(--panel); transition: transform .1s, box-shadow .1s; }
.pager a:hover { background: var(--soft); transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--line); }
.pager a small { display: block; color: var(--muted); font-size: 12px; }
.pager a.next { text-align: right; }
.pager a.prev span::before { content: "← "; }
.pager a.next span::after { content: " →"; }
footer { margin-top: 40px; font-size: 13px; color: var(--muted); border-top: 2px solid var(--line); padding-top: 10px; }

/* Lightbox and back-to-top */
.lightbox { position: fixed; inset: 0; z-index: 20; background: rgba(20, 20, 20, .9); display: flex; flex-direction: column; }
.lightbox[hidden] { display: none; }
.lightbox-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; color: #f1f3f5; font-family: var(--hand); font-size: 18px; }
#lightbox-title { margin-right: auto; }
.lightbox-bar a, .lightbox-bar button { font: 13px var(--body); color: #f1f3f5; background: transparent; border: 1.5px solid #868e96; border-radius: 8px; padding: 4px 10px; cursor: pointer; text-decoration: none; }
.lightbox-bar a:hover, .lightbox-bar button:hover { background: #343a40; }
#lightbox-close { font-size: 20px; line-height: 1; padding: 2px 10px; }
.lightbox-body { flex: 1; overflow: auto; padding: 0 16px 16px; display: grid; place-items: start center; }
.lightbox-body img { max-width: 100%; height: auto; background: #fff; border-radius: 12px; cursor: zoom-in; }
.lightbox.actual .lightbox-body img { max-width: none; cursor: zoom-out; }
.totop { position: fixed; right: 20px; bottom: 20px; width: 40px; height: 40px; border: 2px solid var(--ink); border-radius: 12px; background: var(--yellow); color: #1e1e1e; font-size: 18px; cursor: pointer; box-shadow: 3px 3px 0 var(--line); z-index: 4; }
.totop[hidden] { display: none; }

/* Narrow screens */
@media (max-width: 1180px) {
  .wrap { grid-template-columns: var(--side) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 800px) {
  .wrap { grid-template-columns: 1fr; }
  .top { gap: 10px; padding: 0 12px; }
  .menu { display: grid; gap: 4px; width: 36px; height: 36px; border: 2px solid var(--ink); border-radius: 10px; background: var(--panel); place-content: center; cursor: pointer; padding: 0; flex: none; }
  .menu span { display: block; width: 18px; height: 2px; background: var(--ink); border-radius: 2px; }
  .brand { font-size: 20px; }
  .search { margin-left: 0; flex: 1; min-width: 0; }
  #search { width: 100%; padding-right: 12px; }
  .search kbd, .version { display: none; }
  .side { position: fixed; top: var(--top); left: 0; bottom: 0; width: min(86vw, 320px); transform: translateX(-105%); transition: transform .2s; z-index: 6; box-shadow: 6px 0 20px rgba(0, 0, 0, .25); border-right: 2px solid var(--ink); }
  .side.open { transform: none; }
  .page { padding: 18px 16px 48px; }
  h1 { font-size: 32px; }
  h2 { font-size: 25px; }
  .pager { grid-template-columns: 1fr; }
  .pager a.next { text-align: left; }
  .code .lang { display: none; }
  .copy { opacity: 1; }
  figure.diagram figcaption::after { content: " · tap to enlarge"; }
}
@media print {
  .top, .side, .toc, .pager, .totop, .copy, .lightbox, .crumbs { display: none !important; }
  .wrap { display: block; }
  .page { padding: 0; }
  figure.diagram { box-shadow: none; break-inside: avoid; }
}
