*{box-sizing:border-box}html,body{margin:0;width:100%;height:100%;overflow:hidden;overscroll-behavior:none;background:#202c28;font-family:system-ui,-apple-system,Segoe UI,sans-serif;user-select:none;-webkit-user-select:none;touch-action:manipulation}body{display:grid;place-items:center}#game{position:relative;width:min(100vw,calc(100vh * 420 / 840));height:min(100vh,calc(100vw * 840 / 420));width:min(100vw,calc(100dvh * 420 / 840));height:min(100dvh,calc(100vw * 840 / 420));overflow:hidden;background:#92c56a;box-shadow:0 0 55px #0008;container-type:size}canvas{width:100%;height:100%;display:block;touch-action:none}header{position:absolute;top:1.2%;left:3%;right:3%;height:9%;display:flex;align-items:center;gap:2%;justify-content:space-between;pointer-events:none}header img{width:36%;max-height:100%;object-fit:contain;filter:drop-shadow(0 2px 1px #0005)}.level{font-size:4.4cqw;font-weight:1000;color:white;text-shadow:0 2px #315125;background:linear-gradient(#588a35,#346b27);border:2px solid #b8dc86;padding:2% 4%;border-radius:18px;box-shadow:0 3px #294d25}button{font:inherit;cursor:pointer;color:#fff;border:2px solid #fff9;background:linear-gradient(#7e65d6,#54369d);font-weight:850;box-shadow:0 3px #342365,0 4px 6px #0003;border-radius:13px;pointer-events:auto;-webkit-tap-highlight-color:transparent}button:active{transform:translateY(2px);box-shadow:0 1px #342365}button:disabled{opacity:.5;cursor:default}#settings{width:12%;aspect-ratio:1;font-size:6cqw}footer{position:absolute;bottom:.7%;left:5%;right:5%;height:4.9%;display:flex;gap:3%;justify-content:center}footer button{flex:1;font-size:4.9cqw}footer span{font-size:3.7cqw}#toast{position:absolute;left:5%;right:5%;top:42%;text-align:center;pointer-events:none;opacity:0;transition:opacity .15s;font-size:4.4cqw;font-weight:900;color:white;text-shadow:0 2px #302b3f;background:#342b55e8;padding:2%;border-radius:14px;z-index:5}#toast.show{opacity:1}#overlay{position:absolute;inset:0;background:#1b143c99;display:grid;place-items:center;z-index:10}#overlay[hidden]{display:none}#overlay section{width:85%;background:linear-gradient(#fff,#eee7ff);padding:6%;border-radius:25px;text-align:center;border:4px solid #bba5f0;box-shadow:0 8px #402d77,0 12px 30px #0005;color:#30234b}h1{font-size:8cqw;margin:0 0 3%;line-height:1.1}p{font-size:4.2cqw;margin:3% 0 6%}#dialogActions{display:grid;gap:10px}#dialogActions button{padding:4%;font-size:4.5cqw}button:focus-visible{outline:3px solid #ffd32a;outline-offset:2px}
@media (max-aspect-ratio: 3/4){#game{width:100vw;height:100vh;height:100dvh;box-shadow:none}}

/* R4: separate front end, preserving R3's scene proportions and vehicle layout. */
.screen{position:absolute;inset:0;z-index:7;display:flex;flex-direction:column;background:linear-gradient(180deg,#f5ffe0e8 0%,#a5d57524 37%,#25334cc9 69%,#261a4c 100%);overflow:hidden;color:#fff}
.screen[hidden], [hidden]{display:none!important}
.home-top{display:flex;justify-content:flex-end;padding:4% 5% 0;height:9%;flex-shrink:0}.home-top button{width:12%;aspect-ratio:1;font-size:6cqw}
.hero-logo{width:92%;height:26%;object-fit:contain;margin:0 auto;filter:drop-shadow(0 5px 4px #23163f45);animation:logoIn .45s cubic-bezier(.2,.7,.2,1) both}
.home-content{margin-top:auto;padding:0 6% max(3%,env(safe-area-inset-bottom));display:flex;flex-direction:column;gap:3cqw}
.home-panel{padding:5% 6%;border:2px solid #ffffffb0;border-radius:24px;background:linear-gradient(145deg,#fff,#f0e8ff);color:#33234f;text-align:center;box-shadow:0 6px #442e79,0 10px 24px #0004}
.eyebrow{font-weight:900;font-size:2.8cqw;letter-spacing:.14em;color:#806aa2}.home-panel h1{font-size:8.5cqw;margin:1% 0 3%;letter-spacing:-.04em}.progress-track{height:2.4cqw;background:#ded5ee;overflow:hidden;border-radius:99px;box-shadow:inset 0 1px 3px #54466d25}.progress-track div{height:100%;width:0;background:linear-gradient(90deg,#23c55e,#a9e33c);border-radius:99px}.home-panel p{font-size:3.5cqw;margin:2% 0 4%;color:#746588;font-weight:650}.play,.secondary{display:block;width:100%;padding:3.5%;font-size:5.5cqw;letter-spacing:.01em}.play{background:linear-gradient(#9bea55,#3bb82d 55%,#239622);border-color:#e3ffc2;box-shadow:0 4px #1c6b23,0 6px 9px #3166223b;text-shadow:0 2px #207322}.secondary{margin-top:4%;font-size:4.3cqw;background:linear-gradient(#9774e8,#6944bf)}.home-credit{text-align:center;letter-spacing:.24em;font-size:2.9cqw;font-weight:850;color:#e1d4fa;padding:2% 0}
#levelScreen{background:linear-gradient(160deg,#f9f4ff,#d9c8ff 65%,#bca7e7);color:#39285e;padding:5% 6%}.screen-top{display:flex;align-items:center;gap:5%}.screen-top button{width:12%;font-size:8cqw;line-height:1.1;padding:1%}.screen-top h1{font-size:7cqw;margin:0}.level-intro{color:#73638b;font-weight:650;font-size:3.7cqw;margin:5% 0}#levelGrid{display:grid;grid-template-columns:repeat(3,1fr);gap:4%;overflow:auto;padding:1% 1% 4%;min-height:0}.level-tile{aspect-ratio:1.05;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4%;font-size:7cqw}.level-tile small{font-size:2.7cqw;font-weight:750}.level-tile.done{background:linear-gradient(#68d665,#2b9e43);box-shadow:0 3px #1c7033}.level-tile.current{outline:3px solid #ffd32a;outline-offset:2px}.level-tile:disabled{opacity:.75;background:linear-gradient(#b7adca,#9688ab);box-shadow:0 3px #7d7192}.level-legend{font-size:3.2cqw;color:#73638b;text-align:center;margin:auto 0 3%;padding-top:4%}
#dialogBadge:not(:empty){font-size:12cqw;line-height:1;margin:0 0 4%;color:#56b338;text-shadow:0 3px #d4ebc1}#overlay section{animation:popIn .25s cubic-bezier(.17,.77,.3,1.16) both}#overlay section.win{border-color:#f7d65b;background:linear-gradient(#fffdf3,#fff1c4);box-shadow:0 8px #a7752d,0 12px 30px #0005}#overlay section.win #dialogActions button:first-child{background:linear-gradient(#8bdf4a,#32a535);box-shadow:0 3px #206725}.confetti{position:absolute;z-index:11;pointer-events:none;top:-4%;width:2%;height:1%;border-radius:2px;animation:confettiFall 1.5s ease-in forwards}@keyframes confettiFall{to{transform:translate(var(--drift),95cqh) rotate(620deg);opacity:0}}@keyframes popIn{from{transform:scale(.91);opacity:0}to{transform:scale(1);opacity:1}}@keyframes logoIn{from{transform:translateY(-8px);opacity:0}to{transform:translateY(0);opacity:1}}@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:.01s!important;transition-duration:.01s!important}.confetti{display:none}}
#levelGrid{flex:1 1 auto;align-content:start;gap:3.4cqw;grid-auto-rows:max-content;padding:1.5% 1.5% 4%;scrollbar-width:thin;scrollbar-color:#9d88ca transparent}.level-tile{min-width:0;width:100%;height:auto;aspect-ratio:1.08}.level-legend{flex-shrink:0;margin:0 0 2%;padding-top:3%}.level-tile:disabled small{font-size:2.8cqw;color:#fff}.screen-top,.level-intro{flex-shrink:0}
/* R5 startup and credits */
#splash{z-index:20;background:radial-gradient(ellipse at 50% 35%,#fff 15%,#f2eaff 70%,#ddd0f7);color:#34234f;align-items:center;justify-content:center}
.splash-stage{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3cqw;text-align:center}
.studio-stage img{width:77%;height:auto;display:block;object-fit:contain;background:transparent}.studio-stage span{font-size:3.2cqw;font-weight:900;letter-spacing:.35em;color:#85729c}.studio-stage{animation:studioReveal 2.5s both}.game-stage{animation:gameReveal 2.5s both}.game-stage img{width:94%;max-height:40%;object-fit:contain;filter:drop-shadow(0 7px 8px #4b326d30)}.game-stage p{font-size:4cqw;font-weight:800;color:#6a5489;margin:0}
.splash-road{display:flex;align-items:center;justify-content:center;gap:3cqw;width:65%;height:10cqw;background:linear-gradient(#56506c,#39334e);border-radius:99px;border:2px solid #fff;box-shadow:0 4px #d1c3e9;overflow:hidden}.splash-road i{width:7cqw;height:3cqw;border-radius:2px;background:#ff3b3b;box-shadow:inset 0 1px #fff8;animation:trafficRoll .9s ease-in-out infinite alternate}.splash-road i:nth-child(2){background:#1e90ff;animation-delay:.1s}.splash-road i:nth-child(3){background:#22c55e;animation-delay:.2s}.splash-road i:nth-child(4){background:#ffd32a;animation-delay:.3s}.splash-road i:nth-child(5){background:#a855f7;animation-delay:.4s}
.splash-bottom{position:absolute;bottom:8%;width:60%;display:grid;gap:4cqw;text-align:center;justify-items:center}.splash-track{height:2cqw;width:100%;overflow:hidden;border-radius:99px;background:#d7cce9}.splash-track div{height:100%;width:100%;background:linear-gradient(90deg,#ff3b3b,#ffd32a,#22c55e,#1e90ff,#a855f7);transform-origin:left;animation:bootFill 2.4s linear both}.splash-bottom button{background:transparent;box-shadow:none;border:0;color:#79678e;font-size:3.6cqw;padding:2% 10%}
@keyframes studioReveal{0%{opacity:0;transform:scale(.94)}12%,31%{opacity:1;transform:scale(1)}43%,100%{opacity:0;transform:scale(1.02)}}@keyframes gameReveal{0%,39%{opacity:0;transform:translateY(12px) scale(.96)}55%,100%{opacity:1;transform:none}}@keyframes trafficRoll{from{transform:translateY(-2px)}to{transform:translateY(2px)}}@keyframes bootFill{from{transform:scaleX(.08)}to{transform:scaleX(1)}}
#creditsBody{display:flex;flex-direction:column;gap:2.4cqw;margin:0 0 5%;text-align:left}.credits-logo{width:88%;max-height:23cqh;object-fit:contain;align-self:center}.credit-line{display:flex;flex-direction:column;gap:.7cqw;padding:3% 4%;border-radius:12px;background:#e8ddff;border:1px solid #d8c7f7}.credit-line span{font-size:3.2cqw;font-weight:700;color:#79658f}.credit-line strong{font-size:4.8cqw;line-height:1.15}.credit-footer{text-align:center;font-size:3.3cqw;line-height:1.6;color:#76658c;font-weight:700}.credits-panel{max-height:94%;overflow-y:auto}.credits-panel h1{font-size:7cqw}
#overlay section{max-height:95%;overflow:auto}#dialogActions{gap:2cqw}#dialogActions button{padding:3.4%}button{transition:transform .12s,filter .12s}button:active:not(:disabled){filter:brightness(1.08)}#home:not([hidden]) .home-panel{animation:panelIn .3s ease-out both}@keyframes panelIn{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:none}}
.reduced-motion *,.reduced-motion *::before,.reduced-motion *::after{animation-duration:.01s!important;transition-duration:.01s!important}.reduced-motion .studio-stage{display:none}.reduced-motion .game-stage{opacity:1;transform:none}.reduced-motion .confetti{display:none}@media(prefers-reduced-motion:reduce){.studio-stage{display:none}.game-stage{opacity:1;transform:none}}

/* Square navigation controls: explicitly size both axes, disable flex stretching. */
#game .nav-icon{--icon-size:clamp(44px,11.5cqw,56px);width:var(--icon-size);height:var(--icon-size);min-width:var(--icon-size);min-height:var(--icon-size);max-width:var(--icon-size);max-height:var(--icon-size);flex:0 0 var(--icon-size);align-self:center;aspect-ratio:1;padding:0;display:grid;place-items:center;border-radius:28%;line-height:1;box-shadow:0 3px #342365,0 4px 6px #0003}
#game .nav-icon svg{display:block;width:53%;height:53%;pointer-events:none}
#game .nav-icon:active{box-shadow:0 1px #342365}
.home-top{align-items:center;min-height:60px;padding:3% 5% 0}
.screen-top{align-items:center}
/* Campaign expansion: only the level list scrolls; header and footer remain fixed. */
#levelGrid{grid-template-columns:repeat(4,minmax(0,1fr));gap:2.8cqw;overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain;touch-action:pan-y;padding:2% 2% 5%}
.level-tile{aspect-ratio:1.08;font-size:6.3cqw;gap:3%;padding:2%;border-radius:12px}
.level-tile small,.level-tile:disabled small{font-size:2.45cqw;white-space:nowrap}
