:root {
  --ink: #0b2545;
  --deep: #081a33;
  --ice: #e8f6ff;
  --frost: #9fd3f0;
  --cash: #3fbf6a;
  --gold: #ffc93c;
  --coral: #ff6b4a;
  --panel: rgba(8, 26, 51, 0.92);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% 0%, #1b4b7f 0%, #0b2545 55%, #061428 100%);
  background-color: var(--deep);
  color: var(--ice);
  font-family: "Fredoka", ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- stage ---------- */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
}
.screen {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45), 0 0 0 1px rgba(255,255,255,.08);
  background: #123a63;
}
canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 14px;
  background: rgba(6, 20, 40, 0.42);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.overlay[hidden] { display: none; }
.card {
  width: 100%; max-width: 380px; max-height: 100%;
  overflow-y: auto;
  padding: 20px 20px 18px;
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
  text-align: center;
  -webkit-user-select: text; user-select: text;
}
.card.small { max-width: 300px; }
.card h2 { margin: 0 0 12px; font-size: 30px; }
.logo {
  margin: 0;
  font-size: clamp(38px, 11vw, 52px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: .01em;
  color: #fff;
  text-shadow: 0 3px 0 #5fb0e0, 0 6px 0 #2a6fa8, 0 10px 18px rgba(0,0,0,.4);
}
.tag { margin: 12px 0 10px; font-size: 16px; color: #cfe9fb; }
.tag b { color: var(--gold); }
.how { list-style: none; padding: 0; margin: 0 0 10px; text-align: left; font-size: 14px; line-height: 1.35; }
.how li { display: flex; gap: 10px; align-items: flex-start; padding: 5px 0; }
.how .ico { flex: 0 0 22px; font-size: 18px; line-height: 1.1; text-align: center; }
.keys { margin: 4px 0 12px; font-size: 12.5px; color: var(--frost); }
.keys-touch { display: none; }
body.touch .keys-desk { display: none; }
body.touch .keys-touch { display: block; }

.big {
  display: block; width: 100%;
  padding: 13px 18px; border: 0; border-radius: 16px;
  font-size: 22px; font-weight: 700;
  color: #10351f;
  background: linear-gradient(180deg, #7cf0a3, #3fbf6a);
  box-shadow: 0 5px 0 #23864a, 0 10px 20px rgba(0,0,0,.25);
  transition: transform .08s ease, box-shadow .08s ease;
}
.big:active { transform: translateY(4px); box-shadow: 0 1px 0 #23864a; }
.link { margin-top: 12px; border: 0; background: none; color: var(--frost); text-decoration: underline; font-size: 15px; }

.sb-title { margin: 18px 0 6px; font-size: 16px; }
.scores { margin: 0; padding: 0; list-style: none; font-size: 14px; text-align: left; counter-reset: s; }
.scores li {
  display: flex; gap: 8px; align-items: baseline;
  padding: 5px 8px; border-radius: 8px;
  counter-increment: s;
}
.scores li::before { content: counter(s) "."; width: 22px; color: var(--frost); font-variant-numeric: tabular-nums; }
.scores li:nth-child(odd) { background: rgba(255,255,255,.05); }
.scores li .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores li .p { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--gold); }
.scores li.me { background: rgba(63,191,106,.25); }
.scores .empty { justify-content: center; color: var(--frost); }
.scores .empty::before { content: none; }

.final { margin: 0; font-size: 20px; }
.final b { color: var(--gold); font-size: 28px; }
.sub { margin: 4px 0 12px; color: var(--frost); font-size: 14px; }
.save { display: flex; gap: 8px; margin-bottom: 6px; }
.save input {
  flex: 1; min-width: 0;
  padding: 10px 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.08); color: #fff;
  font: inherit; font-size: 16px; /* 16px stops iOS zooming in */
  -webkit-user-select: text; user-select: text;
}
.save button { border: 0; border-radius: 12px; padding: 10px 14px; font-weight: 700; background: var(--gold); color: #3a2a00; }
.save button:disabled { opacity: .5; }
.msg { min-height: 18px; margin: 2px 0 8px; font-size: 14px; color: var(--frost); }
#overOv .scores { margin-bottom: 14px; }

/* phones: the game fills the whole screen, the HUD floats over the sky, tap the ice to jump */
body.touch { position: fixed; inset: 0; overscroll-behavior: none; }
body.touch .app { padding: 0; position: relative; }
body.touch .stage { padding: 0; }
body.touch .screen { border-radius: 0; box-shadow: none; }
body.touch .overlay { padding-top: calc(env(safe-area-inset-top) + 64px); padding-bottom: calc(env(safe-area-inset-bottom) + 14px); }

@media (max-width: 420px) {
  }
@media (max-width: 360px) {
    }

/* ---------- title screen ---------- */
.title-card { max-width: 400px; padding: 22px 18px 16px; }
.title-head { margin-bottom: 14px; }
.title-head .tag { margin: 10px auto 0; max-width: 320px; font-size: 15px; line-height: 1.3; }
.title-card .big { margin-bottom: 14px; }
.title-cols { display: grid; gap: 12px; text-align: left; }
.panel { padding: 12px 12px 10px; border-radius: 16px; background: rgba(255,255,255,.06); }
.panel-title { margin: 0 0 8px; font-size: 15px; font-weight: 700; letter-spacing: .01em; }
.scores.top li { padding: 6px 8px; font-size: 15px; }
.scores.top li:nth-child(-n+3)::before { content: none; }
.scores.top li:nth-child(1) .n::before { content: "🥇 "; }
.scores.top li:nth-child(2) .n::before { content: "🥈 "; }
.scores.top li:nth-child(3) .n::before { content: "🥉 "; }
.scores.top li:nth-child(-n+3) { padding-left: 6px; }
.mybest { margin: 8px 2px 0; font-size: 13px; color: var(--frost); }
.mybest b { color: var(--gold); }
.tiles { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tiles li {
  display: grid; grid-template-columns: 24px 1fr; column-gap: 6px; align-items: start;
  padding: 7px 8px; border-radius: 12px; background: rgba(255,255,255,.05);
  font-size: 12px; line-height: 1.25; color: #cfe9fb;
}
.tiles .ico { grid-row: span 2; font-size: 18px; line-height: 1.2; text-align: center; }
.tiles b { font-size: 13px; font-weight: 700; color: #fff; }
.how-panel .keys { margin: 10px 2px 0; text-align: center; font-size: 12px; }

@media (min-width: 720px) and (min-height: 560px) {
  .title-card { max-width: 660px; }
  .title-cols { grid-template-columns: 1fr 1.25fr; }
  .title-card .big { max-width: 300px; margin-left: auto; margin-right: auto; }
}

/* ---------- HUD: one clean bar ---------- */
.hud {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 10px 8px;
}
.hud-bar {
  display: flex; align-items: stretch;
  padding: 7px 4px;
  border-radius: 16px;
  background: rgba(7, 21, 43, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.stat {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 66px; padding: 1px 14px;
}
.stat + .stat::before {
  content: ""; position: absolute; left: 0; top: 4px; bottom: 4px; width: 1px;
  background: rgba(255, 255, 255, 0.09);
}
.stat .lbl {
  font: 600 9.5px/1 -apple-system, "SF Pro Text", system-ui, "Segoe UI", sans-serif;
  letter-spacing: .14em; text-transform: uppercase;
  color: rgba(190, 222, 248, 0.62);
  margin-bottom: 5px;
}
.stat b {
  font-size: 18px; font-weight: 600; line-height: 1;
  color: #f4faff;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.stat .bar { display: block; width: 100%; height: 3px; margin-top: 6px; border-radius: 2px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.stat .bar i { display: block; height: 100%; width: 0%; border-radius: 2px; background: linear-gradient(90deg, #3fbf6a, #7cf0a3); transition: width .25s ease; }
.stat.wallet.full b { color: var(--gold); }
.stat.wallet.full .bar i { background: linear-gradient(90deg, #ffb703, #ffd966); }
.stat.warm .bar i { background: linear-gradient(90deg, #5cc8ff, #ffb26b); }
.stat.warm.cold b { color: #8fd8ff; animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.stat.lives b { display: flex; gap: 3px; align-items: center; height: 18px; }
.stat.lives svg { width: 14px; height: 14px; display: block; }
.stat.lives .more { font-size: 13px; color: rgba(255,255,255,.75); margin-left: 1px; }

.hbtn {
  flex: 0 0 auto;
  width: 42px; height: 42px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; color: #e8f6ff; text-decoration: none;
  background: rgba(7, 21, 43, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  transition: background .15s ease, transform .1s ease;
}
.hbtn svg { width: 19px; height: 19px; display: block; }
.hbtn:hover { background: rgba(32, 62, 104, 0.92); }
.hbtn:active { transform: scale(.94); }
.hbtn.sound.off { color: rgba(232, 246, 255, 0.5); }

.toggle {
  display: block; width: 100%; margin-top: 12px;
  padding: 11px 14px; border-radius: 14px;
  border: 1px solid rgba(255,255,255,.12); background: rgba(255,255,255,.06);
  font-size: 16px; font-weight: 600; color: #e8f6ff;
}

/* phones: the bar floats over the sky */
body.touch .hud {
  position: absolute; z-index: 5; left: 0; right: 0; top: 0;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 0;
  gap: 6px; pointer-events: none;
}
body.touch .hbtn { pointer-events: auto; }
body.touch .hbtn.sound { display: none; }          /* sound lives in the pause menu on phones */
@media (max-width: 480px) {
  .hud { gap: 6px; }
  .hud-bar { padding: 6px 2px; border-radius: 14px; flex: 1 1 auto; min-width: 0; max-width: 330px; }
  .stat { flex: 1 1 0; min-width: 0; padding: 1px 4px; }
  .stat .lbl { font-size: 8.5px; letter-spacing: .08em; margin-bottom: 4px; }
  .stat b { font-size: 15px; }
  .stat.lives svg { width: 11px; height: 11px; }
  .stat.lives b { gap: 2px; height: 15px; }
  .hbtn { width: 36px; height: 36px; }
  .hbtn svg { width: 17px; height: 17px; }
}
