:root {
  --pink: #ff3d8b;
  --pink-d: #b0124f;
  --teal: #19e3cf;
  --teal-d: #0b8f83;
  --yellow: #ffd23f;
  --yellow-d: #b88a00;
  --violet: #b98bff;
  --violet-d: #6a3fc4;
  --green: #3ee07f;
  --green-d: #17914a;
  --red: #ff4d6d;
  --red-d: #a8183a;
  --ink: #1b0b3a;
  --panel: #2a1257;
  --line: rgba(255, 255, 255, .14);
  --text: #fff4fa;
  --muted: #cbb9f0;
  --display: 'Bungee', Impact, system-ui, sans-serif;
  --ui: 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--ink); -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; color: var(--text); font: 400 16px/1.45 var(--ui); }
h1, h2, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
[tabindex="-1"]:focus { outline: none; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; white-space: nowrap;
  clip: rect(0 0 0 0); clip-path: inset(50%);
}

/* Backdrop: purple gradient, sunset and a synthwave floor */
.bg {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: radial-gradient(120% 55% at 50% 0%, #4a1585, transparent 65%), linear-gradient(#1b0b3a, #3a0f6b);
}
.sun {
  position: absolute; left: 50%; bottom: 16vh; width: min(80vw, 460px); aspect-ratio: 2;
  transform: translateX(-50%); border-radius: 999px 999px 0 0; opacity: .2;
  background: repeating-linear-gradient(transparent 0 12px, #3a0f6b 12px 16px) bottom / 100% 45% no-repeat,
    linear-gradient(var(--yellow), var(--pink));
}
.grid {
  position: absolute; left: -50%; width: 200%; bottom: 0; height: 70vh;
  transform: perspective(500px) rotateX(58deg); transform-origin: 50% 100%; opacity: .3;
  background-image: linear-gradient(var(--pink) 2px, transparent 2px), linear-gradient(90deg, var(--teal) 2px, transparent 2px);
  background-size: 60px 60px;
  -webkit-mask-image: linear-gradient(transparent, #000 45%);
  mask-image: linear-gradient(transparent, #000 45%);
}

.app {
  width: 100%; max-width: 560px; min-height: 100vh; min-height: 100dvh; margin: 0 auto;
  display: flex; flex-direction: column; gap: 14px;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.status { text-align: center; color: var(--muted); font-weight: 700; padding: 28px 0; }

/* Chunky buttons */
.btn {
  --c: var(--pink); --d: var(--pink-d);
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 56px; padding: 0 26px; border-radius: 18px; background: var(--c); color: var(--ink);
  font: 400 1.05rem/1.1 var(--display); letter-spacing: .02em; box-shadow: 0 6px 0 var(--d);
  transition: transform .08s ease-out, box-shadow .08s ease-out;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--d); }
.btn.alt { --c: var(--teal); --d: var(--teal-d); }

/* Home */
.hero { display: grid; justify-items: center; text-align: center; }
.lobe-wrap { width: 120px; }
.lobe { display: block; width: 100%; height: auto; overflow: visible; }
.wordmark {
  margin-top: 2px; font: 400 clamp(2.5rem, 12.5vw, 3.6rem)/1 var(--display); color: var(--yellow);
  letter-spacing: .02em; transform: rotate(-3deg); text-shadow: 3px 3px 0 var(--pink), 6px 6px 0 var(--teal);
}
.tagline { margin-top: 10px; color: var(--teal); font-weight: 800; font-size: .8rem; letter-spacing: .16em; text-transform: uppercase; }

.toggle {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px;
  border-radius: 999px; background: rgba(0, 0, 0, .28); border: 2px solid var(--line);
}
.toggle button { min-height: 44px; border-radius: 999px; font-weight: 700; color: var(--muted); transition: background .15s, color .15s; }
.toggle [aria-pressed="true"] { background: var(--yellow); color: var(--ink); box-shadow: 0 3px 0 var(--yellow-d); }
.toggle [data-level="beast"][aria-pressed="true"] { background: var(--pink); box-shadow: 0 3px 0 var(--pink-d); }

.cards { display: grid; gap: 16px; padding-top: 6px; }
.cards li { display: grid; }
.card {
  --c: var(--pink); --d: var(--pink-d);
  position: relative; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 14px;
  padding: 14px 16px; text-align: left; border-radius: 22px; background: var(--panel);
  border: 3px solid var(--c); box-shadow: 0 6px 0 var(--d);
  transition: transform .08s ease-out, box-shadow .08s ease-out, background .15s;
}
.card:hover { background: #34186b; }
.card:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--d); }
.c1 { --c: var(--teal); --d: var(--teal-d); }
.c2 { --c: var(--yellow); --d: var(--yellow-d); }
.c3 { --c: var(--violet); --d: var(--violet-d); }
.card-emoji {
  display: grid; place-items: center; width: 54px; height: 54px; border-radius: 50%;
  background: var(--c); font-size: 1.6rem; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .2);
}
.card-text { display: grid; gap: 2px; min-width: 0; }
.card-name { font: 400 1.02rem/1.2 var(--display); color: var(--c); }
.card-blurb { color: var(--muted); font-size: .9rem; line-height: 1.3; }
.card-best {
  position: absolute; top: -12px; right: 14px; padding: 3px 10px; border-radius: 999px;
  background: var(--c); color: var(--ink); font-size: .75rem; font-weight: 800; transform: rotate(3deg);
}

.foot { margin-top: auto; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0 16px; color: var(--muted); font-size: .85rem; }
.link { min-height: 44px; padding: 0 12px; border-radius: 999px; color: var(--muted); font-weight: 700; }
.link:hover { color: var(--text); }
.link[aria-pressed="false"] { opacity: .7; }
.keys-hint { display: none; }

.closed {
  display: grid; justify-items: center; gap: 12px; padding: 22px 18px; text-align: center;
  border-radius: 22px; background: var(--panel); border: 3px dashed var(--pink);
}
.closed h2 { font: 400 1.35rem/1.2 var(--display); color: var(--pink); }
.closed p { color: var(--muted); }

/* Workout */
.topbar { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; background: rgba(255, 255, 255, .08); border: 2px solid var(--line); font-weight: 800; }
.icon-btn:active { transform: translateY(2px); }
.topbar-title { min-width: 0; }
.topbar-title h1 { font: 400 .95rem/1.15 var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title p { color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.stats { display: flex; gap: 6px; font-weight: 800; font-size: .85rem; white-space: nowrap; }
.stats span { padding: 5px 9px; border-radius: 999px; background: rgba(255, 255, 255, .1); }
.streak { opacity: .45; }
.streak.hot { opacity: 1; color: var(--yellow); background: rgba(255, 210, 63, .16); animation: pop .3s ease-out; }

.progress { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.progress i { height: 10px; border-radius: 6px; background: rgba(255, 255, 255, .14); }
.progress .ok { background: var(--green); }
.progress .bad { background: var(--pink); }
.progress .now { background: var(--yellow); animation: glow 1s ease-in-out infinite alternate; }

.stage { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; padding-top: 6px; }
.stage .lobe-wrap { width: 84px; justify-self: end; }
.playcol { display: grid; justify-items: center; gap: 10px; }
.play {
  position: relative; display: grid; place-items: center; width: 112px; height: 112px; border-radius: 50%;
  color: var(--ink); background: radial-gradient(circle at 35% 30%, #ff9cc5, var(--pink) 62%);
  box-shadow: 0 8px 0 var(--pink-d), 0 0 0 9px rgba(255, 61, 139, .16), 0 14px 40px rgba(255, 61, 139, .45);
  transition: transform .08s ease-out, box-shadow .08s ease-out;
}
.play:active { transform: translateY(5px); box-shadow: 0 3px 0 var(--pink-d), 0 0 0 9px rgba(255, 61, 139, .16), 0 8px 24px rgba(255, 61, 139, .4); }
.play .tri { width: 50px; height: 50px; margin-left: 6px; fill: currentColor; }
.play .eq { display: none; align-items: flex-end; gap: 5px; height: 42px; }
.play .eq i { width: 8px; height: 100%; border-radius: 4px; background: currentColor; transform-origin: bottom; transform: scaleY(.4); animation: eq .7s ease-in-out infinite alternate; }
.play .eq i:nth-child(2) { animation-duration: .45s; animation-delay: -.2s; }
.play .eq i:nth-child(3) { animation-duration: .6s; animation-delay: -.5s; }
.play .eq i:nth-child(4) { animation-duration: .5s; animation-delay: -.1s; }
.play .eq i:nth-child(5) { animation-duration: .8s; animation-delay: -.35s; }
.play.playing .eq { display: flex; }
.play.playing .tri { display: none; }
.play:is(.blocked, .error)::after {
  content: ''; position: absolute; inset: -12px; border-radius: 50%; border: 3px solid var(--yellow);
  animation: ring 1.1s ease-out infinite;
}
.play-caption { color: var(--muted); font-size: .76rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; text-align: center; }
.play:is(.blocked, .error) + .play-caption { color: var(--yellow); }
.chip {
  justify-self: start; display: grid; justify-items: center; min-height: 44px; padding: 6px 8px; border-radius: 18px;
  border: 2px solid var(--teal); background: rgba(25, 227, 207, .08); color: var(--teal);
  font-size: .74rem; font-weight: 800; line-height: 1.25; white-space: nowrap; box-shadow: 0 4px 0 var(--teal-d);
  transition: transform .08s ease-out, box-shadow .08s ease-out;
}
.chip span { font-size: 1.15rem; }
.chip:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--teal-d); }

.prompt { text-align: center; font: 400 1rem/1.25 var(--display); }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.answer {
  position: relative; min-height: 64px; padding: 10px 14px; border-radius: 18px; background: #fff4fa; color: var(--ink);
  font-size: 1.05rem; font-weight: 800; line-height: 1.2; box-shadow: 0 6px 0 #a58bdc;
  transition: transform .08s ease-out, box-shadow .08s ease-out, opacity .2s;
}
.answer:not(:disabled):hover { background: #fff; }
.answer:not(:disabled):active { transform: translateY(4px); box-shadow: 0 2px 0 #a58bdc; }
.answer kbd { display: none; position: absolute; top: 7px; left: 10px; font: 800 .68rem/1 var(--ui); color: #8c76c4; }
.answer:is(.right, .reveal) { background: var(--green); box-shadow: 0 6px 0 var(--green-d); }
.answer.right { animation: pop .35s ease-out; }
.answer.reveal { animation: pulse .5s ease-in-out 2; }
.answer.wrong { background: var(--red); box-shadow: 0 6px 0 var(--red-d); animation: shake .4s ease-in-out; }
.answer.dim { opacity: .45; }
.answer:is(.right, .reveal, .wrong)::after { position: absolute; top: 5px; right: 10px; font-size: .85rem; }
.answer:is(.right, .reveal)::after { content: '✓'; }
.answer.wrong::after { content: '✕'; }

.coach {
  display: grid; gap: 8px; padding: 14px 16px; border-radius: 20px;
  background: rgba(255, 255, 255, .07); border: 2px solid var(--line); animation: rise .3s ease-out;
}
.quip { font: 400 1.08rem/1.2 var(--display); }
.good .quip { color: var(--green); }
.oops .quip { color: var(--pink); }
.callout { justify-self: start; padding: 4px 12px; border-radius: 999px; background: var(--yellow); color: var(--ink); font-size: .85rem; font-weight: 800; animation: pop .4s ease-out; }
.verdict { color: var(--muted); }
.verdict b { color: var(--yellow); }
.kb { display: grid; gap: 4px; }
.keys { width: 100%; max-width: 340px; justify-self: center; }
.keys rect { fill: #fff4fa; stroke: var(--ink); stroke-width: 1.5; transition: fill .2s; }
.keys .b rect { fill: #2a1257; }
.keys rect.lit { fill: var(--teal); }
.keys .b rect.lit { fill: var(--pink); }
.keys text { font: 700 8px var(--ui); fill: #8c76c4; text-anchor: middle; }
.heard { text-align: center; color: var(--muted); font-size: .8rem; font-weight: 700; }
.next { width: 100%; }

/* Results */
.results { display: grid; justify-items: center; gap: 6px; text-align: center; }
.results .lobe-wrap { width: 132px; }
.ribbon {
  margin: 4px 0 2px; padding: 10px 26px; background: var(--yellow); color: var(--ink); font: 400 .95rem/1 var(--display);
  clip-path: polygon(0 0, 100% 0, 95% 50%, 100% 100%, 0 100%, 5% 50%); transform: rotate(-3deg); animation: stamp .45s .2s ease-out both;
}
.results-title { font: 400 1.6rem/1.1 var(--display); color: var(--yellow); text-shadow: 3px 3px 0 var(--pink); }
.results-sub { color: var(--muted); font-weight: 700; }
.score { margin: 8px 0 4px; font: 400 1.6rem/1 var(--display); color: var(--muted); }
.score b { font-size: 5rem; font-weight: 400; color: #fff; text-shadow: 4px 4px 0 var(--pink), 8px 8px 0 var(--teal); }
.rank { font: 400 1.3rem/1.2 var(--display); color: var(--teal); }
.rank-line { color: var(--muted); }
.cal { margin-top: 6px; padding: 8px 16px; border-radius: 999px; background: rgba(255, 255, 255, .08); font-weight: 700; }
.cal b { color: var(--yellow); }
.recap { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 10px 0 8px; }
.recap li {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: var(--ink);
  font-size: .75rem; font-weight: 800; animation: pop .3s ease-out both; animation-delay: calc(var(--i) * 70ms);
}
.recap .ok { background: var(--green); }
.recap .bad { background: var(--pink); }
.actions { display: grid; gap: 16px; width: min(100%, 420px); margin-top: 8px; }

.confetti { position: fixed; inset: 0; z-index: 20; overflow: hidden; pointer-events: none; }
.confetti span { position: absolute; top: -48px; font-weight: 700; text-shadow: 0 2px 0 rgba(0, 0, 0, .25); animation: fall 3s linear both; }

/* Lobe the mascot */
.lobe .bod { transform-origin: 84px 168px; animation: step 1.2s ease-in-out infinite; }
.lobe .shadow { fill: rgba(0, 0, 0, .3); transform-box: fill-box; transform-origin: center; animation: squash 1.2s ease-in-out infinite; }
.lobe:not(.is-idle) .shadow { animation: none; }
.lobe .arm { transition: transform .3s cubic-bezier(.3, 1.6, .5, 1); }
.lobe .arm-l { transform-origin: 46px 100px; }
.lobe .arm-r { transform-origin: 120px 100px; }
.lobe .eyes { transform-box: fill-box; transform-origin: center; animation: blink 4s infinite; }
.lobe .spark { opacity: 0; transition: opacity .2s; }
.lobe .spark path { transform-box: fill-box; transform-origin: center; }
.lobe :is(.eyes-happy, .eyes-dizzy, .m-grin, .m-wavy) { display: none; }
.lobe:is(.is-flex, .is-pumped) :is(.eyes, .m-smile),
.is-dizzy :is(.eyes, .m-smile) { display: none; }
.lobe:is(.is-flex, .is-pumped) :is(.eyes-happy, .m-grin),
.is-dizzy :is(.eyes-dizzy, .m-wavy) { display: inline; }
.lobe:is(.is-flex, .is-pumped) .spark { opacity: 1; }
.lobe:is(.is-flex, .is-pumped) .spark path { animation: twinkle .6s ease-in-out infinite alternate; }
.lobe:is(.is-flex, .is-pumped) .arm-l { transform: rotate(75deg); }
.lobe:is(.is-flex, .is-pumped) .arm-r { transform: rotate(-75deg); }
.is-flex .bod { animation: hop .45s ease-out 2; }
.is-pumped .bod { animation: hop .5s ease-in-out infinite; }
.is-pumped .arm-l { animation: pump-l .5s ease-in-out infinite alternate; }
.is-pumped .arm-r { animation: pump-r .5s ease-in-out infinite alternate; }
.is-dizzy .bod { animation: wobble 1s ease-in-out infinite; }
.is-dizzy .eyes-dizzy path { transform-box: fill-box; transform-origin: center; animation: spin 1.2s linear infinite; }

@keyframes step {
  25% { transform: translate(-4px, -6px) rotate(-3deg); }
  50% { transform: none; }
  75% { transform: translate(4px, -6px) rotate(3deg); }
}
@keyframes squash { 25%, 75% { transform: scaleX(.82); } }
@keyframes hop { 50% { transform: translateY(-10px); } }
@keyframes wobble { 25% { transform: rotate(-7deg); } 75% { transform: rotate(7deg); } }
@keyframes pump-l { from { transform: rotate(10deg); } to { transform: rotate(80deg); } }
@keyframes pump-r { from { transform: rotate(-10deg); } to { transform: rotate(-80deg); } }
@keyframes twinkle { from { transform: scale(.6); } to { transform: scale(1.15) rotate(25deg); } }
@keyframes blink { 0%, 93%, 100% { transform: none; } 96% { transform: scaleY(.1); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes eq { to { transform: scaleY(1); } }
@keyframes ring { from { transform: scale(.92); opacity: 1; } to { transform: scale(1.22); opacity: 0; } }
@keyframes glow { to { opacity: .5; } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
@keyframes pulse { 50% { transform: scale(1.05); } }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
@keyframes stamp { from { transform: rotate(-12deg) scale(.4); opacity: 0; } }
@keyframes fall { to { transform: translate(var(--x), calc(100vh + 96px)) rotate(var(--r)); } }

@media (max-width: 339px) {
  .answers { grid-template-columns: 1fr; }
}

@media (hover: hover) and (pointer: fine) {
  .keys-hint, .answer kbd { display: block; }
}

@media (min-width: 640px) {
  .app { gap: 18px; padding-top: calc(24px + env(safe-area-inset-top)); }
  .hero .lobe-wrap { width: 150px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .card { grid-template-columns: 1fr; align-content: start; gap: 10px; }
  .stage { gap: 16px; }
  .stage .lobe-wrap { width: 112px; }
  .chip { padding: 6px 12px; font-size: .8rem; }
  .play { width: 128px; height: 128px; }
  .coach { grid-template-columns: 1fr 230px; column-gap: 18px; }
  .coach > * { grid-column: 1; }
  .coach .kb { grid-column: 2; grid-row: 1 / span 3; align-self: center; }
  .results .lobe-wrap { width: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
