/* ============================================================
   BOMB BLITZ — Neon Bomber Arcade
   All styling lives here; every DOM element is built in JS.
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Rubik:wght@400;600;800&display=swap');

:root {
  --bg0: #07030f;
  --bg1: #140a2e;
  --panel: rgba(16, 10, 38, 0.92);
  --panel-edge: #3b2a7a;
  --neon-pink: #ff3ec8;
  --neon-cyan: #29f0ff;
  --neon-yellow: #ffd23e;
  --neon-green: #3dff8a;
  --neon-red: #ff4a5e;
  --neon-orange: #ff8a2a;
  --text: #e8e6ff;
  --dim: #8f8ac2;
  --font-pixel: 'Press Start 2P', 'Courier New', monospace;
  --font-ui: 'Rubik', 'Segoe UI', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg0);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body {
  /* responsive sizing: the stage, HUD and touch pads all share one width
     that fits BOTH the viewport width and its height (no page scroll).
     --chrome-h approximates HUD + paddings; touchmode adds the D-pad row. */
  --vh: 100vh;
  --chrome-h: 118px;
  --stage-w: min(96vw, 760px, calc((var(--vh) - var(--chrome-h)) * 1.1538));
  background:
    radial-gradient(1200px 700px at 20% -10%, rgba(88, 40, 200, 0.35), transparent 60%),
    radial-gradient(1000px 600px at 90% 110%, rgba(255, 62, 200, 0.18), transparent 60%),
    radial-gradient(700px 500px at 60% 40%, rgba(41, 240, 255, 0.07), transparent 70%),
    linear-gradient(180deg, var(--bg1) 0%, var(--bg0) 100%);
}
@supports (height: 100dvh) {
  body { --vh: 100dvh; }
}
body.touchmode { --chrome-h: 208px; }

#app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 8px 4px;
}

/* ---------------- HUD ---------------- */
.hud {
  width: var(--stage-w);
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-family: var(--font-pixel);
}

.hud-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hud-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, rgba(40, 26, 92, 0.85), rgba(20, 12, 48, 0.9));
  border: 2px solid var(--panel-edge);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 11px;
  box-shadow: 0 0 12px rgba(96, 60, 220, 0.35), inset 0 0 10px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

.hud-chip .val { color: var(--neon-yellow); }
.hud-chip.lives .val { color: var(--neon-red); }
.hud-chip.level .val { color: var(--neon-cyan); }

.hud-score {
  font-size: 16px;
  letter-spacing: 1px;
  text-shadow: 0 0 10px rgba(255, 210, 62, 0.8);
  color: var(--neon-yellow);
}

.hud-timer.low {
  color: var(--neon-red) !important;
  animation: blinkFast 0.5s steps(2) infinite;
}

.hud-lives-icons { display: flex; gap: 3px; }
.hud-lives-icons .mini-heart {
  width: 14px; height: 14px;
  filter: drop-shadow(0 0 4px rgba(255, 74, 94, 0.9));
}

.hud-row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.pchips { display: flex; gap: 5px; flex-wrap: nowrap; overflow: hidden; }

.pchip {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(22, 14, 54, 0.9);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  padding: 3px 7px 3px 4px;
  font-size: 9px;
  color: var(--dim);
}
.pchip canvas { width: 20px; height: 20px; image-rendering: pixelated; display: block; }
.pchip.off { opacity: 0.28; filter: grayscale(1); }
.pchip.glow { box-shadow: 0 0 10px currentColor; animation: chipPop 0.3s ease; }

.hud-hint {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--dim);
  text-align: center;
}

/* ---------------- STAGE / CANVAS ---------------- */
.stage {
  position: relative;
  width: var(--stage-w);
  aspect-ratio: 720 / 624;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid #46329a;
  box-shadow:
    0 0 24px rgba(120, 60, 255, 0.35),
    0 0 60px rgba(255, 62, 200, 0.12),
    inset 0 0 24px rgba(0, 0, 0, 0.6);
  transition: box-shadow 0.3s;
}

.stage.danger {
  border-color: var(--neon-red);
  animation: dangerPulse 0.8s ease-in-out infinite;
}

.stage canvas.game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.fx-scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.16) 0px,
    rgba(0, 0, 0, 0.16) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: multiply;
  opacity: 0.7;
}

.fx-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 10, 0.55) 100%);
}

.no-crt .fx-scanlines { display: none; }

/* ---------------- SCREENS ---------------- */
/* fixed: overlays cover the whole viewport (not just the stage) so menus
   get maximum room on short/landscape screens; stage keeps its own size */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 2, 16, 0.72);
  backdrop-filter: blur(4px);
  z-index: 60;
  animation: screenIn 0.25s ease;
  overflow-y: auto;
  padding: 14px;
}

