:root {
  --ink: #1d2b3a;
  --snow: #eef4fa;
  --wood: #c98b4a;
  --wood-dark: #8a5526;
  --cash: #52b646;
  --danger: #e2433b;
  --ice: #7cc4ec;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #9fb8cc;
  font-family: "Arial Black", "Segoe UI Black", system-ui, sans-serif;
  color: var(--ink);
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; /* no iOS long-press menu */
  overscroll-behavior: none;    /* no pull-to-refresh / bounce */
  touch-action: none;
}

#stage { position: fixed; inset: 0; margin: auto; overflow: hidden; }
/* ?shorts=1 frames the game as a 9:16 phone screen, handy for recording on desktop */
body.shorts #stage { aspect-ratio: 9 / 16; height: 100%; width: auto; max-width: 100%; }

#game { display: block; width: 100%; height: 100%; }

#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.label {
  position: absolute; transform: translate(-50%, -50%);
  font-size: 15px; color: #fff; white-space: nowrap;
  /* a thin dark outline keeps labels readable on light ground (snow, beach sand) */
  text-shadow: 0 2px 0 rgba(0,0,0,.35), 0 0 2px rgba(0,0,0,.65), 0 0 6px rgba(0,0,0,.3);
}
.zone-label { display: flex; align-items: center; gap: 4px; font-size: 17px; }
.zone-label .name { font-size: 11px; opacity: .95; display: block; text-align: center; }
.float-text {
  position: absolute; transform: translate(-50%, -50%);
  font-size: 20px; color: #fff; white-space: nowrap; pointer-events: none;
  text-shadow: 0 2px 0 rgba(0,0,0,.4), 0 0 2px rgba(0,0,0,.65);
}
.float-text.cash { color: #b8ff9c; }
.float-text.warn { color: #ffd34d; }
.float-text.hurt { color: #ff8a80; }

#hud { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 10px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.pill {
  display: flex; align-items: center; gap: 6px;
  background: rgba(20, 35, 50, .55); color: #fff;
  border-radius: 999px; padding: 4px 14px 4px 6px; font-size: 20px; min-width: 96px;
}
.pill.small { font-size: 14px; min-width: 0; }
.pill .ico { font-size: 18px; }
.pill.bump { animation: bump .18s ease-out; }
#tide-pill.hidden { display: none; }
#tide-bar { width: 56px; height: 8px; border-radius: 4px; background: rgba(255,255,255,.25); overflow: hidden; }
#tide-fill { height: 100%; width: 0; border-radius: 4px; background: linear-gradient(90deg, #7fd6ea, #26b4e6); }
#tide-arrow { width: 14px; text-align: center; font-size: 12px; }
@keyframes bump { 50% { transform: scale(1.15); } }

#wave { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); text-align: center; pointer-events: none; }
#wave-title { color: #fff; font-size: 16px; text-shadow: 0 2px 0 rgba(0,0,0,.35), 0 0 2px rgba(0,0,0,.7), 0 0 6px rgba(0,0,0,.3); }
#wave-bar { width: 130px; height: 9px; margin-top: 4px; background: rgba(20,35,50,.5); border-radius: 9px; overflow: hidden; }
#wave-fill { height: 100%; width: 0; background: linear-gradient(90deg, #ffd34d, #ff7a3d); }

/* narrow phones: move the wave/boss block to the right (next to "?") so it never covers the cash */
@media (max-width: 460px) {
  #wave { left: auto; right: 58px; transform: none; text-align: right; }
  #wave-bar { margin-left: auto; }
  #boss-bar { width: 150px; margin: 3px 0 0 auto; }
}

/* forged armor: thin steel-blue bar right above the hp bar */
#armor-bar { position: absolute; bottom: calc(max(18px, env(safe-area-inset-bottom)) + 16px); left: 50%; transform: translateX(-50%); width: 160px; height: 7px; background: rgba(20,35,50,.5); border-radius: 7px; overflow: hidden; pointer-events: none; }
#armor-fill { height: 100%; width: 0; background: linear-gradient(90deg, #7fb8ff, #c9e3ff); transition: width .15s; }

/* boss health under the wave counter */
#boss { margin-top: 8px; }
#boss-name { color: #ffd34d; font-size: 13px; text-shadow: 0 2px 0 rgba(0,0,0,.5), 0 0 2px rgba(0,0,0,.85), 0 0 6px rgba(0,0,0,.4); }
#boss-bar { width: 200px; height: 10px; margin: 3px auto 0; background: rgba(20,35,50,.6); border-radius: 10px; overflow: hidden; border: 2px solid rgba(255,211,77,.8); }
#boss-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #e2433b, #ff7a3d); transition: width .15s; }

/* poisoned: green pulsing edges */
#poison { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 70px 10px rgba(120, 220, 60, .55); animation: poisonpulse 1s ease-in-out infinite; }
@keyframes poisonpulse { 50% { box-shadow: inset 0 0 40px 4px rgba(120, 220, 60, .3); } }

#hp { position: absolute; bottom: max(18px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: 160px; height: 12px; background: rgba(20,35,50,.5); border-radius: 12px; overflow: hidden; pointer-events: none; }
#hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #58d15a, #9bef6c); transition: width .15s; }

#banner {
  position: absolute; top: 22%; left: 0; right: 0; text-align: center; pointer-events: none;
  font-size: 34px; color: #fff; opacity: 0;
  text-shadow: 0 3px 0 rgba(0,0,0,.35), 0 0 18px rgba(226,67,59,.6);
}
#banner.show { animation: banner 2.2s ease-out forwards; }
@keyframes banner {
  0% { opacity: 0; transform: scale(2.2); }
  12% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(.9); }
}

