/* ==========================================================================
   KEPLAR — CRT pass 2
   Everything here layers on top of crt.css to push the tube illusion further:
   phosphor grain, colour convergence error, interlace roll, degauss on power-up,
   a finer scanline pitch on high-DPI screens, and a physical monitor housing
   on anything bigger than a phone.
   ========================================================================== */

/* ------------------------------------------------- 1. phosphor grain -- */
/* A real tube is never clean: static grain sits under the picture and drifts. */

.crt-noise {
  position: absolute;
  inset: -50%;
  z-index: 4;
  pointer-events: none;
  opacity: 0.055;
  mix-blend-mode: screen;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>");
  background-size: 160px 160px;
  animation: grain 900ms steps(4) infinite;
  will-change: transform;
}

@keyframes grain {
  0%   { transform: translate3d(0, 0, 0); }
  25%  { transform: translate3d(-3%, 2%, 0); }
  50%  { transform: translate3d(2%, -3%, 0); }
  75%  { transform: translate3d(-2%, -2%, 0); }
  100% { transform: translate3d(3%, 1%, 0); }
}

/* ------------------------------------- 2. convergence / colour fringe -- */
/* Shadow-mask misconvergence: a red ghost one way, a blue ghost the other.
   Kept sub-pixel so body copy stays sharp enough to read mid-session. */

html[data-fx='full'] .crt-content {
  text-shadow:
    0.35px 0 rgba(255, 40, 90, 0.28),
   -0.35px 0 rgba(60, 160, 255, 0.24),
    0 0 2px rgba(61, 251, 164, 0.75);
}

/* Headings and the wordmark bloom harder, the way bright phosphor does. */
html[data-fx='full'] .brand,
html[data-fx='full'] .sheet-head h2,
html[data-fx='full'] .faction-name {
  text-shadow:
    0.5px 0 rgba(255, 40, 90, 0.35),
   -0.5px 0 rgba(60, 160, 255, 0.3),
    0 0 8px currentColor;
}

/* --------------------------------------------- 3. interlace + h-hold -- */
/* Every so often the vertical hold slips a line, then catches itself. */

html[data-fx='full'] .crt-content {
  animation:
    flicker 7.3s infinite steps(60),
    hold 19s infinite;
}

@keyframes hold {
  0%, 92.4%   { transform: scale(1.006) translateY(0); }
  92.6%       { transform: scale(1.006) translateY(-2px); }
  92.9%       { transform: scale(1.006) translateY(1.5px); }
  93.2%       { transform: scale(1.006) translateY(-0.5px); }
  93.5%, 100% { transform: scale(1.006) translateY(0); }
}

/* ---------------------------------------------------- 4. scanline pitch */
/* On a 2x/3x phone panel the 3px CSS pitch reads as fat black bars, so the
   grille tightens as pixel density rises. */

@media (min-resolution: 2dppx) {
  .crt-glass::before {
    background:
      repeating-linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.30) 0px,
        rgba(0, 0, 0, 0.30) 1px,
        rgba(0, 0, 0, 0.02) 1px,
        rgba(0, 0, 0, 0.02) 2.5px
      ),
      repeating-linear-gradient(
        to right,
        rgba(255, 40, 40, 0.05) 0px,
        rgba(40, 255, 120, 0.04) 1px,
        rgba(60, 90, 255, 0.05) 2px,
        rgba(0, 0, 0, 0.04) 3px
      );
    mix-blend-mode: multiply;
  }
}

/* --------------------------------------------------------- 5. degauss -- */
/* Power-up wobble: the picture blooms, swells and snaps back into geometry. */

html[data-fx='full'] .crt-screen {
  animation: degauss 1400ms cubic-bezier(0.22, 1, 0.36, 1) 1;
}

