:root {
  --ink: #070914;
  --paper: #eee1cf;
  --muted: #aaa0a9;
  --code: #b2ff78;
  --design: #66a6ff;
  --explore: #ff9560;
  --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --display: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; overflow: hidden; color: var(--paper); background: var(--ink); font-family: var(--mono); }
button { font: inherit; }
.app, #scene { width: 100%; height: 100svh; display: block; }
#scene { cursor: crosshair; touch-action: none; }

.hud { position: fixed; z-index: 2; pointer-events: none; text-shadow: 0 2px 18px rgba(0,0,0,.9); }
.hud-top { position: fixed; z-index: 10; display: flex; justify-content: space-between; align-items: center; top: clamp(18px, 3vw, 42px); left: clamp(20px, 4vw, 64px); right: clamp(20px, 4vw, 64px); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.brand, .system { margin: 0; }
.brand { font-weight: 800; font-size: 11px; letter-spacing: .14em; }
.brand span, .system { color: var(--muted); }
.top-controls { display: flex; align-items: center; gap: 16px; pointer-events: auto; }

.audio-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 20, 36, 0.65);
  border: 1px solid rgba(238, 225, 207, 0.2);
  color: var(--paper);
  padding: 6px 12px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .1em;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all .25s ease;
}
.audio-toggle:hover {
  border-color: rgba(238, 225, 207, 0.5);
  background: rgba(25, 34, 58, 0.85);
  color: #fff;
}
.audio-toggle.is-playing {
  border-color: var(--code);
  color: var(--code);
  background: rgba(178, 255, 120, 0.12);
  box-shadow: 0 0 14px rgba(178, 255, 120, 0.2);
}

.sound-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 10px;
}
.sound-bars .bar {
  display: block;
  width: 2px;
  height: 4px;
  background: currentColor;
  border-radius: 1px;
  transition: height .2s ease;
}
.audio-toggle.is-playing .sound-bars .bar:nth-child(1) { animation: soundBar 0.8s ease-in-out infinite alternate; }
.audio-toggle.is-playing .sound-bars .bar:nth-child(2) { animation: soundBar 1.1s ease-in-out infinite 0.2s alternate; }
.audio-toggle.is-playing .sound-bars .bar:nth-child(3) { animation: soundBar 0.7s ease-in-out infinite 0.4s alternate; }
.audio-toggle.is-playing .sound-bars .bar:nth-child(4) { animation: soundBar 0.9s ease-in-out infinite 0.1s alternate; }

@keyframes soundBar {
  0% { height: 3px; }
  100% { height: 11px; }
}

.system { display: flex; align-items: center; gap: 9px; }
.system i { width: 7px; height: 7px; border-radius: 50%; background: var(--code); box-shadow: 0 0 12px var(--code); }
.intro { top: 50%; left: clamp(20px, 7vw, 125px); transform: translateY(-50%); transition: opacity .35s ease, transform .5s ease; }
.kicker { margin: 0 0 13px; color: var(--muted); font-size: 10px; letter-spacing: .13em; text-transform: uppercase; }
h1 { max-width: 450px; margin: 0 0 16px; font: 400 clamp(3.6rem, 6.5vw, 7.8rem)/.82 var(--display); letter-spacing: -.04em; text-transform: uppercase; }
.intro > p:last-child { margin: 0; color: #d0c5bb; font-size: 11px; line-height: 1.65; }
.monitor-ui { display: flex; gap: 7px; left: 50%; bottom: clamp(20px, 3vw, 46px); transform: translateX(-50%); pointer-events: auto; }
.world-button { border: 1px solid rgba(238,225,207,.28); padding: 10px 14px; color: var(--paper); background: rgba(7,9,20,.42); backdrop-filter: blur(8px); cursor: pointer; font-size: 10px; letter-spacing: .07em; text-transform: uppercase; transition: background .25s ease, color .25s ease, border-color .25s ease; }
.world-button span { margin-right: 6px; color: var(--muted); }
.world-button.code:hover, .world-button.code.active { color: var(--code); border-color: var(--code); background: rgba(178,255,120,.1); }
.world-button.design:hover, .world-button.design.active { color: var(--design); border-color: var(--design); background: rgba(102,166,255,.1); }
.world-button.explore:hover, .world-button.explore.active { color: var(--explore); border-color: var(--explore); background: rgba(255,149,96,.1); }
.cursor-note { right: clamp(20px, 4vw, 64px); bottom: clamp(20px, 3vw, 46px); margin: 0; color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; transition: opacity .25s ease; }
.cursor-note span { color: var(--paper); font-size: 16px; vertical-align: -1px; }
body.is-hovering .intro, body.is-hovering .cursor-note { opacity: 0; }
body.is-hovering .intro { transform: translateY(-50%) translateX(-12px); }

.world-view { position: fixed; inset: 0; z-index: 5; display: grid; align-content: center; justify-items: center; gap: 14px; color: var(--world); background: var(--world-bg); text-align: center; opacity: 0; transform: scale(.95); transition: opacity .48s cubic-bezier(.16, 1, 0.3, 1), transform .55s cubic-bezier(.16, 1, 0.3, 1); }
.world-view[hidden] { display: none; }
.world-view.visible { opacity: 1; transform: scale(1); }
.world-view p { margin: 0; font-size: 10px; letter-spacing: .13em; text-transform: uppercase; }
.world-view h2 { margin: 0; font: 400 clamp(6rem, 18vw, 17rem)/.76 var(--display); letter-spacing: -.04em; text-transform: uppercase; }
.world-view span { color: color-mix(in srgb, var(--world) 60%, white); font-size: 12px; }
.world-view[data-world-view="code"] { --world: var(--code); --world-bg: #061108; }
.world-view[data-world-view="design"] { --world: var(--design); --world-bg: #050817; }
.world-view[data-world-view="explore"] { --world: var(--explore); --world-bg: #180906; }
.back-button { margin-top: 20px; border: 1px solid var(--world); padding: 11px 15px; background: transparent; color: var(--world); cursor: pointer; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }
.back-button:hover, .back-button:focus-visible { color: var(--ink); background: var(--world); }

/* --- BOOT ------------------------------------------------------------------
   The room is ~2,700 lines of geometry and a stack of procedurally drawn
   canvases; it cannot appear instantly, and showing the HUD over an empty
   canvas while it builds looked broken. So the wait is dressed as the thing
   the room is about: a CRT warming up.

   Every animation below is transform/opacity only. That matters — those run on
   the compositor, so this keeps moving smoothly through the long synchronous
   block that builds the scene, which a width or colour animation would not. */
.boot-room {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--paper);
  transition: opacity .5s ease, visibility .5s;
}
body.booted .boot-room { opacity: 0; visibility: hidden; }

.boot-room-inner { display: grid; justify-items: center; gap: 14px; text-align: center; }
.boot-brand { margin: 0; font-size: 10px; letter-spacing: .3em; color: var(--muted); }
.boot-title {
  margin: 0;
  font: 400 clamp(2.6rem, 7vw, 5rem)/.9 var(--display);
  letter-spacing: -.03em;
  text-transform: uppercase;
}
/* The tube: a thin scan bar sweeping a dark groove. Indeterminate on purpose —
   a percentage would be a lie, since the browser cannot report progress
   through synchronous work. */
.boot-tube {
  position: relative;
  width: min(240px, 52vw);
  height: 3px;
  margin-top: 6px;
  overflow: hidden;
  background: rgba(238, 225, 207, .12);
}
.boot-tube i {
  position: absolute;
  inset: 0;
  width: 38%;
  background: var(--code);
  box-shadow: 0 0 12px var(--code);
  transform: translateX(-110%);
  animation: bootSweep 1.15s cubic-bezier(.6, 0, .35, 1) infinite;
}
@keyframes bootSweep {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(370%); }
}
.boot-status {
  margin: 0;
  font-size: 9.5px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--muted);
  animation: bootPulse 1.8s ease-in-out infinite;
}
@keyframes bootPulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }

