/* Winter Slope Run - frame, screens, HUD, menus, form, leaderboard.
   Portrait-only: everything lives inside a centred 9:16 (max) frame; on
   desktop / landscape the sides are letterboxed.
   --u is 1% of the frame width, set from JS (main.js layout()). */

:root {
  --u: 4px;
  --ink: #1b2344;
  --red: #e2231a;
  --red-dk: #9e120c;
  --green: #1f8a44;
  --green-dk: #11592b;
  --gold: #ffcf40;
  --ice: #bfe3ff;
  --night: #081536;
  --cream: #f7fbff;
}

*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none;
  background: #050b1c; color: var(--ink);
  font-family: "Baloo 2", "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-weight: 700; -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}

/* letterbox: icy night backdrop with falling-snow dots at the sides */
#app {
  position: fixed; inset: 0; display: flex; justify-content: center;
  background:
    radial-gradient(circle at 12% 20%, rgba(80,160,255,.18), transparent 40%),
    radial-gradient(circle at 88% 80%, rgba(226,35,26,.16), transparent 40%),
    radial-gradient(2px 2px at 20px 30px, rgba(255,255,255,.55), transparent),
    radial-gradient(2px 2px at 90px 120px, rgba(255,255,255,.35), transparent),
    radial-gradient(1.5px 1.5px at 150px 60px, rgba(255,255,255,.45), transparent),
    linear-gradient(180deg, #06112b, #0c2150);
  background-size: auto, auto, 180px 180px, 180px 180px, 180px 180px, auto;
  animation: letterSnow 30s linear infinite;
}
@keyframes letterSnow { to { background-position: 0 0, 0 0, 0 180px, 0 180px, 0 180px, 0 0; } }

#frame {
  position: relative; height: 100%; width: min(100%, 56.25vh); width: min(100%, 56.25dvh);
  overflow: hidden; background: var(--night);
  box-shadow: 0 0 0 3px rgba(191,227,255,.35), 0 0 90px rgba(0,0,0,.7);
  font-size: calc(var(--u) * 4.3);
  user-select: none; -webkit-user-select: none;
}

#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.screen {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  padding: 1em; overflow: hidden;
}
.screen.active { display: flex; }

