:root {
  --bg: #07070d;
  --bg-raised: #10101a;
  --bg-panel: #151522;
  --line: rgba(57, 255, 20, 0.18);
  --line-strong: rgba(57, 255, 20, 0.45);
  --text: #f4f7ff;
  --muted: #8b93b0;
  --blue: #4d7fff;
  --red: #ff2244;
  --green: #39ff14;
  --yellow: #ffe600;
  --accent: #39ff14;
  --accent-2: #4d7fff;
  --warn: #ff2244;
  --glow-green: 0 0 20px rgba(57, 255, 20, 0.55), 0 0 48px rgba(57, 255, 20, 0.22);
  --glow-red: 0 0 22px rgba(255, 34, 68, 0.65), 0 0 48px rgba(255, 34, 68, 0.28);
  --glow-blue: 0 0 22px rgba(77, 127, 255, 0.7), 0 0 48px rgba(77, 127, 255, 0.3);
  --glow-yellow: 0 0 18px rgba(255, 230, 0, 0.55);
  --font-display: "Bricolage Grotesque", sans-serif;
  --font-body: "Figtree", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --stage-w: min(400px, calc(100vw - 24px));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 65% 42% at 10% 5%, rgba(77, 127, 255, 0.28), transparent 55%),
    radial-gradient(ellipse 55% 38% at 92% 12%, rgba(255, 34, 68, 0.22), transparent 50%),
    radial-gradient(ellipse 50% 30% at 50% 100%, rgba(57, 255, 20, 0.1), transparent 55%),
    linear-gradient(180deg, #0c0c16 0%, #06060a 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    rgba(255, 255, 255, 0.012) 3px,
    rgba(255, 255, 255, 0.012) 4px
  );
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  padding-bottom: calc(12px + var(--safe-bottom));
}

.screen {
  width: 100%;
  max-width: 440px;
  height: 100%;
  max-height: 860px;
  display: flex;
  flex-direction: column;
  animation: screen-in 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.screen[hidden] {
  display: none !important;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes pulse-glow {
  0%,
  100% {
    box-shadow: 0 0 22px rgba(77, 127, 255, 0.5), 0 0 36px rgba(57, 255, 20, 0.3);
  }
  50% {
    box-shadow: 0 0 28px rgba(255, 34, 68, 0.55), 0 0 48px rgba(255, 230, 0, 0.35);
  }
}

@keyframes title-shimmer {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 200% 50%;
  }
}

/* —— Buttons —— */
.btn {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.95rem;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 12px 16px;
  background: rgba(16, 16, 28, 0.85);
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.btn:hover {
  transform: scale(1.03);
  border-color: var(--green);
  box-shadow: var(--glow-green);
}

.btn:active {
  transform: scale(0.98);
}

.btn-play {
  width: 100%;
  padding: 16px;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #061208;
  background: linear-gradient(135deg, var(--blue) 0%, var(--green) 40%, var(--yellow) 75%, var(--red) 100%);
  border: none;
  box-shadow: 0 0 24px rgba(77, 127, 255, 0.45), 0 0 40px rgba(57, 255, 20, 0.35);
  animation: pulse-glow 2.8s ease-in-out infinite;
}

.btn-play:hover {
  filter: brightness(1.08);
  box-shadow: 0 0 28px rgba(77, 127, 255, 0.7), 0 0 40px rgba(255, 34, 68, 0.4);
}

.btn-secondary {
  flex: 1;
  background: linear-gradient(180deg, rgba(77, 127, 255, 0.16), rgba(57, 255, 20, 0.06));
  border-color: rgba(77, 127, 255, 0.45);
}

.btn-secondary:hover {
  box-shadow: var(--glow-blue);
  border-color: var(--blue);
}

.btn-neon-blue {
  flex: 1;
  color: #dbe6ff;
  background: rgba(77, 127, 255, 0.18);
  border: 1px solid var(--blue);
  box-shadow: var(--glow-blue);
}

.btn-neon-blue:hover {
  background: rgba(77, 127, 255, 0.3);
  border-color: #7aa0ff;
  box-shadow: 0 0 28px rgba(77, 127, 255, 0.85);
}

.btn-neon-red {
  flex: 1;
  color: #ffd0d8;
  background: rgba(255, 34, 68, 0.16);
  border: 1px solid var(--red);
  box-shadow: var(--glow-red);
}

.btn-neon-red:hover {
  background: rgba(255, 34, 68, 0.28);
  border-color: #ff5570;
  box-shadow: 0 0 28px rgba(255, 34, 68, 0.85);
}

.btn-text {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 10px;
  backdrop-filter: none;
}

.btn-text:hover {
  color: var(--green);
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  transform: none;
}

.btn-chip {
  padding: 8px 12px;
  font-size: 0.8rem;
  background: rgba(16, 16, 28, 0.9);
  min-width: 72px;
  border-color: var(--line);
}

.btn-side {
  flex: 1;
  min-height: 52px;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 0.85rem;
  border-color: rgba(57, 255, 20, 0.35);
  background: linear-gradient(180deg, rgba(57, 255, 20, 0.12), rgba(16, 16, 28, 0.9));
}

.btn-side:active,
.btn-side.is-flash {
  background: rgba(57, 255, 20, 0.35);
  border-color: var(--green);
  box-shadow: var(--glow-green);
  color: #fff;
}

.btn-side:last-child {
  border-color: rgba(255, 26, 26, 0.4);
  background: linear-gradient(180deg, rgba(255, 26, 26, 0.12), rgba(16, 16, 28, 0.9));
}

.btn-side:last-child:active,
.btn-side:last-child.is-flash {
  background: rgba(255, 26, 26, 0.35);
  border-color: var(--red);
  box-shadow: var(--glow-red);
}

/* —— Title screen —— */
.screen-title {
  justify-content: center;
}

.title-stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 8px 4px 16px;
}

.title-kicker {
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--red);
  text-shadow: var(--glow-red);
}

