:root {
  --navy: #1b2466;
  --navy2: #2c3f9c;
  --orange: #f0922b;
  --orange-d: #d9771a;
  --red: #d7263d;
  --peach: #ffdcbc;
  --cream: #fff8ef;
  --ink: #1d1d2b;
  --green: #2bb673;
  --font: "Fredoka", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--navy) url("../assets/bg/night.webp") center bottom / cover no-repeat fixed;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
img { -webkit-user-drag: none; user-select: none; }
button { font-family: inherit; cursor: pointer; }

#app { position: fixed; inset: 0; }

/* ---------- snow ---------- */
#snow { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
#snow i {
  position: absolute; top: -10px; width: 6px; height: 6px; border-radius: 50%;
  background: #fff; opacity: .8; animation: fall linear infinite;
}
@keyframes fall { to { transform: translate3d(var(--dx, 20px), 110vh, 0); } }

/* ---------- screens ---------- */
.screen { position: absolute; inset: 0; display: none; z-index: 1; }
.screen.active { display: flex; animation: fadein .35s ease; }
@keyframes fadein { from { opacity: 0; } }

.topbtns { position: fixed; top: 10px; right: 10px; z-index: 50; display: flex; gap: 8px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 3px solid var(--orange);
  background: var(--cream); font-size: 18px; font-weight: 700; color: var(--ink);
  box-shadow: 0 3px 0 var(--orange-d);
}