.screen.hidden { display: none; }

/* overlays fit instead of scrolling; the wheel/touch scroll still works
   on tiny viewports as a last resort, just without the ugly scrollbar */
.screen, .panel { scrollbar-width: none; }
.screen::-webkit-scrollbar, .panel::-webkit-scrollbar { display: none; }

.panel {
  width: min(94%, 520px);
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-radius: 16px;
  padding: 22px 22px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 0 40px rgba(90, 40, 220, 0.45), inset 0 0 30px rgba(0, 0, 0, 0.55);
  animation: popIn 0.3s cubic-bezier(0.2, 1.6, 0.4, 1);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
}

.panel.wide { width: min(96%, 600px); }

.screen-title {
  font-family: var(--font-pixel);
  font-size: 18px;
  color: var(--neon-cyan);
  text-shadow: 0 0 12px rgba(41, 240, 255, 0.9), 0 0 30px rgba(41, 240, 255, 0.4);
  letter-spacing: 2px;
  text-align: center;
}

.screen-sub {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--dim);
  text-align: center;
  line-height: 1.8;
}

/* menu logo */
.menu-logo {
  font-family: var(--font-pixel);
  font-size: clamp(22px, 5.4vw, 34px);
  letter-spacing: 3px;
  color: #fff;
  text-align: center;
  line-height: 1.35;
  text-shadow:
    0 0 8px #fff,
    0 0 18px var(--neon-pink),
    0 0 36px var(--neon-pink),
    0 0 70px rgba(255, 62, 200, 0.6);
  animation: logoPulse 2.2s ease-in-out infinite;
}

.menu-logo .word2 { color: var(--neon-yellow); text-shadow: 0 0 8px #fff, 0 0 18px var(--neon-yellow), 0 0 40px rgba(255, 210, 62, 0.6); }

.menu-tag {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--neon-green);
  text-shadow: 0 0 8px rgba(61, 255, 138, 0.8);
  letter-spacing: 1px;
}

.menu-art {
  width: 100%;
  aspect-ratio: 2 / 1;
  max-height: 26dvh;
  min-height: 84px;
  border-radius: 12px;
  object-fit: cover;
  border: 2px solid var(--panel-edge);
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.6), 0 0 14px rgba(255, 62, 200, 0.3);
}