.title-logo {
  margin: 0;
  text-align: center;
  line-height: 0.95;
}

.title-main {
  display: block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.6rem, 12vw, 3.6rem);
  letter-spacing: -0.03em;
}

.title-tap {
  color: var(--blue);
  text-shadow: var(--glow-blue);
}

.title-tomb {
  color: var(--red);
  text-shadow: var(--glow-red);
}

.title-sub {
  display: block;
  margin-top: 8px;
  font-family: var(--font-body);
  font-size: clamp(1rem, 4vw, 1.15rem);
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--blue);
  text-shadow: var(--glow-blue);
}

.title-chars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.char-card {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(16, 16, 28, 0.75);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.char-card[data-id="rocket"] {
  border-color: rgba(77, 127, 255, 0.45);
  box-shadow: inset 3px 0 0 var(--blue);
}

.char-card[data-id="ghost"] {
  border-color: rgba(57, 255, 20, 0.4);
  box-shadow: inset 3px 0 0 var(--green);
}

.char-card[data-id="exchange"] {
  border-color: rgba(255, 230, 0, 0.4);
  box-shadow: inset 3px 0 0 var(--yellow);
}

.char-card:hover {
  transform: scale(1.02);
}

.char-card[data-id="rocket"]:hover,
.char-card[data-id="rocket"].selected {
  border-color: var(--blue);
  background: rgba(77, 127, 255, 0.12);
  box-shadow: inset 3px 0 0 var(--blue), var(--glow-blue);
}

.char-card[data-id="ghost"]:hover,
.char-card[data-id="ghost"].selected {
  border-color: var(--green);
  background: rgba(57, 255, 20, 0.1);
  box-shadow: inset 3px 0 0 var(--green), var(--glow-green);
}

.char-card[data-id="exchange"]:hover,
.char-card[data-id="exchange"].selected {
  border-color: var(--yellow);
  background: rgba(255, 230, 0, 0.08);
  box-shadow: inset 3px 0 0 var(--yellow), var(--glow-yellow);
}

.char-avatar {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.char-card[data-id="rocket"] .char-avatar {
  box-shadow: 0 0 14px rgba(77, 127, 255, 0.55);
}

.char-card[data-id="ghost"] .char-avatar {
  box-shadow: 0 0 14px rgba(57, 255, 20, 0.45);
}

.char-card[data-id="exchange"] .char-avatar {
  box-shadow: 0 0 14px rgba(255, 230, 0, 0.45);
}

.char-avatar canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.char-meta {
  min-width: 0;
}

.char-meta strong {
  display: block;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 800;
  margin-bottom: 2px;
}

.char-meta span {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.3;
}

.char-score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  padding-left: 8px;
  min-width: 72px;
}

.char-score-label {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.char-score strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--yellow);
  text-shadow: var(--glow-yellow);
  letter-spacing: -0.02em;
}