/* HUD is held back until the room is actually behind it, then crossfaded with
   the wipe — no delay, or it reads as text arriving late rather than as a
   reveal. Matches the .boot-room fade so the two happen as one gesture. */
body.booting .hud { opacity: 0; }
.hud { transition: opacity .5s ease; }
body.booting .intro { transform: translateY(-50%) translateX(-18px); }

/* Hand-off flood for worlds that navigate to a page of their own.

   The monitor's own colour blooms up to fill the frame, then blows out like a
   camera losing its exposure: the phosphor washes hot, overshoots past pure
   white, holds for a beat, and settles back down onto the destination page's
   exact background. That settle is what sells it — an exposure recovering,
   not a colour being swapped — and it means the document swap happens between
   two frames of identical colour instead of cutting to a white page.

   Nothing moves geometrically. It is entirely brightness. */
.screen-flood {
  position: fixed;
  inset: 0;
  z-index: 40;
  background-color: var(--flood, var(--code));
  opacity: 0;
  transform: scale(1.06);
  pointer-events: none;
  /* background-color is deliberately NOT transitioned — the blow-out drives it
     from JS, and a transition on the same property would race it for control.

     The opacity curve must be ease-OUT. It was cubic-bezier(.7,0,.84,0), an
     extreme ease-in that holds opacity near zero for almost the whole
     transition and then snaps up at the end. Measured on the deployed site,
     the flood was still at opacity 0 at 667ms and 0.06 at 754ms — so the green
     stage of the blow-out was being drawn onto an invisible element, and all
     anyone saw was a white flash. The ramp was never the problem; nothing was
     on screen to show it. */
  transition: opacity .16s ease-out, transform .16s ease-out;
}
.screen-flood.active { opacity: 1; transform: scale(1); }

/* The blow-out itself is driven from app.js via the Web Animations API, with
   literal colour values resolved at runtime. It was originally a @keyframes
   rule whose midpoint used color-mix() through a custom property — which
   worked in Chrome and silently produced no ramp at all in Edge, because a
   var() that fails to resolve inside a keyframe takes the whole declaration
   with it. Keyframes get no custom properties now; nothing to fail to
   resolve, and the same code path runs in every browser. */

@media (max-width: 700px) {
  .intro { top: auto; bottom: 103px; left: 22px; transform: none; }
  h1 { font-size: clamp(3.2rem, 14vw, 5rem); }
  .intro > p:last-child { display: none; }
  .system, .cursor-note { display: none; }
  .monitor-ui { width: calc(100% - 28px); justify-content: center; bottom: 18px; }
  .world-button { flex: 1; padding: 11px 6px; }
  body.is-hovering .intro { transform: translateX(-10px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
