:root {
  --bg: #0a0614;
  --bg-deep: #150a24;
  --pink: #ff2d95;
  --cyan: #00e5ff;
  --purple: #b14aed;
  --yellow: #ffe066;
  --green: #39ff14;
  --red: #ff3b3b;
  --text: #f4ecff;
  --dim: #8a7fa8;
  --font-arcade: 'Press Start 2P', monospace;
  --font-body: 'VT323', monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
  overscroll-behavior: none;
}

#cabinet {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  background: radial-gradient(ellipse at 50% 0%, var(--bg-deep), var(--bg) 70%);
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.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) 1px,
    rgba(0, 0, 0, 0.18) 2px,
    rgba(0, 0, 0, 0.18) 3px
  );
  mix-blend-mode: multiply;
  opacity: 0.5;
  z-index: 50;
}

/* ---------- screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top, 16px) 16px env(safe-area-inset-bottom, 16px);
}

.screen.active { display: flex; }

/* ---------- title ---------- */

#screen-title { justify-content: center; }

#title-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.title-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}

.neon-title {
  font-family: var(--font-arcade);
  font-size: clamp(28px, 9vw, 54px);
  margin: 0;
  color: var(--pink);
  letter-spacing: 2px;
  text-shadow:
    0 0 6px var(--pink),
    0 0 18px var(--pink),
    0 0 40px var(--purple),
    0 4px 0 #3a0a2a;
  animation: flicker 4s infinite;
}

.neon-title.small { font-size: clamp(22px, 7vw, 34px); }

@keyframes flicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: 0.7; }
  94% { opacity: 1; }
  95% { opacity: 0.6; }
  96% { opacity: 1; }
}

.subtitle {
  font-family: var(--font-body);
  font-size: 26px;
  color: var(--cyan);
  text-shadow: 0 0 10px var(--cyan);
  letter-spacing: 4px;
  text-transform: uppercase;
  margin: 0;
}

.hint { color: var(--dim); font-size: 20px; margin: 0; }
.blink { animation: blink 1.4s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.arcade-btn {
  font-family: var(--font-arcade);
  font-size: 16px;
  padding: 14px 32px;
  background: linear-gradient(180deg, #2a1240, #180826);
  color: var(--yellow);
  border: 2px solid var(--yellow);
  border-radius: 6px;
  box-shadow: 0 0 10px rgba(255, 224, 102, 0.5), inset 0 0 10px rgba(255, 224, 102, 0.15);
  cursor: pointer;
  letter-spacing: 1px;
}
.arcade-btn:active { transform: translateY(1px) scale(0.98); }
.arcade-btn:disabled { opacity: 0.35; filter: grayscale(0.6); }

/* ---------- character select ---------- */

.screen-title-sm {
  font-family: var(--font-arcade);
  font-size: clamp(16px, 5vw, 22px);
  color: var(--cyan);
  text-shadow: 0 0 10px var(--cyan);
  margin: 10px 0 4px;
  text-align: center;
}

.screen-sub {
  color: var(--dim);
  font-size: 18px;
  margin: 0 0 4px;
  text-align: center;
}

.select-count {
  color: var(--cyan);
  font-size: 15px;
  margin: 0 0 10px;
  text-align: center;
}

.mute-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 10px) + 8px);
  right: 10px;
  z-index: 60;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.25);
  font-size: 15px;
  line-height: 1;
}

#hud { padding-right: 38px; }

.char-grid {
  flex: 1;
  width: 100%;
  max-width: 480px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  overflow-y: auto;
  padding-bottom: 10px;
}

.char-card {
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.char-card .avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
}

.avatar-sprite {
  width: 36px;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.char-card .cname {
  font-family: var(--font-arcade);
  font-size: 10px;
  line-height: 1.4;
}

.char-card .crole { color: var(--dim); font-size: 15px; margin-top: -4px; }

.char-card.selected {
  border-color: var(--yellow);
  box-shadow: 0 0 14px rgba(255, 224, 102, 0.6);
  transform: translateY(-2px);
}

/* ---------- game ---------- */

#screen-game { padding: env(safe-area-inset-top, 10px) 10px env(safe-area-inset-bottom, 10px); }

#hud { width: 100%; max-width: 480px; z-index: 10; }

.hud-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
}

