:root {
  /* DethSquad palette — matches the "Enter the Grid" banner: black, toxic green, cream */
  --bg: #060A05;
  --bg-card: #0B130A;
  --border: #1B2B17;
  --border-bright: #2E4628;
  --text: #F4F0DA;            /* cream from banner */
  --text-muted: #7E8E73;
  --acid: #B8FF40;            /* dominant toxic green */
  --acid-bright: #D2FF6E;
  --acid-dim: #5BC020;
  --acid-glow: rgba(184, 255, 64, 0.35);
  /* Legacy aliases keep older selectors working */
  --doom-red: var(--acid-dim);
  --doom-red-bright: var(--acid);
  --doom-orange: #FF8C42;     /* keep for hurt + danger contrast */
  --gold: #F4C430;
  --green-bright: var(--acid);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 50% -20%, rgba(120, 200, 40, 0.20), transparent 50%),
    radial-gradient(ellipse at 110% 110%, rgba(255, 110, 42, 0.10), transparent 50%),
    var(--bg);
}

/* Header */
.bs-header {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  padding-top: max(12px, env(safe-area-inset-top));
  z-index: 5;
  pointer-events: none;
}
.bs-header > * { pointer-events: auto; }
.bs-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text);
  font-size: 14px;
  background: rgba(20, 8, 10, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
}
.bs-brand img { width: 22px; }
.bs-brand strong { color: var(--doom-red-bright); font-weight: 800; letter-spacing: 0.04em; }
.bs-header-right { display: flex; gap: 6px; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(20, 8, 10, 0.85);
  backdrop-filter: blur(8px);
  color: var(--text-muted); font-size: 16px;
  cursor: pointer; text-decoration: none;
}
.btn-icon:hover { color: var(--text); border-color: var(--border-bright); }

.screen {
  display: none; min-height: 100vh;
  padding: 80px 20px 40px;
  align-items: center; justify-content: center;
}
.screen.active { display: flex; }

