/* Skimmer Cup 3D - stage + in-game UI. Everything is scoped under #stage so site styles never leak in. */
html.pip-big, html.pip-big body { overflow: hidden; }
#stage { --teal:#0e9fb5; --teal-d:#0a7183; --sun:#ffc21a; --coral:#ff6a5a; --ink:#16324a; --cream:#fffaf0;
  position: relative; width: min(100%, calc(78vh * 0.5625)); width: min(100%, calc(78svh * 0.5625)); aspect-ratio: 9 / 16; margin: 0 auto; overflow: hidden;
  border-radius: 14px; background: linear-gradient(#7fd3ee 0%, #b9ecff 60%, #e8f8ff 100%); color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; line-height: 1.25; }
#stage.is-big { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; z-index: 99999; }
#stage *, #stage *::before, #stage *::after { box-sizing: border-box; }
#stage [hidden] { display: none !important; }
#stage #app { position: absolute; inset: 0; }
#stage #app canvas { display: block; width: 100%; height: 100%; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#stage #ui button, #stage #ui .panel, #stage #ui .card, #stage #ui [data-hold] { pointer-events: auto; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
#stage button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

#stage #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: linear-gradient(#0e9fb5 0%, #5cc8dc 60%, #d8f4fa 100%); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 3px 0 rgba(10,60,80,.45); text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 32px); letter-spacing: 2px; }
#stage .load-in span { font-size: 14px; opacity: .95; }
#stage .spinner { width: 38px; height: 38px; border-radius: 50%; border: 5px solid rgba(255,255,255,.4); border-top-color: #fff; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#stage #ctxlost { position: absolute; left: 12px; right: 12px; top: 40%; z-index: 60; background: rgba(22,50,74,.92); color: #fff; padding: 14px; border-radius: 12px; text-align: center; font-size: 15px; }

/* screens */
#stage .scr { position: absolute; inset: 0; z-index: 10; padding: 12px 12px 14px; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; pointer-events: auto; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
#stage .scr.s-menu { background: linear-gradient(rgba(8,40,60,0) 30%, rgba(8,40,60,.5) 100%); justify-content: flex-start; }
#stage .scr.s-garage { background: linear-gradient(rgba(8,40,60,0) 8%, rgba(8,40,60,.55) 55%); }
#stage .scr.s-cups, #stage .scr.s-tracks, #stage .scr.s-goals, #stage .scr.s-settings, #stage .scr.s-results, #stage .scr.s-pause, #stage .scr.s-tutorial { background: rgba(10,44,66,.62); }
#stage .scr.s-pause, #stage .scr.s-tutorial { justify-content: center; }
#stage .topbar { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex: 0 0 auto; }
#stage .pill { background: rgba(255,255,255,.92); border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 14px; min-height: 32px; display: inline-flex; align-items: center; gap: 8px; }
#stage .pill.coin { color: #a86a00; }
#stage .pill .bar { width: 54px; }
#stage .title { text-align: center; color: #fff; text-shadow: 0 3px 0 rgba(10,60,80,.55); margin: 4px 0 auto; }
#stage .title h2 { font-size: clamp(30px, 10vw, 48px); letter-spacing: 1px; line-height: 1; }
#stage .title p { font-size: 14px; opacity: .95; margin-top: 4px; }
#stage .head { color: #fff; font-size: 22px; text-shadow: 0 2px 0 rgba(10,60,80,.5); text-align: center; flex: 0 0 auto; }
#stage .panel { background: rgba(255,255,255,.94); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 6px 0 rgba(10,60,80,.25); }
#stage .panel.menu { margin-top: auto; }
#stage .panel.center { text-align: center; align-items: stretch; }
#stage .panel.list { gap: 8px; }
#stage .panel.scroll { overflow-y: auto; max-height: 60%; touch-action: pan-y; }
#stage .small { font-size: 12.5px; color: #35546b; text-align: center; }
#stage .scr > .small { color: #e6f6ff; }
#stage .row { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: auto; flex: 0 0 auto; }
#stage .row .btn { flex: 1; }
#stage .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

#stage .btn { min-height: 48px; min-width: 44px; border: 0; border-radius: 14px; padding: 10px 14px; font-weight: 800; font-size: 16px; color: #fff; background: var(--teal); box-shadow: 0 4px 0 var(--teal-d); }
#stage .btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--teal-d); }
#stage .btn.primary { background: var(--coral); box-shadow: 0 4px 0 #c8402f; }
#stage .btn.primary:active { box-shadow: 0 1px 0 #c8402f; }
#stage .btn.big { min-height: 58px; font-size: 20px; }
#stage .btn.ghost { background: #e8f3f8; color: var(--ink); box-shadow: 0 4px 0 #b6cfdb; }
#stage .btn.danger { background: #c8402f; box-shadow: 0 4px 0 #8e2a1d; }
#stage .btn.upg { min-height: 44px; padding: 6px 10px; font-size: 14px; background: #3fae5a; box-shadow: 0 3px 0 #2b7d40; white-space: nowrap; }
#stage .btn.upg.poor { background: #9aa9b3; box-shadow: 0 3px 0 #74828b; }
#stage .dot { background: var(--sun); color: #4a3300; border-radius: 6px; font-size: 10px; padding: 2px 5px; margin-left: 4px; vertical-align: middle; }
#stage .icon { width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.92); color: var(--ink); font-weight: 800; font-size: 16px; box-shadow: 0 3px 0 rgba(10,60,80,.3); }
#stage .chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
#stage .chipb { min-height: 44px; min-width: 44px; padding: 8px 12px; border-radius: 999px; border: 2px solid #b6cfdb; background: #fff; color: var(--ink); font-weight: 700; font-size: 14px; }
#stage .chipb.on { background: var(--teal); border-color: var(--teal-d); color: #fff; }
#stage .chipb.off { opacity: .55; }
#stage .card { display: flex; flex-direction: column; gap: 3px; text-align: left; border: 2px solid #cfe2ec; background: #fff; border-radius: 12px; padding: 10px 12px; min-height: 52px; color: var(--ink); }
#stage .card b { font-size: 16px; } #stage .card span { font-size: 13px; color: #4a6a80; }
#stage .card.sel { border-color: var(--teal); background: #e9fbff; }
#stage .card.off { opacity: .55; }
#stage .card.slim { padding: 8px 12px; min-height: 48px; }
#stage .card.done { background: #effbea; border-color: #9bd68a; }
#stage .tros { display: flex; gap: 6px; font-style: normal; }
#stage .tro { font-size: 12px; font-weight: 800; border-radius: 6px; padding: 1px 6px; background: #cfd8de; }
#stage .tro.p1 { background: #ffd23a; } #stage .tro.p2 { background: #d6dde2; } #stage .tro.p3 { background: #e0a46a; }
#stage .bar { height: 10px; border-radius: 6px; background: #d8e6ee; overflow: hidden; } #stage .bar.thin { height: 6px; }
#stage .bar i { display: block; height: 100%; background: linear-gradient(#5be3a0, #2bb673); border-radius: 6px; }
#stage .setrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 700; }
#stage .how { text-align: left; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }

/* garage */
#stage .gar-name { display: flex; justify-content: space-between; align-items: center; color: #fff; text-shadow: 0 2px 0 rgba(10,60,80,.55); margin-top: auto; }
#stage .gar-name h3 { font-size: 24px; } #stage .gar-name small { font-size: 12px; opacity: .9; }
#stage .stat { display: grid; grid-template-columns: 86px 1fr 22px auto; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; min-height: 44px; }
#stage .sbar { position: relative; height: 12px; background: #d8e6ee; border-radius: 6px; overflow: hidden; }
#stage .sbar i { position: absolute; top: 0; bottom: 0; left: 0; } #stage .sbar .b { background: #4aa3d8; } #stage .sbar .u { background: #3fae5a; }
#stage .max { font-style: normal; font-size: 11px; color: #2b7d40; }
#stage .swatches { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
#stage .sw { width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; color: #fff; font-weight: 800; font-size: 13px; box-shadow: 0 2px 0 rgba(10,60,80,.4); }
#stage .sw.on { border-color: #16324a; } #stage .sw.lock { opacity: .45; }

/* results */
#stage .res { gap: 8px; }
#stage .place { text-align: center; } #stage .place b { display: block; font-size: 52px; line-height: 1; color: var(--coral); } #stage .place small { font-size: 13px; color: #4a6a80; }
#stage .place.p1 b { color: #e0a000; }
#stage .times { display: flex; justify-content: space-around; font-size: 13px; color: #4a6a80; } #stage .times b { color: var(--ink); font-size: 15px; }
#stage .medal { text-align: center; font-weight: 800; } #stage .medal.m3 { color: #c88a00; } #stage .medal.m2 { color: #7d8a93; } #stage .medal.m1 { color: #a8642a; }
#stage .rows { display: flex; flex-direction: column; gap: 3px; }
#stage .srow { display: grid; grid-template-columns: 22px 1fr auto; gap: 6px; font-size: 13px; padding: 3px 6px; border-radius: 8px; } #stage .srow.me { background: #fff1c2; font-weight: 800; } #stage .srow i { font-style: normal; color: #4a6a80; }
#stage .res h4 { font-size: 13px; color: #4a6a80; }
#stage .reward { text-align: center; font-size: 15px; } #stage .reward span { font-size: 12px; color: #4a6a80; }
#stage .note { text-align: center; font-weight: 800; color: #2b7d40; font-size: 13px; }
#stage .goal { text-align: center; font-size: 13px; background: #e9fbff; border-radius: 10px; padding: 8px; }

/* HUD */
#stage .hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
#stage .hud-top { position: absolute; left: 8px; right: 8px; top: 8px; display: flex; gap: 6px; align-items: center; }
#stage .chip { background: rgba(255,255,255,.9); border-radius: 12px; padding: 4px 10px; font-weight: 800; font-size: 15px; display: flex; align-items: baseline; gap: 3px; min-height: 36px; align-items: center; }
#stage .chip b { font-size: 20px; } #stage .chip small { font-size: 11px; color: #4a6a80; }
#stage .chip.time { margin-left: auto; font-family: "Courier New", monospace; font-size: 15px; }
#stage .hud-top .icon { pointer-events: auto; }
#stage #hud-mini { position: absolute; right: 8px; top: 58px; width: 84px; height: 84px; background: rgba(22,50,74,.35); border-radius: 12px; }
#stage .banner { position: absolute; left: 0; right: 0; top: 26%; text-align: center; font-size: clamp(44px, 16vw, 78px); font-weight: 900; color: #fff; text-shadow: 0 4px 0 rgba(10,60,80,.6); opacity: 0; transform: scale(.6); transition: opacity .12s, transform .12s; }
#stage .banner.show { opacity: 1; transform: scale(1); }
#stage .hint { position: absolute; left: 14px; right: 14px; top: 17%; text-align: center; font-size: 15px; font-weight: 700; color: #fff; background: rgba(22,50,74,.72); padding: 8px 10px; border-radius: 12px; opacity: 0; transition: opacity .2s; }
#stage .hint.show { opacity: 1; }
#stage .wrong { position: absolute; left: 0; right: 0; top: 40%; text-align: center; font-size: 30px; font-weight: 900; color: #ff4b3a; text-shadow: 0 3px 0 #fff; }
#stage .hud-bot { position: absolute; left: 12px; right: 12px; bottom: 10px; display: flex; align-items: center; gap: 10px; }
#stage .meter { flex: 1; height: 14px; border-radius: 8px; background: rgba(22,50,74,.55); overflow: hidden; border: 2px solid rgba(255,255,255,.8); }
#stage .meter i { display: block; height: 100%; width: 0; background: #ffb21a; } #stage .meter i.full { background: #ffe23a; } #stage .meter i.hot { background: #ff5a2a; }
#stage .spd { color: #fff; font-weight: 800; text-shadow: 0 2px 0 rgba(10,60,80,.6); font-size: 12px; min-width: 80px; text-align: right; } #stage .spd b { font-size: 22px; }

#stage #hud-best[hidden] { display: none; }
#stage .bestline { position: absolute; left: 8px; top: 50px; background: rgba(22,50,74,.6); color: #fff; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 8px; font-family: "Courier New", monospace; }
#stage .chip.pos { transition: transform .25s, background-color .25s; }
#stage .chip.pos.up { background: #b9f5c4; transform: scale(1.18); } #stage .chip.pos.down { background: #ffd0c8; transform: scale(.92); }
@supports (top: env(safe-area-inset-top)) { #stage .hud-top { top: max(8px, env(safe-area-inset-top)); } }
@media (prefers-reduced-motion: reduce) { #stage .chip.pos { transition: none; transform: none !important; } }

/* touch controls */
#stage .touch { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
#stage .zone { position: absolute; top: 16%; bottom: 0; touch-action: none; }
#stage .zl { left: 0; width: 50%; } #stage .zr { right: 0; width: 50%; } #stage .zd { left: 0; right: 0; display: none; }
#stage.ctl-drag .zl, #stage.ctl-drag .zr { display: none; } #stage.ctl-drag .zd { display: block; }
#stage .zl::after, #stage .zr::after { content: ""; position: absolute; bottom: 70px; width: 0; height: 0; border-style: solid; opacity: .35; }
#stage .zl::after { left: 16px; border-width: 18px 26px 18px 0; border-color: transparent #fff transparent transparent; }
#stage .zr::after { right: 16px; border-width: 18px 0 18px 26px; border-color: transparent transparent transparent #fff; }
#stage .ctl { position: absolute; border: 0; border-radius: 50%; color: #fff; font-weight: 900; touch-action: none; box-shadow: 0 4px 0 rgba(10,60,80,.5); }
#stage .ctl.boost { right: 12px; bottom: 44px; width: 84px; height: 84px; background: #ff7a1a; font-size: 15px; }
#stage .ctl.brake { left: 12px; bottom: 44px; width: 62px; height: 62px; background: #5b7184; font-size: 11px; }
#stage .ctl:active { transform: scale(.95); }

#stage .toast { position: absolute; left: 16px; right: 16px; bottom: 90px; z-index: 30; text-align: center; background: rgba(22,50,74,.9); color: #fff; padding: 9px 12px; border-radius: 12px; font-size: 14px; font-weight: 700; opacity: 0; transition: opacity .2s; pointer-events: none; }
#stage .toast.show { opacity: 1; }
#stage .flash { position: absolute; inset: 0; z-index: 20; opacity: 0; pointer-events: none; transition: opacity .12s; }
#stage .flash.show { opacity: 1; }

/* page chrome below the stage */
.er-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.er-bar .btn { min-height: 44px; min-width: 44px; }
.er-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.er-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.er-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.er-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.er-guide p { margin-bottom: .5rem; font-size: .95rem; }

@media (max-height: 560px) { #stage .title h2 { font-size: 28px; } #stage .stat { min-height: 40px; } }
@media (prefers-reduced-motion: reduce) { #stage .spinner { animation: none; } #stage .banner { transition: none; } }

/* ---- wave 3: full screen fill, duplicate Play big hidden, finish ---- */
.er-bar { display: none; }
.game-wrap .game-title { order: 9; }
.game-wrap { display: flex; flex-direction: column; }
.game-wrap > .game-title, .game-wrap > .er-keys, .game-wrap > noscript { flex: 0 0 auto; }

/* the shell owns full screen: the stage fills the wrap under the rail, never a second fixed layer */
html.pip-immersive .game-wrap.pip-stage { display: flex; flex-direction: column; overflow: hidden !important; padding-left: 0; padding-right: 0; padding-bottom: 0; }
html.pip-immersive .game-wrap.pip-stage > .game-title,
html.pip-immersive .game-wrap.pip-stage > .er-bar,
html.pip-immersive .game-wrap.pip-stage > .er-keys,
html.pip-immersive .game-wrap.pip-stage > noscript { display: none !important; }
html.pip-immersive #stage, html.pip-immersive #stage.is-big { position: relative; inset: auto; z-index: auto; flex: 1 1 0; min-height: 0; width: 100%; max-width: none; height: auto; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-immersive #stage .hud-top { top: 8px; }
html.pip-immersive #stage .hud-bot { bottom: 8px; }
html.pip-immersive #stage .ctl.boost, html.pip-immersive #stage .ctl.brake { bottom: 34px; }

/* wide stage (landscape or desktop full screen): keep menu content in a readable column */
@media (min-aspect-ratio: 5/4) {
  #stage .scr > * { width: 100%; max-width: 560px; margin-left: auto; margin-right: auto; }
  #stage .scr.s-garage > *, #stage .scr.s-tracks > *, #stage .scr.s-cups > * { max-width: 640px; }
  #stage .hud-top { left: 12px; right: 12px; }
  #stage #hud-mini { top: 52px; width: 72px; height: 72px; }
  #stage .zone { top: 12%; }
}
@media (max-height: 460px) {
  #stage .scr { padding: 8px 10px 10px; gap: 6px; }
  #stage .title h2 { font-size: 26px; }
  #stage .btn.big { min-height: 48px; font-size: 18px; }
  #stage .ctl.boost { width: 76px; height: 76px; bottom: 28px; }
  #stage .ctl.brake { width: 58px; height: 58px; bottom: 28px; }
  #stage .toast { bottom: 24px; }
}

/* finish: static layers only, no per-frame cost */
#stage::after { content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none; border-radius: inherit;
  background: radial-gradient(120% 90% at 50% 45%, rgba(0,0,0,0) 62%, rgba(8,40,60,.28) 100%), linear-gradient(rgba(255,255,255,.10), rgba(255,255,255,0) 18%); }
#stage .panel { border: 2px solid rgba(255,255,255,.7); box-shadow: 0 6px 0 rgba(10,60,80,.25), 0 14px 24px rgba(8,40,60,.22); }
#stage .ctl { box-shadow: 0 5px 0 rgba(0,0,0,.28), 0 0 0 4px rgba(255,255,255,.35), 0 10px 18px rgba(8,40,60,.3); transition: transform .08s ease-out; }
#stage .ctl:active, #stage .ctl.on { transform: scale(.94); }
#stage .btn { transition: transform .08s ease-out, box-shadow .08s ease-out; }
#stage .btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--teal-d); }
#stage .title h2 { text-shadow: 0 3px 0 rgba(10,60,80,.55), 0 8px 18px rgba(8,40,60,.35); }
@media (prefers-reduced-motion: reduce) { #stage .ctl, #stage .btn { transition: none; } }
#stage #ui { z-index: 3; }
