/* River Raft 3D - stage and in-game UI. Everything is scoped under #stage so site styles never leak in. */
html.pip-big, html.pip-big body { overflow: hidden; }
#stage { --river: #1e9bd8; --deep: #0c5b8e; --foam: #eaf8ff; --orange: #ff8a2a; --green: #35d06a; --red: #e84a4a; --ink: #12324a; --cream: #f4fbff;
  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(#8fd3ff 0%, #3aa6e0 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; }
.game-wrap.pip-stage #stage { width: min(100%, calc((100vh - 64px) * 0.5625)); width: min(100%, calc((100svh - 64px) * 0.5625)); }
#stage *, #stage *::before, #stage *::after { box-sizing: border-box; }
#stage #app { position: absolute; inset: 0; }
#stage #app canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#stage #ui button, #stage #ui input, #stage .panel, #stage .pad { 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 [hidden] { display: none !important; }

#stage #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: linear-gradient(#8fd3ff 0%, #1e9bd8 100%); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 3px 0 rgba(12,60,100,.5); text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 30px); letter-spacing: 2px; }
#stage .load-in span { font-size: 14px; }
#stage .spinner { width: 42px; height: 42px; border-radius: 50%; border: 6px solid rgba(255,255,255,.35); border-top-color: #ffc81a; animation: rrspin .8s linear infinite; }
@keyframes rrspin { to { transform: rotate(360deg); } }
#stage #ctxlost { position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; background: rgba(12,40,70,.88); color: #fff; font-weight: 700; }

/* HUD */
#stage .hud { position: absolute; inset: 0; padding: max(8px, env(safe-area-inset-top)) 8px 8px; pointer-events: none; }
#stage .hud-top { display: flex; align-items: center; gap: 6px; }
#stage .stat { background: rgba(8,40,70,.6); color: #fff; border-radius: 12px; padding: 4px 8px; display: flex; align-items: baseline; gap: 5px; min-height: 36px; }
#stage .stat { min-width: 0; flex: 0 0 auto; }
#stage .stat.mid { flex: 1 1 auto; min-width: 0; justify-content: center; flex-direction: column; align-items: center; gap: 0; }
#stage .stat .big { font-size: 17px; font-variant-numeric: tabular-nums; }
#stage .stat .small { font-size: 11px; opacity: .9; }
#stage .hearts { display: flex; gap: 1px; align-items: center; }
#stage .heart { color: #ff5a6a; font-size: 15px; }
#stage .heart.off { color: rgba(255,255,255,.25); }
#stage .coinicon { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: #ffc81a; color: #7a5200; font-size: 10px; line-height: 14px; text-align: center; font-weight: 900; }
#stage .ibtn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: rgba(8,40,70,.7); color: #fff; font-weight: 900; font-size: 16px; letter-spacing: 1px; pointer-events: auto; }
#stage .prog { margin: 6px 4px 0; height: 8px; border-radius: 5px; background: rgba(255,255,255,.3); overflow: hidden; }
#stage .prog i { display: block; height: 100%; width: 0; background: var(--orange); }
#stage .stam { position: absolute; left: 12px; right: 12px; bottom: 150px; height: 9px; border-radius: 5px; background: rgba(8,40,70,.45); overflow: hidden; }
#stage .stam i { display: block; height: 100%; width: 100%; background: #5af0ff; }
#stage .stam.low i { background: #ff7a5a; }
#stage .combo { position: absolute; right: 12px; top: 74px; background: var(--orange); color: #fff; font-weight: 900; font-size: 13px; padding: 3px 10px; border-radius: 99px; }
#stage .warn { position: absolute; left: 50%; top: 104px; transform: translateX(-50%); background: #ffe14a; color: #5a3b00; font-weight: 900; letter-spacing: 1px; font-size: 14px; padding: 5px 14px; border-radius: 99px; animation: rrblink .45s infinite alternate; }
@keyframes rrblink { to { opacity: .45; } }
#stage .banner { position: absolute; left: 0; right: 0; top: 17%; text-align: center; pointer-events: none; color: #fff; text-shadow: 0 3px 0 rgba(8,40,70,.6); display: flex; flex-direction: column; gap: 2px; padding: 0 12px; }
#stage .banner b { font-size: clamp(24px, 8vw, 36px); letter-spacing: 1px; }
#stage .banner span { font-size: 14px; font-weight: 700; }
#stage .hint { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); width: 84%; background: rgba(255,255,255,.95); color: var(--ink); font-weight: 800; font-size: 15px; text-align: center; padding: 10px 14px; border-radius: 16px; box-shadow: 0 4px 0 rgba(8,40,70,.35); pointer-events: none; }
#stage .count { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: clamp(54px, 22vw, 96px); font-weight: 900; color: #fff; text-shadow: 0 5px 0 rgba(8,40,70,.55); pointer-events: none; }
#stage .flash { position: absolute; inset: 0; pointer-events: none; }

/* touch controls: two big thumb zones plus a sprint button */
#stage .pads { position: absolute; left: 0; right: 0; bottom: 0; top: 30%; pointer-events: none; }
#stage .pad { position: absolute; top: 0; bottom: 0; width: 50%; touch-action: none; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 28px; }
#stage .padL { left: 0; } #stage .padR { right: 0; }
#stage .pad span { font-size: 40px; font-weight: 900; color: rgba(255,255,255,.55); text-shadow: 0 2px 0 rgba(8,40,70,.4); pointer-events: none; width: 76px; height: 76px; line-height: 70px; text-align: center; border-radius: 50%; }
#stage .padL span { margin-right: 36px; } #stage .padR span { margin-left: 36px; }
#stage .pads.buttons .pad span { background: rgba(255,255,255,.5); color: var(--deep); box-shadow: 0 4px 0 rgba(8,40,70,.35); }
#stage .pad:active span, #stage .pad.down span { background: rgba(255,255,255,.7); }
#stage .sprint { position: absolute; left: 50%; bottom: 30px; transform: translateX(-50%); width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--orange); color: #fff; font-weight: 900; font-size: 16px; letter-spacing: 1px; box-shadow: 0 4px 0 #a04a00; touch-action: none; pointer-events: auto; z-index: 2; }
#stage .sprint:active { transform: translateX(-50%) translateY(3px); box-shadow: 0 1px 0 #a04a00; }

/* screens */
#stage .screens { position: absolute; inset: 0; pointer-events: none; }
#stage .screen { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding: 10px; pointer-events: none; }
#stage .panel { width: 100%; max-height: 100%; background: rgba(244,251,255,.97); border-radius: 20px; padding: 12px 12px 10px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 6px 0 rgba(8,40,70,.35); text-align: center; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
#stage .panel.small { max-width: 340px; align-self: center; }
#stage .panel h2 { margin: 0; font-size: 21px; color: var(--deep); letter-spacing: 1px; }
#stage .panel h3 { margin: 6px 0 2px; font-size: 14px; color: var(--deep); text-align: left; }
#stage .phead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#stage .phead .btn, #stage .phead .spacer { min-width: 64px; }
#stage .scroll { overflow-y: auto; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; touch-action: pan-y; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-right: 2px; }
#stage .menu { width: 100%; height: 100%; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
#stage .menu .logo { display: flex; flex-direction: column; text-align: center; color: #fff; text-shadow: 0 4px 0 rgba(8,40,70,.55); margin-top: 6px; }
#stage .menu .logo b { font-size: clamp(30px, 10vw, 42px); letter-spacing: 2px; line-height: 1; }
#stage .menu .logo span { font-size: 13px; font-weight: 700; margin-top: 4px; }
#stage .menu .wallet { justify-content: center; }
#stage .menu .modes { margin-top: auto; }
#stage .menu button { pointer-events: auto; }
#stage .wallet { display: flex; gap: 6px; justify-content: center; }
#stage .chip { background: rgba(8,40,70,.75); color: #fff; border-radius: 99px; padding: 4px 11px; font-weight: 800; font-size: 13px; }
#stage .modes { display: flex; flex-direction: column; gap: 8px; }
#stage .card { display: flex; flex-direction: column; gap: 3px; text-align: left; background: rgba(244,251,255,.97); border: 0; border-radius: 16px; padding: 10px 12px; color: var(--ink); box-shadow: 0 4px 0 rgba(8,40,70,.35); min-height: 56px; }
#stage .card b { font-size: 16px; color: var(--deep); }
#stage .card span { font-size: 12px; color: #3f5f78; }
#stage .card:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(8,40,70,.35); }
#stage .card.locked { opacity: .6; }
#stage .river .rtop { display: flex; justify-content: space-between; align-items: baseline; }
#stage .river .grade { background: var(--deep); color: #fff; border-radius: 99px; padding: 1px 8px; font-size: 11px; font-weight: 800; }
#stage .river .rbot { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; }
#stage .stars { color: #f0a800; letter-spacing: 2px; font-size: 15px; }
#stage .btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; padding: 8px 14px; border: 0; border-radius: 14px; background: var(--river); color: #fff; font-weight: 800; font-size: 15px; box-shadow: 0 4px 0 var(--deep); }
#stage .btn.small { min-height: 44px; padding: 6px 12px; font-size: 14px; }
#stage .btn.big { background: var(--orange); box-shadow: 0 4px 0 #a04a00; font-size: 17px; min-height: 52px; }
#stage .btn.dim, #stage .btn:disabled { background: #9db3c2; box-shadow: 0 4px 0 #6f8797; opacity: .85; }
#stage .btn.danger { background: var(--red); box-shadow: 0 4px 0 #8a1f1f; }
#stage .btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--deep); }
#stage .row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
#stage .col { display: flex; flex-direction: column; gap: 8px; }
#stage .note { margin: 0; font-size: 12px; color: #3f5f78; text-align: left; }
#stage .tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; touch-action: pan-x; }
#stage .rafttab { flex: 0 0 auto; min-width: 64px; min-height: 52px; border: 2px solid transparent; border-radius: 12px; background: #dcecf6; color: var(--ink); font-size: 12px; font-weight: 800; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 8px; }
#stage .rafttab i { width: 24px; height: 14px; border-radius: 8px; display: block; }
#stage .rafttab em { font-style: normal; font-size: 10px; color: #6a5200; }
#stage .rafttab.on { border-color: var(--orange); background: #fff; }
#stage .gname { display: flex; flex-direction: column; text-align: left; }
#stage .gname b { font-size: 18px; color: var(--deep); } #stage .gname span { font-size: 12px; color: #3f5f78; }
#stage .srow { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 800; text-align: left; }
#stage .srow span { width: 78px; flex: none; }
#stage .bar { flex: 1; height: 9px; background: rgba(18,50,74,.15); border-radius: 6px; overflow: hidden; }
#stage .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--river), #5af0ff); }
#stage .urow { display: flex; justify-content: space-between; align-items: center; gap: 8px; text-align: left; padding: 4px 0; border-bottom: 1px solid rgba(18,50,74,.12); }
#stage .urow b { display: block; font-size: 14px; } #stage .urow span { font-size: 11px; color: #3f5f78; }
#stage .setrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; font-weight: 800; font-size: 14px; min-height: 44px; }
#stage .setrow input[type=range] { flex: 1; max-width: 60%; min-height: 44px; touch-action: none; accent-color: var(--orange); }
#stage .seg { display: flex; gap: 4px; }
#stage .seg button { min-height: 44px; min-width: 44px; padding: 0 10px; border: 0; border-radius: 10px; background: #dcecf6; color: var(--ink); font-weight: 800; font-size: 13px; }
#stage .seg button.on { background: var(--river); color: #fff; }
#stage .mrow, #stage .arow { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; text-align: left; font-size: 13px; padding: 4px 0; border-bottom: 1px solid rgba(18,50,74,.1); }
#stage .mrow .bar { grid-column: 1 / 2; } #stage .mrow em, #stage .arow em { font-style: normal; font-weight: 800; color: #6a5200; }
#stage .arow span { grid-column: 1 / 2; font-size: 11px; color: #3f5f78; } #stage .arow.got { opacity: .65; }
#stage .results .rlist { display: flex; flex-direction: column; gap: 2px; }
#stage .rrow { display: flex; justify-content: space-between; font-size: 14px; padding: 2px 4px; }
#stage .medal { display: flex; flex-direction: column; align-items: center; font-weight: 900; }
#stage .medal b { font-size: 22px; } #stage .medal.m3 b { color: #d99a00; } #stage .medal.m2 b { color: #6f8797; } #stage .medal.m1 b { color: #b0652a; }
#stage .newbest { margin: 0; color: var(--orange); font-weight: 900; }
#stage .earn { display: flex; flex-direction: column; gap: 2px; background: #fff3d6; border-radius: 12px; padding: 6px; font-size: 12px; }
#stage .earn b { font-size: 18px; color: #7a5200; }
#stage .goal { margin: 0; font-size: 13px; font-weight: 800; color: var(--deep); }

/* page chrome around the stage */
.er-bar { display: flex; justify-content: center; margin-top: .6rem; }
.er-keys { text-align: center; font-size: .78rem; color: #64748b; margin-top: .5rem; }
.er-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; color: #1e293b; line-height: 1.6; font-size: .95rem; }
.er-guide h2 { font-size: 1.3rem; margin-bottom: .6rem; }
.er-guide h3 { font-size: 1.02rem; margin: 1rem 0 .3rem; }
.er-guide p { margin-bottom: .6rem; }
@media (max-height: 520px) and (orientation: landscape) { #stage .panel { padding: 8px; } #stage .menu .logo span { display: none; } }
#stage .pace { font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; padding: 1px 7px; border-radius: 9px; background: rgba(8,40,70,.55); color: #fff; margin-top: 2px; }
#stage .pace.ahead { color: #8cf0a6; } #stage .pace.behind { color: #ffb3a0; }
#stage .results .medal { animation: rrpop .5s cubic-bezier(.2,1.6,.4,1) both; }
#stage .results .newbest { animation: rrpop .6s .2s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes rrpop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #stage .results .medal, #stage .results .newbest { animation: none; } }

/* Full screen (shell native + immersive): the stage fills the area under the dock, chrome is hidden. */
html.pip-immersive .game-wrap.pip-stage, html.pip-native .game-wrap.pip-stage { display: flex; flex-direction: column; padding: 0; margin: 0; max-width: none; overflow: hidden; }
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-native .game-wrap.pip-stage > .game-title, html.pip-native .game-wrap.pip-stage > .er-bar, html.pip-native .game-wrap.pip-stage > .er-keys { display: none !important; }
html.pip-immersive .game-wrap.pip-stage #stage, html.pip-native .game-wrap.pip-stage #stage { flex: 1 1 auto; min-height: 0; width: 100%; max-width: none; height: auto; aspect-ratio: auto; margin: 0; border-radius: 0; }
html.pip-immersive #stage .hud, html.pip-native #stage .hud { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
html.pip-immersive #stage .pad, html.pip-native #stage .pad { padding-bottom: max(28px, env(safe-area-inset-bottom)); }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .pads, html.pip-native #stage .pads { top: 22%; }
  #stage .pad { padding-bottom: 14px; }
}
/* Full screen landscape: river list as a grid so every river is on screen. */
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .panel:has(.river) .scroll, html.pip-native #stage .panel:has(.river) .scroll { display: grid; grid-template-columns: repeat(4, 1fr); align-content: start; gap: 6px; }
  html.pip-immersive #stage .river.card, html.pip-native #stage .river.card { min-height: 64px; padding: 6px 8px; gap: 2px; }
  html.pip-immersive #stage .river .rblurb, html.pip-native #stage .river .rblurb { font-size: 11px; line-height: 1.15; }
  html.pip-immersive #stage .river .rtop b, html.pip-native #stage .river .rtop b { font-size: 13px; }
}
