:root {
  --bg: #ebedf2;
  --paper: #f7f8fb;
  --ink: #121821;
  --ink-2: #2c3545;
  --muted: #667084;
  --line: #c5cad6;
  --rail: #101822;
  --rail-ink: #c9d0dc;
  --rail-dim: #7e8899;
  --orange: #ff5c00;
  --orange-2: #e04f00;
  --blue: #2563eb;
  --red: #c81e1e;
  --green: #0f8a5f;
  --warn: #fff4eb;
  --warn-line: #ffc399;
  --font-display: "Bricolage Grotesque", sans-serif;
  --font-body: "Sora", system-ui, sans-serif;
  --font-mono: "Space Mono", ui-monospace, monospace;
  --rail-w: 17.5rem;
  --ease: cubic-bezier(0.2, 0.85, 0.25, 1);
}

*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }
img { max-width: 100%; display: block; }
code, .mono { font-family: var(--font-mono); font-size: 0.88em; }
code {
  background: #e4e7ee;
  padding: 0.08em 0.32em;
  border-radius: 2px;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0.75rem;
  background: var(--orange);
  color: #fff;
  padding: 0.5rem 0.85rem;
  z-index: 100;
}
.skip:focus { left: 0.75rem; }

/* ========== LANDING ========== */
.landing-top {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 3vw, 2rem);
  background: rgba(247, 248, 251, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  line-height: 1.05;
}
.brand__domain {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.03em;
}
.brand__name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.03em;
}
.brand__name span { color: var(--orange); }

.landing-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink-2);
}
.landing-nav a { text-decoration: none; }
.landing-nav a:hover { color: var(--orange-2); }

.cta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 1.6rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.8rem 1.15rem;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.94rem;
  text-decoration: none;
  border: 2px solid transparent;
  transition: transform 0.2s var(--ease), background 0.15s ease, color 0.15s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn--primary { background: var(--orange); color: #fff; }
.btn--primary:hover { background: var(--orange-2); }
.btn--ghost { background: #fff; border-color: var(--ink); color: var(--ink); }
.btn--ghost:hover { background: var(--ink); color: #fff; }

.band {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 4rem 0;
}

.band h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  letter-spacing: -0.03em;
  max-width: 16ch;
  line-height: 1.08;
}

.band .lead {
  margin: 0.85rem 0 0;
  max-width: 40rem;
  color: var(--ink-2);
}

.kicker {
  margin: 0 0 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--orange-2);
}

.project-grid {
  list-style: none;
  margin: 2.2rem 0 0;
  padding: 0;
  display: grid;
  gap: 1rem;
}
@media (min-width: 860px) {
  .project-grid { grid-template-columns: repeat(3, 1fr); }
}

.card {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  background: #fff;
  border: 2px solid var(--ink);
  text-decoration: none;
  overflow: hidden;
  transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease);
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: 6px 6px 0 var(--ink);
}

.card__viz {
  aspect-ratio: 4 / 3;
  border-bottom: 2px solid var(--ink);
  background: #000;
  overflow: hidden;
  position: relative;
}
.card__viz img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  display: block;
  transform: scale(1.02);
}
.card__viz--contain img {
  object-fit: contain;
  background: #0a0c10;
  transform: none;
}

.card__body { padding: 1.1rem 1.15rem 1.25rem; flex: 1; display: flex; flex-direction: column; }
.card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
.card p {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.94rem;
  flex: 1;
}
.card__meta {
  margin-top: 1rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--orange-2);
}

.stat-row {
  display: grid;
  gap: 0.85rem;
  margin-top: 2rem;
}
@media (min-width: 720px) {
  .stat-row { grid-template-columns: repeat(4, 1fr); }
}
.stat {
  background: #fff;
  border-left: 4px solid var(--orange);
  padding: 0.9rem 1rem;
}
.stat b {
  display: block;
  font-family: var(--font-display);
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}
.stat span {
  color: var(--muted);
  font-size: 0.86rem;
}

