/* Infinite Lives Glitch. One room at night, one television, one cartridge.
   Faces: Press Start 2P (the name, the counter, big numbers, section titles) / Figtree (everything else) /
   IBM Plex Mono (addresses, signatures, bytes only). Spacing scale 8 16 24 32 48 64 96. */
@font-face { font-family: "Press Start 2P"; src: url("/fonts/press-start-2p.woff2") format("woff2"); font-display: block; }
@font-face { font-family: "Figtree"; src: url("/fonts/figtree-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("/fonts/figtree-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("/fonts/figtree-800.woff2") format("woff2"); font-weight: 800; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("/fonts/plex-mono-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }

:root {
  --night: #0F0F1E; --wall: #1C1B33; --stone: #3A3A55; --plastic: #9A9AA5; --light: #D8D8E0; --white: #F4F4F8;
  --red: #E43B44; --yellow: #F7E26B; --green: #3CA370; --cyan: #2CE8F5; --rug: #5B3A5E; --cream: #F4EBD0;
  --pix: "Press Start 2P", monospace; --sans: "Figtree", system-ui, sans-serif; --mono: "Plex Mono", ui-monospace, monospace;
  --container: min(1640px, calc(100vw - 48px)); --u: 4px;
  /* first-paint sizes; js/home.js replaces them with whole device-pixel multiples */
  --tv-w: min(688px, calc(100vw - 32px)); --tv-h: calc(var(--tv-w) * 0.814); --win-x: 5.8%; --win-y: 14.3%; --win-w: 72%; --win-h: 68.6%;
  --game-w: 66%; --game-h: auto; --cart-w: min(344px, calc(100vw - 32px)); --cart-h: calc(var(--cart-w) * 1.105);
  --lab-x: 7%; --lab-y: 13.7%; --lab-w: 86%; --lab-h: 55.8%; --st-y: 72.6%; --name: 32px;
}
* { box-sizing: border-box; }
html { background: var(--wall); color: var(--white); -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 16px/1.6 var(--sans); font-variant-numeric: tabular-nums; min-height: 100vh; overflow-x: hidden; }
img, canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
a { color: var(--yellow); text-underline-offset: 3px; }
a:focus-visible, button:focus-visible, canvas:focus-visible, input:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
h1, h2, h3 { margin: 0; font-weight: 400; }
b, strong { font-weight: 800; }
button { font: inherit; cursor: pointer; }
.center { text-align: center; }

/* ---- the room behind the first screen, at a whole device-pixel scale (js/common.js sets the size) ---- */
.room-bg {
  position: absolute; inset: 0 0 auto 0; height: max(100svh, 640px); z-index: -1; overflow: hidden;
  background: url("/img/room-wide.png") center bottom / var(--bg-w, cover) var(--bg-h, auto) no-repeat, var(--wall);
}
.room-bg[data-v="tall"] { background-image: url("/img/room-tall.png"); }


/* ---- nav: one short row, top left ---- */
.nav { position: relative; z-index: 3; max-width: var(--container); margin: 0 auto; padding: 16px 24px 0; display: flex; align-items: center; min-height: 56px; }
.nav-list { display: flex; gap: 8px; margin-left: -16px; } /* the link text sits on the content's left edge */
.nav-list a {
  color: var(--white); text-decoration: none; font-weight: 600; font-size: 16px; padding: 12px 16px; min-height: 48px;
  display: inline-flex; align-items: center; border-bottom: 3px solid transparent;
}
.nav-list a:hover { color: var(--yellow); }
.nav-list a[aria-current="page"] { border-bottom-color: var(--yellow); }
.nav-menu { display: none; }

/* ---- first screen: the television left, the cartridge right ---- */
.stage {
  max-width: var(--container); margin: 0 auto; padding: 8px 24px 0; min-height: calc(max(100svh, 640px) - 72px);
  display: grid; grid-template-columns: auto auto; justify-content: space-between; align-items: end; gap: 32px;
}
.tv-col { display: flex; flex-direction: column; align-items: center; gap: 16px; padding-bottom: 24px; }
.tv { position: relative; width: var(--tv-w); height: var(--tv-h); }
.tv-body { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.screen {
  position: absolute; left: var(--win-x); top: var(--win-y); width: var(--win-w); height: var(--win-h); background: #000;
  display: grid; place-items: center; overflow: hidden;
}
.screen canvas { width: var(--game-w); height: var(--game-h); display: block; outline: none; }
.tv.shake { animation: shake 420ms steps(1) 1; }
@keyframes shake {
  0% { transform: translate(0, 0); } 15% { transform: translate(calc(var(--u) * -2), var(--u)); } 30% { transform: translate(calc(var(--u) * 2), calc(var(--u) * -1)); }
  45% { transform: translate(calc(var(--u) * -1), calc(var(--u) * 2)); } 60% { transform: translate(var(--u), 0); } 75% { transform: translate(calc(var(--u) * -1), calc(var(--u) * -1)); } 100% { transform: translate(0, 0); }
}

.under { display: flex; align-items: center; gap: 24px; width: var(--tv-w); justify-content: space-between; }
.meter { display: flex; flex-direction: column; gap: 12px; min-width: 0; flex: 0 1 auto; }
.count { margin: 0; font: 24px/1 var(--pix); color: var(--white); white-space: nowrap; }
.count b { color: var(--yellow); font-weight: 400; }
.bar { position: relative; height: 16px; background: var(--night); border: 3px solid var(--light); max-width: 360px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--yellow); }
.bar::after { /* the crash line: 40% is the end of the bar */
  content: ""; position: absolute; right: -3px; top: -9px; bottom: -9px; width: 3px; background: var(--red);
}
.bar input { position: absolute; inset: -12px 0; width: 100%; height: 40px; margin: 0; opacity: 0; cursor: ew-resize; }
.bar input:disabled { display: none; }
.bar:focus-within { outline: 3px solid var(--cyan); outline-offset: 3px; }

.blow, .key, .ca-copy, .more-btn {
  font: 800 16px/1 var(--sans); color: var(--night); background: var(--yellow); border: 3px solid var(--night);
  box-shadow: 0 6px 0 var(--night); padding: 0 24px; min-height: 52px; border-radius: 0; white-space: nowrap;
  transition: transform 80ms steps(1), box-shadow 80ms steps(1);
}
.blow:hover, .key:hover, .ca-copy:hover:not(:disabled) { background: #FFF08A; }
.blow:active, .key:active, .key.on, .ca-copy:active:not(:disabled) { transform: translateY(6px); box-shadow: 0 0 0 var(--night); }

.status { margin: 0; width: var(--cart-w); font-size: 16px; line-height: 1.5; color: var(--light); min-height: 72px; }
.status .tag { margin-right: 8px; }
.status code { font: 500 16px var(--mono); color: var(--white); }
.tag { display: inline-block; font: 600 16px/1.25 var(--sans); vertical-align: 1px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--night); background: var(--cyan); padding: 8px 16px; }
.tag.live { background: var(--green); }
.tag.archive { background: var(--plastic); }

.pad { display: none; gap: 12px; width: var(--tv-w); }
.pad .key { flex: 1 1 0; min-width: 0; padding: 0 16px; background: var(--light); }
.tv-col > *, .cart-col > * { max-width: 100%; }

/* the cartridge: name on its paper label, the links as stickers on its body */
.cart-col { display: flex; flex-direction: column; align-items: center; gap: 24px; padding-bottom: 24px; }
.cart { position: relative; width: var(--cart-w); height: var(--cart-h); }
.cart-body { position: absolute; inset: 0; width: 100%; height: 100%; }
.label {
  position: absolute; left: var(--lab-x); top: var(--lab-y); width: var(--lab-w); height: var(--lab-h);
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: calc(var(--name) * 0.38);
  padding: 0 calc(var(--name) * 0.5); color: var(--night); font: var(--name)/1 var(--pix);
}
.label span { display: block; }
.stickers { position: absolute; left: var(--lab-x); width: var(--lab-w); top: var(--st-y); display: flex; gap: 12px; justify-content: space-between; }
.sticker {
  flex: 1 1 0; min-width: 0; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 16px; white-space: nowrap;
  font: 800 16px/1 var(--sans); color: var(--night); text-decoration: none; border: 3px solid var(--night); cursor: pointer;
}
.sticker img { width: 18px; height: 18px; image-rendering: auto; flex: none; }
.s-pump { background: #9BE38F; flex-grow: 1.9; } .s-x { background: var(--white); flex-grow: 0.6; } .s-ca { background: var(--cyan); flex-grow: 0.8; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sticker:hover { filter: brightness(1.08); }
.sticker[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

.contract {
  width: var(--cart-w); display: flex; align-items: center; gap: 16px; padding: 8px 8px 8px 24px; min-height: 68px;
  background: var(--night); border: 3px solid var(--light);
}
.contract.flash { animation: flash 900ms steps(2) 2; }
@keyframes flash { 50% { border-color: var(--cyan); } }
.ca-label { font: 600 16px var(--sans); color: var(--plastic); }
.ca-addr { flex: 1; min-width: 0; font: 500 16px/1.3 var(--mono); color: var(--white); overflow-wrap: anywhere; user-select: all; }
.ca-addr.ca-wait { font: 400 16px/1.3 var(--sans); color: var(--light); user-select: text; }
.ca-copy { min-height: 48px; padding: 0 24px; box-shadow: 0 4px 0 var(--stone); }
.ca-copy:disabled { background: var(--stone); color: var(--plastic); box-shadow: none; cursor: not-allowed; }
.ca-copy.done { background: var(--green); }

/* ---- sections below: more of the room at night ---- */
.band { padding: 48px 24px 0; }
.band:last-of-type { padding-bottom: 48px; }
.wrap { max-width: min(1240px, 100%); margin: 0 auto; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; align-items: stretch; }
.panel { background: rgba(15, 15, 30, 0.92); border: 3px solid var(--plastic); box-shadow: 8px 8px 0 var(--night); padding: 32px; }
h2 { font: 24px/1.3 var(--pix); color: var(--white); margin-bottom: 16px; }
h3 { font: 800 20px/1.3 var(--sans); }
.lede { margin: 0 0 24px; color: var(--light); max-width: 56ch; }
.map-panel #map { width: calc(64px * var(--map-k, 4)); height: calc(64px * var(--map-k, 4)); max-width: 100%; display: block; background: var(--night); }
.legend { list-style: none; padding: 0; margin: 24px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; font-size: 16px; color: var(--light); }
.legend i { display: inline-block; width: 16px; height: 16px; margin-right: 8px; vertical-align: -2px; }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 64px 1fr auto; gap: 4px 16px; padding: 12px 16px; border-top: 1px solid rgba(216, 216, 224, 0.16); font-size: 16px; }
.feed li:first-child { border-top: 0; }
.feed .n { font: 16px/1.5 var(--pix); color: var(--plastic); }
.feed .what { color: var(--white); }
.feed .where { color: var(--light); font-size: 16px; grid-column: 2; }
.feed .bytes { font: 500 16px var(--mono); color: var(--white); text-align: right; white-space: nowrap; }
.feed .bytes .to { color: var(--yellow); }
.feed .sol { color: var(--light); font-size: 16px; text-align: right; }
.feed .sol a { color: var(--light); }
.feed li.blink { animation: blink 1.2s steps(2) 3; }
@keyframes blink { 50% { background: rgba(247, 226, 107, 0.16); } }
.feed li.crash .what { color: var(--red); }
.more { display: inline-block; margin-top: 24px; font-weight: 600; }

.steps { list-style: none; padding: 0; margin: 48px 0 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 24px; counter-reset: s; }
.steps li { background: rgba(15, 15, 30, 0.92); border: 3px solid var(--plastic); box-shadow: 8px 8px 0 var(--night); padding: 32px 24px; text-align: center; }
.steps img { width: 160px; height: 160px; margin: 0 auto 16px; display: block; }
.steps h3 { margin-bottom: 8px; }
.steps p { margin: 0; color: var(--light); }

.error-line { color: var(--red); font-size: 16px; margin: 0; }

.wordmark { display: none; }

/* ---- phone ---- */
@media (max-width: 899px) {
  body { font-size: 16px; }
  .nav { padding: 12px 16px 0; justify-content: flex-end; }
  .nav-menu { display: inline-flex; align-items: center; min-height: 48px; padding: 0 24px; background: var(--night); color: var(--white); border: 3px solid var(--light); font-weight: 800; }
  .nav-list { display: none; position: absolute; right: 16px; top: 68px; flex-direction: column; background: var(--night); border: 3px solid var(--light); padding: 8px; min-width: 200px; z-index: 5; }
  .nav-list.open { display: flex; }
  .stage { max-width: none; grid-template-columns: minmax(0, 1fr); justify-items: center; padding: 8px 16px 0; gap: 16px; min-height: 0; }
  .wordmark { display: flex; flex-direction: column; gap: 16px; margin: 8px 0; align-self: stretch; font: 40px/1 var(--pix); color: var(--white); text-shadow: 4px 4px 0 var(--night); }
  .cart-col { gap: 16px; padding: 24px 0 0; }
  .tv-col { padding-bottom: 0; }
  .pad { display: flex; width: 100%; }
  .under { flex-direction: column; align-items: stretch; gap: 16px; width: 100%; }
  .tv-col { align-self: stretch; justify-self: stretch; width: 100%; }
  /* phone: the stickers sit in one row right under the cartridge, the full width of the column */
  .cart { height: auto; }
  .cart-body { position: relative; display: block; height: var(--cart-h); }
  .stickers { position: static; width: 100%; gap: 8px; margin-top: 12px; }
  .feed .bytes { white-space: normal; }
  .panel { padding: 24px; }
  .count { font-size: 24px; }
  .bar { max-width: none; }
  .blow { width: 100%; }
  .stickers { gap: 8px; }
  .sticker { padding: 0 16px; font-size: 16px; gap: 4px; }
  .contract { width: min(var(--cart-w), calc(100vw - 32px)); padding-left: 16px; }
  .band { padding: 48px 16px 0; }
  .two { grid-template-columns: minmax(0, 1fr); }
  .panel { padding: 24px 16px; }
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .steps li { padding: 24px 16px; min-width: 0; }
  .steps img, .steps-doc img { width: 120px; height: 120px; }
  .panel { padding: 24px; }
  .feed li { padding: 12px 16px; }
  .feed li { grid-template-columns: 48px 1fr; }
  .feed .bytes, .feed .sol { grid-column: 2; text-align: left; }
}
@media (max-width: 360px) { .steps { grid-template-columns: minmax(0, 1fr); } .sticker { font-size: 16px; padding: 0 16px; gap: 4px; } .stickers { gap: 8px; } .stickers .s-x, .stickers .s-ca { flex: 0 0 58px; padding: 0; } }

@media (prefers-reduced-motion: reduce) {
  .tv.shake, .feed li.blink, .contract.flash { animation: none; }
}

/* ---- inner pages: Feed, Archive, Docs ---- */
.page { padding: 32px 24px 48px; }
.narrow { max-width: min(1240px, 100%); }
body.sub .nav { max-width: calc(1240px + 48px); }
.page-head { margin-bottom: 32px; }
.page-title { font: 48px/1.15 var(--pix); color: var(--white); text-shadow: 6px 6px 0 var(--night); margin-bottom: 24px; }
.page-head .lede { font-size: 20px; }
.revs, .toc { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.revs a, .toc a {
  display: inline-flex; align-items: center; min-height: 48px; padding: 0 16px; background: var(--night); color: var(--white);
  border: 3px solid var(--plastic); text-decoration: none; font-weight: 600; font-size: 16px;
}
.revs a[aria-current="page"] { background: var(--yellow); color: var(--night); border-color: var(--night); }
.revs a:hover, .toc a:hover { border-color: var(--yellow); }
.ledger { width: 100%; border-collapse: collapse; font-size: 16px; }
.ledger th { text-align: left; font: 600 16px var(--sans); color: var(--plastic); padding: 0 24px 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.ledger td { padding: 12px 24px; border-top: 1px solid rgba(216, 216, 224, 0.16); vertical-align: top; }
.ledger td.n { font: 16px/1.5 var(--pix); color: var(--plastic); }
.ledger code { font: 500 16px var(--mono); color: var(--white); }
.ledger code.to { color: var(--yellow); }
.ledger .empty { color: var(--light); text-align: center; padding: 32px; }
.panel .ledger { margin: -12px 0 0; }
.panel { overflow-x: auto; }

.archive-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 32px; align-items: center; }
.box { width: var(--box-w, 528px); height: var(--box-h, 216px); max-width: 100%; display: block; justify-self: end; margin-right: 24px; }
@media (max-width: 899px) { .box { justify-self: start; margin: 0; } }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 760px), 1fr)); gap: 32px; }
.card { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 24px; background: rgba(15, 15, 30, 0.92); border: 3px solid var(--plastic); box-shadow: 8px 8px 0 var(--night); padding: 24px; }
.shot { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.shot-glass { position: relative; padding: 12px; background: var(--night); border: 3px solid var(--plastic); border-radius: 16px; box-shadow: inset 0 0 0 3px #000; }
.shot-glass::after { /* light scan lines, the TV's own glass */
  content: ""; position: absolute; inset: 12px; pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, 0.22) 2px 4px); }
.card .frame { display: block; width: var(--frame-w, 320px); height: var(--frame-h, 240px); object-fit: contain; background: #000; image-rendering: pixelated; }
.shot figcaption { font: 600 16px/1.25 var(--sans); color: var(--light); text-align: center; }
.card h2 { font-size: 24px; margin-bottom: 16px; }
.card .tag, .page-head .tag { margin-bottom: 12px; }
.recorded-note { margin: 0; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; color: var(--light); font-size: 16px; }
.card p { margin: 0 0 12px; color: var(--light); }
.card b { color: var(--white); }
.card .memo code { font: 500 16px var(--mono); color: var(--cyan); overflow-wrap: anywhere; }
.card-links { display: flex; gap: 12px; flex-wrap: wrap; }
.card-links .sticker { flex: 0 0 auto; min-height: 48px; padding: 0 24px; font-size: 16px; }
.small { font-size: 16px; }
.small code { font: 500 16px var(--mono); }

.doc { margin-bottom: 48px; }
.doc h2 { margin-bottom: 24px; }
.doc p { color: var(--light); max-width: 72ch; }
.doc p b, .doc p code { color: var(--white); }
.doc code { font: 500 16px var(--mono); }
.doc pre { background: var(--night); border: 3px solid var(--plastic); padding: 24px; overflow-x: auto; margin: 24px 0; }
.doc pre code { font: 500 16px/1.6 var(--mono); color: var(--yellow); }
.steps-doc { margin-top: 0; }
.steps-doc img { width: 160px; height: 160px; }
.map-table { margin: 24px 0; background: rgba(15, 15, 30, 0.92); border: 3px solid var(--plastic); }
.map-table th { padding-top: 16px; }
.split { margin: 24px 0; max-width: 640px; background: rgba(15, 15, 30, 0.92); border: 3px solid var(--plastic); }
.split td:first-child { width: 96px; font: 24px/1.4 var(--pix); color: var(--yellow); }
.split td b { font-weight: 400; }

/* ---- 404 ---- */
.lost { min-height: calc(max(100svh, 640px) - 72px); display: grid; place-items: center; align-content: center; gap: 24px; padding: 24px; text-align: center; }
.lost h1 { font: 40px/1.2 var(--pix); text-shadow: 6px 6px 0 var(--night); }
.lost p { margin: 0; color: var(--light); font-size: 20px; }

@media (max-width: 899px) {
  .page { padding: 24px 16px 48px; }
  .page-title { font-size: 32px; }
  .archive-head { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .card-links .sticker { padding: 0 16px; }
  .shot { align-self: start; }
  .ledger { font-size: 16px; }
  .lost h1 { font-size: 24px; }
}
@media (max-width: 899px) { .doc pre code { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; } .doc pre { padding: 24px; } }

/* the pixel face only at multiples of 8 px: its glyphs are drawn on an 8 x 8 grid */
@media (max-width: 419px) { .count { font-size: 16px; } }
@media (max-width: 360px) { .wordmark { font-size: 32px; } .pad { gap: 8px; } }
.lede, .doc p { font-size: 20px; }
.doc p { font-size: 16px; }
.doc .lede { font-size: 20px; }
/* links: hover, press, keyboard */
a { transition: color 80ms steps(1); }
a:hover { color: #FFF3A6; text-decoration-thickness: 2px; }
a:active { color: var(--white); }
a:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
/* the room ends on purpose: the rug fades into the night wall in four hard steps */
.room-bg::after { content: ""; position: absolute; inset: auto 0 0 0; height: 96px;
  background: linear-gradient(to bottom, transparent 0 25%, rgba(28, 27, 51, 0.4) 25% 50%, rgba(28, 27, 51, 0.7) 50% 75%, var(--wall) 75% 100%); }
[hidden] { display: none !important; }
@media (max-width: 699px) { .card { grid-template-columns: minmax(0, 1fr); } .shot { align-self: center; } }
.recorded-note .tag { margin: 0; }
.recorded-note > span:last-child { flex: 1 1 280px; min-width: 0; }
.shot { align-items: center; }
.shot-glass { width: fit-content; }
.room-bg[data-v="wide-left"] { background-position: var(--bg-x, 0) bottom; }