/* ---------- shared bits ---------- */
.panel {
  position: relative; width: 100%; max-width: 24em; text-align: center;
  background: var(--cream); border: .2em solid var(--ink); border-radius: 1.4em;
  box-shadow: 0 .35em 0 rgba(0,0,0,.3), 0 0 0 .35em rgba(255,255,255,.18); padding: 1.1em 1.2em 1.3em;
}
/* snow drift along the top of every panel */
.panel::before {
  content: ""; position: absolute; left: .6em; right: .6em; top: -.55em; height: 1em;
  background:
    radial-gradient(circle at 10% 100%, #fff .55em, transparent .58em),
    radial-gradient(circle at 30% 100%, #fff .7em, transparent .73em),
    radial-gradient(circle at 52% 100%, #fff .6em, transparent .63em),
    radial-gradient(circle at 74% 100%, #fff .75em, transparent .78em),
    radial-gradient(circle at 92% 100%, #fff .55em, transparent .58em);
  filter: drop-shadow(0 -.1em 0 var(--ink));
}
h1, h2 { margin: 0; font-weight: 800; line-height: 1; }
h2 { font-size: 1.7em; color: var(--red); text-shadow: 0 .06em 0 rgba(0,0,0,.12); }

.btn {
  font: inherit; font-weight: 800; font-size: 1.1em; color: #fff; letter-spacing: .02em;
  background: var(--red); border: 0; border-bottom: .28em solid var(--red-dk); border-radius: 1em;
  padding: .55em 1.5em; min-height: 48px; cursor: pointer; touch-action: manipulation;
  text-shadow: 0 .08em 0 rgba(0,0,0,.25); transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(.15em); border-bottom-width: .13em; }
.btn:disabled { filter: grayscale(.6) brightness(.9); cursor: default; }
.btn-big { font-size: 1.6em; padding: .45em 1.8em; }
.btn-small { font-size: .9em; padding: .4em 1.2em; min-height: 44px; }
.btn-alt { background: var(--green); border-bottom-color: var(--green-dk); }
.btn-row { display: flex; gap: .7em; justify-content: center; flex-wrap: wrap; margin-top: .9em; }
.btn:focus-visible, input:focus-visible, .icon-btn:focus-visible { outline: .18em solid var(--gold); outline-offset: .12em; }

.icon-btn {
  position: absolute; top: 10px; right: 10px; width: 46px; height: 46px; padding: 9px; z-index: 30;
  border-radius: 50%; border: 3px solid var(--ink); background: #fff; color: var(--ink); cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,.3); touch-action: manipulation;
}
.icon-btn.left { right: auto; left: 10px; pointer-events: auto; }
.icon-btn svg { width: 100%; height: 100%; display: block; }
.icon-btn.muted { color: #9a8f8f; }

kbd {
  display: inline-grid; place-items: center; min-width: 1.5em; height: 1.5em; padding: 0 .2em;
  font: inherit; font-weight: 800; color: var(--ink); background: #fff;
  border: .12em solid var(--ink); border-bottom-width: .25em; border-radius: .35em;
}
kbd.k { font-size: .85em; min-width: 1.4em; height: 1.4em; margin: 0 .05em; vertical-align: .05em; }

/* ---------- menu ---------- */
#screen-menu { align-items: flex-start; padding-top: 12%; }
.menu-wrap { display: flex; flex-direction: column; align-items: center; gap: .6em; text-align: center; width: 100%; }
.title {
  font-family: "Mountains of Christmas", "Baloo 2", cursive; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; line-height: .88;
  filter: drop-shadow(0 .12em 0 rgba(0,0,0,.45));
  animation: floaty 3.2s ease-in-out infinite;
}
.title .t1 { font-size: 2.3em; color: #fff; -webkit-text-stroke: .06em #1d4f9a; paint-order: stroke fill; transform: rotate(-4deg); }
.title .t2 {
  font-size: 2.6em; white-space: nowrap; color: var(--gold); -webkit-text-stroke: .05em var(--red-dk); paint-order: stroke fill;
  text-shadow: 0 0 .35em rgba(255,207,64,.55);
}
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-.25em); } }
.tagline {
  margin: .2em 0 .5em; font-size: 1em; color: #fff; text-shadow: 0 .1em .2em rgba(0,0,0,.6);
  background: rgba(8,21,54,.55); padding: .3em .9em; border-radius: 1em;
}
#btn-play { animation: breathe 1.7s ease-in-out infinite; margin-top: 26vh; margin-top: 26dvh; }
#btn-play:hover, #btn-play:active { animation-play-state: paused; }
.btn-play-label { display: inline-block; font-size: 1.25em; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.toggles { display: flex; gap: .6em; }
.toggles b { display: inline-block; min-width: 2.2em; }
.toggles .btn[aria-pressed=false] { background: #6b7280; border-bottom-color: #3f4652; }
.brand-slot {
  margin-top: .4em; padding: .35em .9em; border-radius: .8em; font-size: .8em;
  color: #fff; background: rgba(8,21,54,.6); border: .1em dashed rgba(255,255,255,.5);
}
.brand-slot.small { color: var(--ink); background: #eef6ff; border-color: #9fb9dc; margin: 0 0 .8em; }

/* ---------- instructions ---------- */
.howto-card { max-width: 25em; }
.rules { list-style: none; margin: .8em 0 .4em; padding: 0; display: grid; gap: .4em; text-align: left; }
.rules li {
  display: flex; align-items: center; gap: .7em; padding: .3em .6em; border-radius: .9em;
  background: #fff; border: .12em solid rgba(27,35,68,.15); font-size: .8em; line-height: 1.2; font-weight: 600;
}
.rules li b { display: block; font-size: 1.1em; font-weight: 800; color: var(--ink); letter-spacing: .03em; }
.rules b.red { color: var(--red); } .rules b.green { color: var(--green); } .rules b.gold { color: #c98a00; }
.ic { flex: none; width: 3.4em; height: 3.4em; display: grid; place-items: center; }
.ic img, .ic svg { max-width: 100%; max-height: 100%; display: block; }
.ic.keys { display: flex; gap: .25em; justify-content: center; }
.ic.keys kbd { font-size: 1.05em; animation: keytap 1.4s ease-in-out infinite; }
.ic.keys kbd + kbd { animation-delay: .7s; }
@keyframes keytap { 0%, 35%, 100% { transform: none; background: #fff; } 15% { transform: translateY(.12em); background: #ffe58a; } }
.ic.trio { display: flex; width: 5.6em; gap: 0; }
.ic.trio span { flex: 1; height: 100%; display: grid; place-items: center; }
.curve .holdbar { transform-origin: 6px 60px; animation: holdgrow 1.8s ease-in-out infinite; }
@keyframes holdgrow { 0% { transform: scaleX(.15); } 70%, 100% { transform: scaleX(1); } }
#btn-go { margin-top: .6em; }

/* ---------- HUD ---------- */
#screen-game { padding: 0; align-items: stretch; justify-content: stretch; touch-action: none; cursor: pointer; }
#hud {
  position: absolute; left: 0; right: 0; top: 0; height: calc(var(--u) * 22);
  display: flex; align-items: flex-start; justify-content: center; padding: calc(var(--u) * 2.4) calc(var(--u) * 3);
  pointer-events: none; z-index: 4;
}
.hud-center { display: flex; flex-direction: column; align-items: center; gap: .3em; }
.hud-score {
  min-width: 4.2em; padding: .02em .8em; text-align: center;
  background: rgba(8,21,54,.78); border: .14em solid var(--gold); border-radius: 1.2em;
  color: #fff; font-size: 1.7em; font-weight: 800; line-height: 1.3; box-shadow: 0 .1em 0 rgba(0,0,0,.4);
  font-variant-numeric: tabular-nums;
}
.hud-coins {
  display: flex; align-items: center; gap: .25em; padding: .05em .7em .05em .3em;
  background: rgba(8,21,54,.65); border-radius: 1em; color: var(--gold); font-size: .95em; font-weight: 800;
}
.coin-ic { display: inline-block; width: 1.3em; height: 1.3em; background-size: contain; background-repeat: no-repeat; background-position: center; }
.bump { animation: pop .3s ease-out; }
@keyframes pop { 40% { transform: scale(1.2); } }

.banner {
  position: absolute; left: 0; right: 0; top: 24%; text-align: center; pointer-events: none; z-index: 3;
  opacity: 0; font-weight: 800; color: #fff;
}
.banner .b1 { font-size: 2.2em; line-height: 1; -webkit-text-stroke: .08em var(--ink); paint-order: stroke fill; text-shadow: 0 .08em 0 rgba(0,0,0,.35); }
.banner .b2 { font-size: 2.8em; line-height: 1; color: var(--gold); -webkit-text-stroke: .08em var(--ink); paint-order: stroke fill; }
.banner.cp .b1 { color: #7dffb0; }
.banner.speed .b1 { color: #bfe3ff; font-size: 1.7em; }
.banner.show { animation: bannerIn 1.5s ease-out forwards; }
@keyframes bannerIn {
  0% { opacity: 0; transform: scale(.4); }
  12% { opacity: 1; transform: scale(1.15); }
  22% { transform: scale(1); }
  75% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-1.2em); }
}

.countdown {
  position: absolute; left: 0; right: 0; top: 36%; text-align: center; pointer-events: none; z-index: 3;
  font-size: 6em; font-weight: 800; line-height: 1; color: #fff;
  -webkit-text-stroke: .05em var(--ink); paint-order: stroke fill; text-shadow: 0 .06em 0 rgba(0,0,0,.35), 0 0 .4em rgba(120,200,255,.8);
}
.countdown.pulse { animation: cdPulse .9s ease-out forwards; }
@keyframes cdPulse { 0% { transform: scale(1.8); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 80% { opacity: 1; } 100% { transform: scale(.85); opacity: .0; } }

.hint {
  position: absolute; left: 0; right: 0; bottom: 7%; display: flex; justify-content: space-between; padding: 0 5%;
  pointer-events: none; z-index: 3; transition: opacity .6s;
}
.hint.out { opacity: 0; }
.hint-side {
  display: flex; align-items: center; gap: .4em; padding: .35em .8em; border-radius: 1em;
  background: rgba(8,21,54,.7); color: #fff; font-size: .95em; border: .12em solid rgba(255,255,255,.6);
}
.hint-side .arrow { color: var(--gold); animation: nudge .8s ease-in-out infinite alternate; }
.hint-side:first-child .arrow { animation-name: nudgeL; }
@keyframes nudge { to { transform: translateX(.25em); } }
@keyframes nudgeL { to { transform: translateX(-.25em); } }
/* device-specific instructions: main.js sets body.is-touch on touch-first devices */
.hint .tc, body.is-touch .hint .kb, .rules li.touch-only, body.is-touch .rules li.pc-only { display: none; }
body.is-touch .hint .tc { display: inline; }
body.is-touch .rules li.touch-only { display: flex; }
.touch-only .finger { animation: fingerPulse 1.2s ease-in-out infinite; transform-origin: 17px 44px; }
@keyframes fingerPulse { 50% { transform: scale(.75); } }

.pause { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(5,11,28,.55); z-index: 10; padding: 1em; }
.pause-card { max-width: 17em; }

/* ---------- result ---------- */
#screen-result { z-index: 5; background: rgba(5,11,28,0); flex-direction: column; }
#screen-result.active { animation: fadebg .5s forwards; }
@keyframes fadebg { to { background: rgba(5,11,28,.5); } }
.result-card { opacity: 0; }
.result-card.in { animation: slidein .6s cubic-bezier(.2,1.3,.4,1) forwards; }
@keyframes slidein { from { transform: translateY(-70vh); opacity: 1; } to { transform: translateY(0); opacity: 1; } }
.result-reason {
  display: inline-block; margin: .2em 0 .6em; padding: .2em .8em; border-radius: 1em; font-size: .8em;
  background: #ffe3e0; color: var(--red-dk);
}
.result-label { margin-top: .5em; font-size: .85em; text-transform: uppercase; letter-spacing: .12em; color: #6a7394; }
.result-score { font-size: 4em; font-weight: 800; line-height: 1.05; color: var(--red); text-shadow: 0 .05em 0 rgba(0,0,0,.15); font-variant-numeric: tabular-nums; }
.breakdown { list-style: none; margin: .5em auto .2em; padding: .4em .8em; max-width: 17em; background: #eef6ff; border-radius: .9em; font-size: .85em; display: grid; gap: .15em; }
.breakdown li { display: flex; justify-content: space-between; gap: 1em; }
.breakdown small { color: #6a7394; font-weight: 600; }
.breakdown b { font-variant-numeric: tabular-nums; }
.result-sub { margin: .4em 0 .9em; font-size: .95em; }
#btn-replay { display: block; margin: .7em auto 0; }

/* ---------- form (ski pass) ---------- */
.form-card { text-align: left; background: #fff; padding-top: 2.1em;
  background-image: linear-gradient(90deg, transparent calc(100% - .9em), rgba(226,35,26,.12) 0); }
.tag-hole { position: absolute; top: .75em; left: 50%; width: 1.1em; height: 1.1em; margin-left: -.55em; border-radius: 50%; background: var(--night); border: .15em solid var(--ink); }
.pass-label { text-align: center; margin-top: .2em; font-size: .75em; letter-spacing: .3em; text-transform: uppercase; color: #fff; background: var(--green); border-radius: .5em; padding: .05em 0; }
.form-card h2 { text-align: center; font-family: "Mountains of Christmas", "Baloo 2", cursive; font-size: 1.9em; margin-top: .25em; }
.form-score { text-align: center; margin: .3em 0 .6em; font-size: .95em; }
.form-card label:not(.consent) { display: block; margin-top: .5em; font-size: .85em; }
.form-card input[type=text], .form-card input[type=email] {
  width: 100%; font: inherit; font-weight: 700; font-size: max(16px, 1em); color: var(--ink);
  padding: .5em .8em; margin-top: .25em; background: #fff;
  border: .15em solid var(--ink); border-radius: .7em; user-select: text; -webkit-user-select: text;
}
.form-card input[aria-invalid=true] { border-color: #e02b2b; background: #fff0ee; }
.consent { display: flex; gap: .6em; align-items: flex-start; margin-top: .8em; font-size: .72em; line-height: 1.3; cursor: pointer; font-weight: 600; }
.consent input { flex: none; width: 1.6em; height: 1.6em; margin: 0; accent-color: var(--red); }
.field-error { min-height: 1.1em; margin-top: .2em; font-size: .75em; color: #d62828; }
.field-error.center { text-align: center; }
.form-btns { flex-wrap: nowrap; margin-top: .5em; }
.form-btns .btn { flex: 1; padding-left: .5em; padding-right: .5em; }

/* ---------- leaderboard ---------- */
.board-card { max-width: 26em; font-size: .92em; }
.board-you { margin-top: .35em; font-size: .9em; color: #4d5779; min-height: 1.2em; }
.board-you b { color: var(--red); }
.board-head, .row { display: grid; grid-template-columns: 3em 1fr 5em; gap: .5em; align-items: center; padding: .4em .8em; text-align: left; }
.board-head { margin-top: .4em; font-size: .75em; text-transform: uppercase; letter-spacing: .1em; color: #6a7394; }
.board-head span:last-child, .row .sc { text-align: right; }
.board-rows { list-style: none; margin: 0; padding: 0; max-height: 46vh; overflow-y: auto; display: grid; gap: .3em; }
.row { background: #fff; border-radius: .8em; }
.row:nth-child(even) { background: #eef6ff; }
.row .rk { font-weight: 800; text-align: center; }
.row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sc { font-weight: 800; color: var(--red); font-variant-numeric: tabular-nums; }
.row.r1 .rk { color: #d99a00; } .row.r2 .rk { color: #7d8a96; } .row.r3 .rk { color: #b06a34; }
.row.me { background: #ffe58a; outline: .13em solid var(--ink); animation: meGlow 1.3s ease-in-out infinite; }
@keyframes meGlow {
  0%, 100% { background: #ffe58a; box-shadow: 0 0 0 0 rgba(255,207,64,.6); }
  50% { background: #ffd54f; box-shadow: 0 0 0 .45em rgba(255,207,64,0); }
}
.board-empty { padding: 1.4em 0; color: #6a7394; }
.board-foot { display: flex; justify-content: space-between; gap: .5em; margin-top: .6em; font-size: .72em; color: #6a7394; min-height: 1.2em; }
.board-timer { height: .5em; margin-top: .4em; border-radius: 1em; background: rgba(0,0,0,.12); overflow: hidden; }
.board-timer i { display: block; width: 100%; height: 100%; background: var(--green); transform-origin: left; }
.board-timer.run i { animation: drain var(--dur, 5s) linear forwards; }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* short screens: tighten the instruction card */
@media (max-height: 700px) {
  .rules li { font-size: .72em; padding: .2em .5em; }
  .ic { width: 3em; height: 3em; }
  .howto-card h2 { font-size: 1.4em; }
}

@media (prefers-reduced-motion: reduce) {
  .title, .row.me, #btn-play, .ic.keys kbd, .curve .holdbar, #app { animation: none; }
}
