@font-face { font-family: Fredoka; font-weight: 500; font-display: swap; src: url(../fonts/fredoka-latin-500-normal.woff2) format('woff2'); }
@font-face { font-family: Fredoka; font-weight: 600; font-display: swap; src: url(../fonts/fredoka-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: Fredoka; font-weight: 700; font-display: swap; src: url(../fonts/fredoka-latin-700-normal.woff2) format('woff2'); }

:root {
  --ink: #1c2a5e;
  --sky: #38bdf0;
  --sky-deep: #1994dc;
  --sun: #ffd21f;
  --sun-deep: #f59a0b;
  --leaf: #4fd13a;
  --leaf-deep: #23a12d;
  --paper: #fffdf4;
  --pink: #ff7fb3;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--sky);
  font-family: Fredoka, 'Trebuchet MS', 'Avenir Next Rounded', system-ui, sans-serif; font-weight: 600; color: var(--ink);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none; touch-action: manipulation;
}
img { display: block; -webkit-user-drag: none; pointer-events: none; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }

#game { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

.screen { position: fixed; inset: 0; z-index: 20; overflow: hidden; background: var(--sky); }
.overlay { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; background: rgba(16, 40, 90, .55); }

/* Shared pieces */
.icon-btn { width: 60px; height: 60px; flex: none; transition: transform .1s; }
.icon-btn img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 3px 0 rgba(20, 30, 80, .35)); }
.icon-btn:active { transform: scale(.88); }

