/* Harbour Dash 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 { --cobalt:#2f6df0; --cobalt-d:#1d4bb8; --sun:#ffc21a; --tang:#ff8a1f; --green:#4ad45a; --ink:#23304f; --cream:#fff3d6;
  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(#2f6df0 0%, #74b9ff 55%, #dff2ff 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 #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 input { 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(#2f6df0 0%, #74b9ff 55%, #dff2ff 100%); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 3px 0 rgba(20,40,110,.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: 42px; height: 42px; border-radius: 50%; border: 6px solid rgba(255,255,255,.35); border-top-color: var(--sun); animation: erspin .8s linear infinite; }
@keyframes erspin { 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(20,32,70,.85); color: #fff; font-weight: 700; }
#stage #ctxlost[hidden], #stage .hud[hidden], #stage .screen[hidden], #stage .pad[hidden], #stage .hint-bubble[hidden], #stage .pwi[hidden] { display: none; }

/* HUD */
#stage .hud { position: absolute; inset: 0; display: block; padding: max(8px, env(safe-area-inset-top)) 10px 8px; pointer-events: none; font-family: inherit; font-size: inherit; }
#stage .hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; padding-right: 50px; }
#stage .stat { background: rgba(20,40,110,.55); color: #fff; border-radius: 12px; padding: 4px 9px; display: flex; align-items: baseline; gap: 4px; text-shadow: 0 1px 0 rgba(0,0,0,.3); min-height: 30px; }
#stage .stat b { font-size: 17px; font-variant-numeric: tabular-nums; }
#stage .stat .lbl { font-size: 10px; opacity: .8; letter-spacing: 1px; }
#stage .stat.coins { align-items: center; }
#stage .stat.coins img { width: 18px; height: 18px; }
#stage .mult { background: var(--sun); color: #4a3200; border-radius: 8px; padding: 0 6px; font-weight: 800; font-size: 13px; }
#stage .mult.pop { animation: erpop .35s ease-out; }
@keyframes erpop { 0% { transform: scale(1.6); } 100% { transform: scale(1); } }
#stage .pausebtn { position: absolute; top: max(8px, env(safe-area-inset-top)); right: 8px; width: 44px; height: 44px; border-radius: 12px; border: 0; background: rgba(20,40,110,.65); color: #fff; font-weight: 800; font-size: 16px; letter-spacing: 1px; pointer-events: auto; }
#stage .pw { display: flex; gap: 6px; margin-top: 8px; }
#stage .pwi { width: 52px; background: rgba(255,255,255,.85); border-radius: 10px; padding: 3px; }
#stage .pwi.low { animation: erblink .5s infinite alternate; }
@keyframes erblink { to { opacity: .45; } }
#stage .pwi img { display: block; width: 28px; height: 28px; margin: 0 auto 2px; }
#stage .pwi .bar { height: 5px; background: rgba(0,0,0,.15); border-radius: 3px; overflow: hidden; }
#stage .pwi .bar i { display: block; height: 100%; background: var(--green); transform-origin: left; }
#stage .missions { position: absolute; left: 10px; bottom: 10px; width: 46%; display: flex; flex-direction: column; gap: 3px; opacity: .9; }
#stage.with-pad .missions { bottom: 138px; }
#stage .missions .m { position: relative; background: rgba(20,40,110,.5); color: #fff; font-size: 11px; padding: 3px 7px; border-radius: 7px; overflow: hidden; }
#stage .missions .m span { position: relative; z-index: 1; }
#stage .missions .m i { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(74,212,90,.55); }
#stage .missions .m.done { opacity: .6; }
#stage .hint-bubble { position: absolute; left: 50%; top: 34%; transform: translateX(-50%); max-width: 86%; background: rgba(255,255,255,.95); color: var(--ink); font-weight: 800; font-size: 15px; text-align: center; padding: 10px 16px; border-radius: 16px; box-shadow: 0 4px 0 rgba(20,40,110,.35); animation: erfloat 1.1s ease-in-out infinite alternate; }
@keyframes erfloat { to { transform: translate(-50%, -6px); } }
#stage .pad { position: absolute; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; }
#stage .pad button { height: 64px; min-width: 56px; border: 0; border-radius: 16px; background: rgba(255,255,255,.82); color: var(--cobalt-d); font-size: 26px; box-shadow: 0 4px 0 rgba(20,40,110,.4); touch-action: none; }
#stage .pad button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(20,40,110,.4); }

