:root {
  --pink: #ff3d9a;
  --cyan: #3df5ff;
  --gold: #ffd23f;
  --violet: #9d6bff;
  --ink: #0a0418;
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --body: "Rubik", system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--ink);
  color: #fff;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--body);
}

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }

#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: none; }
[hidden] { display: none !important; }

/* CRT scanlines + vignette over everything */
.crt {
  position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0) 0 2px, rgba(0, 0, 0, .16) 2px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, .55) 100%);
}

/* ── HUD ───────────────────────────────────── */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  padding: calc(12px + env(safe-area-inset-top)) 64px 0 16px;
  font-family: var(--pixel); font-size: clamp(9px, 2.6vw, 13px);
  text-shadow: 0 0 8px var(--pink), 2px 2px 0 #000;
}
.hud-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
#hud-level { color: var(--cyan); text-shadow: 0 0 8px var(--cyan), 2px 2px 0 #000; }
#hud-score { color: var(--gold); text-shadow: 0 0 8px #ff9d00, 2px 2px 0 #000; display: inline-block; }
#hud-score.bump { animation: bump .18s ease-out; }
#hud-score.ouch { animation: bump .18s ease-out; color: #ff4d4d; }
@keyframes bump { 50% { transform: scale(1.35); } }
#hud-time { margin-top: 10px; height: 8px; border: 2px solid #fff; border-radius: 2px; background: rgba(0, 0, 0, .5); box-shadow: 0 0 10px var(--pink); }
#hud-time i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--pink), var(--gold)); transform-origin: left; }

#mute {
  pointer-events: auto; position: absolute; z-index: 5;
  top: calc(8px + env(safe-area-inset-top)); right: 10px;
  width: 42px; height: 42px; font-size: 18px; line-height: 1;
  background: rgba(10, 4, 24, .6); border: 2px solid rgba(255, 255, 255, .5); border-radius: 50%;
  color: #fff; cursor: pointer;
}