#joy-base {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px;
  border-radius: 50%; background: rgba(255,255,255,.22); border: 3px solid rgba(255,255,255,.45);
  display: none; pointer-events: none;
}
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; background: rgba(255,255,255,.85); box-shadow: 0 3px 8px rgba(0,0,0,.25);
}

button {
  font-family: inherit; font-size: 24px; color: #fff; cursor: pointer;
  border: 0; border-radius: 16px; padding: 12px 38px;
  background: linear-gradient(#ffb14a, #f07a22); box-shadow: 0 5px 0 #b3531a;
}
button:active { transform: translateY(3px); box-shadow: 0 2px 0 #b3531a; }

/* ---------- guidance ---------- */
.station-label { font-size: 13px; text-align: center; line-height: 1.15; }
.station-label.learned small { display: none; }
.station-label small { display: block; font-size: 10px; font-family: system-ui, sans-serif; font-weight: 800; opacity: .95; }

#hint {
  /* centered, as wide as its text up to the screen width (left:50% would cap it at half) */
  position: absolute; left: 12px; right: 12px; margin: 0 auto; width: fit-content;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 32px);
  display: flex; align-items: center; gap: 8px;
  max-width: min(520px, calc(100% - 24px)); padding: 8px 14px 8px 10px;
  background: rgba(20, 35, 50, .72); color: #fff; border-radius: 14px;
  font-family: system-ui, sans-serif; font-weight: 700; font-size: 14px; line-height: 1.25;
  pointer-events: none;
}
.hidden { display: none !important; }
body:not(.playing) #hint { display: none; } /* no tips behind the title screen */
#hint-ico { font-size: 20px; }
#hint.pulse { animation: hintpulse .5s ease-out; }
@keyframes hintpulse { 0% { transform: scale(1.08); background: rgba(255, 180, 60, .85); } }

#help-btn {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 10px;
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  font-size: 22px; line-height: 40px; box-shadow: 0 3px 0 #b3531a;
}

#sound-btn {
  position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 48px); right: 10px;
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  font-size: 18px; line-height: 40px;
  background: rgba(20, 35, 50, .55); box-shadow: none;
}

