/* ─── UPLINK — CRT mission control terminal ─────────────────── */

:root {
  --phos: #3ee688;          /* phosphor green */
  --phos-dim: #1d7a48;
  --phos-bright: #b4ffd9;
  --amber: #ffd23e;
  --alert: #ff4a3c;
  --screen: #021008;
  --font: "VT323", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: #060503;
  font-family: var(--font);
  color: var(--phos);
  overflow: hidden;
}

/* the dark control room around the monitor */
.room {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, #14110b 0%, #060503 70%);
  padding: 2vmin;
}

.under {
  font-size: clamp(0.7rem, 1.6vmin, 1rem);
  letter-spacing: 0.35em;
  color: #4a4334;
  user-select: none;
}

/* ─── the CRT itself ─── */
.crt {
  position: relative;
  width: min(96vw, 165vh);
  aspect-ratio: 16 / 10;
  max-height: 88vh;
  background: var(--screen);
  border-radius: 2.2vmin;
  overflow: hidden;
  box-shadow:
    0 0 0 6px #1a1812,
    0 0 0 9px #0c0b08,
    0 22px 80px -12px rgba(0, 0, 0, 0.9),
    inset 0 0 12vmin rgba(0, 0, 0, 0.55);
  animation: poweron 0.9s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes poweron {
  0% { transform: scaleY(0.004) scaleX(0.6); filter: brightness(8); }
  35% { transform: scaleY(0.004) scaleX(1); filter: brightness(8); }
  60% { transform: scaleY(1) scaleX(1); filter: brightness(2.4); }
  100% { transform: none; filter: none; }
}

#bg, #fxc {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#bg { z-index: 1; }
#fxc { z-index: 3; pointer-events: none; }

/* CRT dressing layers */
.scanlines {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px, rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.22) 3px, rgba(0, 0, 0, 0) 4px
  );
  mix-blend-mode: multiply;
}

.scanbar {
  position: absolute; left: 0; right: 0; height: 18%;
  z-index: 4; pointer-events: none;
  background: linear-gradient(to bottom,
    rgba(180, 255, 217, 0) 0%, rgba(180, 255, 217, 0.035) 50%,
    rgba(180, 255, 217, 0) 100%);
  animation: scanbar 7s linear infinite;
}

@keyframes scanbar {
  from { top: -20%; }
  to { top: 110%; }
}

.vignette {
  position: absolute; inset: 0; z-index: 5; pointer-events: none;
  background: radial-gradient(ellipse 95% 90% at 50% 50%,
    rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, 0.5) 100%);
  animation: flicker 0.12s steps(2) infinite;
}

@keyframes flicker {
  0% { opacity: 1; }
  50% { opacity: 0.965; }
  100% { opacity: 1; }
}

/* red rotating alarm wash (phase 4 / packet lost) */
.beacon {
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse 70% 55% at 50% 0%,
    rgba(255, 74, 60, 0.28) 0%, rgba(255, 74, 60, 0) 70%);
  transition: opacity 0.4s;
}

.crt.alert .beacon { opacity: 1; animation: beacon 1.1s ease-in-out infinite; }

@keyframes beacon {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

/* slow-motion grade on the final characters */
.crt.slowmo #bg, .crt.slowmo .screen-ui {
  filter: saturate(1.6) brightness(1.25) contrast(1.1);
  transition: filter 0.3s;
}

/* mistype: chromatic aberration on all screen text */
.screen-ui { transition: none; }
.crt.glitch .screen-ui {
  text-shadow:
    -2.5px 0 rgba(255, 60, 60, 0.85),
    2.5px 0 rgba(60, 200, 255, 0.85),
    0 0 8px currentColor;
  transform: translateX(1.5px);
}

/* ─── screen UI ─── */
.screen-ui {
  position: absolute; inset: 0; z-index: 2;
  display: flex;
  flex-direction: column;
  padding: 2.4% 3%;
  text-shadow: 0 0 8px rgba(62, 230, 136, 0.6);
  text-transform: uppercase;
}