.btn {
  border: none; border-radius: 14px; padding: 14px 34px; font-size: 22px; font-weight: 700;
  background: var(--cream); color: var(--ink); box-shadow: 0 5px 0 #c9b9a6;
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn.primary { background: var(--orange); color: #fff; box-shadow: 0 5px 0 var(--orange-d); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--orange-d); }
.btn:disabled { filter: grayscale(1) opacity(.5); }
.btn.small { padding: 10px 20px; font-size: 18px; }

.panel {
  background: var(--cream); border: 4px solid var(--orange); border-radius: 18px;
  padding: 18px 22px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}

/* ---------- loading ---------- */
#scr-loading { align-items: center; justify-content: center; }
.loader { width: min(320px, 80vw); color: #fff; text-align: center; font-size: 18px; }
.loader-bar { height: 16px; border-radius: 10px; background: rgba(255,255,255,.2); overflow: hidden; border: 3px solid var(--orange); }
.loader-bar i { display: block; height: 100%; width: 0; background: var(--orange); transition: width .2s; }

/* ---------- santa sprite (sprite-gen atlas 4x3, 256px cells) ---------- */
.santa {
  aspect-ratio: 1; background: url("../assets/santa/santa-sheet.webp") 0 0 / 400% 300% no-repeat;
  animation: santa-steps 1s steps(4) infinite;
}
.santa[data-anim="idle"] { background-position-y: 0%; animation-duration: 1s; }
.santa[data-anim="celebrate"] { background-position-y: 50%; animation-duration: .5s; }
.santa[data-anim="oops"] { background-position-y: 100%; animation-duration: .8s; }
@keyframes santa-steps { from { background-position-x: 0%; } to { background-position-x: 133.333%; } }
.santa.big { width: min(240px, 34vh); }
.santa.mid { width: 170px; flex: none; }
.santa.small { width: 92px; flex: none; }

/* ---------- title ---------- */
#scr-title { align-items: center; justify-content: center; text-align: center; }
.title-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 20px; }
.team { color: #c9d3ff; margin: 0; font-size: 16px; letter-spacing: .5px; }
.logo {
  margin: 0; color: #fff; font-size: clamp(34px, 7vw, 72px); line-height: 1.05; font-weight: 700;
  text-shadow: 0 5px 0 var(--red), 0 10px 24px rgba(0,0,0,.35);
}
.logo span { color: var(--orange); }
.tagline { color: #fff; font-size: clamp(16px, 2.4vw, 22px); max-width: 620px; margin: 4px 0 12px; }
.hint { color: #c9d3ff; margin: 0; font-size: 15px; }

/* ---------- story ---------- */
#scr-story { align-items: center; justify-content: center; padding: 16px; }
.story { display: flex; gap: 20px; align-items: center; max-width: 820px; }
.story h2 { margin: 0 0 6px; font-size: 30px; color: var(--red); }
.story p { margin: 6px 0; font-size: 18px; line-height: 1.4; }
.howto { padding-left: 20px; margin: 10px 0 16px; font-size: 17px; line-height: 1.5; }
@media (max-width: 640px) { .story { flex-direction: column; text-align: center; } .howto { text-align: left; } }

/* ---------- controls ---------- */
#scr-controls { align-items: center; justify-content: center; padding: 16px; }
.controls { text-align: center; max-width: 640px; width: 100%; }
.controls h2 { margin: 0 0 16px; color: var(--red); font-size: 30px; }
.ctrl-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ctrl {
  border: 4px solid #eadfcf; background: #fff; border-radius: 18px; padding: 18px 10px; display: flex; flex-direction: column;
  align-items: center; gap: 6px; font-size: 22px; color: var(--ink); box-shadow: 0 5px 0 #d9ccb8; transition: transform .1s;
}
.ctrl .ico { font-size: 46px; }
.ctrl small { font-size: 14px; color: #777; }
.ctrl.sel { border-color: var(--orange); }
.ctrl:active { transform: translateY(3px); }

/* ---------- play ---------- */
#scr-play { flex-direction: column; touch-action: none; }
.hud {
  display: flex; align-items: center; gap: 12px; padding: 10px 116px 10px 14px; color: #fff;
  font-weight: 700; font-size: 20px; z-index: 3;
}
.hud-stage { background: var(--red); padding: 6px 14px; border-radius: 12px; white-space: nowrap; }
.hud-score { background: rgba(0,0,0,.25); padding: 6px 14px; border-radius: 12px; white-space: nowrap; min-width: 90px; }
.progress { flex: 1; height: 16px; border-radius: 8px; background: rgba(0,0,0,.3); border: 3px solid var(--orange); overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #ffd166, var(--orange)); transform-origin: left; transform: scaleX(0); transition: transform .2s; }

.scene { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.side {
  position: absolute; bottom: 0; width: min(34vw, 300px); display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding-bottom: 6px;
}
.side.left { left: 1.5vw; }
.side.right { right: 1.5vw; }
.house { width: 100%; filter: drop-shadow(0 8px 10px rgba(0,0,0,.35)); transition: transform .15s; }
.house.bump { transform: scale(1.05) translateY(-4px); }
.sign {
  background: #a0603a; border: 4px solid #6d3a22; border-radius: 12px; padding: 6px; display: flex; flex-direction: column;
  gap: 5px; box-shadow: 0 6px 12px rgba(0,0,0,.35); min-height: 40px;
}
.sign .row { display: flex; gap: 4px; justify-content: center; background: var(--cream); border-radius: 8px; padding: 4px; }
.sign img { width: clamp(28px, 4.4vw, 50px); height: clamp(28px, 4.4vw, 50px); object-fit: contain; }
.sign .kids img { border-radius: 8px; background: #ffe9d6; object-fit: cover; object-position: top; }
.sign .gifts { background: #fff; }
.sign.big img { width: clamp(40px, 7vw, 64px); height: clamp(40px, 7vw, 64px); }

.stim-wrap {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); display: flex; flex-direction: column;
  align-items: center; gap: 10px; z-index: 3; pointer-events: none;
}
.stim {
  --c: #fff; position: relative; width: clamp(130px, 22vw, 220px); aspect-ratio: 1; border-radius: 14px; background: #fff;
  border: 5px solid var(--orange); box-shadow: 0 10px 24px rgba(0,0,0,.4); overflow: hidden;
}
.stim.kid { background: var(--c); }
.stim.kid img { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; }
.stim.gift img { position: absolute; inset: 12%; width: 76%; height: 76%; object-fit: contain; }
.stim.hidden-stim { visibility: hidden; }
.stim .x {
  position: absolute; inset: 0; display: none; place-items: center; font-size: 110px; font-weight: 700; color: var(--red);
  text-shadow: 0 0 12px #fff; background: rgba(255,255,255,.35);
}
.stim.err .x { display: grid; }
.stim.err { border-color: var(--red); }
.stim.shake { animation: shake .3s; }
@keyframes shake { 25% { translate: -12px 0; } 75% { translate: 12px 0; } }
.stim.fly-l { animation: flyL .22s ease-in forwards; }
.stim.fly-r { animation: flyR .22s ease-in forwards; }
@keyframes flyL { to { transform: translate(-38vw, 18vh) scale(.25) rotate(-25deg); opacity: .2; } }
@keyframes flyR { to { transform: translate(38vw, 18vh) scale(.25) rotate(25deg); opacity: .2; } }
.arrows { display: flex; align-items: center; gap: 14px; color: #fff; font-size: 26px; opacity: .8; }
.arrows em { font-style: normal; font-size: 16px; background: rgba(0,0,0,.3); border-radius: 10px; padding: 2px 10px; }
.combo { height: 30px; color: #ffd166; font-size: 24px; font-weight: 700; text-shadow: 0 3px 0 var(--red); opacity: 0; transition: opacity .2s; }
.combo.on { opacity: 1; }

.glove {
  position: absolute; bottom: 0; left: 50%; width: clamp(80px, 10vw, 130px); z-index: 4; pointer-events: none;
  transform: translateX(-50%) translateY(55%) rotate(0deg);
}
.glove .mitten { width: 100%; display: block; filter: drop-shadow(0 6px 10px rgba(0,0,0,.35)); }
.glove.tilt-l { animation: tiltL .3s; }
.glove.tilt-r { animation: tiltR .3s; }
@keyframes tiltL { 40% { transform: translateX(-70%) translateY(45%) rotate(-22deg); } }
@keyframes tiltR { 40% { transform: translateX(-30%) translateY(45%) rotate(22deg); } }

.overlay { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(15, 20, 60, .55); padding: 14px; }
.intro { text-align: center; max-width: 720px; width: 100%; animation: pop .3s; }
@keyframes pop { 0% { transform: scale(.85); opacity: 0; } }
.intro h2 { margin: 0; color: var(--red); font-size: 30px; }
.intro p { font-size: 19px; margin: 8px 0 12px; }
.intro-signs { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.intro-signs > div { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.intro-signs b { font-size: 28px; color: var(--orange); }
.go-hint { font-weight: 700; color: var(--orange-d); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .4; } }
.hidden { display: none !important; }

/* ---------- done ---------- */
#scr-done { align-items: center; justify-content: center; padding: 16px; }
.done { text-align: center; max-width: 560px; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.done h2 { margin: 0; font-size: 34px; color: var(--red); }
.stars { font-size: 44px; letter-spacing: 6px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; margin: 6px 0 12px; }
.stats div { background: #fff; border-radius: 12px; padding: 8px 4px; display: flex; flex-direction: column; }
.stats b { font-size: 24px; color: var(--orange-d); }
.stats span { font-size: 13px; color: #777; }

/* ---------- results ---------- */
#scr-reveal { overflow-y: auto; justify-content: center; }
.results { width: min(880px, 100%); padding: 20px 14px 60px; display: flex; flex-direction: column; gap: 16px; height: max-content; }
.res-head { display: flex; align-items: center; gap: 12px; color: #fff; }
.res-head h2 { margin: 0; font-size: clamp(28px, 5vw, 44px); text-shadow: 0 4px 0 var(--red); }
.big-score { margin: 4px 0 0; font-size: 22px; }
.big-score b { color: #ffd166; font-size: 34px; }
.results h3 { margin: 0 0 8px; color: var(--red); font-size: 24px; }
.results p { font-size: 17px; line-height: 1.45; margin: 6px 0; }
.lead { color: #fff; font-size: 19px; margin: 6px 0 0; }
.test p { font-size: 16px; }
.rt-bars { display: flex; flex-direction: column; gap: 12px; margin: 10px 0; }
.rt { display: grid; grid-template-columns: minmax(0, 250px) 1fr 70px; align-items: center; gap: 10px; }
.rt .lbl { display: flex; flex-direction: column; }
.rt .lbl small { color: #888; font-size: 12px; }
.pair { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.pair img { width: 26px; height: 26px; object-fit: contain; border-radius: 6px; }
.pair i { font-style: normal; font-weight: 700; margin: 0 3px; color: var(--orange-d); }
.rt .track { height: 22px; border-radius: 11px; background: #eadfcf; overflow: hidden; }
.rt .fill { height: 100%; width: 0; border-radius: 11px; transition: width 1.2s cubic-bezier(.2,.8,.2,1); }
.rt .fill.cong { background: var(--green); }
.rt .fill.inc { background: var(--red); }
.rt b { text-align: right; font-size: 15px; }
.verdict { background: #fff3d6; border-radius: 10px; padding: 8px 12px; }
.verdict .d { display: inline-block; background: var(--ink); color: #fff; border-radius: 8px; padding: 0 8px; margin-right: 6px; font-size: 14px; }
#res-tests { display: flex; flex-direction: column; gap: 16px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.g-item {
  display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; align-items: center; background: #fff; border-radius: 12px;
  padding: 8px; border: 3px solid #eee;
}
.g-item.ok { border-color: var(--green); }
.g-item.no { border-color: #f3b0b8; }
.g-item .kid { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; object-position: top; }
.g-item .t { font-size: 14px; line-height: 1.3; }
.g-item .t b { font-size: 15px; }
.g-item .t .q { color: #666; font-style: italic; display: block; margin-top: 2px; }
.g-item .gifts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; }
.g-item .chip { display: inline-flex; align-items: center; gap: 4px; background: #f4efe7; border-radius: 8px; padding: 2px 8px 2px 4px; font-size: 13px; font-weight: 600; }
.g-item .chip.bad { background: #fde3e6; }
.g-item .gifts img { width: 28px; height: 28px; object-fit: contain; }
.takeaway { background: #fff3d6; }
.fine { color: #777; font-size: 13px !important; }
#btn-again { align-self: center; }

@media (max-width: 640px) {
  .hud { font-size: 15px; gap: 8px; padding-right: 108px; }
  .progress { position: absolute; left: 14px; right: 14px; top: 58px; height: 10px; border-width: 2px; }
  .side { width: 44vw; }
  .sign img { width: 30px; height: 30px; }
  .sign .row { flex-wrap: wrap; }
  .stim-wrap { top: 30%; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .rt { grid-template-columns: 1fr 60px; }
  .rt .lbl { grid-column: 1 / -1; }
  .results { padding-top: 60px; }
  .ctrl-opts { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .card { animation: none; } #snow { display: none; } }