/* ---------- how to play ---------- */
#help { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10, 25, 40, .6); padding: 16px; }
.help-card {
  width: min(100%, 460px); max-height: 100%; overflow-y: auto;
  background: #f4f8fc; border-radius: 20px; padding: 18px 16px 16px; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.help-title { font-size: 26px; color: #2f7fd8; margin-bottom: 10px; }
.help-list { text-align: left; display: flex; flex-direction: column; gap: 8px; }
.help-list .row { display: flex; gap: 10px; align-items: flex-start; font-family: system-ui, sans-serif; font-size: 14px; line-height: 1.3; }
.help-list .row > span { font-size: 22px; width: 28px; text-align: center; flex: none; }
.help-list b { display: block; font-family: "Arial Black", system-ui, sans-serif; font-size: 13px; color: #1d2b3a; }
.help-tip { margin: 12px 0 14px; padding: 10px; border-radius: 12px; background: #fff3d1; font-family: system-ui, sans-serif; font-size: 13px; text-align: left; }
#help-close { width: 100%; }

#defeat { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(30, 10, 10, .45); }
#defeat.hidden, #title-screen.hidden { display: none; }
.defeat-card { text-align: center; }
.defeat-title { font-size: 56px; color: var(--danger); text-shadow: 0 4px 0 #fff, 0 0 30px rgba(0,0,0,.4); letter-spacing: 2px; }
.defeat-sub { color: #fff; margin: 6px 0 22px; font-size: 16px; }

/* ---------- victory + world map (end of a map) ---------- */
#victory { position: absolute; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 50% 42%, rgba(255, 200, 80, .4), transparent 40%), rgba(10, 25, 40, .74); padding: 16px; z-index: 4; }
#victory.hidden, #worldmap.hidden, #map-btn.hidden { display: none; }
.victory-card { text-align: center; animation: victory-in .5s cubic-bezier(.3, 1.6, .5, 1); }
.victory-crown { font-size: 64px; line-height: 1; filter: drop-shadow(0 4px 0 rgba(0,0,0,.25)); }
.victory-title { font-size: 56px; color: #ffc83d; text-shadow: 0 4px 0 #8a5526, 0 0 30px rgba(0,0,0,.35); letter-spacing: 2px; }
.victory-sub { color: #fff; margin: 6px 0 6px; font-size: 16px; text-shadow: 0 2px 0 rgba(0,0,0,.3); }
.victory-stats { color: #fff; margin-bottom: 22px; font-family: system-ui, sans-serif; font-weight: 700; font-size: 14px; opacity: .9; }
@keyframes victory-in { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#worldmap { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10, 25, 40, .6); padding: 16px; z-index: 5; }
.map-card { width: min(100%, 420px); background: #f4f8fc; border-radius: 20px; padding: 18px 16px 16px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.map-title { font-size: 24px; color: #2f7fd8; margin-bottom: 12px; }
/* the sea, with one patch of land per world (colored by main.js, dark while locked) */
.map-board { position: relative; aspect-ratio: 4 / 5; width: min(100%, 60vh * .8); margin: 0 auto; border-radius: 14px; overflow: hidden; background-color: #4f9fd0; }
.map-path { position: absolute; inset: 0; width: 100%; height: 100%; }
.map-path line { stroke-dasharray: 2 2; stroke-linecap: round; vector-effect: non-scaling-stroke; stroke-width: 3; }
.map-path line.open { stroke: #8a5526; }
.map-path line.dark { stroke: #22303e; opacity: .7; }
.map-node { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 1px; background: none; box-shadow: none; padding: 0; border: 0; color: inherit; font: inherit; }
.map-node:active { transform: translate(-50%, -50%) scale(.95); box-shadow: none; }
.map-pin { position: relative; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 24px; background: #fff; box-shadow: 0 4px 0 #b8cadb, 0 6px 14px rgba(0,0,0,.2); }
.map-badge { position: absolute; right: -8px; top: -9px; font-size: 17px; }
.map-node b { font-size: 10px; color: #fff; margin-top: 3px; white-space: nowrap; text-shadow: 0 1px 0 rgba(0,0,0,.6), 0 0 6px rgba(0,0,0,.45); }
.map-node small { font-family: system-ui, sans-serif; font-weight: 800; font-size: 9px; letter-spacing: .4px; padding: 1px 6px; border-radius: 999px; }
.map-node.beaten small { background: var(--cash); color: #fff; }
.map-node.soon small { background: #1d2b3a; color: #ffd34d; }
.map-node.here .map-pin { box-shadow: 0 0 0 3px #ffd34d, 0 4px 0 #b8cadb, 0 6px 14px rgba(0,0,0,.25); }
/* locked worlds: a dark silhouette, no name */
.map-node.locked .map-pin { background: #26323f; box-shadow: 0 4px 0 #16202a; }
.map-node.locked .map-pin > span:first-child { filter: brightness(0); opacity: .6; }
.map-node.locked b { color: #c7d3df; opacity: .75; }
.map-endless { font-family: system-ui, sans-serif; font-size: 14px; margin: 12px 4px 14px; }
#map-play { width: 100%; }
#map-btn {
  position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 142px); right: 10px;
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  font-size: 18px; line-height: 40px;
  background: rgba(20, 35, 50, .55); box-shadow: none;
}

#title-screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: linear-gradient(rgba(170, 210, 240, .55), rgba(120, 160, 195, .7));
}
.loop { display: flex; align-items: center; gap: 6px; margin: 2px 0 14px; color: #fff; font-size: 12px; text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.loop div { display: flex; flex-direction: column; align-items: center; gap: 2px; background: rgba(20, 35, 50, .35); border-radius: 12px; padding: 6px 8px; min-width: 54px; }
.loop span { font-size: 24px; }
.loop i { font-style: normal; font-size: 20px; opacity: .8; }
#title-screen button { width: min(70vw, 260px); }
button.secondary { background: linear-gradient(#5fb0f0, #2f7fd8); box-shadow: 0 5px 0 #1f5a9c; font-size: 18px; padding: 10px 20px; }
button.secondary:active { box-shadow: 0 2px 0 #1f5a9c; }
button.link { background: none; box-shadow: none; font-size: 13px; padding: 4px; text-decoration: underline; font-family: system-ui, sans-serif; font-weight: 700; opacity: .9; }
.logo { font-size: 64px; line-height: .95; text-align: center; color: #fff; text-shadow: 0 5px 0 #3a78a8, 0 10px 24px rgba(0,0,0,.25); letter-spacing: 3px; }
.tag { color: #fff; font-size: 16px; text-shadow: 0 2px 0 rgba(0,0,0,.25); margin-bottom: 12px; }
.hint { color: #fff; font-size: 12px; opacity: .85; font-family: system-ui, sans-serif; font-weight: 600; }

/* ---------- options (⚙️): language + sound ---------- */
#options-btn {
  position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 96px); right: 10px;
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  font-size: 18px; line-height: 40px;
  background: rgba(20, 35, 50, .55); box-shadow: none;
}
#options { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10, 25, 40, .6); padding: 16px; z-index: 5; }
.opt-card { width: min(100%, 360px); background: #f4f8fc; border-radius: 20px; padding: 18px 16px 16px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.opt-title { font-size: 24px; color: #2f7fd8; margin-bottom: 14px; }
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; margin-bottom: 16px; text-align: left; }
.seg { display: flex; background: #dde8f2; border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { display: flex; align-items: center; gap: 5px; border-radius: 9px; padding: 7px 10px; font-size: 13px; color: var(--ink); background: none; box-shadow: none; }
.seg button:active { transform: none; box-shadow: none; }
.seg button.on { background: #fff; box-shadow: 0 2px 0 #b8cadb; color: #2f7fd8; }
.seg .flag { width: 18px; height: 12px; }
#options-close { width: 100%; }

/* small hand-drawn flags (SVG built in main.js) */
.flag { display: inline-block; flex: none; border-radius: 3px; overflow: hidden; box-shadow: 0 1px 0 rgba(0,0,0,.2); }
.flag svg { display: block; width: 100%; height: 100%; }

/* title screen: current language, opens the options */
#lang-link {
  position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; width: auto !important;
  display: flex; align-items: center; gap: 6px; text-decoration: none; opacity: 1;
  background: rgba(20, 35, 50, .55); border-radius: 999px; padding: 5px 12px 5px 6px; font-size: 13px;
}
#lang-link .flag { width: 22px; height: 15px; }

/* ---------- first launch: signpost language picker ---------- */
#lang-screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: linear-gradient(rgba(170, 210, 240, .55), rgba(120, 160, 195, .7));
}
#lang-screen .ask { color: #fff; font-size: 14px; background: rgba(20,35,50,.55); border-radius: 999px; padding: 6px 16px; margin: 6px 0 22px; text-align: center; }
#lang-screen .post { position: relative; display: flex; flex-direction: column; align-items: center; gap: 12px; padding-bottom: 70px; }
#lang-screen .post::before { /* the pole */
  content: ""; position: absolute; top: -12px; bottom: 0; left: 50%; width: 22px; margin-left: -11px;
  background: linear-gradient(90deg, #7a4a20, #a8703a 45%, #7a4a20); border-radius: 6px;
}
#lang-screen .post::after { /* snow mound at its foot */
  content: ""; position: absolute; bottom: -18px; left: 50%; width: 160px; height: 44px; margin-left: -80px;
  background: radial-gradient(ellipse at 50% 30%, #fff 0 60%, transparent 62%);
}
.plank {
  position: relative; z-index: 1; display: flex; align-items: center; gap: 12px;
  width: 250px; height: 62px; padding: 0 22px 0 18px; border-radius: 0; font-size: 22px;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.05) 0 3px, transparent 3px 9px), linear-gradient(#d69a58, #b87a3c);
  box-shadow: 0 5px 0 var(--wood-dark), inset 0 2px 0 rgba(255,255,255,.25);
  text-shadow: 0 2px 0 rgba(90,50,15,.55); transition: transform .15s;
  clip-path: polygon(0 0, 88% 0, 100% 50%, 88% 100%, 0 100%);
}
.plank:active { transform: scale(.97); box-shadow: 0 5px 0 var(--wood-dark); }
.plank.left { clip-path: polygon(12% 0, 100% 0, 100% 100%, 12% 100%, 0 50%); padding: 0 18px 0 34px; justify-content: flex-end; }
.plank:nth-child(1) { transform: rotate(-3deg); }
.plank:nth-child(2) { transform: rotate(2deg); }
.plank:nth-child(3) { transform: rotate(-1.5deg); }
.plank .snowcap { position: absolute; top: -2px; left: 8%; right: 14%; height: 9px; background: #fff; border-radius: 0 0 8px 8px; opacity: .95; }
.plank .code { font-size: 12px; opacity: .8; margin-left: auto; }
.plank.left .code { margin: 0 auto 0 0; }
.plank .nail { width: 8px; height: 8px; border-radius: 50%; background: #5c3a18; box-shadow: inset 1px 1px 0 rgba(255,255,255,.3); }
.plank.sel { background: repeating-linear-gradient(0deg, rgba(0,0,0,.05) 0 3px, transparent 3px 9px), linear-gradient(#ffc56a, #f08a2a); transform: scale(1.06) rotate(0deg); }
.plank.sel .code { display: none; }
.plank.sel::after { content: "✔"; position: absolute; right: 38px; font-size: 18px; }
.plank.left.sel::after { right: auto; left: 38px; }
#lang-go { margin-top: -30px; z-index: 2; width: min(70vw, 260px); }
.help-list i { font-style: normal; }