/* HUD */
.hud {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.hud-label {
  font-size: clamp(0.6rem, 1.5vmin, 0.95rem);
  letter-spacing: 0.22em;
  color: var(--phos-dim);
}

.hud-value {
  font-size: clamp(1.2rem, 3.4vmin, 2.2rem);
  line-height: 1;
  color: var(--phos-bright);
}

.hud-phase {
  font-size: clamp(1rem, 2.6vmin, 1.7rem);
  letter-spacing: 0.3em;
  color: var(--amber);
  text-shadow: 0 0 10px rgba(255, 210, 62, 0.5);
  padding-top: 0.4vmin;
}

.hud-right { display: flex; gap: clamp(0.8rem, 2.5vmin, 2rem); align-items: flex-start; }

.hud-stat { text-align: right; }

/* analog signal gauge */
.gauge { text-align: center; }

.gauge-face {
  position: relative;
  width: clamp(54px, 9vmin, 90px);
  height: clamp(27px, 4.5vmin, 45px);
  border: 1.5px solid var(--phos-dim);
  border-bottom: none;
  border-radius: 200px 200px 0 0;
  overflow: hidden;
  margin-top: 0.3em;
  background:
    conic-gradient(from -90deg at 50% 100%,
      var(--alert) 0deg, var(--amber) 55deg, var(--phos-dim) 90deg,
      var(--phos-dim) 125deg, transparent 125deg) ;
  opacity: 0.95;
}

.gauge-needle {
  position: absolute;
  left: 50%; bottom: 0;
  width: 2px; height: 92%;
  background: var(--phos-bright);
  box-shadow: 0 0 6px var(--phos-bright);
  transform-origin: bottom center;
  transform: rotate(0deg);
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.3, 1.2);
}

/* countdown */
.countdown {
  position: absolute;
  top: 13%;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(2.4rem, 8vmin, 5.5rem);
  color: var(--alert);
  text-shadow: 0 0 18px rgba(255, 74, 60, 0.7);
  letter-spacing: 0.1em;
}

.countdown.low { animation: countpulse 0.5s ease-in-out infinite; }

@keyframes countpulse {
  50% { transform: translateX(-50%) scale(1.12); }
}

