:root {
  --cream: #FFF4E3;
  --card: #FFFFFF;
  --line: #EBD9BF;
  --ink: #3B2416;
  --muted: #7A5A44;
  --brown: #A0582A;
  --brown-dk: #6E3615;
  --pink: #C93D63;
  --pink-dk: #8E2443;
  --green: #3E8E5A;
  --gold: #FFD166;
  --display: 'Baloo 2', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  --body: 'Nunito', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--cream); color: var(--ink); font-family: var(--body); font-weight: 700; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible { outline: 3px solid var(--pink); outline-offset: 2px; }
#app { height: 100%; position: relative; overflow: hidden; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column; gap: 14px; padding: calc(var(--st) + 10px) 18px calc(var(--sb) + 18px); overflow-y: auto; max-width: 560px; margin: 0 auto; }
.screen.active { display: flex; }
.screen.game { padding: 0; max-width: none; gap: 0; overflow: hidden; background: #6EA549; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; }
.topbar h2 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 24px; flex: 1; text-align: center; }
.topbar .spacer { width: 38px; }
.round-btn { width: 38px; height: 38px; border-radius: 50%; background: #fff; display: grid; place-items: center; box-shadow: 0 2px 0 rgba(0,0,0,.15); font-size: 26px; line-height: 1; flex: none; color: var(--ink); }
.round-btn .mute { display: none; }
.round-btn.muted .mute { display: inline; }
.round-btn.muted .waves { display: none; }

/* home */
.hero { text-align: center; display: grid; gap: 4px; }
.hero h1 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 54px; line-height: .95; color: #8A4B22; letter-spacing: -.5px; }
.hero h1 span { color: var(--pink); }
.hero p { margin: 0; color: var(--muted); }
.hero-art { position: relative; height: 150px; }
.hero-art span { position: absolute; bottom: 0; display: block; }
.hero-art .ha-dog { left: 2%; width: 62%; animation: trot .42s ease-in-out infinite; }
.hero-art .ha-hog { right: 2%; width: 40%; animation: trot .3s ease-in-out infinite; }
.hero-art svg { width: 100%; height: auto; display: block; }
@keyframes trot { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.big-btn { display: grid; gap: 2px; text-align: left; padding: 16px 20px; border-radius: 22px; color: #fff; box-shadow: 0 5px 0 var(--sh); transition: transform .08s; }
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--sh); }
.big-btn b { font-family: var(--display); font-weight: 800; font-size: 26px; line-height: 1.05; }
.big-btn small { font-size: 14px; opacity: .9; }
.big-btn.pink { background: var(--pink); --sh: var(--pink-dk); }
.big-btn.brown { background: var(--brown); --sh: var(--brown-dk); }
.link-btn { color: var(--muted); text-decoration: underline; padding: 6px; }
.version { text-align: center; color: var(--muted); font-size: 12px; margin: auto 0 0; opacity: .7; }

.challenge-card { background: #fff; border: 3px dashed var(--pink); border-radius: 20px; padding: 14px 16px; display: grid; gap: 8px; }
.challenge-card b { font-family: var(--display); font-size: 21px; line-height: 1.1; }
.challenge-card p { margin: 0; color: var(--muted); font-size: 14px; }
.challenge-card .row { display: flex; gap: 8px; }

/* tracks */
.track-list { display: grid; gap: 12px; }
.track { display: grid; grid-template-columns: 88px 1fr; gap: 14px; align-items: center; background: #fff; border-radius: 20px; padding: 10px; text-align: left; box-shadow: 0 3px 0 var(--line); }
.track canvas { width: 88px; height: 120px; border-radius: 12px; display: block; }
.track b { font-family: var(--display); font-weight: 800; font-size: 21px; display: block; line-height: 1.1; }
.track small { color: var(--muted); display: block; font-size: 13px; }
.track .loaves { display: flex; gap: 2px; margin-top: 4px; }
.track.locked { opacity: .55; }
.track.locked b::after { content: ' · locked'; color: var(--muted); font-size: 14px; }
.loaves svg { width: 22px; height: 22px; }

/* pick */
.pick-cards { display: grid; gap: 14px; }
.racer-card { background: #fff; border-radius: 22px; padding: 12px 14px 14px; display: grid; gap: 8px; text-align: left; box-shadow: 0 3px 0 var(--line); border: 4px solid transparent; }
.racer-card:active { border-color: var(--pink); }
.racer-card .art { background: #F6EBD8; border-radius: 14px; height: 112px; display: grid; place-items: center; }
.racer-card .art svg { height: 100px; width: auto; }
.racer-card .nm { display: flex; justify-content: space-between; align-items: baseline; }
.racer-card b { font-family: var(--display); font-weight: 800; font-size: 24px; }
.racer-card .kind { color: var(--muted); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.racer-card p { margin: 0; color: var(--muted); font-size: 14px; }
.stats { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.stat { display: grid; grid-template-columns: 54px 1fr; gap: 8px; align-items: center; }
.bar { height: 8px; border-radius: 99px; background: #F2E4CC; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--c, var(--pink)); }

/* game */
#cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.hud { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding-left: 12px; padding-right: 12px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud.top { top: 0; padding-top: calc(var(--st) + 4px); padding-bottom: 4px; background: rgba(42,26,16,.72); color: #fff; min-height: calc(var(--st) + 44px); }
.hud.bottom { bottom: 0; padding-bottom: calc(var(--sb) + 6px); padding-top: 6px; background: rgba(42,26,16,.72); color: #fff; min-height: calc(var(--sb) + 50px); justify-content: space-between; }
.hud .round-btn { width: 34px; height: 34px; font-size: 24px; }
.hud-msg { flex: 1; min-width: 0; display: grid; }
.hud-msg b { font-family: var(--display); font-weight: 800; font-size: 17px; line-height: 1.05; }
.hud-msg small { font-size: 11px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-right { text-align: right; font-variant-numeric: tabular-nums; display: grid; }
.hud-right b { font-family: var(--display); font-weight: 800; font-size: 21px; line-height: 1; }
.hud-right small { font-size: 12px; opacity: .85; }
.actions { display: flex; gap: 8px; }
.pill-btn { background: rgba(255,255,255,.18); color: #fff; padding: 8px 14px; border-radius: 99px; font-weight: 800; font-size: 15px; min-width: 44px; }
.pill-btn.go { background: var(--pink); font-family: var(--display); font-size: 20px; padding: 4px 24px; box-shadow: 0 3px 0 var(--pink-dk); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.meters { display: flex; gap: 12px; align-items: center; }
.meter { display: grid; gap: 2px; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; opacity: .95; }
.meter .pips { display: flex; gap: 3px; }
.meter .pips span { width: 22px; height: 14px; display: grid; place-items: center; opacity: .3; }
.meter .pips span.on { opacity: 1; }
.meter svg { width: 22px; height: 14px; }
#countdown { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 120px; color: #fff; text-shadow: 0 6px 0 var(--pink-dk); pointer-events: none; }
#countdown span { animation: count .6s ease-out both; }
@keyframes count { from { transform: scale(1.8); opacity: 0; } 40% { opacity: 1; } to { transform: scale(1); opacity: 1; } }

/* modal */
.modal { position: absolute; inset: 0; background: rgba(42,26,16,.45); display: grid; align-items: end; z-index: 30; }
.modal[hidden] { display: none; }
.sheet { background: var(--cream); border-radius: 28px 28px 0 0; padding: 22px 20px calc(var(--sb) + 20px); display: grid; gap: 12px; max-height: 92%; overflow-y: auto; max-width: 560px; width: 100%; margin: 0 auto; animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 40px; line-height: 1; text-align: center; color: var(--pink); }
.sheet h3 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 22px; }
.sheet p { margin: 0; color: var(--muted); text-align: center; }
.sheet .loaves { display: flex; justify-content: center; gap: 6px; }
.sheet .loaves svg { width: 46px; height: 46px; }
.results { display: grid; gap: 6px; }
.res { display: grid; grid-template-columns: 28px 52px 1fr auto; gap: 8px; align-items: center; background: #fff; border-radius: 14px; padding: 6px 12px; }
.res.me { outline: 3px solid var(--pink); }
.res .pos { font-family: var(--display); font-size: 20px; }
.res .face svg { width: 52px; height: 32px; display: block; }
.res .tm { font-family: var(--display); font-size: 18px; font-variant-numeric: tabular-nums; }
.res small { display: block; color: var(--muted); font-size: 12px; }
.targets { display: flex; justify-content: center; gap: 14px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { padding: 14px; border-radius: 18px; font-family: var(--display); font-weight: 800; font-size: 18px; background: #fff; box-shadow: 0 3px 0 var(--line); }
.btn.pink { background: var(--pink); color: #fff; box-shadow: 0 3px 0 var(--pink-dk); }
.btn.brown { background: var(--brown); color: #fff; box-shadow: 0 3px 0 var(--brown-dk); }
.btn.wide { grid-column: 1 / -1; }
.name-row { display: flex; gap: 8px; }
.name-row input { flex: 1; min-width: 0; font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); background: #fff; color: var(--ink); }
.how { display: grid; gap: 10px; }
.how li { color: var(--ink); margin-bottom: 6px; }
.how ul { margin: 0; padding-left: 20px; }
.legend { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; font-size: 13px; }
.legend i { display: inline-block; width: 22px; height: 6px; border-radius: 3px; vertical-align: middle; margin-right: 4px; }

#toast { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--sb) + 66px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 14px; z-index: 40; max-width: 88%; text-align: center; }

/* ---------- celebrations ---------- */
#fx { position: absolute; inset: 0; pointer-events: none; z-index: 25; overflow: hidden; }
.super-pop { position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 2px; animation: popIn 1.9s ease-out forwards; }
.super-pop b { font-family: var(--display); font-weight: 800; font-size: 34px; color: #fff; text-shadow: 0 3px 0 var(--pink-dk), 0 0 12px rgba(0,0,0,.25); white-space: nowrap; }
.super-pop small { color: #fff; font-size: 14px; text-shadow: 0 2px 0 rgba(0,0,0,.35); }
.sp-art { width: 92px; height: 82px; display: grid; place-items: center; }
.sp-art svg { width: 100%; height: 100%; }
@keyframes popIn { 0% { transform: translate(-50%, -50%) scale(.3); opacity: 0; } 14% { transform: translate(-50%, -50%) scale(1.12); opacity: 1; } 24% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { transform: translate(-50%, -62%) scale(1); opacity: 0; } }
.sp-wiggle .sp-art { animation: wig .4s ease-in-out 3; }
.sp-spin .sp-art { animation: spin .8s ease-in-out; }
.sp-roll .sp-art { animation: roll 1s ease-out; }
.sp-hotdog .sp-art { animation: wig .25s ease-in-out 5; }
.sp-rise .sp-art { animation: rise .9s ease-out; }
.sp-long .sp-art { width: 170px; animation: grow 1s ease-out; }
.sp-sizzle .sp-art { width: 120px; animation: wig .2s ease-in-out 6; }
.cr-wrap { display: flex; gap: 6px; }
.cr { width: 44px; display: block; }
.cr.a1 { animation: wig .4s ease-in-out 3; }
.cr.a2 { animation: wig .4s ease-in-out .2s 3; }
@keyframes wig { 25% { transform: rotate(-10deg); } 75% { transform: rotate(10deg); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes roll { from { transform: translateX(-80px) rotate(-360deg); } }
@keyframes rise { from { transform: translateY(30px) scale(.7); } }
@keyframes grow { from { transform: scaleX(.4); } }
.crumb { position: absolute; border-radius: 40%; animation: crumb .9s ease-out forwards; }
.crumb.sausage { background: #B4512B; border-radius: 99px; }
@keyframes crumb { to { transform: translate(var(--dx), var(--dy)) rotate(200deg); opacity: 0; } }
.zoomies { position: absolute; top: 46%; left: 0; right: 0; height: 90px; }
.zoomies .zr { position: absolute; width: 150px; animation: zoom 1.8s linear forwards; }
.zoomies .zr svg { width: 100%; height: auto; animation: trot .18s ease-in-out infinite; }
.zoomies .zp { position: absolute; inset: 0; }
@keyframes zoom { from { left: -170px; } to { left: 110%; } }
.say { position: absolute; left: 50%; top: calc(var(--st) + 58px); transform: translateX(-50%); background: #fff; color: var(--ink); padding: 8px 14px 8px 8px; border-radius: 16px; display: flex; align-items: center; gap: 8px; font-size: 15px; box-shadow: 0 3px 0 rgba(0,0,0,.15); white-space: nowrap; animation: sayIn 1.5s ease-out forwards; }
.say.info { padding-left: 14px; }
.say-art { width: 30px; height: 30px; display: block; }
.say-art svg { width: 100%; height: 100%; }
@keyframes sayIn { 0% { opacity: 0; transform: translate(-50%, -8px); } 12%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }
.finale { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 4px; animation: popIn 2.3s ease-out forwards; }
.finale b { font-family: var(--display); font-weight: 800; font-size: 40px; color: #fff; text-shadow: 0 4px 0 var(--pink-dk); white-space: nowrap; }
.finale small { color: #fff; font-size: 16px; text-shadow: 0 2px 0 rgba(0,0,0,.35); }
.fin-art { width: 140px; height: 140px; }
.fin-art svg { width: 100%; height: 100%; }
.finale.golden .fin-art { animation: spin 1.2s ease-out; }
.toast-up { animation: toastUp .7s cubic-bezier(.2,1.6,.4,1) .2s both; }
@keyframes toastUp { from { transform: translateY(40px); } }
.breadcrumb { position: absolute; top: -30px; width: 12px; height: 9px; border-radius: 40%; background: #E3A24C; animation: fall var(--dur, 1.8s) cubic-bezier(.45,.05,.55,.95) forwards; }
.breadcrumb.sausage { width: 22px; height: 9px; border-radius: 99px; background: #B4512B; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
@media (prefers-reduced-motion: reduce) {
  .hero-art span, .pill-btn.go, .zoomies .zr svg { animation: none; }
}