/* ─── Title ─── */
.title-card {
  max-width: 600px; width: 100%; text-align: center;
  background: linear-gradient(180deg, rgba(20,8,10,0.95) 0%, rgba(10,5,6,0.95) 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 28px;
  box-shadow: 0 0 60px rgba(120, 200, 40, 0.10);
}
.doom-logo-img {
  display: block;
  margin: 0 auto 16px;
  width: 100%;
  max-width: 480px;
  height: auto;
  border-radius: 10px;
  filter: drop-shadow(0 8px 30px rgba(184, 255, 64, 0.35));
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.title-tag {
  margin: 0 0 24px;
  color: var(--text-muted); font-size: 15px; line-height: 1.6;
}
.title-buttons { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.title-credit {
  font-size: 11px; color: #6B5856;
  padding-top: 14px; border-top: 1px solid var(--border);
  margin: 0;
}
.title-credit a { color: var(--doom-red-bright); text-decoration: none; }
.title-credit a:hover { text-decoration: underline; }

/* Buttons */
.btn {
  font: inherit; font-weight: 700; font-size: 14px;
  padding: 11px 22px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-doom {
  background: linear-gradient(135deg, #B8FF40 0%, #5BC020 100%);
  color: #082010;
  border-color: rgba(184, 255, 64, 0.7);
  box-shadow: 0 4px 20px rgba(184, 255, 64, 0.35), inset 0 1px 0 rgba(255,255,255,0.25);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 13px;
  font-weight: 800;
}
.btn-doom:hover {
  background: linear-gradient(135deg, #D2FF6E 0%, #80E830 100%);
  box-shadow: 0 4px 28px rgba(184, 255, 64, 0.6), inset 0 1px 0 rgba(255,255,255,0.35);
}
.btn-doom:disabled { background: #1A2818; color: #4A5848; cursor: not-allowed; box-shadow: none; }
.hud-cell { background: linear-gradient(180deg, rgba(11,19,10,0.9) 0%, rgba(20,32,18,0.85) 100%) !important; }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-bright); }

/* Card screens */
.screen-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 24px 24px;
  width: 100%; max-width: 540px; position: relative;
}
.screen-card.narrow { max-width: 380px; text-align: center; }
.screen-card h2 { margin: 0 0 14px; font-size: 22px; font-weight: 800; letter-spacing: 0.02em; text-transform: uppercase; }
.btn-close {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-muted); font-size: 18px; cursor: pointer;
}
.btn-close:hover { color: var(--text); border-color: var(--border-bright); }

/* Controls table */
.controls-table {
  width: 100%; margin: 12px 0 16px;
  border-collapse: collapse;
  color: var(--text-muted); font-size: 14px;
}
.controls-table td {
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
.controls-table td:first-child {
  white-space: nowrap; padding-right: 16px;
}
.controls-table td:last-child {
  color: var(--text);
}
.kbd {
  display: inline-block; padding: 2px 8px; margin: 0 2px;
  border: 1px solid var(--border-bright); border-radius: 5px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px; font-weight: 600;
  color: var(--doom-red-bright);
  background: rgba(184, 255, 64,0.06);
}
.howto-tip {
  background: rgba(120, 200, 40, 0.08);
  border: 1px solid rgba(120, 200, 40, 0.3);
  border-radius: 10px; padding: 12px;
  font-size: 13px; color: var(--text-muted);
  line-height: 1.5;
}
.howto-tip strong { color: var(--doom-red-bright); }

/* ─── Game canvas ─── */
.game-wrap {
  display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 720px; gap: 14px;
}
.canvas-shell {
  position: relative;
  width: 100%; max-width: 800px;
  aspect-ratio: 16 / 10;
  background: #000;
  border: 2px solid var(--border-bright);
  border-radius: 8px;
  overflow: hidden;
  box-shadow:
    0 0 40px rgba(120, 200, 40, 0.25),
    inset 0 0 0 1px rgba(184, 255, 64, 0.1);
}
#game-canvas {
  width: 100%; height: 100%;
  display: block;
  image-rendering: pixelated;
  background: #000;
  outline: none;
}
.hud {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  background: rgba(184, 255, 64, 0.25);
  padding: 0 1px 1px 1px;
}
.hud-cell {
  background: linear-gradient(180deg, rgba(20,8,10,0.85) 0%, rgba(40,15,18,0.85) 100%);
  padding: 6px 10px;
  text-align: center;
}
.hud-label {
  font-size: 9px; font-weight: 800;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--doom-red-bright);
}
.hud-value {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 18px; font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.hud-value.gold { color: var(--gold); }

.click-to-start {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6);
  cursor: pointer;
  color: #fff;
  z-index: 9;
  touch-action: none;
}
.click-to-start[hidden] { display: none; }

/* ─── Mobile touch controls ─── */
.mobile-controls { position: absolute; inset: 0; z-index: 7; pointer-events: none; }
.mobile-controls[hidden] { display: none; }
.mobile-controls > * { pointer-events: auto; }
.joystick {
  position: absolute; left: 14px; bottom: 14px;
  width: 92px; height: 92px;
  background: rgba(184, 255, 64, 0.07);
  border: 1.5px solid rgba(184, 255, 64, 0.35);
  border-radius: 50%;
  touch-action: none;
  opacity: 0.75;
}
.joystick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 36px; height: 36px; margin-left: -18px; margin-top: -18px;
  background: linear-gradient(135deg, #B8FF40 0%, #5BC020 100%);
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(184, 255, 64, 0.55);
}
.fire-btn {
  position: absolute; right: 16px; bottom: 16px;
  width: 100px; height: 100px;
  background: linear-gradient(135deg, rgba(232,80,60,0.8) 0%, rgba(160,30,20,0.8) 100%);
  border: 2px solid rgba(255, 140, 66, 0.9);
  border-radius: 50%;
  color: #fff; font-size: 36px; font-weight: 900;
  cursor: pointer; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
  box-shadow: 0 0 18px rgba(232, 80, 60, 0.45);
}
.fire-btn:active { transform: scale(0.94); }
.action-btn {
  position: absolute;
  width: 56px; height: 56px;
  background: linear-gradient(135deg, rgba(20,32,18,0.85) 0%, rgba(40,60,30,0.85) 100%);
  border: 2px solid rgba(184, 255, 64, 0.6);
  border-radius: 50%;
  color: #B8FF40;
  font-size: 26px; font-weight: 900;
  cursor: pointer; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
  box-shadow: 0 0 14px rgba(184, 255, 64, 0.3);
}
.action-btn:active { transform: scale(0.94); }
.reload-btn { right: 132px; bottom: 22px; }
.swap-btn   { right: 132px; bottom: 86px; }
.look-zone {
  position: absolute; right: 0; top: 0; bottom: 120px;
  width: 60%;
  touch-action: none;
  display: flex; align-items: center; justify-content: center;
}
.look-hint {
  font-size: 11px; font-weight: 800;
  letter-spacing: 0.18em;
  color: rgba(184, 255, 64, 0.55);
  border: 1px dashed rgba(184, 255, 64, 0.4);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0,0,0,0.25);
  pointer-events: none;
  animation: lookPulse 2.4s ease-in-out infinite alternate;
}
.look-zone.used .look-hint { display: none; }
@keyframes lookPulse { 0% { opacity: 0.4; } 100% { opacity: 0.95; } }
.overlay-hint {
  margin-top: 14px; font-size: 12px; color: var(--text-muted);
  border-top: 1px solid var(--border); padding-top: 10px;
}
.overlay-hint .kbd { color: var(--acid); }

.cts-text {
  font-size: 28px; font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--doom-red-bright);
  text-shadow: 0 0 24px rgba(184, 255, 64,0.6);
  margin-bottom: 8px;
  animation: ctsPulse 1.4s ease-in-out infinite alternate;
}
.cts-sub { font-size: 12px; color: var(--text-muted); }
@keyframes ctsPulse { 0% { opacity: 0.6; } 100% { opacity: 1; } }

