:root {
  --fg: #33ff66;
  --dim: #0c5528;
  --bg: #020a04;
  --panel: #06120a;
  --border: #1a6b39;
  --accent: #33ff66;
}

body.lvl-serious {
  --fg: #ffb020;
  --dim: #663f00;
  --bg: #0a0602;
  --panel: #140d02;
  --border: #7a5200;
  --accent: #ffb020;
}

body.lvl-final {
  --fg: #ff3b3b;
  --dim: #5c0d0d;
  --bg: #0c0202;
  --panel: #160404;
  --border: #7a1414;
  --accent: #ff3b3b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(51,255,102,0.06), transparent 60%),
    #000;
  color: var(--fg);
  font-family: "IBM Plex Mono", monospace;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.5s;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px 32px;
  gap: 14px;
}

/* ---------- CRT ---------- */
#crt-wrap {
  width: 100%;
  max-width: 820px;
  display: flex;
  justify-content: center;
}

#crt-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 8 / 5;
  border-radius: 18px;
  background: var(--bg);
  overflow: hidden;
  box-shadow:
    0 0 0 6px #0a0a0a,
    0 0 0 10px #1a1a1a,
    inset 0 0 60px rgba(0,0,0,0.9),
    0 0 40px rgba(51,255,102,0.15);
  border: 2px solid #000;
}

body.lvl-serious #crt-frame { box-shadow: 0 0 0 6px #0a0a0a, 0 0 0 10px #1a1a1a, inset 0 0 60px rgba(0,0,0,0.9), 0 0 40px rgba(255,176,32,0.18); }
body.lvl-final #crt-frame { box-shadow: 0 0 0 6px #0a0a0a, 0 0 0 10px #1a1a1a, inset 0 0 60px rgba(0,0,0,0.9), 0 0 48px rgba(255,59,59,0.25); }

#canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#scanlines {
  position: absolute;
  inset: 0;
  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.28) 3px,
    rgba(0,0,0,0.28) 4px
  );
  animation: scan-flicker 6s infinite steps(60);
  mix-blend-mode: multiply;
}

@keyframes scan-flicker {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 0.95; }
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.75) 100%);
  border-radius: 18px;
}

/* ---------- Controls ---------- */
#controls {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 0 24px rgba(0,0,0,0.6);
}

.ctrl-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.prompt-row { gap: 10px; }

.prompt-tag {
  font-family: "VT323", monospace;
  font-size: 1.35rem;
  letter-spacing: 0.5px;
  color: var(--fg);
  white-space: nowrap;
}

#nameInput {
  flex: 1;
  min-width: 140px;
  background: #000;
  border: 1px solid var(--border);
  color: var(--fg);
  font-family: "VT323", monospace;
  font-size: 1.35rem;
  padding: 6px 12px;
  border-radius: 6px;
  outline: none;
  caret-color: var(--fg);
}
#nameInput:focus {
  box-shadow: 0 0 12px rgba(51,255,102,0.4), inset 0 0 8px rgba(51,255,102,0.1);
  border-color: var(--fg);
}

/* buttons */
button {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: #000;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
button:active { transform: translateY(1px) scale(0.98); }

/* level buttons */
.levels { justify-content: stretch; }
.lvl-btn {
  flex: 1;
  min-width: 100px;
  min-height: 46px;
  font-size: 0.82rem;
  padding: 8px 6px;
}
.lvl-btn[data-level="0"].active { color: #33ff66; border-color: #33ff66; box-shadow: 0 0 14px rgba(51,255,102,0.5); background: rgba(51,255,102,0.08); }
.lvl-btn[data-level="1"].active { color: #ffb020; border-color: #ffb020; box-shadow: 0 0 14px rgba(255,176,32,0.5); background: rgba(255,176,32,0.08); }
.lvl-btn[data-level="2"].active { color: #ff3b3b; border-color: #ff3b3b; box-shadow: 0 0 18px rgba(255,59,59,0.6); background: rgba(255,59,59,0.1); animation: pulse-final 1.2s infinite; }
.lvl-btn:hover { filter: brightness(1.3); }

@keyframes pulse-final {
  0%, 100% { box-shadow: 0 0 12px rgba(255,59,59,0.4); }
  50% { box-shadow: 0 0 26px rgba(255,59,59,0.9); }
}

/* main big button */
.big-btn {
  flex: 1;
  min-height: 58px;
  font-size: 1.05rem;
  color: var(--fg);
  border: 2px solid var(--fg);
  background: rgba(51,255,102,0.06);
  box-shadow: 0 0 18px rgba(51,255,102,0.25);
  animation: breathe 2.4s ease-in-out infinite;
}
body.lvl-serious .big-btn { background: rgba(255,176,32,0.06); box-shadow: 0 0 18px rgba(255,176,32,0.3); }
body.lvl-final .big-btn { background: rgba(255,59,59,0.08); box-shadow: 0 0 22px rgba(255,59,59,0.4); }
.big-btn:hover { filter: brightness(1.35); }

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.012); }
}

/* secondary buttons */
.secondary-actions { justify-content: center; }
.sm-btn {
  min-height: 44px;
  font-size: 0.78rem;
  padding: 8px 12px;
  color: var(--dim);
  filter: brightness(1.6);
}
.sm-btn:hover { color: var(--fg); border-color: var(--fg); filter: none; }
.sm-btn.danger { color: #ff6666; border-color: #7a1414; }
.sm-btn.danger:hover { color: #fff; background: #ff3b3b; border-color: #ff3b3b; box-shadow: 0 0 16px rgba(255,59,59,0.6); }
.sm-btn:disabled { opacity: 0.5; cursor: wait; }

/* stats */
.stats {
  justify-content: space-between;
  font-family: "VT323", monospace;
  font-size: 1.1rem;
  color: var(--dim);
  filter: brightness(1.7);
  border-top: 1px dashed var(--border);
  padding-top: 10px;
  gap: 12px;
}
.stats span { white-space: nowrap; }

/* footer */
footer {
  width: 100%;
  max-width: 820px;
  text-align: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: #2f6b45;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}
footer a {
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px dotted var(--fg);
}
footer a:hover { filter: brightness(1.3); }
.disclaimer { opacity: 0.7; font-style: italic; }

/* ---------- Mobile ---------- */
@media (max-width: 520px) {
  body { padding: 10px 8px 24px; gap: 10px; }
  .prompt-row { flex-wrap: nowrap; }
  .prompt-tag { font-size: 1.05rem; }
  #nameInput { font-size: 1.1rem; min-width: 0; }
  .lvl-btn { font-size: 0.68rem; min-width: 0; padding: 8px 2px; }
  .big-btn { font-size: 0.92rem; min-height: 54px; }
  .sm-btn { flex: 1 1 45%; font-size: 0.7rem; padding: 10px 6px; }
  .secondary-actions { gap: 6px; }
  .stats { font-size: 0.95rem; flex-direction: column; align-items: flex-start; gap: 4px; }
  #controls { padding: 12px; }
}