:root {
  --ink: #2a2140; --ink2: #6b5f86; --panel: #fffdf6; --line: #f0e6cf;
  --green: #3fc24a; --green-d: #279332; --orange: #ff9f1c; --orange-d: #d9780a; --red: #ff4f6a;
  --gold: #ffc21a; --sky: #62b9ff;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Quicksand", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #62b9ff; color: var(--ink); font-family: var(--font);
  -webkit-user-select: none; user-select: none; touch-action: none; overscroll-behavior: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: fixed; inset: 0; touch-action: none; }
svg { display: block; }

/* ---------- HUD ---------- */
.hud { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .25s; }
.hud.on { opacity: 1; }
.hud-top { position: absolute; top: calc(10px + var(--safe-t)); left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r));
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.hud-left, .hud-right { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.hud-right { align-items: flex-end; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: rgba(255, 253, 246, .92); border-radius: 999px;
  padding: 5px 12px 5px 8px; box-shadow: 0 3px 0 rgba(42, 33, 64, .12), 0 6px 16px rgba(42, 33, 64, .12); font-weight: 800; font-size: 17px; }
.chip svg { width: 22px; height: 22px; flex: none; }
.hearts { display: flex; gap: 3px; }
.heart svg { width: 30px; height: 30px; fill: var(--red); stroke: #fff; stroke-width: 2.2px; paint-order: stroke;
  filter: drop-shadow(0 2px 0 rgba(42, 33, 64, .18)); }
.heart.lost svg { fill: rgba(42, 33, 64, .22); stroke: rgba(255, 255, 255, .7); }
.hearts.bump .heart.lost:first-of-type { animation: bump .5s; }
.suns { display: flex; gap: 2px; padding-left: 2px; }
/* power-up timers: a ring (conic) that empties with --p, blinking in the last 1.5 s */
.powers { display: flex; gap: 6px; padding-left: 2px; margin-top: 4px; }
.pw { display: none; width: 38px; height: 38px; border-radius: 50%; position: relative; --p: 1;
  background: conic-gradient(#fff calc(var(--p) * 360deg), rgba(255,255,255,.18) 0); box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.pw.on { display: block; animation: pwIn .3s ease-out; }
.pw::before { content: ''; position: absolute; inset: 4px; border-radius: 50%; background: rgba(30,24,48,.85); }
.pw svg { position: absolute; inset: 8px; width: 22px; height: 22px; }
.pw-shield { background: #4aa8ff; }
.pw.ending { animation: pwBlink .25s steps(2) infinite; }
@keyframes pwIn { from { transform: scale(.3); } to { transform: scale(1); } }
@keyframes pwBlink { 50% { opacity: .35; } }
.sun svg { width: 20px; height: 20px; opacity: .3; filter: grayscale(1); }
.sun.got svg { opacity: 1; filter: drop-shadow(0 0 4px rgba(255, 190, 0, .8)); }
.goal { position: relative; flex-direction: row; min-width: 120px; justify-content: center; padding: 6px 16px 9px 10px; }
.goal-icon svg { width: 26px; height: 26px; }
.goal-text { font-size: 19px; white-space: nowrap; }
.goal-bar { position: absolute; left: 14px; right: 14px; bottom: 4px; height: 4px; border-radius: 4px; background: rgba(42, 33, 64, .1); overflow: hidden; }
.goal-bar i { display: block; height: 100%; background: linear-gradient(90deg, #6fe05a, #3fc24a); transform-origin: left; transform: scaleX(0); transition: transform .3s; }
.goal.pop { animation: pop .35s; }
/* stage 04b: second goal line (rival, followers, wave), boss health chip, Granny Moss hearts */
.goal-sub { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 5px; white-space: nowrap;
  font-size: 13px; font-weight: 800; color: #fff; background: rgba(42, 33, 64, .62); border-radius: 999px; padding: 2px 10px; }
.goal.boss .goal-bar { height: 6px; bottom: 3px; background: rgba(42, 33, 64, .18); }
.goal.boss .goal-bar i { background: linear-gradient(90deg, #ff4d6d, #ff8a3d); }
.goal.boss .goal-text { color: #b0283f; }
.goal.hit { animation: bossHit .45s; }
@keyframes bossHit { 15% { transform: translateX(-6px) scale(1.06); } 35% { transform: translateX(6px); } 55% { transform: translateX(-3px); } }
.granny-hearts { display: flex; align-items: center; gap: 2px; background: rgba(255, 253, 246, .88); border-radius: 999px;
  padding: 2px 8px 2px 4px; align-self: flex-start; box-shadow: 0 2px 0 rgba(42, 33, 64, .12); }
.granny-hearts > svg { width: 26px; height: 26px; margin-right: 2px; }
.granny-hearts .gh svg { width: 18px; height: 18px; fill: #4fbf5a; stroke: #fff; stroke-width: 2px; paint-order: stroke; }
.granny-hearts .gh.lost svg { fill: rgba(42, 33, 64, .22); }
.granny-hearts.wait { animation: pwBlink .6s steps(2) 3; }
.granny-hearts.bump { animation: bump .5s; }
.timer b { font-variant-numeric: tabular-nums; }
.timer small { color: var(--ink2); font-weight: 700; font-size: 13px; }
.timer.over b { color: #e0671f; }
.timer svg { width: 18px; height: 18px; color: var(--ink2); }
.coins b { min-width: 1.5em; font-variant-numeric: tabular-nums; }
.boost-meter { position: absolute; left: 50%; bottom: calc(18px + var(--safe-b)); width: 160px; height: 12px; margin-left: -80px; border-radius: 10px;
  background: rgba(42, 33, 64, .25); border: 2px solid rgba(255, 255, 255, .85); overflow: hidden; }
.boost-meter i { display: block; height: 100%; background: linear-gradient(90deg, #ffd23a, #ff9f1c); transform-origin: left; }
.boost-meter.active i { background: linear-gradient(90deg, #fff07a, #ffb020); box-shadow: 0 0 10px #ffd23a; }
.pause-btn { position: absolute; pointer-events: auto; right: calc(12px + var(--safe-r)); bottom: calc(14px + var(--safe-b)); width: 44px; height: 44px;
  border: 0; border-radius: 50%; background: rgba(255, 253, 246, .9); color: var(--ink); box-shadow: 0 3px 0 rgba(42, 33, 64, .15); cursor: pointer; padding: 11px; }
.pause-btn svg { fill: currentColor; width: 22px; height: 22px; }
.combo { position: absolute; top: 24%; left: 0; right: 0; text-align: center; font-size: 34px; font-weight: 900; color: #fff;
  -webkit-text-stroke: 7px var(--orange-d); paint-order: stroke fill; opacity: 0; transform: scale(.5); }
.combo.on { animation: combo 1s forwards; }
.combo[data-n="4"], .combo[data-n="5"] { -webkit-text-stroke-color: #d42a6b; }
.toast { position: absolute; top: calc(72px + var(--safe-t)); left: 50%; transform: translate(-50%, -12px); max-width: calc(100% - 32px);
  background: var(--ink); color: #fff; padding: 9px 18px; border-radius: 16px; font-weight: 800; font-size: 16px; text-align: center;
  display: flex; align-items: center; gap: 8px; opacity: 0; transition: opacity .2s, transform .2s; box-shadow: 0 6px 18px rgba(42, 33, 64, .3); }
.toast svg { width: 22px; height: 22px; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.float { position: absolute; left: 0; top: 0; font-weight: 900; font-size: 20px; color: #fff; -webkit-text-stroke: 5px rgba(42, 33, 64, .75);
  paint-order: stroke fill; white-space: nowrap; opacity: 0; display: flex; align-items: center; gap: 2px; will-change: transform; }
.float svg { width: 20px; height: 20px; }
.float.combo { color: #fff27a; }
.float.coin { color: #ffd84a; }
.float.bad { color: #ff8a9c; }
.float.gem { color: #8ff3ff; }
.flash { position: absolute; inset: 0; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, var(--c, rgba(255, 40, 60, .35)) 100%); }
.flash.on { animation: flash .45s; }

/* ---------- touch controls ---------- */
.stick { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; opacity: 0; transition: opacity .12s; }
.stick.on { opacity: 1; }
.stick::before { content: ""; position: absolute; left: -48px; top: -48px; width: 96px; height: 96px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .4); background: rgba(255, 255, 255, .12); }
.stick-knob { position: absolute; left: -22px; top: -22px; width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 255, 255, .55);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15); }
.boost-btn { position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(76px + var(--safe-b)); width: 76px; height: 76px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .9); background: rgba(255, 159, 28, .55); color: #fff; padding: 18px; overflow: hidden; touch-action: none; cursor: pointer; }
.boost-btn svg { position: relative; z-index: 1; width: 100%; height: 100%; }
.boost-fill { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--fill, 1) * 100%); background: rgba(255, 159, 28, .75); }
.boost-btn.on { transform: scale(.94); background: rgba(255, 200, 60, .75); }
#ui:not(.playing) .boost-btn, #ui:not(.playing) .stick { display: none; }
#ui:has(.screens.on) .boost-btn, #ui:has(.screens.on) .stick, #ui:has(.screens.on) .pause-btn,
#ui:has(.screens.on:not(.intro-screen)) .boost-meter { display: none; }

/* ---------- screens ---------- */
.screens { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; padding: 16px; pointer-events: none; }
.screens.on { display: flex; }
.screens.on:not(.intro-screen) { background: radial-gradient(ellipse at center, rgba(42, 33, 64, .05), rgba(42, 33, 64, .35)); pointer-events: auto; }
.title-screen.on { background: linear-gradient(180deg, rgba(98, 185, 255, .15), rgba(42, 33, 64, .25)) !important; }
.panel { pointer-events: auto; background: var(--panel); border-radius: 28px; padding: 22px 24px 24px; width: min(420px, 100%); text-align: center;
  box-shadow: 0 8px 0 var(--line), 0 18px 40px rgba(42, 33, 64, .3); animation: panelIn .35s cubic-bezier(.2, 1.4, .4, 1); }
.panel h2 { margin: 2px 0 10px; font-size: 30px; font-weight: 900; letter-spacing: -.01em; }
.panel .lvl { font-weight: 800; color: var(--ink2); font-size: 14px; text-transform: uppercase; letter-spacing: .08em; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.col { display: flex; flex-direction: column; gap: 10px; align-items: stretch; margin-top: 8px; }
.btn { font: inherit; font-weight: 900; font-size: 19px; border: 0; border-radius: 18px; padding: 13px 24px; cursor: pointer; color: var(--ink);
  background: #fff; box-shadow: 0 5px 0 #e2d6bb, 0 8px 16px rgba(42, 33, 64, .12); transition: transform .08s; min-width: 120px; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #e2d6bb; }
.btn.primary { background: var(--green); color: #fff; box-shadow: 0 5px 0 var(--green-d), 0 8px 16px rgba(39, 147, 50, .3); text-shadow: 0 2px 0 rgba(0, 0, 0, .15); }
.btn.primary:active { box-shadow: 0 2px 0 var(--green-d); }
.btn.big { font-size: 24px; padding: 15px 38px; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--ink2); min-width: 0; }

/* title */
.panel.title { background: transparent; box-shadow: none; width: min(560px, 100%); }
.logo { margin: 0; font-size: clamp(48px, 13vw, 92px); font-weight: 900; line-height: 1; letter-spacing: -.02em; }
.logo span { display: inline-block; color: #fff; -webkit-text-stroke: 9px var(--ink); paint-order: stroke fill;
  text-shadow: 0 7px 0 var(--ink); animation: wiggle 2.4s ease-in-out infinite; animation-delay: calc(var(--i) * -.12s); }
.logo span:nth-child(4n+1) { color: #7ce35b; } .logo span:nth-child(4n+2) { color: #ffd23a; }
.logo span:nth-child(4n+3) { color: #ff8fb1; } .logo span:nth-child(4n) { color: #7cd3ff; }
.logo .word { display: inline-block; white-space: nowrap; font-weight: inherit; margin: 0 .12em; }
.sub { margin: 14px 0 0; font-weight: 900; font-size: 20px; color: #fff; -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; }
.studio { margin-top: 18px; font-weight: 800; color: #fff; opacity: .9; font-size: 14px; text-shadow: 0 1px 3px rgba(0, 0, 0, .35); }

/* intro card */
.intro-screen { align-items: flex-end; padding-bottom: calc(28px + var(--safe-b)); }
.panel.intro { width: min(440px, 100%); }
.goal-line { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 900; font-size: 20px; margin: 8px 0 4px;
  background: #fff4d6; border-radius: 16px; padding: 10px 14px; }
.goal-line svg { width: 30px; height: 30px; flex: none; }
.tip { color: var(--ink2); font-weight: 700; font-size: 16px; margin: 10px 0 6px; line-height: 1.35; }
.go { margin: 12px 0 0; font-weight: 900; color: var(--green-d); animation: pulse 1.2s ease-in-out infinite; }

/* stars */
.stars { display: flex; justify-content: center; gap: 6px; margin: 2px 0 6px; }
.star svg { width: 28px; height: 28px; fill: #e6dcc4; }
.star.got svg { fill: var(--gold); stroke: #e09a00; stroke-width: 1.2px; }
.stars.big .star svg { width: 64px; height: 64px; }
.stars.big .star:nth-child(2) svg { width: 78px; height: 78px; margin-top: -10px; }
.stars.big .star.got { animation: stamp .45s cubic-bezier(.3, 1.6, .5, 1) both; animation-delay: var(--d); }
.stats { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.stats li { display: flex; align-items: baseline; gap: 8px; background: #fff7e4; border-radius: 12px; padding: 8px 14px; font-weight: 800; }
.stats li span { color: var(--ink2); flex: 1; text-align: left; }
.stats li b { font-size: 19px; }
.stats li b.good { color: var(--green-d); }
.stats li small { color: var(--ink2); }
.hint { color: var(--ink2); font-weight: 700; margin: 12px 0 0; font-size: 15px; }

@keyframes panelIn { from { transform: scale(.85) translateY(20px); opacity: 0; } }
@keyframes wiggle { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-8px) rotate(3deg); } }
@keyframes pulse { 50% { opacity: .55; transform: scale(.97); } }
@keyframes stamp { from { transform: scale(2.4) rotate(-20deg); opacity: 0; } }
@keyframes pop { 40% { transform: scale(1.12); } }
@keyframes bump { 30% { transform: scale(1.5) rotate(-10deg); } }
@keyframes combo { 0% { opacity: 0; transform: scale(.4) rotate(-6deg); } 15% { opacity: 1; transform: scale(1.15) rotate(2deg); }
  30% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-20px); } }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

@media (max-width: 480px) {
  .chip { font-size: 15px; padding: 4px 10px 4px 7px; }
  .chip svg { width: 19px; height: 19px; }
  .heart svg { width: 25px; height: 25px; }
  .goal { min-width: 96px; padding: 5px 12px 8px 8px; }
  .goal-text { font-size: 16px; }
  .goal-icon svg { width: 22px; height: 22px; }
  .goal-sub { font-size: 12px; }
  .timer small { display: none; }
  .toast { top: calc(96px + var(--safe-t)); font-size: 15px; }
  .boost-meter { width: 120px; margin-left: -60px; }
  .panel h2 { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) { .logo span, .go { animation: none; } }