.landing-foot {
  border-top: 1px solid var(--line);
  background: var(--rail);
  color: var(--rail-ink);
  padding: 2.2rem clamp(1rem, 3vw, 2rem) 2.6rem;
}
.landing-foot a { color: #fff; text-decoration: none; }
.landing-foot a:hover { color: var(--orange); }
.landing-foot__inner {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1.25rem;
}
.landing-foot .brand__domain { color: var(--rail-dim); }
.landing-foot .brand__name { color: #fff; }
.landing-foot p { margin: 0.4rem 0 0; color: var(--rail-dim); font-size: 0.88rem; max-width: 28rem; }

/* ========== DOCS SHELL ========== */
.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: var(--rail);
  color: var(--rail-ink);
  padding: 1.15rem 1rem 2rem;
  border-right: 1px solid #1e2836;
}

.rail .brand { margin-bottom: 1.35rem; }
.rail .brand__domain { color: var(--rail-dim); }
.rail .brand__name { color: #fff; }

.rail__label {
  margin: 1.15rem 0 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--rail-dim);
}

.rail nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.rail a {
  text-decoration: none;
  padding: 0.38rem 0.55rem;
  border-radius: 3px;
  font-size: 0.9rem;
  color: var(--rail-ink);
}
.rail a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.rail a[aria-current="page"] {
  background: rgba(255, 92, 0, 0.18);
  color: #ffb27a;
  font-weight: 600;
}
.rail a.rail__ext { color: var(--rail-dim); font-size: 0.82rem; }

.main {
  min-width: 0;
  background: var(--paper);
}

.main__bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  background: rgba(247, 248, 251, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.main__bar .crumb {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.main__bar .crumb strong { color: var(--ink); font-weight: 700; }

.menu-btn {
  display: none;
  border: 1.5px solid var(--line);
  background: #fff;
  padding: 0.35rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.content {
  width: min(820px, calc(100% - 2.5rem));
  margin: 0 auto;
  padding: 2.25rem 0 4.5rem;
}

.doc-hero {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--line);
}

.doc-hero .eyebrow {
  margin: 0 0 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--orange-2);
}

.doc-hero h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 4.5vw, 2.85rem);
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.doc-hero .lede {
  margin: 0.85rem 0 0;
  color: var(--ink-2);
  max-width: 42rem;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 1.25rem;
  margin-top: 1rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--muted);
}
.meta strong { color: var(--ink); }

.prose h2 {
  margin: 2.6rem 0 0.7rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}
.prose h2:first-child { margin-top: 0; }
.prose h3 {
  margin: 1.6rem 0 0.5rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
}
.prose p, .prose li { color: var(--ink-2); }
.prose ul, .prose ol { padding-left: 1.2rem; }
.prose li + li { margin-top: 0.3rem; }

.toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.85rem;
  margin: 0 0 1.75rem;
  padding: 0.85rem 1rem;
  background: #fff;
  border-left: 4px solid var(--orange);
  font-family: var(--font-mono);
  font-size: 0.74rem;
}
.toc a {
  text-decoration: none;
  color: var(--ink);
  border-bottom: 1px solid transparent;
}
.toc a:hover { border-bottom-color: var(--orange); color: var(--orange-2); }

.table-wrap {
  margin: 1rem 0 1.4rem;
  overflow-x: auto;
  border: 2px solid var(--ink);
  background: #fff;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  line-height: 1.4;
}
table.data th,
table.data td {
  padding: 0.5rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: #eef0f5;
  white-space: nowrap;
}
table.data td:first-child,
table.data th:first-child {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: nowrap;
}
table.data tr:last-child td { border-bottom: none; }
table.data.compact td, table.data.compact th { padding: 0.4rem 0.55rem; }
table.data .op { font-family: var(--font-mono); font-weight: 700; color: var(--orange-2); }

.note {
  margin: 1rem 0 1.25rem;
  padding: 0.8rem 0.95rem;
  background: var(--warn);
  border: 1px solid var(--warn-line);
  color: var(--ink-2);
  font-size: 0.93rem;
}
.note strong { color: var(--ink); }

