/* Layout: one bare CRT screen pinned to the top of the window, with a short narrative column that scrolls
   up underneath it. Single dark look by design. */
:root {
  color-scheme: dark;
  --room: #0b0b0a;
  --edge: #1f1e1b;
  --ink: #d4cfc3;
  --muted: #8a857a;
  --code: #e9e6dc;
  --accent: #ff8a42;
  --crt: #000;
  --phos: #f3f3ec;
  --phos-glow: rgba(255,255,255,.32);
  --f-screen: "VT323", ui-monospace, "Menlo", monospace;
  --f-body: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --gutter: clamp(16px, 3vw, 32px);   /* the same gap above the screen as beside it */
}
html, body { min-height: 100%; }
body { margin: 0; background: var(--room); color: var(--ink); font-family: var(--f-body); font-size: 17px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
.wrap { padding: 0 var(--gutter) 72px; }

/* The screen stays put while the story scrolls; the deck's background hides text passing behind it */
.deck { position: sticky; top: 0; z-index: 5; background: var(--room); padding-top: var(--gutter);
  /* The largest the screen could be is full width, 1200px, or tall enough to leave --story-peek of the
     story visible below (screen height is ~0.71 x width); --screen-scale shrinks that maximum */
  --story-peek: 140px;
  --screen-scale: .6;
  --screen-w: calc(var(--screen-scale) * min(100%, 1200px, calc((100dvh - var(--gutter) - var(--story-peek) - 34px) / 0.71)));
}
.deck::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 28px; pointer-events: none;
  background: linear-gradient(var(--room), transparent); }