.big-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 66px; padding: 8px 30px;
  border-radius: 24px; font-size: 26px; font-weight: 700; color: var(--ink); letter-spacing: .3px;
  background: linear-gradient(#ffe45c, var(--sun)); border: 4px solid var(--ink); box-shadow: 0 7px 0 var(--sun-deep), 0 7px 0 4px var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--sun-deep), 0 2px 0 4px var(--ink); }
.big-btn.go { background: linear-gradient(#8bec5d, var(--leaf)); box-shadow: 0 7px 0 var(--leaf-deep), 0 7px 0 4px var(--ink); }
.big-btn.go:active { box-shadow: 0 2px 0 var(--leaf-deep), 0 2px 0 4px var(--ink); }
.big-btn.calm { background: linear-gradient(#fff, #e4f3ff); box-shadow: 0 7px 0 #a9cfea, 0 7px 0 4px var(--ink); font-size: 21px; min-height: 58px; padding: 6px 20px; }
.big-btn.calm:active { box-shadow: 0 2px 0 #a9cfea, 0 2px 0 4px var(--ink); }

.panel {
  background: var(--paper); border: 5px solid var(--ink); border-radius: 30px;
  box-shadow: 0 8px 0 rgba(20, 30, 80, .35);
}
h1, h2, h3, p { margin: 0; }

.top-bar {
  position: absolute; left: 0; right: 0; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 14px) 10px calc(var(--safe-l) + 14px);
}
.top-title {
  flex: 1; text-align: center; font-size: 25px; font-weight: 700; color: #fff;
  text-shadow: 0 3px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink);
}

/* Boot */
#boot { display: grid; place-items: center; background: radial-gradient(circle at 50% 35%, #8ee4ff, var(--sky) 60%, var(--sky-deep)); }
.boot-inner { width: min(84vw, 420px); text-align: center; }
#boot-logo { width: 100%; margin-bottom: 26px; animation: bob 2.2s ease-in-out infinite; }
.boot-bar { height: 26px; border: 4px solid var(--ink); border-radius: 16px; background: #fff; overflow: hidden; }
#boot-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--sun), var(--sun-deep)); transition: width .2s; }
#boot-text { margin-top: 12px; color: #fff; font-size: 20px; text-shadow: 0 2px 0 var(--ink); }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-9px) rotate(1deg); } }

/* Title */
#screen-title { background: #4cc6f5 center / cover no-repeat url(../assets/screens/title.webp); }
.title-logo { position: absolute; left: 50%; top: calc(var(--safe-t) + 3.5vh); width: min(92vw, 62vh, 620px); margin-left: calc(min(92vw, 62vh, 620px) / -2); animation: bob 3s ease-in-out infinite; }
.title-actions {
  position: absolute; left: 0; right: 0; bottom: calc(var(--safe-b) + 28px); display: flex; align-items: center; justify-content: center; gap: 18px;
}
.title-actions .big-btn { font-size: 34px; padding: 10px 48px; min-height: 80px; }

/* Captain picker */
#screen-captain { background: linear-gradient(#7fdcff, var(--sky-deep)); overflow-y: auto; }
.captain-wrap { min-height: 100%; display: flex; flex-direction: column; align-items: center; padding: calc(var(--safe-t) + 84px) 14px calc(var(--safe-b) + 24px); }
.captain-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; width: min(100%, 440px); }
@media (min-aspect-ratio: 1/1) { .captain-grid { grid-template-columns: repeat(3, minmax(0, 170px)); width: auto; } }
.captain {
  background: var(--paper); border: 5px solid var(--ink); border-radius: 26px; padding: 8px 6px 6px; font-size: 21px; font-weight: 700; transition: transform .1s;
  box-shadow: 0 6px 0 rgba(20, 30, 80, .35);
}
.captain img { width: 100%; height: clamp(84px, 16vh, 150px); object-fit: contain; }
.captain.on { background: #fff4bc; border-color: var(--sun-deep); transform: scale(1.04); box-shadow: 0 0 0 5px var(--sun), 0 6px 0 5px rgba(20, 30, 80, .35); }
.captain:active { transform: scale(.96); }
.captain-go { margin-top: 26px; }

/* Map */
#screen-map { overflow-y: auto; overflow-x: hidden; background: #3fb9ee; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.map-inner { position: relative; left: 50%; transform: translateX(-50%); width: max(min(100vw, 640px), calc(100dvh * 2 / 3)); aspect-ratio: 2 / 3; background: center / cover url(../assets/screens/map.webp); }
.map-bar { position: fixed; z-index: 5; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: center; padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 12px) 8px calc(var(--safe-l) + 12px); pointer-events: none; }
.map-bar > * { pointer-events: auto; }
.star-count {
  display: flex; align-items: center; gap: 4px; background: var(--paper); border: 4px solid var(--ink); border-radius: 20px; padding: 3px 14px 3px 6px; font-size: 22px; font-weight: 700;
}
.star-count img { width: 32px; height: 32px; }
.chip-btn { display: flex; width: 66px; height: 66px; padding: 3px; background: var(--paper); border: 4px solid var(--ink); border-radius: 50%; overflow: hidden; }
.chip-btn img { width: 100%; height: 100%; object-fit: contain; }
.chip-btn:active { transform: scale(.9); }
.map-actions { display: flex; gap: 8px; align-items: center; }

.node {
  position: absolute; width: 74px; height: 74px; margin: -37px 0 0 -37px; display: grid; place-items: center; font-size: 29px; font-weight: 700; color: #fff; z-index: 2;
  text-shadow: 0 2px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink);
  transition: transform .1s;
}
.node > img.base { position: absolute; inset: 0; width: 100%; height: 100%; filter: drop-shadow(0 4px 0 rgba(20, 30, 80, .4)); }
.node span { position: relative; }
.node .lock { position: relative; width: 38px; height: 38px; }
.node:active { transform: scale(.9); }
.node.current { animation: pulse 1.3s ease-in-out infinite; }
.node .stars { position: absolute; top: 66px; left: 50%; transform: translateX(-50%); display: flex; }
.node .stars img { width: 21px; height: 21px; margin: 0 -1px; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.14); } }

/* Level sheet, pause */
.sheet {
  width: min(100%, 520px); max-height: 92dvh; overflow-y: auto; border-radius: 34px 34px 0 0; border-bottom: 0;
  padding: 20px 20px calc(var(--safe-b) + 22px); animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(40%); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.sheet-sub { color: var(--sky-deep); font-size: 18px; }
.sheet-title { font-size: 32px; font-weight: 700; line-height: 1.05; }
.row-stars { display: flex; margin-top: 6px; }
.row-stars img { width: 34px; height: 34px; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.fact { background: #e4f3ff; border-radius: 14px; padding: 4px 12px; font-size: 18px; }
.list-title { display: flex; align-items: center; gap: 6px; font-size: 21px; font-weight: 700; margin: 8px 0 6px; }
.list-title img { width: 30px; height: 30px; }
.times { list-style: none; margin: 0 0 18px; padding: 0; }
.times li { display: flex; align-items: center; gap: 10px; padding: 3px 8px; border-radius: 14px; font-size: 21px; font-weight: 600; }
.times li:nth-child(odd) { background: #f1f8ff; }
.times li.me { background: #fff1a8; }
.times .rank { width: 22px; font-weight: 700; }
.times img.face { width: 38px; height: 38px; object-fit: contain; }
.times .name { flex: 1; min-width: 0; }
.times .time { font-variant-numeric: tabular-nums; font-weight: 700; }
.times .medal { width: 26px; height: 30px; object-fit: contain; }
.empty { font-size: 18px; color: #4a5a8c; padding: 6px 2px 18px; }
.sheet-go { display: flex; justify-content: center; }

#pause { align-items: center; padding: 18px; }
.pause-card { width: min(100%, 340px); padding: 22px 22px 26px; text-align: center; animation: rise .18s ease-out; }
.pause-card h2 { font-size: 34px; margin-bottom: 16px; }
.pause-card .stack { display: flex; flex-direction: column; gap: 18px; }

/* Records */
#screen-records { background: linear-gradient(#7fdcff, var(--sky-deep)); overflow-y: auto; }
.records-list { padding: calc(var(--safe-t) + 88px) 14px calc(var(--safe-b) + 24px); max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.record-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 12px; border-radius: 22px; }
.record-row .num { width: 34px; height: 34px; flex: none; border-radius: 50%; background: var(--sky); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 19px; }
.record-row .label { flex: 1; min-width: 0; font-size: 20px; line-height: 1.1; }
.record-row .label small { display: block; font-size: 16px; font-weight: 500; color: #4a5a8c; }
.record-row .stars { display: flex; }
.record-row .stars img { width: 19px; height: 19px; margin-left: -2px; }
.record-row img.face { width: 36px; height: 36px; object-fit: contain; }
.record-row.locked { opacity: .62; }

/* Results */
#screen-results { background: linear-gradient(#7fdcff, var(--sky-deep)); overflow-y: auto; }
.results-wrap { position: relative; z-index: 2; min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(var(--safe-t) + 16px) 14px calc(var(--safe-b) + 22px); }
.results-card { width: min(100%, 460px); padding: 16px 18px 12px; text-align: center; }
.results-hero { display: flex; align-items: center; justify-content: center; gap: 8px; }
.results-hero .portrait { width: 104px; height: 104px; object-fit: contain; }
.results-hero .medal { width: 74px; height: 96px; object-fit: contain; animation: pop .5s .1s backwards cubic-bezier(.3, 1.8, .5, 1); }
.results-title { font-size: 32px; font-weight: 700; line-height: 1.1; }
.results-note { font-size: 19px; font-weight: 500; color: #3f4f84; }
.results-stars { display: flex; justify-content: center; gap: 2px; margin: 6px 0; }
.results-stars img { width: 56px; height: 56px; animation: pop .45s backwards cubic-bezier(.3, 1.8, .5, 1); }
.results-stars img:nth-child(2) { animation-delay: .22s; }
.results-stars img:nth-child(3) { animation-delay: .44s; }
.new-best { width: 150px; margin: 2px auto -2px; animation: pop .5s .55s backwards cubic-bezier(.3, 1.8, .5, 1); }
@keyframes pop { from { transform: scale(0) rotate(-14deg); opacity: 0; } }
.results-time { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.finish-order { display: flex; justify-content: center; gap: 4px; margin: 6px 0 2px; }
.finisher { position: relative; width: 50px; height: 50px; padding: 3px; border-radius: 50%; background: #e4f3ff; border: 3px solid var(--ink); }
.finisher.me { background: var(--sun); }
.finisher img { width: 100%; height: 100%; object-fit: contain; }
.finisher span { position: absolute; left: -5px; top: -7px; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: #fff; font-size: 14px; font-weight: 700; }
.results-card .times { margin: 8px 0 4px; text-align: left; }
.results-actions { display: flex; gap: 14px; margin-top: 18px; flex-wrap: wrap; justify-content: center; }
.confetti { position: fixed; top: -40px; z-index: 1; width: 22px; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(112vh) rotate(720deg); } }

/* HUD */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.hud-top { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 7px; padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 10px) 0 calc(var(--safe-l) + 10px); }
.hud-chip { height: 44px; display: flex; align-items: center; gap: 4px; padding: 0 12px; background: var(--paper); border: 4px solid var(--ink); border-radius: 20px; font-size: 19px; font-weight: 700; white-space: nowrap; }
.hud-chip img { width: 26px; height: 26px; }
.hud-place { background: var(--sun); font-size: 25px; }
.hud-time { flex: 0 1 auto; font-variant-numeric: tabular-nums; padding: 0 9px 0 6px; }
.hud-pause { width: 52px; height: 52px; margin-left: auto; pointer-events: auto; }
@media (max-width: 374px) { .hud-chip { font-size: 16px; padding: 0 8px; } .hud-time img { display: none; } }
#hud-order { position: absolute; left: calc(var(--safe-l) + 8px); top: calc(var(--safe-t) + 62px); width: 44px; }
.order-face { position: absolute; left: 0; top: 0; width: 44px; height: 44px; padding: 2px; border-radius: 50%; background: var(--paper); border: 3px solid var(--ink); transition: transform .35s; }
.order-face.me { background: var(--sun); }
.order-face img { width: 100%; height: 100%; object-fit: contain; }
#minimap { position: absolute; right: calc(var(--safe-r) + 8px); top: calc(var(--safe-t) + 62px); width: 110px; height: 110px; opacity: .96; }
#hud-power { position: absolute; left: 50%; top: calc(var(--safe-t) + 64px); transform: translateX(-50%); display: flex; align-items: center; gap: 6px; background: var(--paper); border: 4px solid var(--ink); border-radius: 22px; padding: 3px 10px 3px 4px; }
#hud-power-icon { width: 34px; height: 34px; }
.power-bar { width: 70px; height: 13px; border-radius: 7px; background: #cfe3f2; overflow: hidden; }
#hud-power-bar { height: 100%; width: 100%; background: var(--leaf); }
#hud-banner { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); white-space: nowrap; font-size: 28px; font-weight: 700; color: #fff; background: var(--sky-deep); border: 4px solid var(--ink); border-radius: 22px; padding: 6px 20px; animation: pop .3s cubic-bezier(.3, 1.8, .5, 1); }
#hud-word { position: absolute; left: 50%; top: 40%; width: min(62vw, 44vh, 340px); max-height: 34vh; object-fit: contain; margin-left: calc(min(62vw, 44vh, 340px) / -2); transform: translateY(-50%); }
#hud-word.show { animation: word .8s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes word { 0% { transform: translateY(-50%) scale(.2); opacity: 0; } 30% { transform: translateY(-50%) scale(1.1); opacity: 1; } 75% { transform: translateY(-50%) scale(1); opacity: 1; } 100% { transform: translateY(-50%) scale(1.15); opacity: 0; } }
#stick-base, #stick-knob { position: fixed; left: 0; top: 0; z-index: 12; pointer-events: none; }
#stick-base { width: 132px; height: 132px; margin: -66px 0 0 -66px; opacity: .78; }
#stick-knob { width: 62px; height: 62px; margin: -31px 0 0 -31px; object-fit: contain; }
#steer-hint { position: absolute; left: 50%; bottom: calc(var(--safe-b) + 7vh); width: min(86vw, 340px); transform: translateX(-50%); text-align: center; padding: 10px 14px; background: rgba(255, 253, 244, .94); border: 4px solid var(--ink); border-radius: 24px; font-size: 21px; line-height: 1.15; }
.hint-track { position: relative; height: 54px; margin-bottom: 4px; }
.hint-track img { position: absolute; top: 2px; left: 50%; width: 50px; height: 50px; margin-left: -25px; object-fit: contain; animation: hint 2.4s ease-in-out infinite; }
@keyframes hint { 0%, 100% { transform: translateX(-74px); } 50% { transform: translateX(74px); } }

#fatal { display: grid; place-items: center; padding: 24px; text-align: center; font-size: 22px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
