:root {
  --bg: #121738;
  --bg-2: #1a2150;
  --panel: #1f2858;
  --panel-2: #2a3470;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f6f3ff;
  --muted: #aab1de;
  --gold: #ffc53d;
  --gold-2: #ff9f1c;
  --red: #e5383b;
  --red-2: #b8232a;
  --green: #44b35b;
  --snow: #e9edff;
  --radius: 22px;
  --shadow: 0 10px 30px rgba(5, 8, 30, 0.45);
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; min-height: 100%; }

body {
  background: radial-gradient(120% 60% at 50% 0%, #26306e 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 32px);
  position: relative;
  z-index: 1;
}

img { display: block; max-width: 100%; user-select: none; -webkit-user-drag: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 600; }

/* ---------- falling snow ---------- */
#snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.flake {
  position: absolute; top: -10px; border-radius: 50%; background: #fff; opacity: .6;
  animation: fall linear infinite;
}
@keyframes fall { to { transform: translate3d(var(--drift), 105vh, 0); } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 54px; padding: 12px 20px;
  border: 0; border-radius: 18px; cursor: pointer;
  font-size: 18px; font-weight: 600; letter-spacing: .2px;
  background: var(--panel-2); color: var(--text);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .25);
  transition: transform .12s ease, filter .12s ease;
}
.btn:active { transform: translateY(2px) scale(.99); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .25); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-gold { background: linear-gradient(180deg, #ffd35c, var(--gold-2)); color: #4a2600; }
.btn-red { background: linear-gradient(180deg, #f2534f, var(--red-2)); color: #fff; }
.btn-green { background: linear-gradient(180deg, #5fd179, #2d8c45); color: #fff; }
.btn-ghost { background: transparent; box-shadow: none; color: var(--muted); min-height: 44px; font-weight: 500; }
.btn-small { min-height: 40px; font-size: 15px; padding: 8px 14px; border-radius: 14px; width: auto; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.stack { display: grid; gap: 12px; }

/* ---------- cards ---------- */
.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card + .card, .card + section, section + .card, section + section { margin-top: 16px; }
.eyebrow { font-size: 13px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--gold); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- onboarding ---------- */
.hero { text-align: center; padding-top: 8px; }
.hero .santa { width: 46%; max-width: 210px; margin: 0 auto -6px; animation: wave 2.4s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes wave { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg) translateY(-3px); } }
.hero h1 { font-size: 31px; margin: 10px 0 8px; }
.hero h1 span { color: var(--gold); }
.story { color: var(--muted); font-size: 16px; margin: 0 auto 18px; max-width: 420px; }
.story b { color: var(--text); font-weight: 500; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 14px; color: var(--muted); font-weight: 500; }
.input {
  width: 100%; min-height: 52px; padding: 12px 16px; border-radius: 16px;
  border: 2px solid var(--line); background: rgba(0, 0, 0, .22); color: var(--text);
  font: inherit; font-size: 18px; outline: none;
}
.input:focus { border-color: var(--gold); }
.input.code { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-weight: 600; font-size: 24px; }

.avatars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.avatar-opt {
  border: 2px solid var(--line); border-radius: 18px; background: rgba(0, 0, 0, .18);
  padding: 8px 4px 10px; cursor: pointer; text-align: center; font-size: 14px; color: var(--muted);
}
.avatar-opt.on { border-color: var(--gold); background: rgba(255, 197, 61, .12); color: var(--text); }
.avatar-opt .sprite { margin: 0 auto 4px; }

.pace { display: flex; align-items: center; gap: 12px; }
.pace input[type=range] { flex: 1; accent-color: var(--gold); height: 32px; }
.pace output { min-width: 84px; text-align: right; font-weight: 600; }

.back { display: inline-flex; align-items: center; gap: 4px; background: none; border: 0; color: var(--muted); padding: 6px 0; margin-bottom: 8px; cursor: pointer; font-size: 16px; }

.claim { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- sprites ---------- */
.sprite {
  background-repeat: no-repeat;
  background-size: calc(var(--frames) * 100%) 100%;
  animation: sprite var(--speed, .5s) steps(var(--frames)) infinite;
}
@keyframes sprite { from { background-position-x: 0%; } to { background-position-x: calc(var(--frames) / (var(--frames) - 1) * 100%); } }
.sprite.still { animation: none; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.topbar h1 { font-size: 22px; }
.topbar .sub { font-size: 14px; color: var(--muted); }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 6px 12px 6px 6px; cursor: pointer; font-size: 15px; flex-shrink: 0;
}
.faces { display: flex; }
.faces .face { width: 30px; height: 30px; border-radius: 50%; background: var(--panel-2); border: 2px solid var(--panel); overflow: hidden; margin-left: -8px; }
.faces .face:first-child { margin-left: 0; }
.face .sprite { width: 52px; height: 52px; margin: -2px 0 0 -8px; animation: none; }

/* ---------- scene ---------- */
.scene {
  position: relative; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 1704 / 620; box-shadow: var(--shadow); border: 1px solid var(--line);
  background: #1b2252 url(assets/scene.jpg) center / cover no-repeat;
}
.scene .runner { position: absolute; transform: translate(-50%, -100%); transition: left 1s linear, top 1s linear; z-index: 3; }
.scene .runner .sprite { height: 100%; }
.scene .tag {
  position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%);
  background: rgba(15, 18, 50, .82); border-radius: 999px; padding: 1px 8px; font-size: 11px; white-space: nowrap; font-weight: 500;
}
.scene .worker { position: absolute; left: 72%; top: 47%; height: 26%; z-index: 2; }
.scene .sleigh {
  position: absolute; top: 4%; height: 30%; left: 0; z-index: 4;
  animation: fly 9s linear infinite; filter: drop-shadow(0 0 14px rgba(255, 210, 90, .6));
}
@keyframes fly {
  0% { transform: translateX(-110%) translateY(30%) rotate(-4deg); }
  50% { transform: translateX(80%) translateY(-6%) rotate(-7deg); }
  100% { transform: translateX(330%) translateY(-30%) rotate(-10deg); }
}
.scene .sleigh img { height: 100%; width: auto; max-width: none; }
.scene-caption {
  position: absolute; left: 10px; top: 8px; z-index: 5;
  background: rgba(12, 15, 44, .72); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--snow);
}

/* ---------- action card ---------- */
#action { margin-top: 16px; }
.action h2 { font-size: 22px; margin: 4px 0 4px; }
.action .meta { color: var(--muted); margin-bottom: 14px; }
.action .part-chip { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.action .part-chip img { width: 64px; height: 64px; object-fit: contain; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .35)); }
.timer { font-size: 40px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.bar { height: 12px; border-radius: 999px; background: rgba(0, 0, 0, .3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), var(--gold-2)); transition: width .6s ease; }
.running-note { display: flex; align-items: center; gap: 10px; background: rgba(0, 0, 0, .2); border-radius: 14px; padding: 8px 12px; margin-bottom: 12px; font-size: 15px; }
.running-note .sprite { width: 38px; height: 38px; flex-shrink: 0; }
.last-try { border-color: rgba(255, 197, 61, .5); background: linear-gradient(180deg, #4a2d12, #2a1f3a); }

/* ---------- sled ---------- */
.workshop { position: relative; }
.sled-wrap { position: relative; margin: 6px -8px 0; }
.sled { position: relative; width: 100%; aspect-ratio: var(--sled-ratio); }
.sled > img { position: absolute; max-width: none; }
.sled .ghost { inset: 0; width: 100%; height: 100%; }
.sled .layer.pop { animation: pop .9s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes pop {
  0% { opacity: 0; transform: translateY(-30%) scale(.6); filter: brightness(2.5); }
  60% { opacity: 1; filter: brightness(1.6); }
  100% { opacity: 1; transform: none; filter: none; }
}
.sled .gift { width: 17%; left: 55%; top: 22%; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .4)); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.stat { background: rgba(0, 0, 0, .2); border-radius: 16px; padding: 10px 12px; }
.stat b { display: block; font-size: 24px; font-weight: 600; }
.stat span { font-size: 13px; color: var(--muted); }
.stat .bar { margin-top: 6px; height: 8px; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 4px 10px; }
.cal-head h2 { font-size: 22px; }
.calendar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.door {
  position: relative; aspect-ratio: 172 / 187; border: 0; padding: 0; background: none; cursor: pointer;
  transition: transform .15s ease;
}
.door:active { transform: scale(.95); }
.door > img { width: 100%; height: 100%; object-fit: contain; }
.door .num {
  position: absolute; left: 50%; bottom: 13%; transform: translateX(-50%);
  min-width: 30px; padding: 0 6px; border-radius: 999px; background: rgba(40, 20, 6, .78);
  font-weight: 600; font-size: 15px; color: #fff3d6;
}
.door .icon { position: absolute; left: 18%; top: 34%; width: 50%; height: 42%; object-fit: contain; filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .5)); }
.door .check {
  position: absolute; right: 2%; top: 2%; width: 26px; height: 26px; border-radius: 50%;
  background: var(--green); display: grid; place-items: center; font-size: 15px; font-weight: 700; box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.door.locked > img { filter: grayscale(.85) brightness(.55); }
.door.locked .num { background: rgba(10, 12, 30, .8); color: var(--muted); }
.door.open > img { filter: drop-shadow(0 0 10px rgba(255, 197, 61, .75)); animation: glow 1.8s ease-in-out infinite; }
.door.today .num { background: var(--gold); color: #4a2600; }
@keyframes glow { 50% { filter: drop-shadow(0 0 18px rgba(255, 197, 61, 1)); } }

/* ---------- finale ---------- */
.finale { text-align: center; background: linear-gradient(180deg, #3b2a12, #1f2858); border-color: rgba(255, 197, 61, .4); }
.finale h2 { font-size: 26px; margin: 6px 0 6px; }
.finale .org { font-size: 14px; color: var(--muted); margin: 8px 0 14px; }
.countdown { text-align: center; }
.countdown b { color: var(--gold); }

/* ---------- modal / sheet ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgba(6, 8, 28, .66);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .2s ease;
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border-radius: 28px 28px 0 0; padding: 12px 18px calc(env(safe-area-inset-bottom) + 18px);
  animation: up .28s cubic-bezier(.2, .9, .3, 1); border: 1px solid var(--line);
}
.sheet .grip { width: 44px; height: 5px; border-radius: 9px; background: rgba(255, 255, 255, .25); margin: 0 auto 12px; }
.sheet h2 { font-size: 24px; margin-bottom: 4px; }
.sheet .part-big { width: 56%; max-width: 220px; margin: 4px auto 6px; filter: drop-shadow(0 8px 16px rgba(0, 0, 0, .45)); }
.sheet .center { text-align: center; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40%); opacity: .4; } }

.reward { text-align: center; padding-top: 10px; }
.reward .burst { position: relative; width: 70%; max-width: 260px; margin: 0 auto; }
.reward .burst::before {
  content: ''; position: absolute; inset: -18%; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 214, 102, .65), rgba(255, 214, 102, 0) 65%);
  animation: pulse 1.6s ease-in-out infinite;
}
.reward .burst img { position: relative; animation: pop .9s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes pulse { 50% { transform: scale(1.12); opacity: .7; } }

.member-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.member-row:last-child { border-bottom: 0; }
.member-row .sprite { width: 48px; height: 48px; flex-shrink: 0; }
.member-row .you { font-size: 12px; color: var(--gold); margin-left: 6px; }
.invite { background: rgba(0, 0, 0, .22); border-radius: 18px; padding: 14px; text-align: center; margin: 14px 0; }
.invite .code { font-size: 32px; letter-spacing: 8px; font-weight: 600; color: var(--gold); }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); z-index: 40;
  transform: translate(-50%, 140%); transition: transform .3s ease; max-width: calc(100% - 32px);
  background: #fff; color: #1b1f45; border-radius: 16px; padding: 12px 18px; font-weight: 500; box-shadow: var(--shadow);
}
#toast.show { transform: translate(-50%, 0); }
#toast.err { background: #ffe1e1; color: #7a1010; }

.debug {
  margin-top: 28px; padding: 12px; border: 1px dashed rgba(255, 255, 255, .25); border-radius: 14px;
  font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.debug input { font: inherit; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }

.loading { min-height: 70vh; display: grid; place-items: center; color: var(--muted); }

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