/* Geist (body) and IBM Plex Mono (titles), both SIL Open Font License; see fonts/OFL-*.txt. */
@font-face { font-family: "Geist"; font-style: normal; font-weight: 100 900; font-display: swap; src: url(fonts/geist.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 600; font-display: swap; src: url(fonts/ibm-plex-mono-600.woff2) format("woff2"); }

:root {
  --bg: #ffffff;
  --fg: #000000;
  --muted: #6e6e6e;
  --rule: #e5e5e5;
  --rule-strong: #b8b8b8;
  --panel: #f5f5f5;
  --grid-bg: #ffffff;
  --cell: #000000;
  --code-bg: #f2f2f2;
  --display: "IBM Plex Mono", var(--mono);
  --sans: "Geist", "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --fg: #f2f2f2;
    --muted: #9a9a9a;
    --rule: #2a2a2a;
    --rule-strong: #555555;
    --panel: #161616;
    --grid-bg: #000000;
    --cell: #ffffff;
    --code-bg: #1c1c1c;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.55 var(--sans); letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.1; letter-spacing: -0.03em; }
h1 { font-size: clamp(2rem, 4.6vw, 3rem); margin: 0.3em 0 0.35em; }
h2 { font-size: 1.55rem; margin: 2.2em 0 0.5em; padding-top: 0.5em; border-top: 1px solid var(--fg); }
h3 { font-size: 1.15rem; margin: 1.6em 0 0.4em; }
strong { font-weight: 600; }
code, pre { font-family: var(--mono); font-size: 0.85em; }
pre { background: var(--code-bg); padding: 0.8em 1em; overflow-x: auto; border-radius: 10px; }

.site-header { border-bottom: 1px solid var(--rule); background: var(--bg); }
.site-header .inner { max-width: 1100px; margin: 0 auto; padding: 0.9rem 16px; display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.4rem 1.6rem; }
.brand { font-family: var(--display); font-weight: 600; font-size: 1.1rem; line-height: 1.1; color: var(--fg); text-decoration: none; letter-spacing: -0.03em; }
nav.main { display: flex; flex-wrap: wrap; gap: 0.2rem 1.1rem; font-size: 0.9rem; }
nav.main a { color: var(--fg); text-decoration: none; }
nav.main a:hover, nav.main a.active { text-decoration: underline; text-decoration-color: currentColor; text-underline-offset: 4px; }

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.prose { max-width: 720px; }
.lede { font-size: 1.25rem; line-height: 1.4; color: var(--fg); letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.note { background: var(--panel); padding: 0.85em 1.1em; border-radius: 12px; margin: 1.2em 0; }
.site-footer { border-top: 1px solid var(--rule); color: var(--muted); font-size: 0.85rem; }
.site-footer .inner { max-width: 1100px; margin: 0 auto; padding: 1.4rem 16px 2.4rem; }

/* Pattern player */
.pattern { position: relative; background: var(--grid-bg); border: 1px solid var(--rule); border-radius: 12px; overflow: hidden; }
.pattern canvas { display: block; width: 100%; cursor: pointer; }
.pbar { display: flex; align-items: center; gap: 0.3rem; padding: 0.35rem 0.45rem; border-top: 1px solid var(--rule); font-size: 0.8rem; flex-wrap: nowrap; }
.pbar button { flex: none; }
.pbar button { font: inherit; background: none; border: 1px solid var(--rule); color: var(--fg); border-radius: 999px; padding: 0.1rem 0.65rem; cursor: pointer; min-height: 28px; }
.pbar button:hover { border-color: var(--fg); }
.pinfo { position: absolute; top: 7px; left: 8px; pointer-events: none; color: var(--muted); background: var(--grid-bg); opacity: 0.9; padding: 0 0.3rem; border-radius: 3px; font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.03em; line-height: 1.5; white-space: pre; font-variant-numeric: tabular-nums; }
.pcopy { margin-left: auto; min-width: 5.2em; }
.entry .src { font-size: 0.78rem; color: var(--muted); margin-top: auto; }

/* Glossary */
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 1rem 0 1.5rem; position: sticky; top: 0; background: var(--bg); padding: 0.7rem 0; z-index: 2; border-bottom: 1px solid var(--rule); }
.toolbar input { font: inherit; padding: 0.35rem 0.85rem; border: 1px solid var(--rule-strong); border-radius: 999px; background: var(--bg); color: var(--fg); min-width: 0; flex: 1 1 180px; max-width: 320px; }
.toolbar input:focus { outline: none; border-color: var(--fg); }
[hidden] { display: none !important; }
.chip { font: inherit; font-size: 0.85rem; border: 1px solid var(--rule-strong); background: var(--bg); color: var(--fg); border-radius: 999px; padding: 0.2rem 0.8rem; cursor: pointer; }
.chip:hover { border-color: var(--fg); }
.chip[aria-pressed="true"] { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.entries { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.entry { background: var(--panel); border-radius: 14px; padding: 1rem 1.05rem 1.05rem; display: flex; flex-direction: column; gap: 0.6rem; scroll-margin-top: 80px; }
.entry h3 { margin: 0; font-size: 1.1rem; }
.entry h3 a { color: inherit; text-decoration: none; }
.entry .meta { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.1rem 0.55rem; border-radius: 999px; background: var(--bg); color: var(--fg); border: 1px solid var(--rule); }
.tag.credit { color: var(--muted); }
.entry p { margin: 0; font-size: 0.93rem; }
.entry .note { background: var(--bg); margin: 0; font-size: 0.93rem; }
.entry h4 { margin: 0.4rem 0 -0.3rem; font-size: 0.95rem; font-weight: 600; }
.entry.term { background: transparent; border: 1px solid var(--rule); }
.entry img.orig { image-rendering: pixelated; max-width: 100%; height: auto; align-self: flex-start; background: #fff; border: 1px solid var(--rule); border-radius: 6px; }
.letter { grid-column: 1 / -1; font-family: var(--display); font-weight: 600; letter-spacing: -0.03em; font-size: 1.7rem; line-height: 1; margin: 1rem 0 -0.2rem; padding-top: 0.3rem; border-top: 1px solid var(--fg); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0.8rem 0 1.6rem; border: 1px solid var(--rule); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; background: var(--bg); }
th, td { padding: 0.4rem 0.65rem; border-bottom: 1px solid var(--rule); text-align: left; white-space: nowrap; }
th { background: var(--panel); font-weight: 600; position: sticky; top: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }

/* News timeline */
.timeline { list-style: none; padding: 0; margin: 0; max-width: 760px; }
.timeline li { display: grid; grid-template-columns: 7.5rem 1fr; gap: 1rem; padding: 0.85rem 0; border-bottom: 1px solid var(--rule); }
.timeline time { font-size: 0.8rem; color: var(--muted); padding-top: 0.2rem; font-variant-numeric: tabular-nums; }
.timeline p { margin: 0 0 0.5em; }
.era { font-family: var(--display); font-weight: 600; letter-spacing: -0.03em; font-size: 1.7rem; margin: 2.4rem 0 0.3rem; }
@media (max-width: 560px) { .timeline li { grid-template-columns: 1fr; gap: 0.2rem; } }

/* Files */
.files { display: grid; gap: 0.6rem; }
.file { display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 1rem; padding: 0.8rem 1rem; background: var(--panel); border-radius: 12px; }
.file .name { font-weight: 600; }
.file .desc { grid-column: 1 / 2; color: var(--muted); font-size: 0.9rem; }
.file .actions { grid-row: 1 / 3; grid-column: 2; display: flex; gap: 0.7rem; align-items: center; font-size: 0.85rem; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 560px) { .file { grid-template-columns: 1fr; } .file .actions { grid-row: auto; grid-column: 1; justify-content: flex-start; } }

.hero { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 2.5rem; align-items: start; }
.hero h1 { margin-top: 0.15em; }
@media (max-width: 800px) { .hero { grid-template-columns: 1fr; } }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin: 1rem 0; }
.card { display: block; padding: 1rem 1.1rem 1.1rem; border-radius: 14px; background: var(--panel); text-decoration: none; color: var(--fg); }
a.card:hover { background: var(--code-bg); }
.card strong { font-family: var(--display); font-weight: 600; letter-spacing: -0.03em; font-size: 1.15rem; line-height: 1.2; color: var(--fg); display: block; margin-bottom: 0.25rem; }
.card span { font-size: 0.88rem; color: var(--muted); }
.status { font-size: 0.75rem; font-weight: 600; padding: 0.05rem 0.5rem; border-radius: 999px; white-space: nowrap; }
.status.ok { background: #dcefdc; color: #1f5d24; }
.status.part { background: #f6ecc9; color: #6a5208; }
.status.lost { background: #f3d9d5; color: #85261b; }
@media (prefers-color-scheme: dark) {
  .status.ok { background: #1f3a21; color: #a6dba9; }
  .status.part { background: #3d3415; color: #e9d48a; }
  .status.lost { background: #45201b; color: #f0a99f; }
}
.iter-svg { display: block; max-width: 100%; height: auto; border: 1px solid var(--rule); border-radius: 12px; background: var(--grid-bg); }
.iter-svg .grid { stroke: var(--rule); stroke-width: 0.5; }
.ic-black { fill: var(--cell); } .ic-blue { fill: #2a6fdb; } .ic-green { fill: #2f9a3b; } .ic-red { fill: #c8322a; } .ic-gray { fill: #bdbdbd; }
.ic-ring { stroke: var(--cell); stroke-width: 1.6; }
.swatch { display: inline-block; vertical-align: -0.1em; margin-right: 0.15em; }
@media (prefers-color-scheme: dark) {
  .ic-blue { fill: #6ea6f5; } .ic-green { fill: #6cc072; } .ic-red { fill: #ec6a5e; } .ic-gray { fill: #555555; }
}
.iter { display: grid; grid-template-columns: auto 1fr; gap: 1rem 1.5rem; align-items: start; margin-bottom: 1.5rem; }
@media (max-width: 600px) { .iter { grid-template-columns: 1fr; } }
.prose td { white-space: normal; min-width: 9rem; }
