:root {
  --cyan: #3df0ff;
  --pink: #ff4d9d;
  --gold: #ffd23e;
  --green: #6dff8f;
  --bg0: #06060f;
  --bg1: #0e0e22;
  --ink: #e7ecff;
  --muted: #8a90b8;
  --panel: rgba(14, 16, 38, 0.82);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg0);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  cursor: default;
  user-select: none;
}

#game {
  position: fixed;
  inset: 0;
}

#canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ===== Overlays ===== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 35%, rgba(8, 10, 28, 0.45), rgba(4, 4, 12, 0.86));
  backdrop-filter: blur(3px);
  opacity: 1;
  transition: opacity 0.28s ease;
  z-index: 10;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.panel {
  width: min(560px, 92vw);
  padding: 40px 36px;
  text-align: center;
  background: var(--panel);
  border: 1px solid rgba(61, 240, 255, 0.18);
  border-radius: 20px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.panel.wide {
  width: min(880px, 96vw);
}

.title {
  font-size: clamp(56px, 14vw, 128px);
  font-weight: 800;
  letter-spacing: 0.14em;
  line-height: 1;
  color: #fff;
  text-shadow:
    0 0 12px rgba(61, 240, 255, 0.9),
    0 0 36px rgba(61, 240, 255, 0.55),
    0 0 80px rgba(255, 77, 157, 0.4);
  animation: pulse 3.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { text-shadow: 0 0 12px rgba(61, 240, 255, 0.9), 0 0 36px rgba(61, 240, 255, 0.5), 0 0 80px rgba(255, 77, 157, 0.35); }
  50%      { text-shadow: 0 0 18px rgba(61, 240, 255, 1), 0 0 52px rgba(61, 240, 255, 0.7), 0 0 110px rgba(255, 77, 157, 0.55); }
}

.subtitle {
  margin: 14px auto 0;
  max-width: 42ch;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.controls {
  margin: 26px auto 30px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.key {
  display: inline-block;
  min-width: 22px;
  padding: 2px 7px;
  margin: 0 2px;
  border: 1px solid rgba(231, 236, 255, 0.28);
  border-bottom-width: 3px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.hint {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
  min-height: 1em;
}

/* ===== Buttons ===== */
.btn {
  appearance: none;
  margin: 8px 6px 0;
  padding: 13px 34px;
  border: 2px solid var(--cyan);
  border-radius: 12px;
  background: transparent;
  color: var(--cyan);
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.18s ease, box-shadow 0.18s ease, color 0.18s ease;
}

.btn:hover {
  background: var(--cyan);
  color: var(--bg0);
  box-shadow: 0 0 26px rgba(61, 240, 255, 0.55);
  transform: translateY(-2px);
}

.btn:active { transform: translateY(0); }

.btn-ghost {
  border-color: rgba(231, 236, 255, 0.3);
  color: var(--muted);
  font-size: 14px;
  padding: 10px 24px;
}

.btn-ghost:hover {
  background: rgba(231, 236, 255, 0.12);
  color: var(--ink);
  box-shadow: none;
}

/* ===== Level-up cards ===== */
.levelup-title {
  font-size: clamp(30px, 6vw, 46px);
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--gold);
  text-shadow: 0 0 26px rgba(255, 210, 62, 0.6);
}

.cards {
  margin-top: 26px;
  display: flex;
  gap: 18px;
  justify-content: center;
  flex-wrap: wrap;
}

.card {
  position: relative;
  width: 230px;
  padding: 26px 20px 22px;
  border: 1px solid rgba(61, 240, 255, 0.22);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(36, 40, 78, 0.6), rgba(14, 16, 38, 0.6));
  cursor: pointer;
  text-align: center;
  transition: transform 0.14s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.card:hover {
  transform: translateY(-8px);
  border-color: var(--pink);
  box-shadow: 0 18px 50px rgba(255, 77, 157, 0.28);
}

.card .emoji {
  font-size: 42px;
  line-height: 1;
}

.card .cardName {
  margin-top: 14px;
  font-size: 19px;
  font-weight: 700;
  color: #fff;
}

.card .cardDesc {
  margin-top: 8px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.4;
}

.card .cardLevel {
  margin-top: 12px;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--cyan);
  text-transform: uppercase;
}

.card .cardKey {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 26px;
  height: 26px;
  line-height: 24px;
  border-radius: 8px;
  background: var(--bg1);
  border: 1px solid rgba(61, 240, 255, 0.4);
  color: var(--cyan);
  font-size: 13px;
  font-weight: 700;
}

/* ===== Game-over stats ===== */
.gameover-title {
  font-size: clamp(34px, 7vw, 54px);
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--pink);
  text-shadow: 0 0 30px rgba(255, 77, 157, 0.5);
}

.stats {
  margin: 24px auto 28px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 420px;
}

.stat {
  padding: 16px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.stat .statVal {
  font-size: 28px;
  font-weight: 800;
  color: var(--cyan);
}

.stat .statLabel {
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat.highlight .statVal { color: var(--gold); }

.newbest {
  margin-top: 4px;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.12em;
}

@media (max-width: 520px) {
  .panel { padding: 30px 22px; }
  .card { width: 100%; }
}
