* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

@keyframes bubbleRise {
    0% { transform: translateY(0) translateX(0) scale(var(--bub-s)); opacity: 0; }
    10% { opacity: var(--bub-o); }
    85% { opacity: var(--bub-o); }
    100% { transform: translateY(calc(-100vh - 40px)) translateX(calc(var(--bub-drift) * 1px)) scale(var(--bub-s)); opacity: 0; }
}
@keyframes countPop {
    0% { transform: scale(2.2) rotate(-6deg); opacity: 0; text-shadow: 0 0 0 transparent; }
    30% { opacity: 1; }
    50% { transform: scale(1) rotate(1deg); text-shadow: 0 6px 0 rgba(0,0,0,0.7), 0 12px 0 rgba(0,0,0,0.4), 0 18px 0 rgba(0,0,0,0.15), 0 0 60px var(--marigold-glow); }
    100% { transform: scale(0.7) rotate(0deg); opacity: 0; text-shadow: 0 4px 0 rgba(0,0,0,0.5), 0 0 40px var(--marigold-glow); }
}
@keyframes waterShimmer {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

:root {
    --deep-mid: #112240;
    --deep-surface: rgba(12,24,42,0.92);
    --bark: #D8CCBA;
    --bark-dark: #2A1A0E;
    --sage: #4CC870;
    --sage-dark: #38A058;
    --sage-glow: rgba(76,200,112,0.3);
    --marigold: #F0A830;
    --marigold-glow: rgba(240,168,48,0.4);
    --marigold-dark: #B88018;
    --blush: #FF6850;
    --sand: #1E3048;
    --paper: rgba(10,22,40,0.90);
    --paper-border: rgba(240,168,48,0.18);
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-soft: cubic-bezier(0.25, 0.1, 0.25, 1);
}
html, body { width: 100%; height: 100%; overflow: hidden;
    background: var(--deep);
    font-family: var(--font-body); color: var(--bark); user-select: none; }
canvas { display: block; position: fixed; inset: 0; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; z-index: 20; gap: 18px; }
.screen.hidden { display: none; }
#bg-dim { position: fixed; inset: 0; z-index: 18; pointer-events: none; display: none;
    background:
        radial-gradient(ellipse 140% 80% at 50% 115%, rgba(5,12,25,0.95), transparent 65%),
        radial-gradient(ellipse 60% 80% at -5% 50%, rgba(5,12,25,0.88), transparent 55%),
        radial-gradient(ellipse 60% 80% at 105% 50%, rgba(5,12,25,0.75), transparent 55%),
        radial-gradient(ellipse 80% 60% at 50% 50%, transparent 25%, rgba(5,12,25,0.5) 100%),
        linear-gradient(180deg, rgba(10,22,40,0.55) 0%, rgba(10,22,40,0.1) 35%, rgba(10,22,40,0.7) 100%); }
#bg-dim.on { display: block; }
#bg-dim::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 80px; pointer-events: none;
    background: linear-gradient(180deg, transparent,
        rgba(88,184,232,0.03) 30%,
        rgba(88,184,232,0.06) 60%,
        rgba(88,184,232,0.04) 100%);
    background-size: 200% 100%;
    animation: waterShimmer 6s linear infinite; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: center; }

#screen-menu { justify-content: flex-start; align-items: flex-start; padding: 0; gap: 0; }

#nametags { position: fixed; inset: 0; z-index: 9; pointer-events: none; overflow: hidden; }
.nametag { position: absolute; transform: translate(-50%, -100%); white-space: nowrap;
    font-family: var(--font-body); font-weight: 700; font-size: 13px; padding: 2px 9px; border-radius: 10px;
    background: var(--paper); color: var(--cream); border: 1px solid var(--paper-border);
    text-shadow: none; box-shadow: 0 2px 8px rgba(0,0,0,0.5); will-change: left, top; }
.nametag.you { color: var(--bark-dark); background: var(--marigold);
    border-color: var(--marigold-dark); font-size: 14px;
    box-shadow: 0 2px 10px var(--marigold-glow); }
#countdown { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
    z-index: 15; font-family: var(--font-head); font-size: clamp(90px,25vw,220px); font-weight: 700; color: var(--cream);
    pointer-events: none; opacity: 0;
    -webkit-text-stroke: 2px rgba(184,128,24,0.4); }