/* ── Buttons ───────────────────────────────── */
.btn {
  pointer-events: auto; cursor: pointer;
  font-family: var(--pixel); font-size: clamp(10px, 2.8vw, 13px); color: #fff;
  padding: 14px 18px; border: 3px solid #fff; border-radius: 4px;
  background: linear-gradient(180deg, #ff5fae, #c2187a);
  box-shadow: 0 5px 0 #6b0c45, 0 0 24px rgba(255, 61, 154, .7);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, .45);
  transition: transform .06s, box-shadow .06s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #6b0c45, 0 0 24px rgba(255, 61, 154, .7); }
.btn.alt { background: linear-gradient(180deg, #4b3a8f, #2a1f5c); box-shadow: 0 5px 0 #150e36, 0 0 18px rgba(157, 107, 255, .5); }
.btn.big { font-size: clamp(13px, 3.8vw, 18px); padding: 18px 26px; }
.blink { animation: blink 1.1s steps(2, jump-none) infinite; }
@keyframes blink { 50% { filter: brightness(1.6); box-shadow: 0 5px 0 #6b0c45, 0 0 46px rgba(255, 61, 154, 1); } }

/* ── Title ─────────────────────────────────── */
#title {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(14px, 3vh, 26px); text-align: center; padding: 24px;
  background: radial-gradient(ellipse at center, rgba(10, 4, 24, .15), rgba(10, 4, 24, .7));
}
.kicker { font-family: var(--pixel); font-size: clamp(8px, 2.2vw, 11px); color: var(--cyan); letter-spacing: .08em; text-shadow: 0 0 10px var(--cyan); }
#title h1 { display: flex; flex-direction: column; align-items: center; gap: 12px; font-weight: 400; }
.neon {
  font-family: "Monoton", var(--pixel); font-size: clamp(54px, 15vw, 150px); line-height: 1; color: #fff;
  text-shadow: 0 0 6px #fff, 0 0 18px var(--pink), 0 0 42px var(--pink), 0 0 90px #ff0080;
  animation: flicker 4s infinite;
}
@keyframes flicker { 0%, 18%, 22%, 62%, 64%, 100% { opacity: 1; } 20%, 63% { opacity: .72; } }
#title .sub {
  font-family: var(--pixel); font-size: clamp(15px, 4.6vw, 38px); color: var(--gold);
  text-shadow: 3px 3px 0 #b3006b, 0 0 22px rgba(255, 210, 63, .7);
}
.tagline { font-size: clamp(14px, 3.4vw, 19px); opacity: .9; font-weight: 600; letter-spacing: .04em; }
.hint { font-size: 13px; opacity: .65; }
.hiscore { font-family: var(--pixel); font-size: 10px; color: var(--gold); min-height: 12px; }

/* ── Level cards ───────────────────────────── */
#card {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 20px;
  background: rgba(6, 2, 16, .62); backdrop-filter: blur(3px);
  animation: fadein .25s ease-out;
}
@keyframes fadein { from { opacity: 0; } }
.card-inner {
  width: min(520px, 100%); padding: clamp(22px, 5vw, 36px); text-align: center;
  display: flex; flex-direction: column; gap: 18px; align-items: center;
  background: linear-gradient(180deg, rgba(34, 14, 72, .95), rgba(14, 6, 36, .95));
  border: 3px solid var(--cyan); border-radius: 10px;
  box-shadow: 0 0 0 3px #0a0418, 0 0 40px rgba(61, 245, 255, .45), inset 0 0 30px rgba(157, 107, 255, .25);
  animation: pop .35s cubic-bezier(.2, 1.5, .4, 1);
}
@keyframes pop { from { transform: scale(.8); opacity: 0; } }
#card h2 { font-family: var(--pixel); font-size: clamp(17px, 5vw, 28px); line-height: 1.35; color: var(--gold); text-shadow: 3px 3px 0 #b3006b; }
#card-body { font-size: clamp(15px, 3.6vw, 18px); line-height: 1.55; display: flex; flex-direction: column; gap: 10px; }
#card-body .em { font-size: 2.2em; letter-spacing: .12em; }
#card-body .stat { font-family: var(--pixel); font-size: .72em; color: var(--cyan); line-height: 1.9; }
#card-body .small { font-size: .82em; opacity: .7; }
#card-buttons { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }

/* ── Wish toast ────────────────────────────── */
#toast {
  position: absolute; left: 50%; top: calc(70px + env(safe-area-inset-top)); transform: translateX(-50%);
  width: min(440px, calc(100% - 28px)); padding: 12px 16px;
  background: linear-gradient(180deg, #fff6d6, #ffe08a); color: #3b1d00; border-radius: 12px;
  border: 3px solid #fff; box-shadow: 0 0 30px rgba(255, 210, 63, .8);
  font-size: 15px; line-height: 1.4; text-align: center;
  animation: toast 4.2s ease both;
}
#toast b { display: block; font-family: var(--pixel); font-size: 9px; margin-bottom: 6px; color: #b3006b; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -24px) scale(.9); } 7%, 88% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, -12px); } }

/* ── Finale sheet ──────────────────────────── */
#finale {
  position: absolute; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(560px, calc(100% - 24px)); max-height: 56vh; overflow-y: auto; pointer-events: auto;
  padding: 20px; text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center;
  background: linear-gradient(180deg, rgba(34, 14, 72, .9), rgba(14, 6, 36, .94));
  border: 3px solid var(--gold); border-radius: 12px;
  box-shadow: 0 0 40px rgba(255, 210, 63, .4);
  animation: rise .6s cubic-bezier(.2, 1.2, .4, 1);
  -webkit-user-select: text; user-select: text;
}
@keyframes rise { from { transform: translate(-50%, 110%); } }
#finale .level-up { font-family: var(--pixel); font-size: clamp(10px, 2.8vw, 13px); color: var(--cyan); text-shadow: 0 0 10px var(--cyan); line-height: 1.6; }
#finale .score { font-family: var(--pixel); font-size: clamp(22px, 7vw, 38px); color: var(--gold); text-shadow: 3px 3px 0 #b3006b; }
#finale .rank { font-family: var(--pixel); font-size: clamp(9px, 2.6vw, 12px); line-height: 1.7; }
#finale .rank em { color: var(--pink); font-style: normal; }
#finale .newbest { font-family: var(--pixel); font-size: 10px; color: #5dff8f; animation: blink 1s steps(2, jump-none) infinite; }
#finale .msg { font-size: clamp(15px, 3.6vw, 18px); line-height: 1.55; }
#finale .from { font-weight: 600; color: var(--gold); }
#finale .wishes { width: 100%; display: flex; flex-direction: column; gap: 8px; text-align: left; }
#finale .wish { padding: 10px 12px; border-radius: 8px; background: rgba(255, 255, 255, .08); border-left: 4px solid var(--pink); font-size: 14.5px; line-height: 1.45; }
#finale .wish b { display: block; font-family: var(--pixel); font-size: 8.5px; color: var(--gold); margin-bottom: 5px; }
#finale .wish.locked { opacity: .55; border-left-color: #777; }
#finale .row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
#finale-toggle { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); }
#finale-toggle:active { transform: translate(-50%, 4px); }

@media (prefers-reduced-motion: reduce) {
  .neon, .blink { animation: none; }
}
