:root {
  color-scheme: light;
  color: #17304a;
  background: #10283e;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 650;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  background:
    repeating-radial-gradient(ellipse at 100% 76%, transparent 0 32px, #9fbcd510 33px 34px, transparent 35px 54px),
    linear-gradient(145deg, #244662, #0c2135 73%);
}

.game {
  position: relative;
  isolation: isolate;
  width: min(100vw, 480px, 74vh);
  width: min(100vw, 480px, 74dvh);
  height: min(100vh, 900px);
  height: min(100dvh, 900px);
  overflow: hidden;
  background: #f7fbfe;
  box-shadow: 0 0 0 1px #b6ced860, 0 24px 80px #050d1890;
  overscroll-behavior: contain;
}

#slope { display: block; width: 100%; height: 100%; touch-action: none; }
#slope:focus { outline: none; }

.hud {
  position: absolute;
  inset: max(12px, env(safe-area-inset-top)) 12px auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px 9px;
  align-items: center;
  pointer-events: none;
}

.hud-readout {
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .55rem;
  padding: 0 .8rem;
  border: 1px solid #c0d7e4;
  border-radius: 9px;
  background: #f8fcfff5;
  min-height: 44px;
}

.surface { font-size: .875rem; font-weight: 800; }
.surface[data-surface="ice"] { color: #155977; }
.surface[data-surface="ice"]::before { content: "◇ "; }
.speed { white-space: nowrap; font-size: .875rem; }
.speed span { font-weight: 850; font-variant-numeric: tabular-nums; }
.stat { white-space: nowrap; font-size: .75rem; color: #31536b; }
.stat strong { color: #17304a; font-size: .875rem; font-variant-numeric: tabular-nums; }
.hud progress { grid-column: 1 / -1; grid-row: 2; width: 100%; height: 6px; border: 0; border-radius: 7px; background: #c8dce9; }
.hud progress::-webkit-progress-bar { border-radius: 7px; background: #c8dce9; }
.hud progress::-webkit-progress-value { border-radius: 7px; background: #176cd1; }
.hud progress::-moz-progress-bar { border-radius: 7px; background: #176cd1; }

button {
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible { outline: 3px solid #17304a; outline-offset: 4px; }
button:disabled { opacity: .6; cursor: wait; }

.pause {
  grid-column: 2;
  grid-row: 1;
  border: 0;
  border-radius: 9px;
  min-width: 46px;
  min-height: 44px;
  color: #fff;
  background: #17304a;
  font-size: 1.3rem;
  pointer-events: auto;
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  justify-items: center;
  text-align: center;
}
.start-screen {
  align-items: start;
  padding: max(1.55rem, calc(env(safe-area-inset-top) + .75rem)) .8rem 0;
  background: linear-gradient(#f7fbfe 0%, #f7fbfef1 22%, #f7fbfe00 62%);
}
.start-card { width: min(100%, 360px); }
.hero-portrait {
  grid-row: 2;
  align-self: center;
  display: block;
  height: min(38dvh, 260px);
  aspect-ratio: 350 / 524;
  max-width: 82%;
  filter: drop-shadow(0 12px 10px #17304a28);
}
.crowned-portrait { position: relative; container-type: inline-size; }
.crowned-portrait img { display: block; width: 100%; height: 100%; object-fit: contain; }
.crowned-portrait b {
  position: absolute;
  top: 14%;
  left: 50%;
  translate: -50% -50%;
  color: #ffe36b;
  text-shadow: 0 1px 2px #151515;
  font-size: 27cqw;
  line-height: 1;
  font-weight: 950;
}
.menu-record { margin-top: .7rem; font-size: .875rem; }
.trail-mark { display: flex; justify-content: center; gap: 4px; margin: 0 auto .65rem; transform: skewX(-24deg); }
.trail-mark i { width: 19px; height: 6px; background: #176cd1; border-radius: 1px; }
.trail-mark i:last-child { background: #c92d3f; }
h1, h2, p { margin: 0; }
h1 {
  font-size: clamp(2.05rem, 9.4vw, 3.5rem);
  font-size: clamp(2.05rem, min(9.4vw, 9.7dvh), 3.5rem);
  line-height: .98;
  font-weight: 950;
  letter-spacing: -.055em;
  font-style: italic;
}
h1 span { display: block; white-space: nowrap; }
h1 em { color: #bb2d3e; font-style: inherit; }
.control-guide { font-size: .875rem; margin-top: .9rem; color: #31536b; }
.control-guide span { padding: 0 .24rem; }
.touch-guide { display: none; }
@media (pointer: coarse) {
  .control-guide { display: none; }
  .touch-guide { display: block; }
}

.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: min(100%, 182px);
  min-height: 50px;
  margin-top: 1.05rem;
  padding: .6rem 1rem;
  color: white;
  background: #1763bd;
  border: 0;
  border-radius: 9px;
  box-shadow: 0 4px 0 #103f78;
  font-size: 1rem;
  font-weight: 820;
}
.action:hover { background: #104f9d; }
.action:active { translate: 0 2px; box-shadow: 0 2px 0 #103f78; }

.modal-screen { place-items: center; padding: 1rem; background: #081c30a6; }
.result-card { width: min(100%, 300px); padding: 1.65rem 1rem 1.8rem; border-radius: 16px; background: #f7fbfe; box-shadow: 0 10px 28px #10283e4f; }
.result-card h2 { font-size: clamp(1.6rem, 7vw, 2.2rem); letter-spacing: -.04em; }
.run-time { margin-top: .4rem; font-variant-numeric: tabular-nums; }
.birthday-message { color: #9f2535; margin-top: .28rem; }
.result-score { margin-top: .4rem; }
.result-score span { padding: 0 .35rem; }

.drive-controls {
  position: absolute;
  inset: auto 12px max(14px, env(safe-area-inset-bottom)) 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}
.drive-controls button {
  pointer-events: auto;
  min-width: 84px;
  min-height: 54px;
  border: 2px solid #fff;
  border-radius: 11px;
  color: #fff;
  background: #1763bd;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.drive-controls #brake { background: #a0273a; }
.drive-controls button[aria-pressed="true"] { background: #10283e; transform: translateY(2px); }
.drive-controls #brake[aria-pressed="true"] { background: #611729; }

.ski-hint, .debug {
  position: absolute;
  pointer-events: none;
  left: 50%;
  translate: -50% 0;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 62px);
  white-space: nowrap;
  padding: .45rem .7rem;
  color: #fff;
  background: #17304a;
  border-radius: 7px;
  font-size: .875rem;
}
.debug {
  margin: 0;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 100px);
  max-width: calc(100% - 1rem);
  white-space: pre;
  font: .75rem/1.35 ui-monospace, monospace;
}

@media (max-width: 370px) {
  .hud-readout { padding: 0 .42rem; gap: .25rem; }
  .surface, .speed, .stat, .stat strong { font-size: .75rem; }
  .hud { inset-inline: 8px; gap: 6px; }
}

@media (max-width: 500px) {
  .game { width: 100%; height: 100vh; height: 100dvh; }
}

@media (max-height: 515px) {
  .start-screen { padding-top: .65rem; }
  .trail-mark { margin-bottom: .4rem; }
  .control-guide { margin-top: .6rem; }
  .action { margin-top: .7rem; }
  .hero-portrait { height: min(29dvh, 150px); }
}

.run-settings { display: flex; align-items: center; justify-content: center; gap: .55rem; margin-top: .75rem; font-size: .875rem; }
.run-settings select { font: inherit; color: inherit; min-height: 40px; background: #fff; border: 1px solid #8fadc0; border-radius: 8px; padding: .3rem .55rem; }

.health { grid-column: 1 / -1; display: flex; align-items: center; gap: .45rem; justify-self: start; padding: .18rem .45rem; border-radius: 7px; background: #f8fcfff5; font-size: .75rem; font-weight: 800; }
.health meter { width: 72px; height: 12px; }

.hud .end-run { grid-row: 3; font-size: 1.45rem; background: #8b263b; }
.secondary-action {
  display: block;
  margin: .9rem auto 0;
  min-height: 44px;
  padding: .4rem .8rem;
  border: 0;
  background: transparent;
  color: #8b263b;
  font-weight: 800;
}

.music-toggle {
  grid-row: 3;
  grid-column: 1;
  justify-self: end;
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid #a7c8de;
  border-radius: 8px;
  background: #f7fbfe;
  color: #17304a;
}
.speaker-icon { position: relative; display: block; width: 21px; height: 18px; }
.speaker-icon::before {
  content: "";
  position: absolute;
  inset: 1px auto 1px 0;
  width: 11px;
  background: currentColor;
  clip-path: polygon(0 30%, 38% 30%, 100% 0, 100% 100%, 38% 70%, 0 70%);
}
.speaker-icon::after {
  content: "";
  position: absolute;
  inset: 2px 2px 2px auto;
  width: 6px;
  border-right: 2px solid currentColor;
  border-radius: 0 70% 70% 0;
}
.music-toggle[aria-pressed="false"] .speaker-icon::after {
  content: "×";
  inset: 0 0 0 auto;
  width: 9px;
  border: 0;
  font: 800 15px/18px system-ui, sans-serif;
}

#finish-screen { overflow-y: auto; padding: .55rem; }
#finish-screen .result-card { width: min(100%, 396px); padding: .8rem .75rem 1rem; }
.finish-actions { display: flex; justify-content: center; align-items: center; gap: .65rem; margin-top: .8rem; }
.finish-actions .action { margin: 0; min-width: min(45%, 140px); }
.finish-actions .music-toggle { flex-shrink: 0; }
.podium-scene {
  --step: clamp(25px, 7dvh, 52px);
  position: relative;
  isolation: isolate;
  overflow: hidden;
  height: min(43dvh, 330px);
  margin-top: .4rem;
  border-radius: 11px;
  background: linear-gradient(#101a39, #2f5179 68%, #c8e3f1 69%, #f3faff);
}
.podium-steps {
  position: absolute;
  inset: auto 17% 7% 17%;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
}
.podium-steps b {
  height: calc(var(--step) * .72);
  display: grid;
  place-items: center;
  border-top: 4px solid #f4faff;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(#d7eafa, #84aac9);
  color: #18446a;
  font-size: 1.1rem;
  box-shadow: 0 8px 10px #17304a45;
}
.podium-steps b:nth-child(2) {
  height: var(--step);
  border-top-color: #fff1b4;
  background: linear-gradient(#fbd06f, #dc971c);
  color: #502e00;
  font-size: 1.45rem;
}
.podium-steps b:last-child { height: calc(var(--step) * .55); }
.podium-winner {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: calc(7% + var(--step) - 1px);
  height: min(68%, 222px);
  aspect-ratio: 335 / 540;
  translate: -50% 0;
}
.podium-body {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  clip-path: polygon(evenodd, 0 0, 100% 0, 100% 100%, 0 100%, 0 0,
    35% 14%, 36% 10%, 39% 7%, 47% 6.5%, 55% 7%, 61% 9%, 64% 13%, 64% 20%,
    62% 24%, 58% 28%, 54% 31.2%, 48% 32%, 41% 30%, 37% 28%, 34% 22%, 34% 16%, 35% 14%, 0 0);
}
.podium-face {
  position: absolute;
  left: 35.4%;
  top: 6%;
  width: 27.2%;
  aspect-ratio: 350 / 524;
}
.finish-fans {
  position: absolute;
  bottom: 19%;
  width: 29%;
  aspect-ratio: 1;
  background-image: url("./assets/skiers/spectator-atlas.png");
  background-size: 300% 200%;
}
.finish-fans-left { left: 0; background-position: 0 0; }
.finish-fans-right { right: 0; background-position: 100% 0; }

.firework, .champagne { position: absolute; pointer-events: none; }
.firework { z-index: 1; }
.firework i, .champagne i {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  opacity: 0;
  animation: burst .92s ease-out var(--delay) both;
}
.firework i { background: var(--color); box-shadow: 0 0 6px var(--color); }
.champagne { left: 80%; top: 16%; }
.champagne i { background: #fff3b5; box-shadow: 0 0 4px #fff9e3; animation-name: spray; }
.champagne b {
  position: absolute;
  width: 8px;
  height: 6px;
  border-radius: 3px;
  background: #eac899;
  opacity: 0;
  animation: cork .65s ease-out .29s both;
}
@keyframes burst {
  0% { opacity: .9; transform: scale(.6); }
  55% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--x), var(--y)) scale(.28); }
}
@keyframes spray {
  0% { opacity: 1; transform: scale(.5); }
  70% { opacity: .9; transform: translate(var(--x), var(--y)); }
  100% { opacity: 0; transform: translate(var(--x), calc(var(--y) + 23px)) scale(.4); }
}
@keyframes cork {
  0% { opacity: 1; }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(23px, -36px) rotate(190deg); }
}
@media (prefers-reduced-motion: reduce) {
  .firework, .champagne { display: none; }
}
