/* CRT layer. Three strengths, chosen per player in Display settings:
   off · subtle · full. Paper palette (C) never gets a CRT.
   Everything here is cosmetic and never blocks clicks. */

.crt-glass { display: none; }

html[data-crt="subtle"] body,
html[data-crt="full"] body { background: var(--screen-edge, #000); }

html[data-crt="subtle"] .crt-glass,
html[data-crt="full"] .crt-glass {
  display: block;
  position: fixed; inset: 0; z-index: 55; pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, var(--crt-scan)) 0 1px, transparent 1px var(--crt-pitch)),
    radial-gradient(ellipse 120% 90% at 50% 50%, transparent 58%, rgba(0, 0, 0, var(--crt-vig)) 100%),
    radial-gradient(ellipse 70% 40% at 28% 6%, rgba(255, 255, 255, var(--crt-glare)), transparent 70%);
}

html[data-crt="subtle"] { --crt-scan: 0.14; --crt-pitch: 3px; --crt-vig: 0.45; --crt-glare: 0.015; }
html[data-crt="full"]   { --crt-scan: 0.28; --crt-pitch: 3px; --crt-vig: 0.8;  --crt-glare: 0.035; }
[data-view="tv"][data-crt="full"] { --crt-pitch: 4px; }

/* Phosphor glow on all text */
html[data-crt="subtle"] .app,
html[data-crt="subtle"] .coach-card,
html[data-crt="subtle"] .briefing { text-shadow: 0 0 4px var(--glow); }
html[data-crt="full"] .app,
html[data-crt="full"] .coach-card,
html[data-crt="full"] .popover,
html[data-crt="full"] .briefing {
  text-shadow:
    0.6px 0 0 rgba(255, 50, 20, 0.28),
    -0.6px 0 0 rgba(40, 200, 255, 0.16),
    0 0 6px var(--glow),
    0 0 14px var(--glow);
}

/* Curved glass: rounded screen, dark falloff at the edges */
html[data-crt="full"] .app {
  border-radius: 26px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  filter: saturate(1.12) contrast(1.06);
}
html[data-crt="full"] .crt-glass::before {
  content: ""; position: absolute; inset: 0;
  border-radius: 26px;
  box-shadow: inset 0 0 140px rgba(0, 0, 0, 0.85), inset 0 0 22px rgba(0, 0, 0, 0.9);
}
[data-view="tv"][data-crt="full"] .crt-glass::before { inset: 2.5vh 2.5vw; }

/* A faint band rolling down the screen, like a real tube */
html[data-crt="full"] .crt-glass::after {
  content: ""; position: absolute; left: 0; right: 0; top: -20%; height: 18%;
  background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.035), transparent);
  animation: crt-roll 9s linear infinite;
}
@keyframes crt-roll { to { transform: translateY(650%); } }

/* Bloom on the live displays (waterfall, sky, decoder) */
html[data-crt="full"] .glowable { position: relative; }
html[data-crt="full"] .glowable::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  backdrop-filter: blur(5px) brightness(1.7);
  -webkit-backdrop-filter: blur(5px) brightness(1.7);
  mix-blend-mode: screen; opacity: 0.4;
}
html[data-crt="full"] canvas { filter: brightness(1.08); }

/* Power-on: a bright line opens into the picture */
html[data-crt="full"] .app.crt-boot,
html[data-crt="subtle"] .app.crt-boot { animation: crt-on 1.1s cubic-bezier(.2,.7,.2,1) both; }
@keyframes crt-on {
  0%   { transform: scale(0, 0.004); filter: brightness(6); }
  35%  { transform: scale(1, 0.004); filter: brightness(4); }
  70%  { transform: scale(1, 1); filter: brightness(1.6); }
  100% { transform: scale(1, 1); filter: brightness(1); }
}

/* No CRT on the paper palette, and respect reduced-motion */
html[data-palette="chart"] .crt-glass { display: none !important; }
html[data-palette="chart"] .app { text-shadow: none !important; filter: none !important; border-radius: 0 !important; }
html[data-palette="chart"] .glowable::after { display: none; }
@media (prefers-reduced-motion: reduce) {
  .crt-glass::after { animation: none !important; display: none; }
  .app.crt-boot { animation: none !important; }
}
