@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@700;900&family=Oxanium:wght@600;700;800&display=swap');

:root {
  color-scheme: dark;
  --bg: #050816;
  --panel: rgba(6, 14, 33, 0.82);
  --panel-border: rgba(75, 227, 255, 0.22);
  --text: #defbff;
  --muted: #7fb2c7;
  --accent: #3df6ff;
  --accent-dark: #149fd3;
  --accent-glow: rgba(61, 246, 255, 0.38);
  --board: #020713;
  --board-grid: rgba(58, 185, 255, 0.12);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 20%, rgba(61, 246, 255, 0.12), transparent 24%),
    radial-gradient(circle at 80% 0%, rgba(20, 159, 211, 0.2), transparent 28%),
    linear-gradient(180deg, #06101f 0%, #030712 55%, #01030a 100%);
}

.app-shell {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 10px;
  touch-action: none;
}

.game-card {
  width: min(100%, 1600px);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  padding: 24px 28px 28px;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.game-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(61, 246, 255, 0.08), transparent 26%),
    linear-gradient(315deg, rgba(20, 159, 211, 0.08), transparent 22%);
  pointer-events: none;
}

.game-copy {
  margin-bottom: 24px;
  position: relative;
  z-index: 1;
}

.title-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 16px;
}

.player-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 14px;
  background: rgba(9, 22, 48, 0.72);
  border: 1px solid rgba(61, 246, 255, 0.18);
  font-size: 0.82rem;
  flex-shrink: 0;
  margin: 0 auto;
  align-self: center;
}

.player-select {
  background: rgba(10, 24, 52, 0.86);
  color: var(--accent);
  border: 1px solid rgba(61, 246, 255, 0.28);
  border-radius: 8px;
  padding: 4px 8px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  outline: none;
  max-width: 130px;
}

.player-select:focus-visible {
  outline: 2px solid rgba(61, 246, 255, 0.4);
  outline-offset: 2px;
}

.player-select option {
  background: #06101f;
  color: var(--text);
}

.delete-player-button {
  flex: none;
  min-width: 0;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 107, 107, 0.38);
  background: rgba(60, 12, 18, 0.82);
  color: #ff8f8f;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}

.delete-player-button:hover {
  background: rgba(110, 18, 30, 0.92);
  box-shadow: 0 0 14px rgba(255, 107, 107, 0.22);
}

.delete-player-button.hidden {
  display: none;
}

.audio-toggle-button {
  flex: none;
  min-width: 6.8rem;
  padding: 8px 12px;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  box-shadow: 0 0 16px rgba(61, 246, 255, 0.24);
}

.audio-toggle-button.is-muted {
  background: linear-gradient(180deg, #6c7f8a, #445763);
  color: #d7eef6;
  box-shadow: 0 0 12px rgba(116, 152, 170, 0.18);
}

.coin-display {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 10px;
  border-left: 1px solid rgba(61, 246, 255, 0.2);
}

.coin-icon {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe566, #f0a000);
  box-shadow: 0 0 6px rgba(240, 160, 0, 0.7);
  flex-shrink: 0;
}

.coin-display strong {
  color: #ffd84d;
  text-shadow: 0 0 8px rgba(255, 200, 0, 0.6);
}

.mobile-inventory {
  display: none;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--accent-dark);
}

h1 {
  margin: 0;
  font-size: clamp(2.4rem, 4vw, 4rem);
  line-height: 0.95;
}

.hero-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: clamp(92px, 16vw, 148px);
  padding: clamp(14px, 2.2vw, 20px) clamp(24px, 4vw, 38px);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(3, 10, 22, 0.18), rgba(3, 10, 22, 0.42)),
    url('./assets/hero.png') center / cover no-repeat;
  border: 1px solid rgba(61, 246, 255, 0.24);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    0 18px 34px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.hero-title {
  margin: 0;
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: clamp(1.9rem, 3.6vw, 3.1rem);
  line-height: 0.95;
  letter-spacing: 0.08em;
  color: var(--text);
  text-transform: uppercase;
  text-align: center;
  text-shadow:
    0 3px 18px rgba(0, 0, 0, 0.72),
    0 0 18px rgba(61, 246, 255, 0.18);
}

.hero-ultimate {
  color: var(--accent);
}

.description,
.help p,
.leaderboard-header p,
.modal-copy {
  margin: 10px 0 0;
  max-width: 60ch;
  color: var(--muted);
  line-height: 1.55;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
  position: relative;
  z-index: 1;
}

