:root {
  --ink: #45446a;
  --ink-soft: #8583a8;
  --deck: #f4f1fb;
  --deck-2: #e7e1f6;
  --lilac: #c9b8f0;
  --mint: #a8e0cf;
  --butter: #f9e2a0;
  --coral: #f7a8a0;
  --sky: #a6d8f0;
  --display: "Baloo 2", ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  --type: "Lexend", ui-rounded, system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; overflow: hidden; background: #d9eff7; color: var(--ink); font-family: var(--display); -webkit-font-smoothing: antialiased; user-select: none; }
#app { height: 100%; display: flex; flex-direction: column; }

/* ---------- stage (3D) ---------- */
#stage { position: relative; flex: 1; min-height: 0; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#stage.shake { animation: shake .22s linear; }
@keyframes shake { 20% { transform: translate(-7px, 3px); } 40% { transform: translate(6px, -4px); } 60% { transform: translate(-4px, 2px); } 80% { transform: translate(3px, -1px); } }
#vignette { position: absolute; inset: 0; pointer-events: none; opacity: 0; box-shadow: inset 0 0 160px 40px #f08a8a; transition: opacity .25s; }

.hud { position: absolute; top: 18px; pointer-events: none; text-shadow: 0 2px 0 rgba(255, 255, 255, .7); }
.hud-score { left: 26px; }
.score { font-size: 54px; font-weight: 800; line-height: .95; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.score.bump { animation: bump .18s ease-out; }
@keyframes bump { 40% { transform: scale(1.08) rotate(-1deg); } }
.mult { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 15px; font-weight: 500; color: var(--ink-soft); }
.mult-chip { font-size: 24px; font-weight: 800; color: var(--ink); background: var(--butter); padding: 0 12px 0 10px; line-height: 34px; clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%); text-shadow: none; transition: background .3s; }
.mult-chip.up { animation: chip .5s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes chip { 30% { transform: scale(1.5) rotate(-6deg); } }
.mult-bar { width: 120px; height: 10px; background: rgba(255, 255, 255, .7); clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%); }
.mult-bar i { display: block; height: 100%; width: 0; background: var(--ink); transition: width .12s; }

.hud-height { left: 50%; transform: translateX(-50%); text-align: center; }
.height { font-size: 40px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.zone { font-size: 17px; font-weight: 500; color: var(--ink-soft); }

.hud-right { right: 64px; display: flex; align-items: center; gap: 10px; pointer-events: auto; }
.hearts { display: flex; gap: 5px; margin-right: 6px; }
.heart { width: 28px; height: 25px; background: linear-gradient(115deg, #f9b6b0 50%, #ef8f8f 50%); clip-path: polygon(50% 100%, 0 42%, 0 16%, 20% 0, 40% 0, 50% 14%, 60% 0, 80% 0, 100% 16%, 100% 42%); transition: transform .3s, filter .3s, opacity .3s; }
.heart.off { filter: grayscale(1) brightness(1.15); opacity: .45; transform: scale(.78); }
.heart.pop { animation: chip .5s; }
.icon-btn { width: 38px; height: 38px; border: 0; cursor: pointer; background: rgba(255, 255, 255, .75); color: var(--ink); clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px); display: grid; place-items: center; }
.icon-btn:hover { background: #fff; }
.icon-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; clip-path: none; }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }

#tape { position: absolute; right: 10px; top: 76px; bottom: 40px; width: 150px; height: calc(100% - 116px); pointer-events: none; }

#banner { position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%); pointer-events: none; text-align: center; opacity: 0; }
#banner.show { animation: banner 2.6s ease-out; }
#banner h2 { font-size: 64px; font-weight: 800; line-height: 1; color: #fff; -webkit-text-stroke: 10px var(--ink); paint-order: stroke fill; }
#banner p { margin-top: 6px; font-size: 20px; font-weight: 700; background: var(--butter); display: inline-block; padding: 2px 16px; clip-path: polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%); }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.7); } 12% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); } 18% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -70%); } }

.orb { position: absolute; width: 74px; height: 74px; margin: -37px; border: 0; padding: 0; cursor: pointer; background: none; animation: orbIn .35s cubic-bezier(.2, 1.6, .4, 1); }
.orb i { position: absolute; inset: 0; background: conic-gradient(from 20deg, #fdeebb, #f9e2a0, #f6cf7a, #fdeebb, #f3c768, #f9e2a0, #fdeebb); clip-path: polygon(50% 0, 63% 33%, 98% 35%, 71% 57%, 80% 92%, 50% 72%, 20% 92%, 29% 57%, 2% 35%, 37% 33%); animation: orbSpin 3s linear infinite; }
.orb.heart-orb i { background: linear-gradient(115deg, #f9b6b0 50%, #ef8f8f 50%); clip-path: polygon(50% 100%, 0 42%, 0 16%, 20% 0, 40% 0, 50% 14%, 60% 0, 80% 0, 100% 16%, 100% 42%); animation: orbBeat .6s ease-in-out infinite; }
.orb::after { content: ""; position: absolute; inset: -10px; border: 4px solid rgba(255, 255, 255, .9); border-radius: 50%; animation: orbRing var(--life, 4.5s) linear forwards; }
.orb:hover i { filter: brightness(1.08); }
@keyframes orbIn { from { transform: scale(0); } }
@keyframes orbSpin { to { transform: rotate(360deg); } }
@keyframes orbBeat { 50% { transform: scale(1.14); } }
@keyframes orbRing { to { transform: scale(.35); opacity: .2; } }

/* ---------- deck (typing) ---------- */
#deck { position: relative; flex: none; height: 236px; margin-top: -18px; padding-top: 30px; background: var(--deck); clip-path: polygon(0 16px, 8% 2px, 19% 15px, 33% 4px, 46% 17px, 60% 3px, 74% 14px, 89% 1px, 100% 13px, 100% 100%, 0 100%); }
#deck::before { content: ""; position: absolute; inset: 0; background: var(--deck-2); clip-path: polygon(0 16px, 8% 2px, 19% 15px, 33% 4px, 46% 17px, 60% 3px, 74% 14px, 89% 1px, 100% 13px, 100% 30px, 89% 22px, 74% 34px, 60% 20px, 46% 36px, 33% 21px, 19% 33px, 8% 19px, 0 32px); }
#lane { position: relative; height: 112px; overflow: hidden; -webkit-mask-image: linear-gradient(to right, transparent, #000 12%, #000 86%, transparent); mask-image: linear-gradient(to right, transparent, #000 12%, #000 86%, transparent); }
#track { position: absolute; left: 0; top: 16px; white-space: nowrap; font-family: var(--type); font-size: 52px; line-height: 76px; font-weight: 400; will-change: transform; }
#track span { display: inline-block; padding: 0 3px; color: var(--ink); transition: color .15s, opacity .4s; }
#track span.sp { width: .5em; }
#track span.done { color: #6fbfa5; opacity: .5; }
#track span.cur { background: var(--butter); clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%); }
#track span.bad { background: var(--coral); animation: bad .22s linear; }
@keyframes bad { 25% { transform: translateX(-5px) rotate(-3deg); } 75% { transform: translateX(5px) rotate(3deg); } }
#ghost { position: absolute; top: -6px; left: -1400px; width: 1400px; height: 88px; pointer-events: none; background: linear-gradient(to right, rgba(247, 168, 160, .5) 0, rgba(247, 168, 160, .5) calc(100% - 46px), rgba(247, 168, 160, 0) 100%); }
#ghost svg { position: absolute; right: -4px; top: 27px; width: 34px; height: 34px; animation: orbBeat .7s ease-in-out infinite; }
#caret { position: absolute; left: 34%; bottom: 2px; width: 22px; height: 12px; margin-left: -11px; background: var(--ink); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
#deck.danger #caret { background: #ea7f7f; }

#stats { display: flex; justify-content: center; align-items: flex-end; gap: 44px; padding: 10px 24px 0; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 84px; }
.stat b { font-size: 28px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 14px; font-weight: 500; color: var(--ink-soft); }
.stat-wide { width: 260px; }
.stab { width: 100%; height: 18px; margin-bottom: 8px; background: #fff; clip-path: polygon(7px 0, 100% 0, calc(100% - 7px) 100%, 0 100%); }
.stab i { display: block; height: 100%; width: 100%; background: linear-gradient(100deg, var(--mint) 50%, #94d6c2 50%); transition: width .15s, background .3s; }
.stab.low i { background: linear-gradient(100deg, var(--coral) 50%, #ef8f8f 50%); }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* ---------- overlay ---------- */
#overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(217, 239, 247, .55); backdrop-filter: blur(3px); transition: opacity .3s; }
#overlay.hidden { opacity: 0; pointer-events: none; }
.card { width: min(560px, 92vw); padding: 38px 44px 34px; background: #fff; text-align: center; clip-path: polygon(28px 0, 100% 0, 100% calc(100% - 28px), calc(100% - 28px) 100%, 0 100%, 0 28px); }
.title { display: flex; flex-direction: column; align-items: center; margin-bottom: 20px; }
.title span { font-size: 56px; font-weight: 800; line-height: 1; padding: 6px 22px 2px; margin-top: -2px; }
.title span:nth-child(1) { background: var(--lilac); transform: rotate(-2.5deg) translateX(-6px); }
.title span:nth-child(2) { background: var(--butter); transform: rotate(2deg) translateX(8px); font-size: 40px; }
.title span:nth-child(3) { background: var(--mint); transform: rotate(-1.5deg); padding-inline: 44px; }
.card h1 { font-size: 44px; font-weight: 800; line-height: 1.05; margin-bottom: 6px; }
.card p { font-size: 18px; font-weight: 500; line-height: 1.45; color: var(--ink-soft); max-width: 42ch; margin: 0 auto 10px; }
.card p b { color: var(--ink); font-weight: 700; }
.results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 8px; margin: 22px 0 8px; }
.results div { display: flex; flex-direction: column; }
.results b { font-size: 30px; font-weight: 800; line-height: 1.1; }
.results span { font-size: 14px; color: var(--ink-soft); font-weight: 500; }
.best { font-size: 15px; color: var(--ink-soft); font-weight: 500; margin-top: 4px; }
.go { margin-top: 20px; font: 800 24px/1 var(--display); color: var(--ink); background: var(--coral); border: 0; cursor: pointer; padding: 18px 36px 14px; clip-path: polygon(14px 0, 100% 0, calc(100% - 14px) 100%, 0 100%); transition: transform .12s, background .12s; }
.go:hover { transform: translateY(-2px) scale(1.03); background: #f9b9b2; }
.go:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; clip-path: none; }
.hint { display: block; margin-top: 12px; font-size: 14px; color: var(--ink-soft); font-weight: 500; }

@media (max-height: 640px) { #deck { height: 196px; } #stats { gap: 28px; } .stat b { font-size: 22px; } }
@media (max-width: 820px) { .stat-wide { width: 160px; } #stats { gap: 18px; } .score { font-size: 40px; } .height { font-size: 30px; } .stat:nth-child(4), .stat:nth-child(5) { display: none; } }
@media (prefers-reduced-motion: reduce) { #stage.shake, .orb i, #ghost svg { animation: none; } }

/* high altitude: sky turns dark, HUD flips to light ink */
#stage.night .hud { color: #fff; text-shadow: 0 2px 0 rgba(20, 18, 46, .6); }
#stage.night .zone, #stage.night .mult { color: #d9d4f5; }
#stage.night .mult-chip { color: var(--ink); }
#stage.night .mult-bar i { background: #fff; }
#stage.night .mult-bar { background: rgba(255, 255, 255, .25); }

.tempo { display: inline-block; margin-top: 8px; font-size: 17px; font-weight: 700; line-height: 28px; padding: 0 12px; color: var(--ink); text-shadow: none; clip-path: polygon(7px 0, 100% 0, calc(100% - 7px) 100%, 0 100%); }
.tempo:empty { display: none; }
.tempo[data-t="1"] { background: var(--mint); }
.tempo[data-t="2"] { background: var(--sky); }
.tempo[data-t="3"] { background: var(--coral); animation: orbBeat .5s ease-in-out infinite; }