.hex {
  margin: 1rem 0 1.35rem;
  padding: 0.95rem 1.05rem;
  background: var(--rail);
  color: #d5dbe6;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.75;
  overflow-x: auto;
  white-space: pre;
}
.hex .c { color: #7f8a9c; }
.hex .a { color: #7aa2ff; }
.hex .v { color: #ff9a4a; }
.hex .s { color: #6ee7b7; }

.bytemap {
  margin: 1rem 0 1.4rem;
  border: 2px solid var(--ink);
  background: #fff;
}
.bytemap__bar {
  display: flex;
  height: 2.4rem;
  border-bottom: 2px solid var(--ink);
}
.bytemap__seg {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  min-width: 0;
  padding: 0 0.2rem;
  overflow: hidden;
  white-space: nowrap;
}
.bytemap__legend {
  display: grid;
  gap: 0.35rem;
  padding: 0.75rem 0.9rem;
  font-size: 0.86rem;
}
.bytemap__legend div {
  display: grid;
  grid-template-columns: 0.75rem 4.5rem 1fr;
  gap: 0.55rem;
  align-items: start;
}
.bytemap__sw {
  width: 0.75rem;
  height: 0.75rem;
  margin-top: 0.25rem;
}
.bytemap__legend code { font-size: 0.8em; }
.bm-a { background: #2563eb; }
.bm-b { background: #ff5c00; }
.bm-c { background: #0f8a5f; }
.bm-d { background: #c81e1e; }
.bm-e { background: #7c3aed; }
.bm-f { background: #0f766e; }
.bm-g { background: #334155; }

.callout-grid {
  display: grid;
  gap: 0.85rem;
  margin: 1.25rem 0;
}
@media (min-width: 700px) {
  .callout-grid { grid-template-columns: 1fr 1fr; }
}
.callout {
  border: 2px solid var(--ink);
  background: #fff;
  padding: 0.95rem 1rem;
}
.callout h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 800;
}
.callout p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.figure {
  margin: 1.25rem 0 1.6rem;
  border: 2px solid var(--ink);
  background: #0a0c10;
  overflow: hidden;
}
.figure img {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
  background: #0a0c10;
}
.figure--contain {
  background: #11151c;
}
.figure--contain img {
  max-height: 420px;
  width: auto;
  max-width: 100%;
  margin: 0 auto;
  object-fit: contain;
}
.figure figcaption {
  margin: 0;
  padding: 0.7rem 0.9rem;
  background: #fff;
  border-top: 2px solid var(--ink);
  color: var(--ink-2);
  font-size: 0.88rem;
  line-height: 1.45;
}
.figure figcaption code { font-size: 0.84em; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.85rem;
  margin: 1.25rem 0 1.6rem;
}

.gallery--wide {
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
}

/* Dialogue faces ~173×151 — larger cards, natural aspect */
.gallery--faces {
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
}
.gallery--faces img {
  aspect-ratio: 173 / 151;
  min-height: 9rem;
}

/* Ultra-wide level strips (e.g. TwinWorld 5120×160) — scroll, don't squash */
.gallery--strips {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  margin: 1.25rem 0 1.6rem;
}
.gallery--strips figure {
  margin: 0;
  border: 2px solid var(--ink);
  background: #0a0c10;
  overflow: hidden;
}
.gallery--strips .strip {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0 48px,
      rgba(255,255,255,0.03) 48px 49px
    );
}
.gallery--strips img {
  display: block;
  height: 320px; /* 2× native 160 — readable on desktop */
  width: auto;
  max-width: none;
  aspect-ratio: auto;
  image-rendering: pixelated;
  background: #0a0c10;
}
.gallery--strips figcaption {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  background: #fff;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-2);
}
.gallery--strips figcaption .hint {
  color: var(--muted);
  font-weight: 400;
}
.gallery a,
.gallery figure {
  margin: 0;
  border: 2px solid var(--ink);
  background: #0a0c10;
  text-decoration: none;
  overflow: hidden;
}
.gallery img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  image-rendering: pixelated;
  display: block;
  background: #0a0c10;
}
.gallery figcaption,
.gallery .cap {
  display: block;
  padding: 0.45rem 0.55rem;
  background: #fff;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-2);
}

.manifesto {
  margin: 1.5rem 0 0;
  max-width: 46rem;
  color: var(--ink-2);
  font-size: 1.02rem;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}
.pager a {
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--orange-2);
}
.pager a:hover { color: var(--ink); }

.rail-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 45;
}

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 50;
    width: min(18.5rem, 86vw);
    transform: translateX(-105%);
    transition: transform 0.25s var(--ease);
  }
  .shell.nav-open .rail { transform: none; }
  .shell.nav-open .rail-backdrop { display: block; }
  .menu-btn { display: inline-block; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