.stat {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(9, 22, 48, 0.72);
  border: 1px solid rgba(61, 246, 255, 0.16);
  box-shadow: inset 0 0 18px rgba(61, 246, 255, 0.05);
}

.label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 6px;
}

.stat strong {
  font-size: 1.4rem;
}

#status {
  display: block;
  min-height: 1.4em;
  font-size: 1rem;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 10px;
}

.controls-row .controls {
  flex-shrink: 0;
  margin-bottom: 0;
}

#pause-button {
  min-width: 7.25rem;
}

.game-stage {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  min-height: 0;
  margin-bottom: 8px;
  overflow: hidden;
}

.leaderboard {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(4, 13, 30, 0.88);
  border: 1px solid rgba(61, 246, 255, 0.26);
  box-shadow:
    0 0 24px rgba(20, 159, 211, 0.18),
    inset 0 0 20px rgba(61, 246, 255, 0.04);
}

.leaderboard-header {
  margin-bottom: 6px;
}

.leaderboard-header h2 {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: row;
  gap: 6px;
}

.leaderboard-list li {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 10px;
  background: rgba(10, 24, 52, 0.72);
  border: 1px solid rgba(61, 246, 255, 0.08);
  font-size: 0.72rem;
  min-width: 0;
}

.leaderboard-rank {
  font-weight: 800;
  color: #85f8ff;
}

.leaderboard-name {
  font-weight: 700;
  letter-spacing: 0.04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  text-align: center;
}

.leaderboard-score {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #8fdcff;
}

.board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  height: min(100%, max(320px, calc(100dvh - 520px)));
  width: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  flex: none;
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
}

.start-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 10;
  border-radius: 24px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  background: rgba(3, 8, 22, 0.45);
}

.gamemode-wrap {
  display: flex;
  gap: 8px;
}

.gamemode-wrap[hidden] {
  display: none;
}

.mode-btn {
  width: auto !important;
  min-width: 0 !important;
  padding: 7px 16px !important;
  font-size: 0.75rem !important;
  letter-spacing: 0.05em !important;
  border-radius: 999px !important;
  box-shadow: none !important;
  opacity: 0.5;
}

.mode-btn--active {
  opacity: 1;
  box-shadow: 0 0 14px rgba(61, 246, 255, 0.5) !important;
}

.start-overlay.hidden {
  display: none;
}

.start-overlay button {
  width: auto;
  min-width: 140px;
  padding: 14px 36px;
  border-radius: 999px;
  font-size: 1rem;
  letter-spacing: 0.12em;
  flex: none;
  box-shadow:
    0 0 32px rgba(61, 246, 255, 0.4),
    0 0 64px rgba(61, 246, 255, 0.15);
}

.game-over-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  z-index: 10;
  pointer-events: none;
  padding: 0 0 38px;
}

.game-over-overlay.hidden {
  display: none;
}

.game-over-overlay button {
  pointer-events: all;
  width: 68%;
  max-width: 220px;
  min-width: 0;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  flex: none;
}

.victory-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  z-index: 10;
  pointer-events: none;
  padding: 0 0 38px;
}

.victory-overlay.hidden {
  display: none;
}

.victory-overlay button {
  pointer-events: all;
  width: 68%;
  max-width: 220px;
  min-width: 0;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  flex: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  touch-action: none;
  background:
    linear-gradient(var(--board-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--board-grid) 1px, transparent 1px),
    var(--board);
  background-size: calc(100% / 20) calc(100% / 20);
  border-radius: 24px;
  border: 3px solid rgba(61, 246, 255, 0.34);
  box-shadow:
    0 0 36px rgba(20, 159, 211, 0.22),
    inset 0 0 0 1px rgba(61, 246, 255, 0.14);
}

.run-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  position: relative;
  z-index: 1;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  position: relative;
  z-index: 1;
}

.start-level-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
}

.start-level-wrap .label {
  display: inline;
  margin-bottom: 0;
  white-space: nowrap;
}