@keyframes degauss {
  0%   { filter: blur(1.4px) saturate(2.4) brightness(1.5) hue-rotate(-14deg); transform: scale(1.045, 1.03); }
  18%  { filter: blur(0.9px) saturate(1.9) brightness(1.25) hue-rotate(10deg);  transform: scale(0.985, 1.02); }
  36%  { filter: blur(0.5px) saturate(1.5) brightness(1.12) hue-rotate(-6deg);  transform: scale(1.018, 0.995); }
  58%  { filter: blur(0.2px) saturate(1.2) brightness(1.05) hue-rotate(3deg);   transform: scale(0.996, 1.004); }
  100% { filter: none; transform: none; }
}

/* ------------------------------------------------- 6. glass and bloom -- */
/* A slightly stronger centre bulge highlight plus a warmer edge falloff, so
   the picture looks like it is sitting behind curved glass rather than on it. */

html[data-fx='full'] .crt-glass::after {
  background:
    radial-gradient(115% 95% at 50% 50%, rgba(0, 0, 0, 0) 46%, rgba(0, 0, 0, 0.5) 84%, rgba(0, 0, 0, 0.92) 100%),
    radial-gradient(70% 45% at 26% 6%, rgba(200, 255, 240, 0.11), rgba(255, 255, 255, 0) 72%),
    radial-gradient(45% 26% at 80% 94%, rgba(120, 220, 255, 0.06), rgba(255, 255, 255, 0) 72%),
    radial-gradient(90% 70% at 50% 44%, rgba(80, 255, 190, 0.045), rgba(0, 0, 0, 0) 70%);
}

/* Ambient spill: the tube lights the room it sits in. */
.crt-hood {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(70% 50% at 50% 45%, rgba(40, 200, 140, 0.10), rgba(0, 0, 0, 0) 72%);
}

/* ------------------------------------------------- 7. monitor housing -- */
/* Phones get the full-bleed tube; anything roomier gets the actual monitor. */

.crt-plate { display: none; }

@media (min-width: 860px) {
  body {
    background:
      radial-gradient(120% 90% at 50% 40%, #0d1512 0%, #070b0a 55%, #010302 100%);
  }

  .crt-cabinet {
    padding: 26px 26px 0;
    flex-direction: column;
    align-items: center;
  }

  .crt-screen {
    width: 100%;
    max-width: 1180px;
    border-radius: 34px;
    /* thick moulded plastic bezel around the glass */
    box-shadow:
      inset 0 0 70px rgba(0, 0, 0, 0.95),
      inset 0 0 160px rgba(0, 30, 20, 0.5),
      0 0 0 14px #23262a,
      0 0 0 15px #34383d,
      0 0 0 26px #1b1e21,
      0 26px 60px rgba(0, 0, 0, 0.8),
      0 0 90px rgba(28, 140, 96, 0.16);
  }

  .crt-plate {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 1180px;
    margin-top: 40px;
    padding: 10px 18px 12px;
    border-radius: 0 0 16px 16px;
    background: linear-gradient(to bottom, #2a2e33, #1b1e21 60%, #15171a);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.07);
    font-size: 11px;
    letter-spacing: 3px;
    color: #7d8a86;
  }

  .crt-led {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #46ffb0;
    box-shadow: 0 0 8px #46ffb0, 0 0 18px rgba(70, 255, 176, 0.6);
    animation: ledPulse 3.4s ease-in-out infinite;
  }

  .crt-vents {
    flex: 1;
    height: 8px;
    margin-left: auto;
    max-width: 220px;
    background: repeating-linear-gradient(to right, #101214 0 3px, transparent 3px 8px);
    border-radius: 2px;
    opacity: 0.8;
  }

  @keyframes ledPulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.72; }
  }
}

/* ----------------------------------------------------- 8. FX overrides -- */

html[data-fx='soft'] .crt-noise { opacity: 0.03; animation: none; }
html[data-fx='soft'] .crt-content { animation: none; }
html[data-fx='soft'] .crt-screen { animation: none; }

html[data-fx='off'] .crt-noise,
html[data-fx='off'] .crt-hood { display: none; }
html[data-fx='off'] .crt-content { animation: none; text-shadow: none; }
html[data-fx='off'] .crt-screen { animation: none; }
html[data-fx='off'] .brand,
html[data-fx='off'] .sheet-head h2,
html[data-fx='off'] .faction-name { text-shadow: none; }

@media (prefers-reduced-motion: reduce) {
  .crt-noise { animation: none; }
  html[data-fx='full'] .crt-content { animation: none; }
  html[data-fx='full'] .crt-screen { animation: none; }
  .crt-led { animation: none; }
}

/* ==========================================================================
   Pass 3 additions — crew manifest, course plotter, live indicator, legend
   ========================================================================== */

/* ------------------------------------------------------- live indicator -- */

.live-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: baseline;
  background: #2b3a35;
  box-shadow: none;
  transition: background 200ms linear;
}
.live-dot[data-state='live'] {
  background: var(--phos);
  box-shadow: 0 0 6px var(--phos);
  animation: livePulse 2.6s ease-in-out infinite;
}
.live-dot[data-state='retry'] {
  background: var(--amber);
  box-shadow: 0 0 6px var(--amber);
  animation: livePulse 0.8s ease-in-out infinite;
}
@keyframes livePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ------------------------------------------------------------ crew cards -- */