#stage .feed { position: absolute; left: 0; right: 0; top: 26%; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; }
#stage .feed .f { background: rgba(255,255,255,.92); color: var(--ink); font-weight: 800; font-size: 13px; padding: 4px 12px; border-radius: 99px; animation: erfeed 1.8s ease-out forwards; }
#stage .feed .f.mission { background: var(--green); color: #063; }
#stage .feed .f.pw { background: var(--sun); color: #4a3200; }
@keyframes erfeed { 0% { opacity: 0; transform: translateY(8px); } 12% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }
#stage .banner { position: absolute; left: 0; right: 0; top: 18%; text-align: center; pointer-events: none; opacity: 0; transform: scale(.8); transition: opacity .25s, transform .25s; color: #fff; text-shadow: 0 3px 0 rgba(20,40,110,.55); }
#stage .banner.show { opacity: 1; transform: scale(1); }
#stage .b-main { font-size: clamp(26px, 9vw, 40px); font-weight: 900; letter-spacing: 2px; }
#stage .b-sub { font-size: 14px; font-weight: 700; }
#stage .flash { position: absolute; inset: 0; opacity: 0; pointer-events: none; background: #fff; }

/* screens */
#stage .screen { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding: 10px; pointer-events: none; overflow-y: auto; }
#stage .screen .panel { pointer-events: auto; width: 100%; max-height: 100%; background: rgba(255,247,226,.96); border-radius: 20px; padding: 14px 14px 12px; display: flex; flex-direction: column; gap: 9px; box-shadow: 0 6px 0 rgba(20,40,110,.35); text-align: center; }
#stage .screen .panel { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
#stage .panel.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
#stage .srow input[type=range] { touch-action: none; }
/* inside the site's own game shell (native or immersive full screen) keep the 9:16 stage fitting the viewport */
.game-wrap.pip-stage #stage { width: min(100%, calc((100vh - 64px) * 0.5625)); width: min(100%, calc((100svh - 64px) * 0.5625)); }
#stage .panel h2 { margin: 0; font-size: 22px; color: var(--cobalt-d); letter-spacing: 1px; }
#stage .logo { display: flex; flex-direction: column; line-height: 1; }
#stage .logo span { font-size: 15px; letter-spacing: 6px; color: var(--cobalt); font-weight: 800; }
#stage .logo b { font-size: clamp(30px, 10vw, 44px); color: var(--tang); letter-spacing: 3px; text-shadow: 0 3px 0 rgba(120,50,0,.25); }
#stage .tag { margin: 0; font-size: 13px; color: #4a5778; }
#stage .tag.small { font-size: 12px; }
#stage .rankbar { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 13px; color: var(--cobalt-d); }
#stage .rankbar .bar { flex: 1; height: 10px; background: rgba(35,48,79,.15); border-radius: 6px; overflow: hidden; }
#stage .rankbar .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cobalt), #5ab0ff); }
#stage .coinpill { display: inline-flex; align-items: center; gap: 4px; background: #fff; border-radius: 99px; padding: 3px 10px 3px 6px; font-weight: 800; color: #6a4a00; font-size: 14px; }
#stage .coinpill img { width: 18px; height: 18px; }
#stage .chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
#stage .chip { min-height: 44px; padding: 6px 12px; border-radius: 12px; border: 2px solid #c9d4ee; background: #fff; color: var(--ink); font-weight: 800; font-size: 13px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
#stage .chip small { font-size: 10px; font-weight: 700; opacity: .7; }
#stage .chip.on { border-color: var(--cobalt); background: #e6efff; color: var(--cobalt-d); }
#stage .chip:disabled { opacity: .5; cursor: default; }
#stage .chip.wide { width: 100%; }
#stage .chips.stages .chip { flex: 1 1 44%; }
#stage .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 8px 14px; border: 0; border-radius: 14px; background: var(--cobalt); color: #fff; font-weight: 800; font-size: 15px; box-shadow: 0 4px 0 var(--cobalt-d); text-decoration: none; }
#stage .btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--cobalt-d); }
#stage .btn:disabled { background: #9aa7c6; box-shadow: 0 4px 0 #7886a8; cursor: default; }
#stage .btn.big { min-height: 56px; font-size: 22px; letter-spacing: 3px; background: var(--tang); box-shadow: 0 5px 0 #b85a00; }
#stage .btn.danger { background: #d94a4a; box-shadow: 0 4px 0 #962b2b; }
#stage .btn.buy { min-width: 84px; font-size: 14px; }
#stage .btn.buy img { width: 18px; height: 18px; }
#stage .row { display: flex; gap: 8px; } #stage .row > * { flex: 1; }
#stage .col { display: flex; flex-direction: column; gap: 8px; }
#stage .best { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; color: #4a5778; flex-wrap: wrap; }
#stage .linkbtn { background: none; border: 0; color: var(--cobalt-d); font-weight: 800; font-size: 12px; text-decoration: underline; min-height: 44px; padding: 0 8px; }
#stage .tabs { display: flex; gap: 6px; }
#stage .tabs button { flex: 1; min-height: 44px; border: 2px solid #c9d4ee; background: #fff; border-radius: 12px; font-weight: 800; font-size: 13px; color: var(--ink); }
#stage .tabs button.on { border-color: var(--cobalt); background: #e6efff; color: var(--cobalt-d); }
#stage .items { display: flex; flex-direction: column; gap: 8px; text-align: left; }
#stage .item { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 14px; padding: 8px; }
#stage .item > img { width: 44px; height: 44px; }
#stage .swatch { width: 44px; height: 44px; border-radius: 12px; flex: none; border: 2px solid rgba(0,0,0,.1); }
#stage .meta { flex: 1; display: flex; flex-direction: column; min-width: 0; font-size: 12px; color: #4a5778; }
#stage .meta b { font-size: 14px; color: var(--ink); }
#stage .pips { display: flex; gap: 3px; margin-top: 3px; } #stage .pips i { width: 14px; height: 6px; border-radius: 3px; background: #d5dcee; } #stage .pips i.on { background: var(--green); }
#stage .owned { font-weight: 800; font-size: 12px; color: #2a8a3a; min-width: 70px; text-align: center; } #stage .owned.lock { color: #8a6a2a; }
#stage .shop-head { display: flex; justify-content: space-between; align-items: center; }
#stage .mlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; text-align: left; }
#stage .mlist li { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: #fff; border-radius: 10px; padding: 8px 10px; font-size: 13px; font-weight: 700; }
#stage .mlist li.done { background: #d8f5dc; }
#stage .mlist small { display: block; font-weight: 600; opacity: .7; font-size: 11px; }
#stage .mlist em { font-style: normal; font-weight: 800; font-size: 12px; white-space: nowrap; }
#stage .srow { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 800; font-size: 14px; text-align: left; min-height: 44px; }
#stage .srow input[type=range] { flex: 1; height: 32px; accent-color: var(--cobalt); } #stage .srow output { width: 28px; text-align: right; font-size: 12px; }
#stage .seg { display: flex; gap: 4px; } #stage .seg button { min-height: 44px; min-width: 56px; border: 2px solid #c9d4ee; background: #fff; border-radius: 10px; font-weight: 800; font-size: 13px; color: var(--ink); }
#stage .seg button.on { background: var(--cobalt); border-color: var(--cobalt); color: #fff; }
#stage .plain { text-align: left; margin: 0; padding-left: 18px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
#stage .big-score { font-size: clamp(34px, 12vw, 52px); font-weight: 900; color: var(--tang); text-shadow: 0 3px 0 rgba(120,50,0,.2); line-height: 1; }
#stage .grid, #stage .rewards { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#stage .grid div, #stage .rewards div { background: #fff; border-radius: 10px; padding: 5px; display: flex; flex-direction: column; font-size: 11px; color: #4a5778; }
#stage .grid b, #stage .rewards b { font-size: 16px; color: var(--ink); }
#stage .gain { margin: 0; font-weight: 800; font-size: 13px; color: #2a7a3a; }
#stage .goal { margin: 0; font-weight: 800; font-size: 13px; color: var(--cobalt-d); background: #e6efff; border-radius: 10px; padding: 7px 9px; }

