/**
 * RoccOS Boot Terminal — first-run cold boot
 *
 * A full-viewport faux-terminal log shown ONCE, the first time a visitor lands.
 * Gated by the `.first-boot` class on <html> (set by an inline <head> script in
 * index.html before first paint). Hidden — `display: none` — for everyone else,
 * so it never touches the desktop, the test suite, or returning visitors.
 *
 * Palette: deep pine background, orchid text.
 */

:root {
  --boot-bg: #1C4030;   /* deep pine green — matches desktop --os-band */
  --boot-fg: #C38BC0;   /* orchid */
  --boot-dim: #6E9B85;  /* muted green — leaders + prompt chrome */
  --boot-ok: #E2BFE0;   /* brighter orchid — status tags + welcome */
}

/* Hidden by default. Only the first-run path reveals it. */
.boot-terminal { display: none; }

/* Freeze the page behind the overlay while it's on screen. */
.first-boot { overflow: hidden; }

.first-boot .boot-terminal {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 100000; /* above everything — taskbar, spotlight, preloader */
  align-items: center;
  justify-content: center;
  /* Same dark monitor housing as .scene — the curved glass sits inside it. */
  background: #10130d;
  transition: opacity var(--boot-fade, 0.5s) ease;
}

.boot-terminal[hidden] { display: none !important; }

.boot-terminal.boot-done {
  opacity: 0;
  pointer-events: none;
}

/* ── The curved glass — mirrors .desktop sizing/radius exactly, so the boot
   screen and the desktop that follows it read as the SAME physical tube. ── */
.boot-glass {
  /* Deliberately NOT a flex container — a flex box + this SVG barrel filter
     (feImage/feDisplacementMap) makes Chromium mis-measure the filtered
     element's paint bounds (a large, asymmetric bounding-box inflation that
     reads as the glass bleeding past the housing). Centering the content
     lives one level down, on `.boot-glass-content`, exactly like `.desktop`
     (a plain block) stays clean and only its children use flex/absolute
     layout. Keep this element's own display a plain block. */
  position: absolute;
  aspect-ratio: 16 / 10;
  width: 100vw;
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  inset: 0;
  margin: auto;
  border-radius: 18px;
  overflow: hidden;
  /* The housing/tube glass itself is always near-black — the pine green is
     the PHOSPHOR (`.boot-phosphor`, below), a separate layer that powers on
     over it. That's beat 1 of the three-beat boot: black glass → green
     phosphor lights (empty) → text fades in a moment later. */
  background: #050805;
  color: var(--boot-fg);
  cursor: var(--cur-hand); --crt-cursor: hand;
}

.boot-glass.has-crt-warp {
  filter: url('#crt-barrel-filter-boot') blur(0.45px);
}

/* ── Beat 2: the phosphor lights, empty ──
   A dedicated layer BELOW the text so the power-on flicker/scale reads as
   the screen itself turning on, not the copy. Living on this child — not on
   `.boot-glass`, which carries the SVG barrel filter — keeps the transform
   off the flex+filter combination that inflates Chromium's paint bounds
   (see the note on `.boot-glass` above). */
.boot-phosphor {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--boot-bg);
  opacity: 0;
  transform: scaleY(0.005);
  filter: brightness(6);
  transform-origin: 50% 50%;
}

/* CRT power-on: a bright thin line snaps open to full height with a couple
   of flicker steps (~180ms), then the phosphor settles to normal brightness
   (~another ~120ms). Transform/opacity/brightness only — no width/height —
   so it can't retrigger the flex+filter bug. */
@keyframes boot-power-on {
  0% {
    opacity: 1;
    transform: scaleY(0.005);
    filter: brightness(6);
    animation-timing-function: steps(1, end);
  }
  12% {
    opacity: 0;
    animation-timing-function: steps(1, end);
  }
  24% {
    opacity: 1;
    transform: scaleY(0.35);
    filter: brightness(5);
    animation-timing-function: steps(1, end);
  }
  38% {
    opacity: 0.4;
    transform: scaleY(0.7);
    filter: brightness(3.4);
    animation-timing-function: steps(1, end);
  }
  55% {
    opacity: 1;
    transform: scaleY(1);
    filter: brightness(2.2);
    animation-timing-function: ease-out;
  }
  100% {
    opacity: 1;
    transform: scaleY(1);
    filter: brightness(1);
  }
}