.crew-card {
  border: 1px solid var(--rule);
  border-left: 3px solid var(--phos-dim);
  background: var(--panel);
  padding: 10px;
  margin-bottom: 10px;
}
.crew-card.critical { border-left-color: var(--alert); }
.crew-card.is-hidden { border-left-color: var(--amber); border-style: dashed; }

.crew-top { display: flex; gap: 10px; align-items: flex-start; }
.crew-portrait {
  flex: 0 0 auto;
  margin: 0;
  padding: 4px 6px;
  border: 1px solid var(--rule-soft);
  background: rgba(0, 0, 0, 0.45);
  font-size: 10px;
  line-height: 1.05;
  color: var(--phos);
  text-shadow: var(--glow-sm);
  white-space: pre;
}
.crew-id { flex: 1; min-width: 0; }
.crew-name { font-size: 14px; letter-spacing: 1.5px; color: var(--phos-bright); word-break: break-word; }
.crew-name a { color: inherit; text-decoration: none; }
.crew-sub { font-size: 11.5px; color: var(--phos); }
.crew-sub.muted { color: var(--phos-dim); }

.track {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 11.5px;
}
.track-label { color: var(--cyan); letter-spacing: 1px; min-width: 52px; }
.track-meter { color: var(--phos); letter-spacing: -0.5px; white-space: nowrap; }
.track-num { color: var(--phos-bright); min-width: 46px; text-align: right; }
.track.wounds .track-meter { color: var(--alert); }
.crew-card.critical .track:not(.wounds) .track-meter { color: var(--amber); text-shadow: 0 0 6px var(--amber); }
.track button { min-height: 30px; padding: 2px 9px; }

/* -------------------------------------------------------- course plotter -- */

.course-leg {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px dashed var(--rule-soft);
  font-size: 12.5px;
}
.course-leg:last-of-type { border-bottom: 0; }
.course-num { color: var(--phos-dim); }
.course-line { flex: 1; min-width: 0; }
.course-time { color: var(--cyan); white-space: nowrap; font-size: 11.5px; }
.course-total {
  display: flex;
  align-items: center;
  color: var(--phos-bright);
  letter-spacing: 1.5px;
  font-size: 13px;
  text-shadow: var(--glow-sm);
}

/* --------------------------------------------------------------- legend -- */

.map-legend {
  position: absolute;
  left: 8px;
  top: 40px;
  z-index: 3;
  max-width: 230px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  background: rgba(2, 12, 9, 0.92);
  font-size: 11px;
  line-height: 1.7;
  color: var(--phos);
}
.map-legend h4 {
  margin: 0 0 4px;
  font-size: 10px;
  font-weight: normal;
  letter-spacing: 2px;
  color: var(--cyan);
}
.map-legend .g { display: inline-block; width: 16px; color: var(--phos-bright); }
.map-legend .swatch { display: inline-block; width: 10px; height: 10px; margin-right: 5px; vertical-align: -1px; }