.hud-row .hud-chip { flex: 1 1 0; text-align: center; }

.hud-chip {
  font-family: var(--font-arcade);
  font-size: 9px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 6px 6px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

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

.heat-label {
  font-family: var(--font-arcade);
  font-size: 9px;
  color: var(--red);
}

.heat-bar {
  flex: 1;
  height: 12px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 59, 59, 0.5);
  border-radius: 6px;
  overflow: hidden;
}

.heat-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--red));
  transition: width 0.15s linear;
}

.heat-fill.danger { animation: pulse-red 0.5s infinite; }
@keyframes pulse-red { 50% { filter: brightness(1.6); } }

#toast-layer {
  position: absolute;
  top: 70px;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.toast {
  font-family: var(--font-body);
  font-size: 20px;
  background: rgba(10, 6, 20, 0.85);
  border: 1px solid var(--pink);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 20px;
  box-shadow: 0 0 10px rgba(255, 45, 149, 0.5);
  animation: toast-in-out 2.4s ease forwards;
  text-align: center;
  max-width: 90%;
}

@keyframes toast-in-out {
  0% { opacity: 0; transform: translateY(-8px); }
  10%, 80% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-6px); }
}

#canvas-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#game-canvas {
  background: #0d0818;
  border-radius: 8px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08), 0 0 30px rgba(177, 74, 237, 0.25);
}

.prompt {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-arcade);
  font-size: 10px;
  color: var(--yellow);
  background: rgba(0, 0, 0, 0.6);
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--yellow);
  white-space: nowrap;
  text-shadow: 0 0 6px var(--yellow);
}

.prompt.hidden { display: none; }

#controls {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 6px 4px;
  z-index: 10;
}

.joystick-base {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(0, 229, 255, 0.4);
  position: relative;
  touch-action: none;
}

.joystick-knob {
  position: absolute;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #5ff2ff, var(--cyan));
  box-shadow: 0 0 12px var(--cyan);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.strike-btn {
  font-family: var(--font-arcade);
  font-size: 13px;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4a0f10, #2a0506);
  color: var(--red);
  border: 3px solid var(--red);
  box-shadow: 0 0 10px rgba(255, 59, 59, 0.4);
  touch-action: none;
}

.strike-btn.ready {
  color: #1a0505;
  background: radial-gradient(circle at 35% 30%, #ff8a8a, var(--red));
  box-shadow: 0 0 22px var(--red), 0 0 40px var(--red);
  animation: ready-pulse 0.6s infinite;
}

@keyframes ready-pulse { 50% { transform: scale(1.06); } }

.strike-btn:active { transform: scale(0.95); }

/* ---------- end screen ---------- */

#screen-end { justify-content: center; text-align: center; gap: 16px; }

.end-stats {
  width: 100%;
  max-width: 420px;
  max-height: 60vh;
  overflow-y: auto;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 14px;
}

.score-meta {
  font-size: 18px;
  color: var(--cyan);
  margin-bottom: 10px;
  text-align: center;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 17px;
}

.score-row.mine { background: rgba(255, 224, 102, 0.1); border-radius: 6px; }

.score-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-arcade);
  font-size: 8px;
  color: #0a0614;
  flex-shrink: 0;
}

.score-name { flex: 1; text-align: left; }
.score-kills { color: var(--dim); }
.score-status { font-size: 14px; white-space: nowrap; }

/* ---------- desktop cabinet framing ---------- */

@media (min-width: 560px) {
  #cabinet {
    background: radial-gradient(circle at 50% 20%, #1a0f2e, #000 70%);
  }
  #app {
    max-width: 480px;
    height: min(100%, 860px);
    border-radius: 22px;
    border: 3px solid rgba(255, 255, 255, 0.08);
    box-shadow:
      0 0 0 10px #0d0414,
      0 0 50px rgba(177, 74, 237, 0.35),
      0 20px 60px rgba(0, 0, 0, 0.8);
  }
}