/* landscape phones: panels become a two-column friendly width, pad stays reachable */
@media (orientation: landscape) and (max-height: 520px) {
  #stage.is-big .screen { align-items: center; }
  #stage.is-big .screen .panel { max-width: 460px; }
  #stage.is-big .pad button { height: 56px; }
}
@media (max-height: 560px) { #stage .logo b { font-size: 28px; } #stage .big-score { font-size: 30px; } }
@media (prefers-reduced-motion: reduce) { #stage * { animation: none !important; transition: none !important; } }

/* page chrome under the game */
.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; }

/* shell full screen (native and immersive): the stage fills the space under the dock; the page's own Play big is redundant */
html.pip-immersive .game-wrap { display: flex; flex-direction: column; }
html.pip-immersive .game-wrap > #stage { flex: 1 1 0; min-height: 0; width: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-immersive .er-bar, html.pip-immersive .er-keys, html.pip-immersive .game-wrap > noscript { display: none; }
.er-bar { display: none; }
#stage::after { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1; background: radial-gradient(ellipse at 50% 45%, transparent 62%, rgba(10,25,80,.22) 100%); }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .screen { align-items: center; }
  html.pip-immersive #stage .screen .panel { max-width: 460px; max-height: 100%; overflow-y: auto; }
  html.pip-immersive #stage .pad button { height: 56px; min-width: 56px; }
  html.pip-immersive #stage .missions { display: none; }
}