.title-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.title-row {
  display: flex;
  gap: 8px;
}

.title-row-tight {
  justify-content: space-between;
}

/* —— High scores —— */
.screen-scores {
  justify-content: center;
}

.scores-panel {
  background: linear-gradient(180deg, rgba(20, 20, 36, 0.95), rgba(10, 10, 18, 0.95));
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 18px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 100%;
  overflow: auto;
  box-shadow: var(--glow-green), inset 0 0 40px rgba(47, 91, 255, 0.06);
  backdrop-filter: blur(12px);
}

.scores-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.scores-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(90deg, var(--green), var(--blue));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.score-heroes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.score-hero {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 8px;
  text-align: center;
}

.score-hero:nth-child(1) {
  border-color: rgba(255, 230, 0, 0.4);
  box-shadow: inset 0 0 16px rgba(255, 230, 0, 0.08);
}

.score-hero:nth-child(2) {
  border-color: rgba(47, 91, 255, 0.45);
}

.score-hero:nth-child(3) {
  border-color: rgba(57, 255, 20, 0.35);
}

.score-hero-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.score-hero strong {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--yellow);
  text-shadow: 0 0 10px rgba(255, 230, 0, 0.4);
}

.scores-list-title {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue);
  text-shadow: 0 0 10px rgba(47, 91, 255, 0.45);
}

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

.scores-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.9rem;
}

.scores-list .rank {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--green);
  text-shadow: 0 0 8px rgba(57, 255, 20, 0.5);
}

.scores-list .run-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.scores-list .run-meta strong {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scores-list .run-meta span {
  font-size: 0.75rem;
  color: var(--muted);
}

.scores-list .run-score {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--yellow);
}

.scores-empty {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 20px 8px;
}

/* —— Play —— */
.screen-play {
  gap: 10px;
}

.play-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.play-live {
  display: flex;
  gap: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.play-live em {
  font-style: normal;
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--yellow);
  text-shadow: 0 0 10px rgba(255, 230, 0, 0.45);
  font-size: 0.95rem;
  letter-spacing: 0;
  text-transform: none;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  display: block;
  width: var(--stage-w);
  height: auto;
  max-height: calc(100vh - 180px);
  aspect-ratio: 400 / 700;
  background: #080810;
  border: 2px solid rgba(57, 255, 20, 0.4);
  border-radius: 14px;
  cursor: crosshair;
  touch-action: none;
  box-shadow:
    0 0 0 1px rgba(47, 91, 255, 0.25),
    var(--glow-green),
    0 20px 50px rgba(0, 0, 0, 0.55);
}

.hud-ability {
  margin: 8px 0 0;
  min-height: 1.1em;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--yellow);
  text-shadow: var(--glow-yellow);
}

.play-controls {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* —— Overlay —— */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 4, 12, 0.72);
  backdrop-filter: blur(6px);
  border-radius: 12px;
  z-index: 5;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  width: min(100%, 300px);
  padding: 22px 18px;
  background: linear-gradient(160deg, rgba(22, 22, 40, 0.95), rgba(12, 12, 22, 0.96));
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  text-align: center;
  box-shadow: var(--glow-green), var(--glow-blue);
  animation: screen-in 0.25s ease;
}

.overlay-prompt {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--green), var(--yellow));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay-detail {
  margin: 0 0 14px;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.45;
  white-space: pre-line;
}

.overlay-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}

.overlay-stats div {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 4px;
}

.overlay-stats span {
  display: block;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.overlay-stats strong {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
  color: var(--yellow);
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.overlay-actions .btn {
  width: 100%;
}

.overlay-actions .btn-play {
  font-size: 1.05rem;
  padding: 14px;
  animation: none;
}

@media (min-width: 720px) {
  .play-controls {
    max-width: var(--stage-w);
    width: 100%;
    margin: 0 auto;
  }

  #app {
    padding: 20px;
  }
}