/* ---------------- BUTTONS ---------------- */
.btn {
  font-family: var(--font-pixel);
  font-size: 12px;
  color: var(--text);
  background: linear-gradient(180deg, #2b1c66, #1a103f);
  border: 2px solid #5b3fb8;
  border-radius: 10px;
  padding: 12px 18px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: transform 0.08s, box-shadow 0.15s, border-color 0.15s, background 0.15s;
  width: 100%;
  text-align: center;
}
.btn:hover {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 14px rgba(41, 240, 255, 0.5);
  transform: translateY(-2px) scale(1.02);
}
.btn:active { transform: translateY(1px) scale(0.98); }

.btn.primary {
  background: linear-gradient(180deg, #ff3ec8, #b01790);
  border-color: #ff7ad9;
  box-shadow: 0 0 16px rgba(255, 62, 200, 0.55);
  text-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
}
.btn.primary:hover { box-shadow: 0 0 26px rgba(255, 62, 200, 0.85); border-color: #fff; }

.btn.more {
  background: linear-gradient(180deg, #0f7a4a, #0a5c38);
  border-color: var(--neon-green);
  color: #d6ffe8;
  box-shadow: 0 0 12px rgba(61, 255, 138, 0.35);
}
.btn.more:hover { box-shadow: 0 0 24px rgba(61, 255, 138, 0.7); border-color: #b9ffd9; }

.btn.saved {
  background: linear-gradient(180deg, #0f7a4a, #0a5c38);
  border-color: var(--neon-green);
  color: #d6ffe8;
  box-shadow: 0 0 12px rgba(61, 255, 138, 0.35);
  font-size: 11px;
}
.btn.saved:hover { box-shadow: 0 0 22px rgba(61, 255, 138, 0.65); border-color: #b9ffd9; }

.btn.small { font-size: 10px; padding: 9px 12px; width: auto; }
.btn.danger { border-color: var(--neon-red); color: #ffd9dd; }
.btn.danger:hover { box-shadow: 0 0 14px rgba(255, 74, 94, 0.6); border-color: #ff8b96; }

.btn-row { display: flex; gap: 10px; width: 100%; }
.btn-row .btn { flex: 1; }

/* segmented control */
.seg {
  display: flex;
  gap: 6px;
  width: 100%;
}
.seg button {
  flex: 1;
  font-family: var(--font-pixel);
  font-size: 10px;
  padding: 9px 4px;
  color: var(--dim);
  background: rgba(30, 18, 70, 0.7);
  border: 2px solid var(--panel-edge);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.seg button.on {
  color: #fff;
  background: linear-gradient(180deg, #35207e, #221456);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 12px rgba(41, 240, 255, 0.4);
}

.lbl {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--dim);
  align-self: flex-start;
  letter-spacing: 1px;
}

/* sliders + toggles */
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  font-family: var(--font-pixel);
  font-size: 10px;
}
.set-row input[type="range"] {
  flex: 1;
  max-width: 220px;
  accent-color: var(--neon-pink);
  cursor: pointer;
}
.toggle {
  position: relative;
  width: 52px;
  height: 26px;
  border-radius: 13px;
  border: 2px solid var(--panel-edge);
  background: rgba(30, 18, 70, 0.8);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--dim);
  transition: all 0.2s;
}
.toggle.on { border-color: var(--neon-green); background: rgba(61, 255, 138, 0.15); }
.toggle.on::after { left: 27px; background: var(--neon-green); box-shadow: 0 0 8px var(--neon-green); }

/* ---------------- TABLES / LISTS ---------------- */
.score-table {
  width: 100%;
  font-family: var(--font-pixel);
  font-size: 10px;
  border-collapse: collapse;
}
.score-table th {
  color: var(--neon-yellow);
  padding: 6px 4px;
  border-bottom: 2px solid var(--panel-edge);
  text-align: left;
}
.score-table td {
  padding: 7px 4px;
  color: var(--text);
  border-bottom: 1px solid rgba(90, 70, 180, 0.25);
}
.score-table td.rank { color: var(--neon-pink); }
.score-table td.num { text-align: right; color: var(--neon-yellow); }
.score-table tr.me td { background: rgba(255, 62, 200, 0.12); }

.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  width: 100%;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(24, 15, 58, 0.85);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 11px;
  color: var(--text);
}
.legend-item canvas { width: 26px; height: 26px; image-rendering: pixelated; flex-shrink: 0; }
.legend-item b { color: var(--neon-cyan); font-weight: 600; }

.ctrl-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  width: 100%;
  font-size: 12px;
  align-items: center;
}
.ctrl-grid kbd {
  font-family: var(--font-pixel);
  font-size: 9px;
  background: #241654;
  border: 1px solid #5b3fb8;
  border-bottom-width: 3px;
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--neon-yellow);
  white-space: nowrap;
}
.ctrl-grid span { color: var(--dim); }

.name-input {
  font-family: var(--font-pixel);
  font-size: 14px;
  letter-spacing: 4px;
  text-transform: uppercase;
  text-align: center;
  width: 200px;
  padding: 10px;
  color: var(--neon-yellow);
  background: rgba(10, 6, 30, 0.9);
  border: 2px solid var(--panel-edge);
  border-radius: 8px;
  outline: none;
}
.name-input:focus { border-color: var(--neon-cyan); box-shadow: 0 0 12px rgba(41, 240, 255, 0.4); }

.stat-lines {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  font-family: var(--font-pixel);
  font-size: 11px;
}
.stat-lines .line {
  display: flex;
  justify-content: space-between;
  color: var(--dim);
}
.stat-lines .line b { color: var(--text); }
.stat-lines .line.hl b { color: var(--neon-yellow); text-shadow: 0 0 8px rgba(255, 210, 62, 0.6); }

/* ---------------- TOASTS ---------------- */
.toast-wrap {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: 90%;
}

.toast {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: #fff;
  background: rgba(20, 12, 50, 0.95);
  border: 2px solid var(--neon-cyan);
  border-radius: 8px;
  padding: 8px 14px;
  box-shadow: 0 0 16px rgba(41, 240, 255, 0.5);
  animation: toastIn 0.25s ease, toastOut 0.4s ease 2.2s forwards;
  text-align: center;
}
.toast.bad { border-color: var(--neon-red); box-shadow: 0 0 16px rgba(255, 74, 94, 0.55); }
.toast.good { border-color: var(--neon-green); box-shadow: 0 0 16px rgba(61, 255, 138, 0.55); }
.toast.gold { border-color: var(--neon-yellow); box-shadow: 0 0 16px rgba(255, 210, 62, 0.55); }

/* ---------------- TOUCH CONTROLS ---------------- */
.touch {
  display: none;
  width: var(--stage-w);
  justify-content: space-between;
  align-items: flex-end;
  padding: 2px 6px 6px;
  gap: 10px;
}

body.touchmode .touch { display: flex; }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 4px;
}

.tc-btn {
  border: 2px solid rgba(91, 63, 184, 0.8);
  background: rgba(30, 18, 70, 0.75);
  border-radius: 12px;
  color: var(--neon-cyan);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
  transition: background 0.08s, transform 0.08s;
}
.tc-btn:active, .tc-btn.held {
  background: rgba(41, 240, 255, 0.25);
  transform: scale(0.94);
  box-shadow: 0 0 14px rgba(41, 240, 255, 0.4);
}
.tc-btn.bomb {
  width: 74px; height: 74px;
  border-radius: 50%;
  font-size: 26px;
  border-color: var(--neon-pink);
  color: #ffb8ea;
}
.tc-btn.bomb:active, .tc-btn.bomb.held { background: rgba(255, 62, 200, 0.3); box-shadow: 0 0 18px rgba(255, 62, 200, 0.6); }
.tc-btn.remote {
  width: 54px; height: 54px;
  border-radius: 50%;
  font-size: 18px;
  border-color: var(--neon-yellow);
  color: var(--neon-yellow);
}
.tc-btn.pause {
  width: 44px; height: 44px;
  border-radius: 10px;
  font-size: 15px;
  border-color: var(--panel-edge);
  color: var(--dim);
  cursor: pointer;
}
.tc-btn.pause:active { background: rgba(255, 255, 255, 0.12); box-shadow: none; }
.tc-side { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.tc-arrow-row { display: flex; justify-content: center; }
.tc-blank { visibility: hidden; }

/* ---------------- BOOT ---------------- */
.boot-bar {
  width: 260px;
  height: 14px;
  border: 2px solid var(--panel-edge);
  border-radius: 7px;
  overflow: hidden;
  background: rgba(10, 6, 30, 0.9);
}
.boot-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--neon-pink), var(--neon-cyan));
  box-shadow: 0 0 12px rgba(255, 62, 200, 0.7);
  transition: width 0.15s;
}

.tiny-note { font-size: 10px; color: var(--dim); font-family: var(--font-ui); }
.tiny-note a { color: var(--neon-cyan); text-decoration: none; }

/* ---------------- ANIMATIONS ---------------- */
@keyframes logoPulse {
  0%, 100% { text-shadow: 0 0 8px #fff, 0 0 18px var(--neon-pink), 0 0 36px var(--neon-pink), 0 0 70px rgba(255, 62, 200, 0.6); }
  50% { text-shadow: 0 0 10px #fff, 0 0 26px var(--neon-yellow), 0 0 44px rgba(255, 210, 62, 0.8), 0 0 90px rgba(255, 62, 200, 0.5); }
}
@keyframes popIn { 0% { transform: scale(0.85); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes screenIn { 0% { opacity: 0; } 100% { opacity: 1; } }
@keyframes toastIn { 0% { transform: translateY(-14px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }
@keyframes toastOut { 0% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }
@keyframes blinkFast { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0.35; } }
@keyframes chipPop { 0% { transform: scale(1.35); } 100% { transform: scale(1); } }
@keyframes dangerPulse {
  0%, 100% { box-shadow: 0 0 24px rgba(255, 74, 94, 0.35), inset 0 0 24px rgba(0, 0, 0, 0.6); }
  50% { box-shadow: 0 0 40px rgba(255, 74, 94, 0.85), inset 0 0 24px rgba(0, 0, 0, 0.6); }
}

/* ---------------- MOBILE ---------------- */
@media (max-width: 640px) {
  .hud-chip { font-size: 9px; padding: 5px 8px; }
  .hud-score { font-size: 12px; }
  .pchip { font-size: 7px; padding: 2px 4px 2px 3px; }
  .pchip canvas { width: 16px; height: 16px; }
  .hud-hint { display: none; }
  .panel { padding: 16px 12px 14px; gap: 10px; }
  .screen-title { font-size: 14px; }
  .btn { font-size: 10px; padding: 10px 12px; }
  .menu-logo { font-size: clamp(18px, 6vw, 26px); }
}

/* short viewports (landscape phones, small laptops): keep the menu on one
   screen — shrink panels and drop the key art before any scrollbar shows */
@media (max-height: 640px) {
  #app { gap: 4px; padding: 4px; }
  .panel { gap: 8px; padding: 12px 14px 10px; }
  .menu-logo { font-size: clamp(16px, 4.6vw, 24px); }
  .menu-art { max-height: 18dvh; }
  .screen { padding: 8px; }
}
@media (max-height: 500px) {
  .menu-art { display: none; }
  .hud-row2 .hud-hint { display: none; }
}