.boot-glass.crt-on .boot-phosphor {
  animation: boot-power-on 300ms ease-out forwards;
}

/* CSS-only safety net: if crt-homepage.js never runs (blocked script, JS
   error upstream, ancient browser), the phosphor still lights on its own
   after 2.5s instead of staying black forever. `.crt-on` — added by JS well
   before this fires on any normal load — always wins by simply having
   already put the element in its lit end state before this one triggers. */
@keyframes boot-phosphor-failsafe {
  to {
    opacity: 1;
    transform: scaleY(1);
    filter: brightness(1);
  }
}

.boot-phosphor {
  animation: boot-phosphor-failsafe 0s 2.5s forwards;
}

/* ── Beat 3: the text fades in, a beat after the phosphor is lit ──
   `.text-on` lands on `.boot-glass` from boot-terminal.js once the phosphor
   animation has finished AND the extra hold has elapsed. The header
   (prompt/version) and the log both live inside this one content block, so
   they fade in together — the header doesn't get its own separate timing,
   it just rides along with the content's opacity. */
.boot-glass-content {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(20px, 6vw, 80px);
  /* Pure SYSTEM monospace — deliberately NOT var(--font-system).
     In the default theme --font-system resolves to Satoshi (a web font with
     font-display:swap), which the cold-boot overlay would paint before the
     font finishes loading → a fallback→Satoshi swap mid-animation (flicker),
     plus per-frame width jitter of the dotted leaders because the scramble's
     "constant length" promise only holds for a fixed-advance monospace font.
     A system mono stack paints instantly on the first frame and keeps every
     glyph the same width, so the decode stays rock-steady. */
  font-family: ui-monospace, 'SF Mono', 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', 'Courier New', monospace;
  -webkit-font-smoothing: antialiased;
  opacity: 0;
  transition: opacity 250ms ease-out;
}

.boot-glass.text-on .boot-glass-content {
  opacity: 1;
}

/* Failsafe partner to `.boot-phosphor`'s — reveal the text even if JS never
   flips `.text-on`. */
@keyframes boot-content-failsafe {
  to { opacity: 1; }
}

.boot-glass-content {
  animation: boot-content-failsafe 0s 2.5s forwards;
}

.boot-terminal-inner {
  position: relative;
  z-index: 1;
  width: min(760px, 100%);
  margin: 0 auto;
}

/* ── Header (static prompt + version) ── */
.boot-head {
  margin-bottom: 1.5em;
  font-size: clamp(12px, 1.5vw, 15px);
  line-height: 1.7;
  letter-spacing: 0.03em;
}

.boot-prompt { color: var(--boot-dim); }

.boot-version {
  color: var(--boot-fg);
  opacity: 0.92;
}

/* ── Log ── */
.boot-log {
  font-size: clamp(12px, 1.5vw, 15px);
  line-height: 1.95;
}

.boot-line {
  display: flex;
  align-items: baseline;
  opacity: 0;
  transform: translateY(4px);
}

.boot-line.visible {
  opacity: 1;
  transform: none;
  transition: opacity 0.28s ease-out, transform 0.28s ease-out;
}

.boot-line-label {
  white-space: pre-wrap;
}

/* Dotted leader fills the gap between label and status, terminal-style. */
.boot-line-leader {
  flex: 1 1 auto;
  min-width: 1.5ch;
  margin: 0 0.75ch;
  transform: translateY(-0.28em);
  border-bottom: 1px dotted var(--boot-dim);
  opacity: 0.7;
}

.boot-line-status {
  flex: 0 0 auto;
  color: var(--boot-ok);
  white-space: nowrap;
  opacity: 0;
}

.boot-line-status.visible {
  opacity: 1;
  transition: opacity 0.22s ease-out;
}

/* ── Welcome line + blinking cursor ── */
.boot-welcome {
  margin-top: 1.6em;
  font-size: clamp(15px, 2vw, 20px);
  color: var(--boot-ok);
  letter-spacing: 0.01em;
  opacity: 0;
}