button {
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #04111d;
  background: linear-gradient(180deg, #76fbff, #1ed8ff);
  box-shadow: 0 0 22px var(--accent-glow);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 28px rgba(61, 246, 255, 0.52);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 3px solid rgba(61, 246, 255, 0.32);
  outline-offset: 3px;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(1, 6, 15, 0.7);
  touch-action: none;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(100%, 420px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 24px;
  border-radius: 24px;
  background: rgba(6, 14, 33, 0.96);
  border: 1px solid rgba(61, 246, 255, 0.24);
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0;
  font-size: 1.8rem;
}

.initials-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.initials-form input {
  width: 100%;
  border: 1px solid rgba(61, 246, 255, 0.22);
  border-radius: 16px;
  padding: 14px 16px;
  font: inherit;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--text);
  background: rgba(10, 24, 52, 0.86);
}

.initials-form input:focus-visible {
  outline: 3px solid rgba(61, 246, 255, 0.32);
  outline-offset: 2px;
}

.name-error {
  margin: 0;
  font-size: 0.82rem;
  color: #ff6b9d;
  text-shadow: 0 0 8px rgba(255, 45, 120, 0.5);
}

.name-error.hidden {
  display: none;
}

/* ── Upgrades bar ────────────────────────────────── */

.upgrades-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 2px;
  margin-bottom: 16px;
  position: relative;
  z-index: 1;
}

#shop-title {
  font-family: 'Oxanium', sans-serif;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.upgrade-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  line-height: 1;
  user-select: none;
}

.upgrade-heart {
  color: #ff4f7b;
  text-shadow:
    0 0 8px rgba(255, 79, 123, 0.9),
    0 0 20px rgba(255, 79, 123, 0.45);
  animation: heartPulse 2.4s ease-in-out infinite;
}

@keyframes heartPulse {
  0%, 100% { transform: scale(1);    opacity: 1;    }
  50%       { transform: scale(1.18); opacity: 0.78; }
}

.upgrade-star {
  cursor: pointer;
  transition: transform 120ms ease;
  animation: rainbowCycle 1.6s linear infinite;
}

.upgrade-star:hover {
  transform: scale(1.25);
}

.upgrade-star--active {
  animation: rainbowCycle 0.7s linear infinite, starSpin 1.4s linear infinite;
  cursor: default;
}