/* wave4: shell full screen on phones (native or immersive), landscape. Menu and results fit without scrolling. */
html.pip-native #stage { aspect-ratio: auto; border-radius: 0; }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-native #stage .missions { display: none; }
  html.pip-native #stage .pad button { height: 56px; min-width: 56px; }
  html.pip-native #stage .screen, html.pip-immersive #stage .screen { align-items: center; padding: 6px 12px; }
  html.pip-native #stage .screen .panel, html.pip-immersive #stage .screen .panel { max-width: 460px; max-height: 100%; padding: 8px 12px; gap: 5px; }

  /* menu: one compact column, descriptions and rank bar hidden */
  html.pip-native #stage .panel.menu, html.pip-immersive #stage .panel.menu { max-width: 620px; }
  html.pip-native #stage .panel.menu .rankbar, html.pip-immersive #stage .panel.menu .rankbar,
  html.pip-native #stage .panel.menu .tag, html.pip-immersive #stage .panel.menu .tag { display: none; }
  html.pip-native #stage .panel.menu .logo, html.pip-immersive #stage .panel.menu .logo { flex-direction: row; justify-content: center; align-items: baseline; gap: 10px; }
  html.pip-native #stage .panel.menu .logo b, html.pip-immersive #stage .panel.menu .logo b { font-size: 24px; }
  html.pip-native #stage .panel.menu .chips.stages .chip, html.pip-immersive #stage .panel.menu .chips.stages .chip { flex: 1 1 20%; }
  html.pip-native #stage .panel.menu .btn.big, html.pip-immersive #stage .panel.menu .btn.big { min-height: 48px; font-size: 20px; }

  /* results: stats on the left, buttons always visible on the right */
  html.pip-native #stage .panel.results, html.pip-immersive #stage .panel.results { display: grid; grid-template-columns: minmax(0, 1fr) 210px; column-gap: 14px; row-gap: 0; align-content: start; max-width: 680px; }
  html.pip-native #stage .panel.results > *, html.pip-immersive #stage .panel.results > * { grid-column: 1; margin-bottom: 5px; }
  html.pip-native #stage .panel.results > .col, html.pip-immersive #stage .panel.results > .col { grid-column: 2; grid-row: 1 / span 12; align-self: start; position: sticky; top: 0; margin-bottom: 0; }
  html.pip-native #stage .panel.results .big-score, html.pip-immersive #stage .panel.results .big-score { font-size: 28px; }
  html.pip-native #stage .panel.results h2, html.pip-immersive #stage .panel.results h2 { font-size: 18px; }
}
