/* Santa's Gift 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: #241626;
  --red: #e2231a;
  --red-dk: #9e120c;
  --green: #1f8a44;
  --green-dk: #11592b;
  --gold: #ffcf40;
  --ice: #bfe3ff;
  --night: #0b1a3a;
  --cream: #fff8ec;
}

*, *::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: festive night backdrop at the sides */
#app {
  position: fixed; inset: 0; display: flex; justify-content: center;
  background:
    radial-gradient(circle at 15% 25%, rgba(226,35,26,.22), transparent 38%),
    radial-gradient(circle at 85% 75%, rgba(31,138,68,.22), transparent 38%),
    radial-gradient(2px 2px at 20px 30px, rgba(255,255,255,.5), 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,.4), transparent),
    #060d22;
  background-size: auto, auto, 180px 180px, 180px 180px, 180px 180px, auto;
}

#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(255,207,64,.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,.15); padding: 1.1em 1.2em 1.3em;
}
/* candy-cane trim along the top of every panel */
.panel::before {
  content: ""; position: absolute; left: 1.2em; right: 1.2em; top: -.2em; height: .45em; border-radius: 1em;
  background: repeating-linear-gradient(-45deg, var(--red) 0 .5em, #fff .5em 1em);
  border: .12em solid 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 svg { width: 100%; height: 100%; display: block; }
.icon-btn.muted { color: #9a8f8f; }

/* ---------- menu ---------- */
#screen-menu { align-items: flex-start; padding-top: 9%; }
.menu-wrap { display: flex; flex-direction: column; align-items: center; gap: .6em; text-align: center; }
.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.5em; color: #fff; -webkit-text-stroke: .06em var(--red-dk); paint-order: stroke fill; transform: rotate(-4deg); }
.title .t2 {
  font-size: 3.2em; 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 .6em; font-size: 1em; color: #fff; text-shadow: 0 .1em .2em rgba(0,0,0,.6);
  background: rgba(11,26,58,.55); padding: .3em .9em; border-radius: 1em;
}
#btn-play { animation: breathe 1.7s ease-in-out infinite; }
#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); } }
#btn-audio b { display: inline-block; min-width: 2.2em; }
#btn-audio[aria-pressed=true] { background: #6b7280; border-bottom-color: #3f4652; }

/* ---------- instructions ---------- */
.howto-card { max-width: 25em; }
.rules { list-style: none; margin: .8em 0 .4em; padding: 0; display: grid; gap: .45em; text-align: left; }
.rules li {
  display: flex; align-items: center; gap: .75em; padding: .35em .6em; border-radius: .9em;
  background: #fff; border: .12em solid rgba(36,22,38,.15); font-size: .82em; line-height: 1.2; font-weight: 600;
}
.rules li b { display: block; font-size: 1.15em; font-weight: 800; color: var(--ink); letter-spacing: .04em; }
.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 { max-width: 100%; max-height: 100%; display: block; }
.ic.duo { display: flex; gap: .1em; }
.ic.duo span { flex: 1; height: 100%; display: grid; place-items: center; }
.hold-ic svg { width: 70%; height: 70%; animation: press 1.2s ease-in-out infinite; }
@keyframes press { 0%, 100% { transform: translateY(0); } 40%, 60% { transform: translateY(.2em) scale(.95); } }
#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) * 19);
  display: flex; align-items: flex-start; justify-content: center; padding: calc(var(--u) * 3) calc(var(--u) * 3);
  pointer-events: none;
}
.hud-left { position: absolute; left: calc(var(--u) * 3); top: calc(var(--u) * 3.2); display: grid; gap: .35em; }
.hud-energy { display: flex; align-items: center; gap: .1em; }
.hud-energy .bolt { width: 1.9em; height: 1.9em; z-index: 1; margin-right: -.55em; filter: drop-shadow(0 .08em 0 rgba(0,0,0,.4)); }
.hud-energy .bolt svg { width: 100%; height: 100%; display: block; }
.bar {
  position: relative; width: 6.4em; height: 1.05em; border-radius: 1em; overflow: hidden;
  background: rgba(10,20,45,.7); border: .14em solid #fff; box-shadow: 0 .1em 0 rgba(0,0,0,.35);
}
.bar i { position: absolute; inset: 0; transform-origin: left; border-radius: 1em; }
#energy-fill { background: linear-gradient(180deg, #7dffb0, #1fbf5c); transition: transform .12s linear; }
.hud-energy.low #energy-fill { background: linear-gradient(180deg, #ff8a80, #e2231a); }
.hud-energy.low .bar { animation: lowpulse .5s ease-in-out infinite alternate; }
@keyframes lowpulse { to { border-color: #ff8a80; box-shadow: 0 0 .6em #ff4d4d; } }
.hud-energy.bump .bar { animation: refill .45s ease-out; }
@keyframes refill { 30% { transform: scale(1.14); box-shadow: 0 0 1em #5dff9c; } }
.hud-boost { display: flex; align-items: center; gap: .35em; font-size: .75em; color: var(--gold); text-shadow: 0 .1em 0 #000; animation: boostin .25s ease-out; }
.hud-boost .bar { width: 5.2em; height: .9em; border-color: var(--gold); }
#boost-fill { background: repeating-linear-gradient(-45deg, #ffcf40 0 .45em, #ff9f1a .45em .9em); }
@keyframes boostin { from { transform: scale(.4); opacity: 0; } }

.hud-score {
  display: flex; align-items: center; gap: .25em; padding: .1em .75em .1em .3em; margin-top: calc(var(--u) * -.6);
  background: rgba(10,20,45,.72); border: .14em solid var(--gold); border-radius: 1.2em;
  color: #fff; font-size: 1.5em; font-weight: 800; box-shadow: 0 .1em 0 rgba(0,0,0,.4);
}
.hud-score.bump { animation: pop .25s ease-out; }
@keyframes pop { 40% { transform: scale(1.18); } }
.gift-ic { display: inline-block; width: 1.5em; height: 1.5em; background-size: contain; background-repeat: no-repeat; background-position: center; }

.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: 15em; }
.pause-card p { margin: .5em 0 0; }

/* ---------- result ---------- */
#screen-result { z-index: 5; background: rgba(5,11,28,0); }
#screen-result.active { animation: fadebg .5s forwards; }
@keyframes fadebg { to { background: rgba(5,11,28,.55); } }
.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-reason.energy { background: #fff1c7; color: #8a5a00; }
.result-label { margin-top: .6em; font-size: .85em; text-transform: uppercase; letter-spacing: .12em; color: #7b6a7a; }
.result-score { display: flex; align-items: center; justify-content: center; gap: .15em; font-size: 4.6em; font-weight: 800; line-height: 1.05; color: var(--red); text-shadow: 0 .05em 0 rgba(0,0,0,.15); }
.result-score .gift-ic { width: .9em; height: .9em; }
.result-sub { margin: .1em 0 1em; font-size: .95em; }

/* ---------- form (gift tag) ---------- */
.form-card { text-align: left; background: #fff4dc; padding-top: 2.1em; }
.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); }
.form-card h2 { text-align: center; font-family: "Mountains of Christmas", "Baloo 2", cursive; font-size: 1.9em; }
.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: #5a4a5a; min-height: 1.2em; }
.board-you b { color: var(--red); }
.board-head, .row { display: grid; grid-template-columns: 3em 1fr 4em; 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: #7b6a7a; }
.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); }
.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: #7b6a7a; }
.board-foot { display: flex; justify-content: space-between; gap: .5em; margin-top: .6em; font-size: .72em; color: #7b6a7a; 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: 640px) {
  .rules li { font-size: .74em; padding: .25em .5em; }
  .ic { width: 3em; height: 3em; }
}

@media (prefers-reduced-motion: reduce) {
  .title, .row.me, #btn-play, .hold-ic svg { animation: none; }
}