.upgrade-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.upgrade-badge {
  position: absolute;
  top: -5px;
  right: -9px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 0.58rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 1px 4px;
  line-height: 1.4;
  border: 1px solid rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

/* Empty inventory slot — ghost/outline treatment */
.upgrade-slot--empty {
  border: 1px dashed rgba(61, 246, 255, 0.22);
  border-radius: 10px;
  padding: 3px;
}

.upgrade-slot--empty .upgrade-icon {
  opacity: 0.22;
  filter: grayscale(1);
  animation: none !important;
  cursor: default;
}

/* Vertical divider between consumables and permanent upgrades */
.upgrades-divider {
  display: inline-block;
  width: 1px;
  align-self: stretch;
  min-height: 1.4rem;
  background: rgba(61, 246, 255, 0.22);
  margin: 0 10px;
  border-radius: 999px;
  flex-shrink: 0;
}

@keyframes rainbowCycle {
  0%   { color: #ff3333; text-shadow: 0 0 12px rgba(255,  51,  51, 0.9); }
  16%  { color: #ff8800; text-shadow: 0 0 12px rgba(255, 136,   0, 0.9); }
  33%  { color: #ffe600; text-shadow: 0 0 12px rgba(255, 230,   0, 0.9); }
  50%  { color: #33ff66; text-shadow: 0 0 12px rgba( 51, 255, 102, 0.9); }
  66%  { color: #00aaff; text-shadow: 0 0 12px rgba(  0, 170, 255, 0.9); }
  83%  { color: #aa00ff; text-shadow: 0 0 12px rgba(170,   0, 255, 0.9); }
  100% { color: #ff3333; text-shadow: 0 0 12px rgba(255,  51,  51, 0.9); }
}

@keyframes starSpin {
  from { transform: rotate(0deg) scale(1.1); }
  to   { transform: rotate(360deg) scale(1.1); }
}

/* ── Shop ─────────────────────────────────────────── */

.shop-card {
  width: min(100%, 640px);
}

.shop-balance {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 20px;
  font-size: 0.88rem;
  color: var(--muted);
}

.shop-balance .coin-icon {
  flex-shrink: 0;
}

.shop-balance strong {
  color: #ffd84d;
  text-shadow: 0 0 8px rgba(255, 200, 0, 0.5);
}

.shop-cap-note {
  margin: -10px 0 16px;
  font-size: 0.75rem;
  color: var(--accent-dark);
  letter-spacing: 0.03em;
}

.shop-section {
  margin-bottom: 18px;
}

.shop-section-title {
  margin: 0 0 10px;
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.shop-items {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.shop-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 12px 12px;
  border-radius: 14px;
  background: rgba(10, 24, 52, 0.72);
  border: 1px solid rgba(61, 246, 255, 0.12);
  text-align: center;
}

.shop-icon {
  font-size: 2rem;
  line-height: 1;
}

.shop-item-desc {
  display: none;
  font-size: 0.75rem;
  color: var(--text-dim, rgba(255,255,255,0.65));
  margin: 4px 0 2px;
  line-height: 1.4;
  text-align: left;
}

.info-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid rgba(61, 246, 255, 0.4);
  color: var(--accent);
  border-radius: 999px;
  min-width: 0;
  flex: none;
  padding: 3px 8px;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
  cursor: pointer;
  vertical-align: middle;
  margin-left: 5px;
  flex-shrink: 0;
  background: rgba(10, 24, 52, 0.72);
}

.info-toggle:hover {
  background: rgba(61, 246, 255, 0.12);
  box-shadow: 0 0 12px rgba(61, 246, 255, 0.16);
}

.upgrade-info-card {
  position: relative;
  width: min(100%, 460px);
  padding-top: 44px;
}

.modal-close-button {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  min-width: 0;
  padding: 0;
  border-radius: 999px;
  background: rgba(10, 24, 52, 0.9);
  border: 1px solid rgba(61, 246, 255, 0.28);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-close-button:hover {
  transform: scale(1.05);
}

.shop-icon-heart {
  color: #ff4f7b;
  text-shadow: 0 0 14px rgba(255, 79, 123, 0.8);
}

.shop-icon-star {
  animation: rainbowCycle 1.6s linear infinite;
}

.shop-icon-cube,
.upgrade-cube {
  position: relative;
  display: inline-block;
  line-height: 1;
  overflow: visible;
  background:
    linear-gradient(180deg, var(--bash-fill-hi), var(--bash-fill-low)) 34% 34% / 24% 24% no-repeat,
    linear-gradient(180deg, var(--bash-fill-hi), var(--bash-fill-low)) 66% 34% / 24% 24% no-repeat,
    linear-gradient(180deg, var(--bash-fill-hi), var(--bash-fill-low)) 34% 66% / 24% 24% no-repeat,
    linear-gradient(180deg, var(--bash-fill-hi), var(--bash-fill-low)) 66% 66% / 24% 24% no-repeat;
  filter: drop-shadow(0 0 12px var(--bash-glow)) drop-shadow(0 0 22px var(--bash-glow-soft));
}

.shop-icon-cube {
  width: 1.75rem;
  height: 1.75rem;
}

.upgrade-cube {
  width: 1rem;
  height: 1rem;
  filter: drop-shadow(0 0 8px var(--bash-glow)) drop-shadow(0 0 16px var(--bash-glow-soft));
}

.shop-icon-cube::before,
.shop-icon-cube::after,
.upgrade-cube::before,
.upgrade-cube::after {
  content: "";
  position: absolute;
  inset: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.shop-icon-cube::before,
.upgrade-cube::before {
  width: 30%;
  height: 30%;
  border-radius: 2px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.92) 0%, rgba(255, 255, 255, 0.2) 72%, transparent 100%);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.45);
}

.shop-icon-cube::after,
.upgrade-cube::after {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  opacity: 0.55;
}

.shop-icon-red-bash,
.upgrade-red-bash {
  --bash-glow: rgba(255, 92, 66, 0.85);
  --bash-glow-soft: rgba(255, 92, 66, 0.45);
  --bash-fill-hi: #ff9b80;
  --bash-fill-mid: #ff5c42;
  --bash-fill-low: #a11f14;
  animation: bashShardBurst 1.2s ease-in-out infinite, pacmanGlowWarm 2s ease-in-out infinite;
}

.shop-icon-blue-bash,
.upgrade-blue-bash {
  --bash-glow: rgba(54, 182, 255, 0.85);
  --bash-glow-soft: rgba(54, 182, 255, 0.45);
  --bash-fill-hi: #8bddff;
  --bash-fill-mid: #36b6ff;
  --bash-fill-low: #124ab0;
  animation: bashShardBurst 1.2s ease-in-out infinite, pacmanGlowCool 2s ease-in-out infinite;
}

@keyframes bashShardBurst {
  0%, 100% {
    background-position:
      34% 34%,
      66% 34%,
      34% 66%,
      66% 66%;
    transform: scale(1);
  }
  50% {
    background-position:
      20% 20%,
      80% 20%,
      20% 80%,
      80% 80%;
    transform: scale(1.05);
  }
}

@keyframes pacmanGlowWarm {
  0%, 100% {
    filter: drop-shadow(0 0 10px rgba(255, 92, 66, 0.85)) drop-shadow(0 0 20px rgba(255, 92, 66, 0.45));
  }
  50% {
    filter: drop-shadow(0 0 16px rgba(255, 120, 80, 1)) drop-shadow(0 0 30px rgba(255, 70, 40, 0.6));
  }
}

@keyframes pacmanGlowCool {
  0%, 100% {
    filter: drop-shadow(0 0 10px rgba(54, 182, 255, 0.85)) drop-shadow(0 0 20px rgba(54, 182, 255, 0.45));
  }
  50% {
    filter: drop-shadow(0 0 16px rgba(105, 210, 255, 1)) drop-shadow(0 0 30px rgba(40, 136, 255, 0.6));
  }
}

.shop-icon-bomb {
  animation: bombGlow 1.8s ease-in-out infinite;
}

.upgrade-bomb {
  cursor: pointer;
  transition: transform 120ms ease;
  animation: bombGlow 1.8s ease-in-out infinite;
}

.upgrade-bomb:hover {
  transform: scale(1.25);
}

@keyframes bombGlow {
  0%, 100% {
    text-shadow:
      0 0 10px rgba(255, 140, 0, 0.85),
      0 0 22px rgba(255, 80, 0, 0.45);
  }
  50% {
    text-shadow:
      0 0 18px rgba(255, 190, 0, 1),
      0 0 36px rgba(255, 100, 0, 0.8),
      0 0 54px rgba(200, 50, 0, 0.45);
  }
}

.shop-icon-lasso {
  animation: lassoGlow 2s ease-in-out infinite;
}

.upgrade-lasso {
  animation: lassoGlow 2s ease-in-out infinite;
}

@keyframes lassoGlow {
  0%, 100% {
    text-shadow:
      0 0 10px rgba(80, 220, 80, 0.85),
      0 0 22px rgba(80, 220, 80, 0.45);
  }
  50% {
    text-shadow:
      0 0 18px rgba(120, 255, 100, 1),
      0 0 36px rgba(80, 220, 80, 0.75),
      0 0 52px rgba(30, 160, 30, 0.4);
  }
}

.shop-icon-mirror {
  animation: mirrorGlow 2s ease-in-out infinite;
}

.upgrade-mirror {
  animation: mirrorGlow 2s ease-in-out infinite;
}

.upgrade-mirror--active {
  animation: rainbowCycle 1s linear infinite;
}

@keyframes mirrorGlow {
  0%, 100% {
    text-shadow:
      0 0 10px rgba(180, 220, 255, 0.85),
      0 0 22px rgba(140, 180, 255, 0.45);
  }
  50% {
    text-shadow:
      0 0 18px rgba(220, 240, 255, 1),
      0 0 36px rgba(160, 200, 255, 0.8),
      0 0 52px rgba(100, 140, 255, 0.4);
  }
}

.shop-icon-venom {
  animation: venomGlow 1.4s ease-in-out infinite;
  color: #c040ff;
}

.upgrade-venom {
  animation: venomGlow 1.4s ease-in-out infinite;
  color: #c040ff;
}

@keyframes venomGlow {
  0%, 100% {
    text-shadow:
      0 0 10px rgba(180, 60, 255, 0.85),
      0 0 22px rgba(180, 60, 255, 0.45);
  }
  50% {
    text-shadow:
      0 0 18px rgba(220, 100, 255, 1),
      0 0 36px rgba(180, 60, 255, 0.8),
      0 0 52px rgba(100, 0, 180, 0.45);
  }
}

.shop-item-info {
  width: 100%;
}

.shop-item-name {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.shop-item-owned {
  font-size: 0.75rem;
  color: var(--accent-dark);
  letter-spacing: 0.06em;
}

.shop-buy-button {
  width: 100%;
  padding: 6px 8px !important;
  font-size: 0.72rem !important;
  line-height: 1.2;
  margin-top: auto;
  flex: none;
}

#quit-button {
  background: linear-gradient(180deg, #ff6b8a, #d63060);
  color: #fff;
  box-shadow: 0 0 18px rgba(214, 48, 96, 0.38);
}

#quit-button:hover {
  box-shadow: 0 0 26px rgba(214, 48, 96, 0.6);
}

.shop-buy-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}

.help {
  position: relative;
  z-index: 1;
}

/* ── Desktop two-column layout ──────────────────────── */
@media (min-width: 1181px) {
  /*
    Grid layout:
      Row 1 (auto):  hero banner — spans both columns full-width
      Row 2 (auto):  hud   |  canvas (rows 2–4)
      Row 3 (auto):  run-controls  |  canvas
      Row 4 (1fr):   controls + leaderboard  |  canvas
      Row 5 (auto):  help text  |  upgrades bar (below canvas)
  */
  .game-card {
    display: grid;
    grid-template-columns: clamp(380px, 34%, 460px) 1fr;
    grid-template-rows: auto auto auto 1fr auto;
    column-gap: 24px;
    padding: 20px 24px 20px;
  }

  /* Row 1: hero spans the full width */
  .game-copy {
    grid-column: 1 / 3;
    grid-row: 1;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(61, 246, 255, 0.14);
  }

  /* Hero banner: tall and wide across the full card */
  .title-row {
    flex-direction: row;
    align-items: stretch;
    gap: 16px;
  }

  .hero-brand {
    flex: 1;
    min-height: clamp(72px, 9vh, 110px);
    padding: 14px 28px;
    justify-content: flex-start;
  }

  .hero-title {
    font-size: clamp(1.8rem, 2.4vw, 3rem);
    text-align: left;
  }

  /* Player badge sits to the right of the hero banner */
  .player-badge {
    flex-shrink: 0;
    align-self: stretch;
    flex-wrap: nowrap;
    margin: 0;
    justify-content: flex-start;
    padding: 10px 18px;
  }

  /* Left sidebar: rows 2–5 */
  .hud          { grid-column: 1; grid-row: 2; margin-bottom: 10px; }
  .run-controls { grid-column: 1; grid-row: 3; margin-bottom: 10px; }
  .controls-row { grid-column: 1; grid-row: 4; align-self: start; margin-bottom: 0; }
  .help         { grid-column: 1; grid-row: 5; margin-bottom: 0; align-self: center; }

  /* Right column: canvas rows 2–4, upgrades bar row 5 */
  .game-stage   { grid-column: 2; grid-row: 2 / 5; margin-bottom: 0; }
  .upgrades-bar { grid-column: 2; grid-row: 5; margin-bottom: 0; justify-content: center; padding: 10px 8px; gap: 12px; }

  .hud {
    gap: 8px;
  }

  .stat {
    padding: 8px 10px;
  }

  .stat strong {
    font-size: 1.1rem;
  }

  /* Stack upgrade/pause buttons above the leaderboard in the sidebar */
  .controls-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  /* Leaderboard: vertical list in sidebar */
  .leaderboard {
    flex: none;
  }

  .leaderboard-list {
    flex-direction: column;
    gap: 4px;
  }

  .leaderboard-list li {
    flex-direction: row;
    flex: none;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 5px 8px;
  }

  .leaderboard-name {
    text-align: left;
    flex: 1;
  }

  /* Canvas fills the space between hero row and upgrades row */
  .board-wrap {
    height: 100%;
    width: auto;
    max-width: 100%;
    max-height: 100%;
    margin: auto;
  }

  /* Inventory icons: roughly one game-grid square wide/tall.
     Canvas width ≈ (100vw - sidebar - padding) so 1 square ≈ that / 20. */
  .upgrade-wrap {
    min-width: clamp(36px, 3.5vw, 60px);
    min-height: clamp(36px, 3.5vw, 60px);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .upgrade-icon {
    font-size: clamp(1.8rem, 3.2vw, 3.6rem);
  }

  /* Cube icons use explicit width/height instead of font-size — match emoji size */
  .upgrade-cube {
    width: clamp(1.8rem, 3.2vw, 3.6rem);
    height: clamp(1.8rem, 3.2vw, 3.6rem);
  }

  .upgrade-badge {
    font-size: 0.78rem;
    padding: 2px 5px;
  }
}

@media (min-width: 1400px) and (min-height: 1000px) {
  .app-shell {
    padding: 16px;
  }

  .game-card {
    width: min(100%, 1700px);
    padding: 18px 24px 20px;
  }

  .game-copy {
    margin-bottom: 16px;
  }

  /* Full-width hero banner gets a bit more height on large screens */
  .hero-brand {
    min-height: clamp(88px, 9vh, 120px);
    padding: 16px 32px;
  }

  .hero-title {
    font-size: clamp(2rem, 2.6vw, 3.2rem);
  }

  .hud {
    margin-bottom: 14px;
  }

  .stat {
    padding: 10px 14px;
  }

  .run-controls,
  .controls-row {
    margin-bottom: 10px;
  }

  .game-stage {
    margin-bottom: 0;
  }

  /* Canvas fills game-stage height (1fr row already handles sizing) */
  .board-wrap {
    height: 100%;
    width: auto;
    max-width: 100%;
    max-height: 100%;
  }
}

/* ── Tablet / iPad ────────────────────────────────── */
@media (min-width: 641px) and (max-width: 1180px) {
  /* Compress chrome so the canvas gets maximum vertical space */
  .game-card {
    padding: 14px 18px 16px;
  }

  .game-copy {
    margin-bottom: 10px;
  }

  .hero-brand {
    min-height: clamp(60px, 10vw, 90px);
    padding: 10px 20px;
    border-radius: 20px;
  }

  .hero-title {
    font-size: clamp(1.4rem, 2.6vw, 2rem);
  }

  .hud {
    gap: 8px;
    margin-bottom: 10px;
  }

  .stat {
    padding: 8px 10px;
  }

  .stat strong {
    font-size: 1.1rem;
  }

  .run-controls {
    margin-bottom: 8px;
  }

  .controls-row {
    margin-bottom: 8px;
  }

  .upgrades-bar {
    min-height: 24px;
    margin-bottom: 8px;
  }

  .game-stage {
    flex: 0 1 auto;
    margin-bottom: 4px;
  }

  .board-wrap {
    height: min(100%, max(360px, calc(100dvh - 500px)));
    width: auto;
    max-height: 100%;
  }

  canvas {
    width: 100%;
    height: 100%;
    max-height: 100%;
  }

  .modal {
    padding: 20px;
  }

  .modal-card {
    width: min(90vw, 760px);
    max-height: calc(100vh - 40px);
  }

  .shop-card {
    width: min(90vw, 760px);
  }

  .modal-card h2 {
    font-size: 2rem;
  }

  .shop-balance {
    font-size: 1rem;
    margin: 12px 0 18px;
  }

  .shop-cap-note {
    font-size: 0.82rem;
  }

  .shop-items {
    gap: 14px;
    margin-bottom: 20px;
  }

  .shop-item {
    padding: 16px 14px 14px;
    gap: 8px;
  }

  .shop-icon {
    font-size: 2.4rem;
  }

  .shop-icon-pacman {
    width: 2.4rem;
    height: 2.4rem;
  }

  .shop-item-name {
    font-size: 1rem;
    margin-bottom: 4px;
  }

  /* Show descriptions inline on tablet — enough room */
  .shop-item-desc {
    display: block;
    font-size: 0.8rem;
  }

  .shop-item-owned {
    font-size: 0.8rem;
  }

  .shop-buy-button {
    padding: 9px 12px !important;
    font-size: 0.8rem !important;
  }
}

@media (max-width: 640px) {
  body {
    min-height: 100dvh;
    height: auto;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .app-shell {
    min-height: 100dvh;
    height: auto;
    overflow: visible;
    align-items: flex-start;
    padding:
      max(10px, env(safe-area-inset-top))
      10px
      max(10px, env(safe-area-inset-bottom))
      10px;
  }

  .game-card {
    min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px);
    padding: 12px 14px 14px;
    border-radius: 22px;
    overflow: visible;
  }

  /* Compact header */
  .game-copy {
    margin-bottom: 10px;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: 1.6rem;
  }

  .title-row {
    gap: 12px;
  }

  .hero-brand {
    min-height: clamp(56px, 16vw, 76px);
    padding: 10px 16px;
    border-radius: 22px;
    background-position: center;
  }

  .hero-title {
    font-size: clamp(1.5rem, 7vw, 2.1rem);
    letter-spacing: 0.06em;
  }

  .player-badge {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }

  /* HUD stays single row, tighter */
  .hud {
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    margin-bottom: 10px;
  }

  .stat {
    padding: 6px 4px;
  }

  .stat strong {
    font-size: 0.95rem;
  }

  .label {
    font-size: 0.58rem;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
  }

  .game-stage {
    flex: 0 1 auto;
    margin-bottom: 10px;
  }

  .board-wrap {
    height: min(100%, max(220px, calc(100dvh - 430px)));
    width: auto;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    flex: none;
    margin: 0 auto;
  }

  /* Collapse the controls-row to just buttons on mobile; hide leaderboard */
  .controls-row {
    gap: 8px;
    margin-bottom: 8px;
  }

  .controls-row .controls {
    flex: 1;
    min-width: 0;
  }

  .leaderboard {
    display: none;
  }

  .upgrades-bar {
    display: none;
  }

  .mobile-inventory {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-wrap: nowrap;
    padding-left: 8px;
    border-left: 1px solid rgba(61, 246, 255, 0.2);
  }

  .mobile-inventory .upgrade-icon {
    font-size: 12px;
    line-height: 1;
  }

  .mobile-inventory .upgrade-cube {
    width: 12px;
    height: 12px;
  }

  .mobile-inventory .upgrade-badge {
    top: -3px;
    right: -4px;
    font-size: 0.38rem;
    padding: 1px 2px;
  }

  .mobile-inventory .upgrades-divider {
    width: 1px;
    height: 12px;
    background: rgba(61, 246, 255, 0.2);
    margin: 0 2px;
  }

  .upgrade-wrap {
    min-width: 0;
    min-height: 0;
    flex: 0 0 auto;
    padding: 1px;
  }

  .upgrade-icon {
    font-size: clamp(0.7rem, 3vw, 0.95rem);
  }

  .upgrade-cube {
    width: clamp(0.65rem, 2.8vw, 0.85rem);
    height: clamp(0.65rem, 2.8vw, 0.85rem);
  }

  .upgrade-slot--empty {
    padding: 1px;
    border-radius: 6px;
  }

  .upgrade-badge {
    top: -3px;
    right: -4px;
    font-size: 0.42rem;
    padding: 1px 2px;
  }

  .upgrades-divider {
    min-height: 0.8rem;
    margin: 0 1px;
  }

  /* Run controls above the board — always one row */
  .run-controls {
    flex-wrap: nowrap;
    gap: 8px;
    margin-bottom: 8px;
  }

  .run-controls > button,
  .run-controls > .start-level-wrap {
    flex: 1;
    min-width: 0;
  }

  /* Action controls (upgrade + pause) below the board — always one row */
  .controls {
    flex-wrap: nowrap;
    gap: 8px;
    margin-bottom: 8px;
  }

  .controls > button {
    flex: 1;
    min-width: 0;
  }

  canvas {
    width: 100%;
    height: auto;
    max-height: 100%;
  }

  button {
    flex: 1 1 calc(50% - 4px);
    padding: 10px 10px;
    font-size: 0.78rem;
  }

  /* Start overlay button: centered, not stretched */
  .start-overlay button {
    flex: none;
    width: auto;
    min-width: 130px;
    padding: 13px 32px;
  }

  /* Game-over overlay buttons: contained pills, not stretched */
  .game-over-overlay button {
    flex: none;
    width: 72%;
    max-width: 200px;
    padding: 11px 20px;
    font-size: 0.8rem;
    border-radius: 999px;
  }

  .game-over-overlay {
    padding-bottom: 24px;
  }

  .victory-overlay button {
    flex: none;
    width: 72%;
    max-width: 200px;
    padding: 11px 20px;
    font-size: 0.8rem;
    border-radius: 999px;
  }

  .victory-overlay {
    padding-bottom: 24px;
  }

  /* Tighter shop modal on small screens */
  .modal {
    padding: 16px;
  }

  .modal-card {
    padding: 16px;
    max-height: calc(100vh - 32px);
    border-radius: 18px;
  }

  .shop-balance {
    margin: 6px 0 12px;
  }

  .shop-cap-note {
    margin: -6px 0 10px;
    font-size: 0.7rem;
  }

  .shop-items {
    gap: 7px;
    margin-bottom: 12px;
  }

  .shop-item {
    padding: 8px 8px 8px;
    gap: 4px;
  }

  .shop-icon {
    font-size: 1.5rem;
  }

  .shop-icon-pacman {
    width: 1.5rem;
    height: 1.5rem;
  }

  .shop-item-name {
    font-size: 0.82rem;
    margin-bottom: 2px;
  }

  .shop-item-owned {
    font-size: 0.68rem;
  }

  .shop-buy-button {
    padding: 4px 6px !important;
    font-size: 0.66rem !important;
  }

  /* Keep descriptions out of the grid; use the overlay dialog instead */
  .shop-item-desc {
    display: none;
  }

  .shop-item-name-row {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 2px;
  }

  /* Width-driven sizing: canvas fills container width, height follows aspect-ratio.
     Overrides the desktop height:100% approach which breaks square on narrow widths. */
  canvas {
    width: 100%;
    height: auto;
  }

  .help {
    display: block;
    margin-top: 4px;
    text-align: center;
  }

  .help p {
    margin: 0;
    max-width: none;
    font-size: 0.76rem;
    line-height: 1.35;
  }
}

@media (max-width: 640px) and (max-height: 920px) {
  .game-copy {
    margin-bottom: 8px;
  }

  .hud {
    margin-bottom: 8px;
  }

  .run-controls,
  .controls-row,
  .controls,
  .upgrades-bar,
  .game-stage {
    margin-bottom: 6px;
  }

  .board-wrap {
    height: min(100%, max(220px, calc(100dvh - 400px)));
    width: auto;
    max-height: 100%;
  }

  button {
    padding: 9px 10px;
    font-size: 0.75rem;
  }
}
