@font-face {
  font-family: 'VT323';
  src: url('../vendor/VT323.woff2') format('woff2');
  font-display: block;
}

:root {
  --bg: #020803;
  --fg: #3dff7a;
  --fg-dim: #1d8a43;
  --glow: rgba(61, 255, 122, 0.55);
  --side-a: #6fd8ff;
  --side-b: #ff4f3a;
  --blast: #fff6d8;
  --hint: #7aa48a;
  --font-size: clamp(17px, 2.1vw, 30px);
}

:root[data-color="amber"] {
  --bg: #0a0600;
  --fg: #ffb22e;
  --fg-dim: #8f5f10;
  --glow: rgba(255, 178, 46, 0.55);
  --side-a: #ffe7a8;
  --side-b: #ff5a2a;
  --hint: #a58a5c;
}

:root[data-color="blue"] {
  --bg: #01040c;
  --fg: #a9d6ff;
  --fg-dim: #3c6a9a;
  --glow: rgba(120, 190, 255, 0.55);
  --side-a: #7fe3ff;
  --side-b: #ff4a4a;
  --hint: #7088a6;
}

:root[data-color="white"] {
  --bg: #050506;
  --fg: #e8ecf2;
  --fg-dim: #7a7f88;
  --glow: rgba(230, 236, 255, 0.45);
  --side-a: #8fd3ff;
  --side-b: #ff5252;
  --hint: #8b8f96;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  overflow: hidden;
}

body {
  font-family: 'VT323', ui-monospace, Menlo, monospace;
  font-size: var(--font-size);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- the tube ---------- */

.crt {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--bg) 70%, var(--fg) 4%) 0%, var(--bg) 70%, #000 100%);
  overflow: hidden;
  transition: transform 0.45s cubic-bezier(.2,.9,.2,1), filter 0.45s, opacity 0.3s;
}

.crt.off {
  transform: scale(1, 0.002);
  filter: brightness(6);
  opacity: 0;
}

.crt.warming {
  transform: scale(1, 0.002);
  filter: brightness(6);
  opacity: 1;
  transition: transform 0.08s, opacity 0.08s;
}

.crt.dying {
  transform: scale(0.001, 0.001);
  filter: brightness(8);
  transition: transform 0.35s ease-in, filter 0.35s;
}

#screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: max(2.2vh, 16px) max(3.2vw, 16px);
  text-shadow: 0 0 2px var(--fg), 0 0 9px var(--glow);
  animation: jitter 7s infinite steps(1);
}

@keyframes jitter {
  0%, 100% { transform: translate(0, 0); }
  47% { transform: translate(0.4px, 0); }
  48% { transform: translate(-0.3px, 0.2px); }
  49% { transform: translate(0, 0); }
}

.scanlines, .flicker, .vignette, #flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scanlines {
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0px, rgba(0,0,0,0) 2px, rgba(0,0,0,0.28) 3px, rgba(0,0,0,0) 4px);
  mix-blend-mode: multiply;
}

.flicker {
  background: var(--fg);
  opacity: 0.012;
  animation: flicker 0.12s infinite alternate;
}

@keyframes flicker {
  from { opacity: 0.008; }
  to { opacity: 0.022; }
}

.vignette {
  background:
    radial-gradient(ellipse at center, rgba(0,0,0,0) 58%, rgba(0,0,0,0.55) 88%, rgba(0,0,0,0.9) 100%);
  box-shadow: inset 0 0 90px rgba(0,0,0,0.85);
}

#flash {
  background: var(--blast);
  opacity: 0;
  mix-blend-mode: screen;
}

/* ---------- terminal ---------- */

#term {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  overflow: hidden;
  line-height: 1.12;
}

#output {
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 0;
}

#output > div { min-height: 1.12em; }

#output .user { color: var(--fg); opacity: 0.92; }
#output .hint { color: var(--hint); text-shadow: none; font-style: normal; }
#output .alert { color: var(--side-b); text-shadow: 0 0 2px var(--side-b), 0 0 10px var(--side-b); }
#output .big { font-size: 2.2em; line-height: 1; letter-spacing: 0.06em; }

#inputline {
  white-space: pre;
  min-height: 1.12em;
  flex: 0 0 auto;
}

#inputline.hidden { visibility: hidden; }

#cursor {
  display: inline-block;
  width: 0.55em;
  height: 0.95em;
  vertical-align: -0.1em;
  background: var(--fg);
  box-shadow: 0 0 8px var(--glow);
  animation: blink 1.06s steps(1) infinite;
}

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

#kbd {
  position: fixed;
  left: -1000px;
  top: 0;
  opacity: 0;
  width: 10px;
  height: 10px;
  font-size: 16px; /* stops iOS zoom */
}

/* ---------- the big board ---------- */

#board {
  position: relative;
  flex: 0 0 0;
  height: 0;
  opacity: 0;
  overflow: hidden;
  transition: flex-basis 0.6s ease, opacity 0.6s ease, margin 0.6s ease;
  margin-bottom: 0;
}

#screen.board-mode #board {
  flex-basis: 60%;
  opacity: 1;
  margin-bottom: 1.2vh;
}

#screen.board-full #board {
  flex-basis: 100%;
  opacity: 1;
}

#screen.board-full #term { flex: 0 0 0; }

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: 0.9em;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hud-top, .hud-bottom {
  display: flex;
  justify-content: space-between;
  gap: 1em;
  padding: 0.15em 0.3em;
}

#hud-defcon.defcon-1, #hud-defcon.defcon-2 {
  color: var(--side-b);
  text-shadow: 0 0 2px var(--side-b), 0 0 12px var(--side-b);
  animation: blink 0.8s steps(1) infinite;
}

#hud-a { color: var(--side-a); text-shadow: 0 0 8px var(--side-a); }
#hud-b { color: var(--side-b); text-shadow: 0 0 8px var(--side-b); text-align: right; }

#hud-big {
  align-self: center;
  font-size: 3.4em;
  letter-spacing: 0.08em;
  text-align: center;
  line-height: 1;
  padding: 0.15em 0.5em;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  opacity: 0;
  transition: opacity 0.15s;
}

#hud-big.on { opacity: 1; }

/* ---------- power switch ---------- */

#power {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2em;
  background: #000;
  color: #6b6b6b;
  font-size: 22px;
  z-index: 10;
  transition: opacity 0.3s;
  padding: 16px;
  text-align: center;
}

#power.gone { opacity: 0; pointer-events: none; }

#power p { margin: 0; max-width: 28em; }

#power-btn {
  font: inherit;
  font-size: 28px;
  letter-spacing: 0.2em;
  color: #c8c8c8;
  background: linear-gradient(#2a2a2a, #161616);
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  padding: 0.5em 1.2em;
  display: flex;
  align-items: center;
  gap: 0.7em;
  cursor: pointer;
  box-shadow: 0 2px 0 #000, inset 0 1px 0 #444;
}

#power-btn:hover { color: #fff; }
#power-btn:active { transform: translateY(2px); box-shadow: inset 0 1px 0 #444; }

.led {
  width: 0.45em;
  height: 0.45em;
  border-radius: 50%;
  background: #3a0d0d;
  box-shadow: inset 0 0 2px #000;
}

#power-btn:hover .led { background: #ff3b2f; box-shadow: 0 0 10px #ff3b2f; }

@media (max-width: 640px) {
  :root { --font-size: 17px; }
  #screen.board-mode #board { flex-basis: 42%; }
  #hud { font-size: 0.75em; }
  #hud-big { font-size: 2.2em; }
}

@media (prefers-reduced-motion: reduce) {
  #screen, .flicker, #cursor { animation: none; }
}