/* terminal center */
.terminal {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

/* boot log */
.boot {
  align-self: flex-start;
  font-size: clamp(0.95rem, 2.6vmin, 1.6rem);
  line-height: 1.55;
  letter-spacing: 0.06em;
  white-space: pre-wrap;
}

.boot .cursor::after {
  content: "█";
  animation: blink 0.8s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* menu */
.menu { text-align: center; }

.logo {
  font-family: monospace;
  font-size: clamp(0.45rem, 1.55vmin, 1rem);
  line-height: 1.15;
  color: var(--phos-bright);
  text-shadow: 0 0 14px rgba(62, 230, 136, 0.8);
  margin-bottom: 2vmin;
}

.menu-sub {
  font-size: clamp(0.8rem, 2.2vmin, 1.3rem);
  letter-spacing: 0.3em;
  color: var(--phos-dim);
  margin-bottom: 3vmin;
}

.menu-best {
  font-size: clamp(0.85rem, 2.3vmin, 1.4rem);
  color: var(--amber);
  min-height: 1.4em;
  margin-bottom: 2vmin;
}

.menu-lang {
  display: flex;
  justify-content: center;
  gap: 3vmin;
  font-size: clamp(0.9rem, 2.4vmin, 1.5rem);
  margin-bottom: 4vmin;
}

.lang { color: var(--phos-dim); }
.lang.on { color: var(--phos-bright); text-shadow: 0 0 10px rgba(62, 230, 136, 0.8); }

.menu-start {
  font-size: clamp(1rem, 3vmin, 1.9rem);
  letter-spacing: 0.12em;
}

.type-target .ch { color: var(--phos-dim); }
.type-target .ch.done { color: var(--phos-bright); text-shadow: 0 0 12px rgba(180, 255, 217, 0.9); }

/* play area */
.play { width: 100%; text-align: center; }

.incoming {
  font-size: clamp(0.75rem, 2vmin, 1.2rem);
  letter-spacing: 0.5em;
  color: var(--phos-dim);
  margin-bottom: 3.5vmin;
  animation: blink 1.6s steps(1) infinite;
}

.line {
  font-size: clamp(1.6rem, 5.4vmin, 4rem);
  letter-spacing: 0.08em;
  line-height: 1.3;
  min-height: 1.3em;
  word-break: break-word;
  padding: 0 4%;
}

.line .ch { color: var(--phos-dim); transition: color 0.05s; }
.line .ch.done { color: var(--phos-bright); text-shadow: 0 0 14px rgba(180, 255, 217, 0.9); }
.line .ch.cur { animation: curblink 0.9s steps(1) infinite; }

/* the letter stays readable in both blink phases */
@keyframes curblink {
  0%, 49% {
    color: var(--screen);
    background: var(--phos);
    box-shadow: 0 0 12px var(--phos);
  }
  50%, 100% {
    color: var(--phos-bright);
    background: rgba(62, 230, 136, 0.18);
    box-shadow: none;
  }
}

/* storm makes the text itself tremble */
.crt.storm .line { animation: tremble 0.18s linear infinite; }

@keyframes tremble {
  0% { transform: translate(0.6px, -0.4px); }
  33% { transform: translate(-0.5px, 0.5px); }
  66% { transform: translate(0.4px, 0.3px); }
  100% { transform: translate(-0.4px, -0.5px); }
}

/* per-line transmit timer */
.linetimer {
  width: min(54%, 460px);
  height: 5px;
  margin: 4vmin auto 0;
  border: 1px solid var(--phos-dim);
}

.linetimer-fill {
  height: 100%;
  width: 100%;
  background: var(--phos);
  box-shadow: 0 0 8px var(--phos);
  transform-origin: left;
}

.linetimer-fill.warn { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.linetimer-fill.crit { background: var(--alert); box-shadow: 0 0 8px var(--alert); }

/* phase banner */
.banner {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.6rem, 6vmin, 4.2rem);
  letter-spacing: 0.4em;
  color: var(--amber);
  text-shadow: 0 0 22px rgba(255, 210, 62, 0.8);
  background: rgba(2, 16, 8, 0.55);
  text-transform: uppercase;
  animation: bannerIn 1.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  pointer-events: none;
}

.banner.bad { color: var(--alert); text-shadow: 0 0 22px rgba(255, 74, 60, 0.8); }

@keyframes bannerIn {
  0% { opacity: 0; letter-spacing: 1.2em; }
  15% { opacity: 1; letter-spacing: 0.4em; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* progress track + ghost race */
.track {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  font-size: clamp(0.7rem, 1.8vmin, 1.1rem);
}

.track-bar {
  position: relative;
  flex: 1;
  height: 8px;
  border: 1px solid var(--phos-dim);
}

.track-you {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 0%;
  background: var(--phos);
  box-shadow: 0 0 10px var(--phos);
}

.track-ghost {
  position: absolute; top: -5px; bottom: -5px;
  left: 0%;
  width: 2px;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}

.track-delta { min-width: 9ch; text-align: right; color: var(--amber); }
.track-delta.ahead { color: var(--phos-bright); }

/* ─── mission report ─── */
.report {
  width: min(92%, 760px);
  max-height: 100%;
  overflow: hidden;
  font-size: clamp(0.95rem, 2.5vmin, 1.55rem);
  line-height: 1.5;
  letter-spacing: 0.05em;
  white-space: pre-wrap;
}

.report .r-line { overflow: hidden; }

.report .amber { color: var(--amber); }
.report .bright { color: var(--phos-bright); }

.report .keyboard {
  display: flex;
  flex-direction: column;
  gap: 0.4vmin;
  margin: 1vmin 0;
}

.report .krow { display: flex; gap: 0.4vmin; justify-content: flex-start; }
.report .krow:nth-child(2) { padding-left: 1.4vmin; }
.report .krow:nth-child(3) { padding-left: 3.4vmin; }

.report .key {
  width: clamp(20px, 3.6vmin, 34px);
  height: clamp(20px, 3.6vmin, 34px);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--phos-dim);
  font-size: clamp(0.7rem, 1.9vmin, 1.1rem);
  color: var(--phos);
}

.report .key.h1 { background: rgba(255, 210, 62, 0.25); border-color: var(--amber); color: var(--amber); }
.report .key.h2 { background: rgba(255, 74, 60, 0.3); border-color: var(--alert); color: #ffb0a8; }

#scope { border: 1px solid var(--phos-dim); display: block; margin: 0.6vmin 0; }

@media (max-width: 700px) {
  .crt { aspect-ratio: auto; height: 92vh; }
  .logo { font-size: 0.38rem; }
}
