/* SUBLAYER — a phosphor terminal. One canvas, one character grid.
   Single-theme by design: the CRT is always dark. --phosphor is set from JS. */
:root {
  color-scheme: dark;
  --phosphor: rgb(255, 176, 20);
  --phosphor-bg: rgb(14, 8, 0);
  --case: #050403;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--case);
  color: var(--phosphor);
  font-family: "VT323", ui-monospace, monospace;
  overflow: hidden;
}

/* The tube: rounded glass, inset into the case. */
.crt {
  position: fixed;
  inset: 0;
  padding: max(6px, env(safe-area-inset-top, 0px)) max(6px, env(safe-area-inset-right, 0px)) max(6px, env(safe-area-inset-bottom, 0px)) max(6px, env(safe-area-inset-left, 0px));
  background: var(--case);
}
.screen, .bloom {
  position: absolute;
  inset: 6px;
  width: calc(100% - 12px);
  height: calc(100% - 12px);
  border-radius: 22px / 26px;
  display: block;
}
.screen { background: var(--phosphor-bg); outline: none; cursor: default; transform-origin: 50% 50%; }
/* The glow: term.js draws it there at a third of the size, as light on a
   transparent layer, already soft; the page just lays it over the tube. */
.bloom {
  pointer-events: none;
  opacity: 0.3;
  transform-origin: 50% 50%;
}
/* The glass: scanlines, a faint aperture grille, the curve falling off into
   the corners, and a reflection. */
.glass {
  position: absolute;
  inset: 6px;
  border-radius: 22px / 26px;
  pointer-events: none;
  overflow: hidden;
  background:
    repeating-linear-gradient(180deg, rgba(0, 0, 0, 0.3) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.09) 0 1px, transparent 1px 3px),
    radial-gradient(130% 105% at 50% 48%, transparent 55%, rgba(0, 0, 0, 0.42) 80%, rgba(0, 0, 0, 0.9) 100%),
    radial-gradient(60% 40% at 28% 6%, rgba(255, 255, 255, 0.055), transparent 70%),
    linear-gradient(160deg, rgba(255, 255, 255, 0.04), transparent 35%);
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.92),
    inset 0 0 70px rgba(0, 0, 0, 0.72),
    inset 0 0 14px 3px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 3px rgba(255, 255, 255, 0.025);
  animation: flicker 7s infinite steps(1);
}
@keyframes flicker {
  0%, 100% { opacity: 1; }
  41% { opacity: 0.94; }
  42% { opacity: 1; }
  77% { opacity: 0.97; }
  78% { opacity: 1; }
}
/* Power on: a dot, a line, the picture, too bright, then warm. Clipped,
   not scaled, so the canvases keep their real boxes while it plays (the
   handheld lines its grid up against them). */
.screen, .pad-screen { animation: power-on 1.7s cubic-bezier(0.2, 0.7, 0.3, 1) backwards; }
.bloom, .pad-bloom { animation: bloom-on 1.7s ease-out backwards; }
@keyframes power-on {
  0% { clip-path: inset(49.7% 49.6% 49.7% 49.6%); filter: brightness(8); }
  9% { clip-path: inset(49.7% 0 49.7% 0); filter: brightness(6); }
  20% { clip-path: inset(0 0 0 0); filter: brightness(2.4); }
  42% { filter: brightness(0.7); }
  100% { clip-path: inset(0 0 0 0); filter: none; }
}
@keyframes bloom-on {
  0% { clip-path: inset(49.7% 49.6% 49.7% 49.6%); opacity: 0; }
  9% { clip-path: inset(49.7% 0 49.7% 0); opacity: 1; }
  20% { clip-path: inset(0 0 0 0); opacity: 1; }
  100% { clip-path: inset(0 0 0 0); opacity: 0.3; }
}
.no-crt .bloom { display: none; }
.no-crt .glass { background: none; animation: none; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.9); }
.no-crt .screen, .no-crt .pad-screen { animation: none; }

@media (max-width: 760px) {
  .screen, .bloom, .glass { inset: 2px; width: calc(100% - 4px); height: calc(100% - 4px); border-radius: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .glass, .screen, .bloom, .pad-screen, .pad-bloom { animation: none; }
}

/* ---------------------------------------------------------------- handheld
   Phones get a control panel drawn on the same tube: a second canvas behind
   the screen's, filling the glass, drawn by the same terminal. Upright, the
   screen shrinks to make room below; sideways, the screen takes the middle
   and the controls sit either side. main.js sets body.handheld and --pad-h. */
.pad-screen, .pad-bloom { display: none; }
body.handheld {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
body.handheld .pad-screen, body.handheld .pad-bloom {
  display: block;
  position: absolute;
  inset: 2px;
  width: calc(100% - 4px);
  height: calc(100% - 4px);
  border-radius: 10px;
}
body.handheld .pad-screen { background: var(--phosphor-bg); touch-action: none; }
body.handheld .pad-bloom {
  pointer-events: none;
  opacity: 0.3;
}
body.handheld.no-crt .pad-bloom { display: none; }
body.handheld .screen, body.handheld .bloom {
  inset: auto;
  top: 2px;
  left: 2px;
  width: calc(100% - 4px);
  height: calc(100% - 4px - var(--pad-h, 280px));
  border-radius: 10px 10px 0 0;
}
@media (orientation: landscape) {
  body.handheld { --side: clamp(170px, 26vw, 250px); }
  body.handheld .screen, body.handheld .bloom {
    left: var(--side);
    width: calc(100% - 2 * var(--side));
    height: calc(100% - 4px);
    border-radius: 0;
  }
}