#toast { position: fixed; top: 22%; left: 50%; transform: translateX(-50%); z-index: 16;
    font-family: var(--font-head); font-size: clamp(22px,6vw,40px); font-weight: 700; opacity: 0; pointer-events: none;
    text-shadow: 0 3px 0 rgba(0,0,0,0.8), 0 6px 0 rgba(0,0,0,0.4), 0 0 30px var(--marigold-glow);
    white-space: nowrap; color: var(--cream);
    padding: 8px 24px; border-radius: 6px;
    background: linear-gradient(135deg, rgba(42,26,14,0.85), rgba(30,18,8,0.75));
    border: 2px solid rgba(200,152,48,0.3); }
#wrongway { position: fixed; top: 38%; left: 50%; transform: translateX(-50%); z-index: 16;
    font-family: var(--font-head); font-size: clamp(16px,4.5vw,28px); font-weight: 700; color: var(--blush); opacity: 0;
    pointer-events: none; transition: opacity .2s;
    text-shadow: 0 2px 0 rgba(0,0,0,0.7), 0 0 20px rgba(255,104,80,0.5);
    white-space: nowrap; animation: wwblink 0.7s steps(2) infinite;
    padding: 6px 20px; border-radius: 6px;
    background: linear-gradient(135deg, rgba(80,20,10,0.85), rgba(60,15,8,0.75));
    border: 2px solid rgba(255,104,80,0.4); }
@keyframes wwblink { 50% { color: var(--marigold); } }

#touch { position: fixed; inset: 0; z-index: 13; display: none; pointer-events: none; touch-action: none; }
#touch.on { display: block; }
.tbtn { position: absolute; pointer-events: auto; touch-action: none; -webkit-user-select: none; user-select: none;
    display: flex; flex-direction: column; gap: 2px; align-items: center; justify-content: center;
    border-radius: 50%; background: linear-gradient(135deg, rgba(42,26,14,0.85), rgba(30,18,8,0.75));
    border: 3px solid rgba(200,152,48,0.35);
    color: var(--cream); font-weight: 700; backdrop-filter: blur(4px);
    box-shadow: 0 4px 14px rgba(0,0,0,0.5), inset 0 1px 0 rgba(240,168,48,0.08);
    transition: transform .06s, background .06s; }
.tbtn .ic { font-size: 1.6em; line-height: 1; pointer-events: none; }
.tbtn .ic img { width: 100%; height: 100%; object-fit: contain; }
.tbtn .tx { font-family: var(--font-body); font-size: 0.62em; letter-spacing: 1px; pointer-events: none;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5); }
.tbtn:active, .tbtn.hold { transform: scale(0.92); border-color: var(--marigold);
    box-shadow: 0 0 16px var(--marigold-glow), 0 4px 14px rgba(0,0,0,0.5); }
#t-left, #t-right { width: 88px; height: 88px; bottom: calc(28px + env(safe-area-inset-bottom,0px)); font-size: 34px; }
#t-left  { left: 22px; }
#t-right { left: 122px; }
#t-gas   { width: 110px; height: 110px; right: 24px; bottom: calc(40px + env(safe-area-inset-bottom,0px)); font-size: 17px;
    background: linear-gradient(135deg, rgba(40,80,50,0.8), rgba(30,60,38,0.7)); border-color: rgba(76,200,112,0.5); }
#t-brake { width: 80px; height: 80px; right: 144px; bottom: calc(34px + env(safe-area-inset-bottom,0px)); font-size: 15px;
    background: linear-gradient(135deg, rgba(80,30,20,0.8), rgba(60,20,15,0.7)); border-color: rgba(255,104,80,0.5); }
#t-jump  { width: 86px; height: 86px; right: 40px; bottom: calc(170px + env(safe-area-inset-bottom,0px)); font-size: 16px;
    background: linear-gradient(135deg, rgba(80,55,20,0.8), rgba(60,42,15,0.7)); border-color: rgba(240,168,48,0.5); }

.bubble-particle { position: fixed; border-radius: 50%; pointer-events: none; z-index: 19;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.2), rgba(88,184,232,0.08));
    border: 1px solid rgba(88,184,232,0.12);
    animation: bubbleRise var(--bub-dur) ease-in infinite;
    animation-delay: var(--bub-delay); }
.credit { position: fixed; bottom: 8px; right: 12px; font-size: 11px; opacity: .35; z-index: 8; pointer-events: none; }
.hide { display: none !important; }
