:root {
  --bg: #120a1f;
  --bg2: #1e1033;
  --gold: #ffcc33;
  --gold-deep: #e09a00;
  --pink: #ff3d8b;
  --cyan: #37e8ff;
  --ink: #f6eeff;
  --muted: #a690c7;
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% -10%, #3b1a63 0%, transparent 55%),
    radial-gradient(circle at 100% 100%, #2a0f3d 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: "Space Mono", ui-monospace, monospace;
  overscroll-behavior: none;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 18px 16px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  user-select: none;
}

.title { text-align: center; }

h1 {
  font-family: "Bungee", sans-serif;
  font-size: clamp(2rem, 9vw, 3rem);
  margin: 0;
  letter-spacing: 1px;
  background: linear-gradient(180deg, #fff3b0 0%, var(--gold) 45%, var(--gold-deep) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 #7a3b00) drop-shadow(0 0 18px rgba(255, 204, 51, .35));
  position: relative;
}

h1 .crown {
  -webkit-text-fill-color: initial;
  display: inline-block;
  animation: bob 2.4s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  50% { transform: translateY(-5px) rotate(6deg); }
}

.sub {
  margin: 6px 0 0;
  font-family: "Bungee", sans-serif;
  font-size: .9rem;
  letter-spacing: 3px;
  color: var(--pink);
}
.sub b { color: var(--cyan); font-weight: 400; }

.hud {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat {
  background: linear-gradient(180deg, var(--bg2), #150b25);
  border: 1px solid #3a2560;
  border-radius: 12px;
  padding: 8px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat small { font-size: .62rem; letter-spacing: 2px; color: var(--muted); }
.stat b { font-family: "Bungee", sans-serif; font-weight: 400; font-size: 1.05rem; color: var(--gold); white-space: nowrap; }
.stat b.pop { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(1.5); color: #fff; } 100% { transform: scale(1); } }

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 18px;
  padding: 6px;
  background: linear-gradient(135deg, var(--gold), var(--pink) 50%, var(--cyan));
  box-shadow: 0 0 40px rgba(255, 61, 139, .25), 0 10px 30px rgba(0, 0, 0, .5);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 13px;
  background: #0c0616;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 6px;
  border-radius: 13px;
  background: rgba(12, 6, 22, .82);
  backdrop-filter: blur(3px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 20px;
  transition: opacity .2s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay h2 {
  font-family: "Bungee", sans-serif;
  font-weight: 400;
  font-size: clamp(1.8rem, 8vw, 2.6rem);
  margin: 0;
  color: var(--gold);
  text-shadow: 0 3px 0 #7a3b00;
}
.overlay p { margin: 0 0 6px; color: var(--ink); line-height: 1.5; font-size: .9rem; }

.btn {
  font-family: "Bungee", sans-serif;
  font-size: 1rem;
  letter-spacing: 2px;
  border: 0;
  border-radius: 12px;
  padding: 12px 28px;
  cursor: pointer;
  transition: transform .08s, filter .15s;
}
.btn:active { transform: translateY(2px) scale(.98); }
.btn.gold {
  background: linear-gradient(180deg, #fff0a0, var(--gold) 50%, var(--gold-deep));
  color: #3a1d00;
  box-shadow: 0 4px 0 #8a4b00, 0 0 20px rgba(255, 204, 51, .4);
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  grid-template-rows: repeat(2, 64px);
  grid-template-areas: ". up ." "left down right";
  gap: 8px;
  margin-top: 4px;
}
.dir {
  font-size: 1.5rem;
  color: var(--ink);
  background: linear-gradient(180deg, #2c1850, #1a0e30);
  border: 1px solid #4b2f7c;
  border-radius: 14px;
  box-shadow: 0 4px 0 #0a0514;
  cursor: pointer;
  touch-action: none;
}
.dir:active, .dir.held {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #0a0514;
  color: var(--gold);
  border-color: var(--gold);
}
.up { grid-area: up; }
.left { grid-area: left; }
.down { grid-area: down; }
.right { grid-area: right; }

.restart {
  background: transparent;
  color: var(--pink);
  border: 2px solid var(--pink);
  box-shadow: 0 0 14px rgba(255, 61, 139, .3);
}
.restart:hover { filter: brightness(1.2); }

@media (min-width: 700px) and (min-height: 900px) {
  .app { padding-top: 32px; }
}
