/* Stunt Grandpa — toy-block UI: chunky glossy plastic buttons, primary colours, Florida pastels. */
:root {
  --red: #ff595e; --yellow: #ffca3a; --green: #8ac926; --blue: #1982c4; --purple: #6a4c93;
  --pink: #ff8fc7; --mint: #7fd8be; --ink: #3b2a4a; --paper: #fffaf0;
  --font: "Baloo 2", "Nunito", system-ui, "Noto Sans", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #1a2b4a; overflow: hidden; font-family: var(--font); color: var(--ink); user-select: none; -webkit-user-select: none; touch-action: none; }
#viewport { position: fixed; inset: 0; overflow: hidden; }
#stage { position: absolute; left: 0; top: 0; width: 1280px; height: 720px; transform-origin: 0 0; }
#game { position: absolute; inset: 0; width: 1280px; height: 720px; display: block; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- buttons */
.btn {
  font: 800 22px/1 var(--font); color: #fff; border: 0; border-radius: 18px; padding: 14px 22px 16px; cursor: pointer;
  background: var(--c, var(--blue)); box-shadow: inset 0 -6px 0 rgba(0,0,0,.22), inset 0 3px 0 rgba(255,255,255,.35), 0 5px 0 rgba(0,0,0,.25);
  text-shadow: 0 2px 0 rgba(0,0,0,.25); transition: transform .08s, filter .15s; position: relative; white-space: nowrap;
}
.btn:hover { transform: translateY(-2px) scale(1.03); filter: brightness(1.07); }
.btn:active { transform: translateY(3px) scale(.97); box-shadow: inset 0 -3px 0 rgba(0,0,0,.22), 0 2px 0 rgba(0,0,0,.25); }
.btn.go { --c: var(--green); } .btn.pink { --c: #ff5fa2; } .btn.sun { --c: #f4a100; } .btn.teal { --c: #12a39a; }
.btn.plum { --c: var(--purple); } .btn.red { --c: var(--red); } .btn.blue { --c: var(--blue); }
.btn.big { font-size: 34px; padding: 18px 44px 22px; border-radius: 24px; }
.btn.sm { font-size: 17px; padding: 10px 14px 12px; border-radius: 14px; }
.btn.icon { padding: 12px 16px 14px; }
.btn[disabled] { filter: grayscale(.8) brightness(.9); cursor: default; transform: none; }
.btn.off { filter: grayscale(.9) brightness(.85); }
.badge { position: absolute; top: -10px; right: -8px; background: var(--red); color: #fff; font: 800 15px/1 var(--font); font-style: normal; border-radius: 12px; padding: 4px 8px; box-shadow: 0 2px 0 rgba(0,0,0,.3); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.15); } }

/* ---------------------------------------------------------------- overlays & modals */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(30,20,60,.45); z-index: 20; }
.modal { background: var(--paper); border-radius: 28px; padding: 26px 32px; min-width: 460px; max-width: 760px; max-height: 680px; overflow: auto; box-shadow: 0 10px 0 rgba(0,0,0,.25), inset 0 -8px 0 rgba(0,0,0,.06); border: 5px solid #fff; animation: pop .25s cubic-bezier(.3,1.6,.5,1); text-align: center; }
.modal.wide { width: 860px; max-width: 860px; }
.modal.garage { padding: 18px 24px; }
.garage .actions { margin-top: 8px; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.modal h2 { margin: 0 0 6px; font-size: 36px; color: var(--purple); line-height: 1.05; }
.sub { margin: 4px 0 12px; font-size: 19px; font-weight: 600; opacity: .85; }
.sub.small { font-size: 15px; }
.actions { display: flex; gap: 14px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; margin: 14px auto; width: 320px; }
.row { display: flex; gap: 10px; justify-content: center; margin: 10px 0; flex-wrap: wrap; }
.langrow { display: flex; gap: 10px; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; margin: 6px 0; }
select { font: 700 17px var(--font); border-radius: 12px; border: 3px solid var(--blue); padding: 6px 10px; background: #fff; color: var(--ink); }

/* ---------------------------------------------------------------- loading + title */
.loader { text-align: center; color: #fff; font-size: 26px; font-weight: 800; }
.wheelspin { width: 90px; height: 90px; margin: 0 auto 10px; border-radius: 50%; border: 14px solid #2b2b33; background: radial-gradient(circle, var(--red) 0 22%, var(--yellow) 23% 60%, #2b2b33 61%); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader .bar { width: 320px; height: 14px; border-radius: 8px; background: rgba(255,255,255,.25); margin: 12px auto; overflow: hidden; }
.loader .bar i { display: block; height: 100%; width: 0; background: var(--yellow); transition: width .2s; }
.overlay.title { background: linear-gradient(180deg, rgba(25,130,196,.25), rgba(106,76,147,.35)); }
.title-card { text-align: center; }
.logo { display: inline-flex; flex-direction: column; align-items: center; transform: rotate(-4deg); filter: drop-shadow(0 8px 0 rgba(0,0,0,.25)); }
.logo span { font-weight: 800; letter-spacing: 2px; line-height: .9; -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; }
.logo .l1 { font-size: 64px; color: var(--yellow); }
.logo .l2 { font-size: 104px; color: var(--red); animation: wob 2.4s ease-in-out infinite; }
@keyframes wob { 50% { transform: rotate(3deg) scale(1.03); } }
.logo.small { transform: rotate(-3deg) scale(.42); transform-origin: left center; margin-right: -230px; }
.tagline { color: #fff; font-size: 26px; font-weight: 800; text-shadow: 0 3px 0 var(--ink), 0 0 12px rgba(0,0,0,.4); margin: 14px 0 22px; max-width: 760px; }
.hint { color: #fff; font-weight: 700; opacity: .9; text-shadow: 0 2px 0 var(--ink); }
.title-lang { display: inline-flex; gap: 8px; align-items: center; font-size: 22px; margin-top: 6px; }

/* ---------------------------------------------------------------- menu */
.overlay.menu { flex-direction: column; justify-content: flex-start; padding: 16px 28px; background: linear-gradient(180deg, rgba(20,40,80,.55), rgba(40,20,70,.7)); }
.menu-head { width: 100%; display: flex; justify-content: space-between; align-items: center; height: 70px; }
.chips { display: flex; gap: 10px; }
.chip { background: #fff; border-radius: 16px; padding: 6px 14px 8px; font-weight: 800; font-size: 22px; box-shadow: 0 4px 0 rgba(0,0,0,.25); }
.chip.streak { background: #ffe8a3; }
.goal-hint { color: #fff; font-weight: 800; font-size: 20px; text-shadow: 0 2px 0 var(--ink); min-height: 28px; margin: 2px 0 6px; }
.world-tabs { display: flex; gap: 8px; margin-bottom: 6px; }
.wtab { font: 800 18px var(--font); border: 0; border-radius: 16px 16px 8px 8px; padding: 10px 16px; cursor: pointer; background: #fff; color: var(--ink); box-shadow: inset 0 -5px 0 rgba(0,0,0,.12); opacity: .85; }
.wtab.on { background: var(--yellow); opacity: 1; transform: translateY(-3px); }
.wtab.locked { background: #b9b3c8; }
.world-head { color: #fff; font-size: 20px; font-weight: 700; text-shadow: 0 2px 0 var(--ink); margin-bottom: 8px; }
.levels { display: grid; grid-template-columns: repeat(9, 124px); gap: 10px; }
.lvl { height: 150px; border-radius: 20px; border: 0; cursor: pointer; background: #fff; box-shadow: inset 0 -7px 0 rgba(0,0,0,.12), 0 5px 0 rgba(0,0,0,.25); font-family: var(--font); color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 10px 6px 12px; transition: transform .1s; }
.lvl:hover { transform: translateY(-4px) rotate(-1deg); }
.lvl .n { font-size: 30px; font-weight: 800; line-height: 1; }
.lvl .st { font-size: 20px; letter-spacing: -2px; color: #ddd; } .lvl .st b { color: #f4a100; font-weight: 400; }
.lvl .bt { font-size: 14px; font-weight: 700; opacity: .75; }
.lvl .cat { font-size: 18px; filter: grayscale(1) opacity(.35); } .lvl .cat.got { filter: none; }
.lvl.locked { background: #cfc9dc; cursor: default; } .lvl.locked .n { opacity: .4; }
.lvl.next { background: #fff6cc; animation: pulse 1.4s infinite; }
.menu-row { display: flex; gap: 12px; margin-top: auto; padding-bottom: 6px; align-items: center; }
.menu-row small { font-size: 14px; opacity: .9; }

/* ---------------------------------------------------------------- HUD */
#hud { position: absolute; left: 0; right: 0; top: 0; padding: 12px 16px; display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; z-index: 10; }
.hud-left, .hud-right { display: flex; gap: 8px; align-items: center; }
.hud-left { flex-direction: column; align-items: flex-start; }
.pill { background: rgba(255,255,255,.92); border-radius: 16px; padding: 4px 14px 6px; font-weight: 800; box-shadow: 0 4px 0 rgba(0,0,0,.2); display: flex; gap: 8px; align-items: baseline; }
.pill.level b { color: var(--purple); font-size: 20px; } .pill.level span { font-size: 16px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill.timer b { font-size: 30px; font-variant-numeric: tabular-nums; min-width: 118px; } .pill.timer small { font-size: 16px; }
.pill.timer small.ahead { color: #2f9e44; } .pill.timer small.behind { color: #e03131; }
.pill.goals { font-size: 15px; gap: 10px; } .pill.goals span.hit { color: #f4a100; } .pill.goals span.miss { opacity: .35; text-decoration: line-through; }
.pill.coupons { font-size: 22px; }
.hud-center { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); text-align: center; }
.style-box { background: rgba(59,42,74,.75); color: #fff; border-radius: 16px; padding: 2px 18px 6px; }
.style-box small { display: block; font-size: 12px; letter-spacing: 3px; opacity: .8; }
.style-box b { font-size: 28px; font-variant-numeric: tabular-nums; }
.combo { margin-top: 6px; background: var(--yellow); border-radius: 14px; padding: 2px 14px 8px; box-shadow: 0 4px 0 rgba(0,0,0,.25); animation: pop .2s; position: relative; }
.combo b { font-size: 30px; color: var(--red); -webkit-text-stroke: 1px var(--ink); }
.combo i { position: absolute; left: 8px; right: 8px; bottom: 4px; height: 5px; border-radius: 3px; background: var(--red); transform-origin: left; }
.hbtn { pointer-events: auto; width: 54px; height: 54px; border-radius: 16px; border: 0; background: #fff; font-size: 26px; cursor: pointer; box-shadow: inset 0 -5px 0 rgba(0,0,0,.12), 0 4px 0 rgba(0,0,0,.25); color: var(--ink); }
.hbtn:active { transform: translateY(3px); }
.progress { position: absolute; left: 50%; bottom: -14px; width: 360px; margin-left: -180px; height: 8px; border-radius: 4px; background: rgba(255,255,255,.35); display: none; }
.progress i { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--green); }
.progress em { position: absolute; inset: 0; }
.progress em b { position: absolute; top: -3px; width: 6px; height: 14px; margin-left: -3px; background: var(--pink); border-radius: 3px; }
#hud .progress { display: block; top: 118px; bottom: auto; }

/* ---------------------------------------------------------------- touch controls */
#touch { position: absolute; left: 0; right: 0; bottom: 0; height: 200px; z-index: 9; pointer-events: none; }
.tgroup { position: absolute; bottom: 18px; display: flex; gap: 14px; }
.tgroup.left { left: 18px; } .tgroup.right { right: 18px; }
.tbtn { pointer-events: auto; width: 150px; height: 150px; border-radius: 34px; border: 5px solid rgba(255,255,255,.8); color: #fff; font-family: var(--font); background: rgba(59,42,74,.45); display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none; box-shadow: 0 6px 0 rgba(0,0,0,.2); }
.tbtn span { font-size: 58px; line-height: 1; } .tbtn small { font-weight: 800; font-size: 17px; letter-spacing: 1px; }
.tbtn.gas { background: rgba(138,201,38,.6); width: 170px; height: 170px; } .tbtn.brake { background: rgba(255,89,94,.55); }
.tbtn.on { transform: scale(.92); filter: brightness(1.3); }

/* ---------------------------------------------------------------- tutorial + toast */
.tut { position: absolute; left: 50%; top: 150px; transform: translateX(-50%); background: #fff; border-radius: 20px; padding: 12px 22px 14px; font-weight: 800; font-size: 24px; box-shadow: 0 6px 0 rgba(0,0,0,.25); z-index: 11; border: 4px solid var(--yellow); max-width: 820px; text-align: center; animation: pop .3s; pointer-events: none; }
.tut kbd, kbd { display: inline-block; background: var(--ink); color: #fff; border-radius: 8px; padding: 0 9px 2px; margin: 0 3px; font: 800 18px var(--font); box-shadow: 0 3px 0 #000; }
.toast { position: absolute; left: 50%; bottom: 205px; transform: translateX(-50%); background: var(--ink); color: #fff; border-radius: 16px; padding: 10px 22px 12px; font-weight: 800; font-size: 21px; z-index: 40; box-shadow: 0 5px 0 rgba(0,0,0,.3); animation: pop .25s; max-width: 900px; text-align: center; }

/* ---------------------------------------------------------------- garage */
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.gtabs { display: flex; gap: 8px; }
.gtab { font: 800 22px var(--font); border: 0; border-radius: 14px; padding: 8px 18px 10px; background: #e8e2f3; color: var(--ink); cursor: pointer; }
.gtab.on { background: var(--purple); color: #fff; }
.garage-body { display: flex; gap: 16px; text-align: left; }
.g-list { display: flex; flex-direction: column; gap: 8px; width: 270px; max-height: 470px; overflow: auto; padding: 4px; }
.g-item { display: flex; align-items: center; gap: 10px; border: 0; border-radius: 16px; padding: 8px 12px; background: #fff; cursor: pointer; font: 700 18px var(--font); color: var(--ink); box-shadow: inset 0 -4px 0 rgba(0,0,0,.1), 0 3px 0 rgba(0,0,0,.15); text-align: left; }
.g-item img { width: 70px; height: 42px; object-fit: contain; }
.g-item.sel { outline: 4px solid var(--yellow); }
.g-item.locked { opacity: .6; }
.g-item small { display: block; font-size: 14px; opacity: .75; }
.g-detail { flex: 1; }
#g-preview { width: 520px; height: 190px; background: linear-gradient(#bfe9ff, #fff3d6 70%, #ffca3a 70%); border-radius: 20px; }
.g-name { font-size: 24px; font-weight: 800; margin: 4px 0 0; }
.g-desc { font-size: 15px; font-weight: 600; opacity: .8; margin-bottom: 4px; }
.stats2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.stat { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; }
.stat span { width: 84px; } .stat i { display: inline-block; width: 22px; height: 10px; border-radius: 5px; background: #e1dbe9; } .stat i.on { background: var(--green); }
.upg { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 14px; padding: 4px 10px; margin: 4px 0; box-shadow: 0 2px 0 rgba(0,0,0,.1); }
.upg .ui { font-size: 26px; } .upg .ut { flex: 1; font-weight: 700; font-size: 16px; } .upg .ut small { display: block; font-size: 13px; opacity: .7; font-weight: 600; }
.upg .pips i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: #e1dbe9; margin-right: 3px; } .upg .pips i.on { background: var(--blue); }

/* ---------------------------------------------------------------- missions */
.rows { display: flex; flex-direction: column; gap: 10px; margin: 10px 0; }
.mrow { display: flex; align-items: center; gap: 14px; background: #fff; border-radius: 16px; padding: 10px 14px; box-shadow: 0 3px 0 rgba(0,0,0,.12); text-align: left; }
.mrow .mt { flex: 1; font-weight: 700; font-size: 19px; }
.mrow .pb { height: 10px; border-radius: 5px; background: #e8e2f3; margin-top: 4px; overflow: hidden; } .mrow .pb i { display: block; height: 100%; background: var(--green); }
.mrow .rw { font-weight: 800; }
.lifetime { font-size: 15px; font-weight: 700; opacity: .75; margin-top: 8px; }

/* ---------------------------------------------------------------- result */
.modal.result { min-width: 560px; }
.stars { font-size: 70px; letter-spacing: 6px; height: 86px; }
.stars span { display: inline-block; color: #ddd; transform: scale(0); animation: starpop .45s cubic-bezier(.3,1.8,.5,1) forwards; }
.stars span.on { color: #f4a100; text-shadow: 0 4px 0 #b86e00; }
@keyframes starpop { to { transform: scale(1); } }
.rtime { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rtime small { display: block; font-size: 17px; opacity: .75; }
.stats { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 8px 0; font-weight: 700; font-size: 17px; }
.stats span { background: #fff; border-radius: 12px; padding: 4px 10px; box-shadow: 0 2px 0 rgba(0,0,0,.1); }
.rcoupons { font-size: 17px; font-weight: 700; } .rcoupons b.total { display: block; font-size: 30px; color: #12a39a; }
.result-extra { font-weight: 800; color: var(--red); min-height: 24px; }
.keys-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; text-align: left; font-size: 18px; margin: 10px 0; }
ul.howto { text-align: left; font-size: 17px; line-height: 1.4; }

#rotate { display: none; position: fixed; inset: 0; background: var(--purple); color: #fff; font: 800 28px var(--font); align-items: center; justify-content: center; text-align: center; padding: 30px; z-index: 99; }
@media (orientation: portrait) and (max-width: 900px) and (pointer: coarse) { #rotate { display: flex; } } /* touch phones only: a narrow desktop window is never blocked */
/* phones: the scaled-down stage makes the title's language picker tiny — give it a finger-sized height */
@media (pointer: coarse) { #lang-title { min-height: 72px; font-size: 22px; } }
@media (pointer: coarse) { .hbtn { width: 78px; height: 78px; font-size: 32px; } }