.screen {
  position: relative; background: var(--crt); border: 1px solid var(--edge); border-radius: 14px;
  overflow: hidden; cursor: text; margin-inline: auto;
  width: var(--screen-w);
  box-shadow: 0 0 80px rgba(255,255,255,.03);
}
.screen:focus-within { border-color: #3a3832; }
.screen.drop { border-color: var(--accent); }
.raster { position: relative; margin: 3.2%; aspect-ratio: 280 / 192; background: #000; }
.raster canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
#glow { filter: blur(3px); opacity: .55; mix-blend-mode: screen; pointer-events: none; }
#txt {
  position: absolute; left: 0; bottom: 0; width: 100%; margin: 0; background: #000; color: var(--phos);
  transform-origin: left bottom; font-kerning: none; font-variant-ligatures: none;
  font-family: var(--f-screen); white-space: pre; overflow: hidden; text-shadow: 0 0 5px var(--phos-glow);
  font-size: 16px; line-height: 1;
}
.raster[data-mode="split"] #txt { height: calc(100% / 6); }
.raster[data-mode="full"] #txt { display: none; }
.raster[data-mode="text"] #txt { height: 100%; }
.raster[data-mode="text"] canvas { visibility: hidden; }
.raster.mono { --phos: #5dff86; --phos-glow: rgba(70,255,120,.5); }
.cur { background: var(--phos); color: #000; animation: blink 1s steps(1) infinite; }
/* Blinks between inverse and normal, so a character under the cursor stays readable */
@keyframes blink { 50% { background: transparent; color: var(--phos); } }
/* On phones the screen keeps the full width; a 75% screen would be too small to read */
@media (max-width: 600px) { .deck { --screen-scale: 1; } }

/* The monitor switch under the screen's right corner: color TV or green monochrome monitor */
.monitor { width: var(--screen-w); margin: 8px auto 0; display: flex; justify-content: flex-end; }
.monitor button { display: inline-flex; align-items: center; gap: 8px; font-family: var(--f-screen); font-size: 18px; letter-spacing: .1em;
  color: var(--muted); background: none; border: 1px solid var(--edge); border-radius: 6px; padding: 2px 10px; cursor: pointer; }
.monitor button:hover { border-color: #3a3832; color: var(--ink); }
.monitor button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.monitor .led { width: 7px; height: 7px; border-radius: 50%; background: #2a2a26; }
.monitor button[aria-pressed="true"] { color: var(--ink); }
.monitor button[aria-pressed="true"] .led { background: #5dff86; box-shadow: 0 0 6px rgba(93,255,134,.8); }
@media (prefers-reduced-motion: reduce) { .cur { animation: none; } }
.glass { position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background:
    repeating-linear-gradient(180deg, transparent 0 2px, rgba(0,0,0,.26) 2px 3px),
    radial-gradient(ellipse at 50% 50%, transparent 62%, rgba(0,0,0,.5) 100%); }
#kbd { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0; font-size: 16px; background: transparent; color: transparent; cursor: text; z-index: 3; }

/* The story, rendered from story/*.md. ## headings read as the dateline; a > blockquote is the italic aside */
.story { max-width: 62ch; margin: clamp(32px, 6vw, 64px) auto 0; display: grid; gap: 1.1em; }
.story { font-kerning: normal; font-variant-numeric: oldstyle-nums; font-feature-settings: "kern", "liga", "clig", "calt"; }
.story section { display: grid; gap: 1.1em; }
.story p, .story ul, .story ol, .story blockquote, .story pre { margin: 0; text-wrap: pretty; }
.story h1, .story h2, .story h3 { margin: 0; font-family: var(--f-screen); font-weight: 400; letter-spacing: .12em; color: var(--muted); line-height: 1.2; }
.story h1 { font-size: 28px; color: var(--ink); }
.story h2 { font-size: 20px; }
.story h3 { font-size: 18px; color: var(--ink); }
.story ul, .story ol { padding-left: 1.4em; }
.story hr { width: 100%; border: 0; border-top: 1px solid var(--edge); margin: .4em 0; }
.story blockquote { color: var(--muted); font-style: italic; display: grid; gap: 1.1em; }
.story code { font-family: var(--f-screen); font-size: 1.2em; color: var(--code); letter-spacing: .02em; font-style: normal; }
.story pre { background: #000; border: 1px solid var(--edge); border-radius: 8px; padding: 12px 14px; overflow-x: auto; }
.story pre code { font-size: 18px; line-height: 1.2; opacity: .6; }
.story pre { cursor: pointer; }
.story pre:hover { border-color: var(--accent); }
.story a { color: var(--accent); font-style: normal; text-decoration: underline; text-underline-offset: 3px; }
/* Pager: one story page at a time */
/* Sized in the story's font so it lines up with the text column; its contents use the screen font */
.pager { max-width: 62ch; margin: 2.2em auto 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.pager > * { font-family: var(--f-screen); font-size: 20px; letter-spacing: .08em; color: var(--muted); }
.pager[hidden] { display: none; }
.pager button { color: var(--accent); background: none; border: 1px solid var(--edge); border-radius: 6px;
  padding: 4px 12px; cursor: pointer; min-width: 7.5em; }
.pager button:hover { border-color: var(--accent); }
.pager button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pager .next { text-align: right; }
/* On the first and last pages the lone button sits centered under the page number */
.pager.single { flex-direction: column; gap: 10px; }
.pager.single #pageno { order: -1; }
.pager.single .next { text-align: center; }
.story a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
#probe { position: absolute; left: -9999px; top: 0; visibility: hidden; white-space: pre; font-family: var(--f-screen); }

/* Everything but the screen stays hidden while DREAMS draws on page load, then fades in */
.monitor, .story, .pager, .power { transition: opacity 1.6s ease, visibility 1.6s; }
.pager, .power { transition-delay: 1.4s; }
.intro .monitor, .intro .story, .intro .pager, .intro .power { opacity: 0; visibility: hidden; }
@media (prefers-reduced-motion: reduce) { .monitor, .story, .pager, .power { transition: none; } }

/* The power button on the last page, and the TV switch-off: the picture collapses to a bright line,
   the line to a dot, and the dot fades out */
.power { max-width: 62ch; margin: 2.4em auto 0; display: flex; justify-content: center; }
.power[hidden] { display: none; }
.power button { display: inline-flex; align-items: center; gap: 10px; font-family: var(--f-screen); font-size: 20px; letter-spacing: .1em;
  color: var(--muted); background: none; border: 1px solid var(--edge); border-radius: 6px; padding: 6px 14px; cursor: pointer; }
.power button:hover { border-color: var(--accent); color: var(--ink); }
.power button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.power .led { width: 7px; height: 7px; border-radius: 50%; background: #2a2a26; }
.power button[aria-pressed="true"] .led { background: #ff5a3c; box-shadow: 0 0 6px rgba(255,90,60,.8); }
.wrap { position: relative; --line: .006; --dot: .006; }
.wrap::after { content: ""; position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 10; }
body.tv-off { background: #000; overflow: hidden; }
.tv-off .wrap { animation: crt-off .7s cubic-bezier(.6,0,.4,1) forwards; pointer-events: none; }
.tv-off .wrap::after { animation: crt-flash .7s forwards; }
@keyframes crt-off {
  0% { transform: scale(1, 1); opacity: 1; }
  45% { transform: scale(1, var(--line)); opacity: 1; }
  75% { transform: scale(var(--dot), var(--line)); opacity: 1; }
  100% { transform: scale(0, 0); opacity: 0; }
}
@keyframes crt-flash { 0% { opacity: 0; } 40%, 100% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .tv-off .wrap { animation: none; opacity: 0; transition: opacity .4s; }
  .tv-off .wrap::after { animation: none; }
}