.game-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.85);
  z-index: 6;
}
.game-overlay[hidden] { display: none; }
.game-overlay-card {
  text-align: center; padding: 24px 28px;
  max-width: 380px;
}
.game-overlay-card h3 {
  margin: 0 0 8px;
  font-size: 32px; font-weight: 900;
  color: var(--doom-red-bright);
  letter-spacing: 0.04em;
  text-shadow: 0 0 24px rgba(184, 255, 64,0.5);
}
.game-overlay-card p { margin: 0 0 16px; color: var(--text-muted); font-size: 14px; }
.overlay-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* HS modal + leaderboard styles (shared shape) */
.hs-card { padding-top: 28px; text-align: center; }
.hs-trophy { font-size: 44px; margin-bottom: 4px; }
.hs-card h2 { margin-bottom: 6px; }
.hs-sub { margin: 0 0 18px; color: var(--text-muted); font-size: 13px; }
.hs-score-display {
  background: linear-gradient(135deg, rgba(244,196,48,0.10) 0%, rgba(184, 255, 64,0.10) 100%);
  border: 1px solid rgba(244,196,48,0.3);
  border-radius: 12px; padding: 16px; margin-bottom: 16px;
}
.hs-score-num {
  font-size: 36px; font-weight: 900;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  color: var(--gold); letter-spacing: -0.02em;
  text-shadow: 0 0 20px rgba(244,196,48,0.4);
}
.hs-rank { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.hs-rank.high { color: #FFB840; font-weight: 700; }
.hs-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; text-align: left; }
.hs-form input {
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
  color: var(--text); font: inherit; font-size: 14px; outline: none;
}
.hs-form input:focus { border-color: var(--doom-red-bright); }
.hs-disclaimer { margin: 4px 0 8px; font-size: 11px; color: var(--text-muted); line-height: 1.4; }
.hs-status { min-height: 18px; font-size: 12px; margin-bottom: 6px; color: var(--text-muted); text-align: center; }
.hs-status.error { color: var(--doom-orange); }
.hs-status.success { color: var(--green-bright); }

.lb-card { padding-top: 36px; max-width: 480px; }
.lb-sub { margin: 0 0 16px; color: var(--text-muted); font-size: 13px; }
.lb-list { list-style: none; padding: 0; margin: 0; }
.lb-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 6px;
}
.lb-list li.you { background: rgba(184, 255, 64,0.12); border-color: rgba(184, 255, 64,0.4); }
.lb-list li.lb-empty { justify-content: center; color: var(--text-muted); font-size: 13px; }
.lb-rank {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; background: #1A0E10;
  font-weight: 800; font-size: 14px; color: var(--text-muted); flex-shrink: 0;
}
.lb-rank.gold { background: linear-gradient(135deg, #F4C430 0%, #D9A410 100%); color: #2A1F00; box-shadow: 0 0 14px rgba(244,196,48,0.4); }
.lb-rank.silver { background: linear-gradient(135deg, #C0C8C4 0%, #94A097 100%); color: #1A1F1B; }
.lb-rank.bronze { background: linear-gradient(135deg, #C58E5C 0%, #8E6238 100%); color: #1F1208; }
.lb-name { flex: 1; min-width: 0; font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-family: 'JetBrains Mono', ui-monospace, monospace; font-weight: 800; font-size: 15px; color: var(--gold); font-variant-numeric: tabular-nums; flex-shrink: 0; }

.title-best { font-size: 13px; color: var(--text-muted); padding-top: 14px; border-top: 1px solid var(--border); margin-top: 6px; }
.title-best span { color: var(--gold); font-weight: 800; }
.game-hint {
  font-size: 12px; color: var(--text-muted); text-align: center;
}

/* ─── Rate (shared) ─── */
.rate-card { padding-top: 36px; }
.rate-sub { margin: 4px 0 14px; color: var(--text-muted); font-size: 13px; }
.rate-stars { display: flex; justify-content: center; gap: 6px; margin: 6px 0 16px; }
.star-btn {
  background: none; border: none; cursor: pointer;
  font-size: 32px; line-height: 1;
  color: rgba(244, 196, 48, 0.22);
  padding: 4px 6px; border-radius: 6px;
  transition: color 0.12s, transform 0.12s;
}
.star-btn:hover { color: rgba(244, 196, 48, 0.65); transform: scale(1.08); }
.star-btn.lit { color: var(--gold); text-shadow: 0 0 14px rgba(244, 196, 48, 0.5); }
.rate-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; text-align: left; }
.rate-form input, .rate-form textarea {
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
  color: var(--text); font: inherit; font-size: 14px;
  resize: vertical; outline: none;
}
.rate-form input:focus, .rate-form textarea:focus { border-color: var(--doom-red-bright); }
.rate-status { min-height: 18px; font-size: 12px; margin-bottom: 6px; color: var(--text-muted); text-align: center; }
.rate-status.error { color: var(--doom-orange); }
.rate-status.success { color: var(--green-bright); }
.rate-signup {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 12px; color: var(--text-muted); line-height: 1.4;
  padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 10px; background: rgba(120, 200, 40,0.04);
  cursor: pointer; user-select: none; text-align: left;
}
.rate-signup input[type="checkbox"] { margin-top: 2px; accent-color: var(--doom-red); }
.rate-signup small { display: block; opacity: 0.75; font-size: 11px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }

@media (max-width: 540px) {
  .doom-logo-img { max-width: 320px; }
}

/* ─── Clear Back-to-Games button ─── */
.btn-back {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 14px; height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(184, 255, 64, 0.45);
  background: linear-gradient(135deg, rgba(184,255,64,0.18) 0%, rgba(91,192,32,0.18) 100%);
  color: var(--acid, #B8FF40);
  font-size: 13px; font-weight: 700; letter-spacing: 0.04em;
  text-decoration: none; cursor: pointer;
  transition: all 0.15s;
}
.btn-back:hover {
  background: linear-gradient(135deg, rgba(184,255,64,0.28) 0%, rgba(91,192,32,0.28) 100%);
  color: #fff;
  border-color: rgba(184, 255, 64, 0.7);
}
.btn-back .ba-arrow { font-size: 16px; line-height: 1; }
@media (max-width: 540px) {
  .btn-back { padding: 0 10px; font-size: 12px; }
}

/* ─── Controls hint bar (bottom of game screen) ─── */
.controls-hint {
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  justify-content: center;
  font-size: 12px;
  padding: 12px 16px;
  background: rgba(11, 19, 10, 0.7);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 800px;
  margin: 0 auto;
}
.controls-hint span { white-space: nowrap; color: var(--text-muted); }
.controls-hint strong { color: var(--acid); font-weight: 700; }
.controls-hint .kbd { font-size: 10px; }
.mobile-hint { display: none; }