.boot-welcome.visible {
  opacity: 1;
  transition: opacity 0.45s ease-out;
}

.boot-cursor {
  display: inline-block;
  width: 0.6ch;
  height: 1.05em;
  margin-left: 0.3ch;
  vertical-align: text-bottom;
  background: var(--boot-fg);
  animation: bootCursorBlink 1.05s steps(1) infinite;
}

@keyframes bootCursorBlink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* ── CRT atmosphere: scanlines + rolling band + vignette + glare ──
   Same treatment as .desktop (see desktop.css "CRT Screen" block), reused
   here so the boot glass and the desktop it hands off to read as one tube. */
.boot-glass::before,
.boot-glass::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.boot-glass::before {
  background:
    /* rolling refresh band */
    linear-gradient(180deg,
      transparent 0%,
      rgba(255, 252, 237, 0.05) 42%,
      rgba(255, 252, 237, 0.11) 50%,
      rgba(255, 252, 237, 0.05) 58%,
      transparent 100%),
    /* scanlines */
    repeating-linear-gradient(0deg,
      rgba(6, 12, 8, 0.24) 0px,
      rgba(6, 12, 8, 0.24) 1px,
      transparent 1px,
      transparent 3px),
    /* RGB phosphor triads */
    repeating-linear-gradient(90deg,
      rgba(255, 48, 48, 0.03) 0px,
      rgba(255, 48, 48, 0.03) 1px,
      rgba(64, 255, 100, 0.024) 1px,
      rgba(64, 255, 100, 0.024) 2px,
      rgba(70, 100, 255, 0.03) 2px,
      rgba(70, 100, 255, 0.03) 3px);
  background-size: 100% 220px, 100% 3px, 3px 100%;
  background-repeat: no-repeat, repeat, repeat;
  animation:
    crt-roll 9s linear infinite,
    crt-scan-drift 8s steps(2, end) infinite;
  mix-blend-mode: multiply;
}

.boot-glass::after {
  box-shadow: inset 0 0 60px 18px rgba(12, 16, 10, 0.22);
  animation: crt-breathe 4.8s ease-in-out infinite;
}

.boot-glare {
  z-index: 3;
}

/* ── Mobile ── */
@media (max-width: 767px) {
  .boot-glass.has-crt-warp {
    filter: none;
  }

  .boot-glass-content {
    padding: 24px 16px;
    justify-content: flex-start;
    padding-top: clamp(48px, 18vh, 140px);
  }

  .boot-head { font-size: 11px; }
  /* Slightly smaller so even the longest line (Calculator → it refused)
     never clips on narrow phones. */
  .boot-log { font-size: 11px; line-height: 1.9; }
  .boot-line { overflow: hidden; }
  .boot-line-leader { min-width: 0.5ch; margin: 0 0.5ch; }
  .boot-welcome { font-size: 15px; }

  .boot-glass::before {
    background-image:
      repeating-linear-gradient(0deg,
        rgba(6, 12, 8, 0.12) 0px,
        rgba(6, 12, 8, 0.12) 1px,
        transparent 1px,
        transparent 3px);
    background-size: 100% 3px;
    animation: none;
  }
  .boot-glass::after { box-shadow: inset 0 0 24px 8px rgba(18, 23, 15, 0.12); }
}

/* ── Reduced motion: no blink, no transforms ── */
@media (prefers-reduced-motion: reduce) {
  .boot-line,
  .boot-line.visible { transform: none; transition: none; }
  .boot-line,
  .boot-line-status,
  .boot-welcome { transition: none; }
  .boot-cursor { animation: none; }
  .boot-glass::before,
  .boot-glass::after { animation: none; }

  /* Power-on becomes an instant cut, not a flicker — same three-beat pacing
     (black → phosphor → text), just no flicker/scale/fade animating between
     the beats. The failsafe keyframes stay (duration is already 0 — there's
     nothing to "reduce"), only the animated/transitioned properties are. */
  .boot-phosphor { transform: none; }
  .boot-glass.crt-on .boot-phosphor {
    animation: none;
    opacity: 1;
    filter: none;
  }
  .boot-glass-content { transition: none; }
  .boot-glass.text-on .boot-glass-content { opacity: 1; }
}
