:root {
  --night: #0b1d3a;
  --cream: #fff8ec;
  --ink: #1f1a17;
  --muted: #6d6259;
  --line: #e0d5c6;
  --red: #c62828;
  --red-dark: #8e1b1b;
  --green: #1f7a3a;
  --green-dark: #145228;
  --gold: #f4c542;
  --festive: 'Mountains of Christmas', Georgia, serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.45;
  color: var(--cream);
  background-color: var(--night);
  background-image: radial-gradient(120% 80% at 50% 0%, #22457d 0%, var(--night) 55%, #060f22 100%);
  background-attachment: fixed;
}
canvas.snow, canvas.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
canvas.snow { z-index: 0; }
canvas.confetti { z-index: 100; }

/* String lights across the top */
.lights {
  position: relative; z-index: 1; display: flex; justify-content: space-between;
  height: 26px; padding: 0 8px; overflow: hidden;
  background: linear-gradient(#26402c, #26402c) top / 100% 2px no-repeat;
}
.lights span {
  width: 10px; height: 15px; margin-top: 5px; border-radius: 50%;
  background: var(--c); box-shadow: 0 0 10px 2px var(--c);
  animation: twinkle 2.4s infinite ease-in-out; animation-delay: calc(var(--i) * -0.37s);
}
.lights span:nth-child(4n + 1) { --c: #ff4d4d; }
.lights span:nth-child(4n + 2) { --c: #ffd54a; }
.lights span:nth-child(4n + 3) { --c: #4dd36b; }
.lights span:nth-child(4n + 4) { --c: #4db8ff; }

.top { position: relative; z-index: 1; text-align: center; padding: 8px 16px 0; }
.title { font-family: var(--festive); font-weight: 700; font-size: 1.9rem; line-height: 1.1; color: var(--gold); text-shadow: 0 2px 0 rgba(0,0,0,.35); }
#app { position: relative; z-index: 1; max-width: 560px; margin: 0 auto; padding: 4px 16px 96px; }

.card {
  position: relative; overflow: hidden; margin: 14px 0; padding: 26px 18px 18px;
  background: var(--cream); color: var(--ink); border-radius: 18px; box-shadow: 0 10px 24px rgba(0,0,0,.35);
}
.card::before {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 8px;
  background: repeating-linear-gradient(45deg, var(--red) 0 10px, #fff 10px 20px);
}
.card h2 { margin: 0 0 10px; font-size: 1.2rem; }
.card p { margin: 8px 0; }
.muted { color: var(--muted); }
.big { font-family: var(--festive); font-weight: 700; font-size: 2.2rem; line-height: 1.1; color: var(--red); }
.hero { text-align: center; }
.helper-note { background: #fff1c9; border-radius: 12px; padding: 10px 12px; }
.steps { margin: 0; padding-left: 1.3em; }
.steps li { margin: 6px 0; }

.btn {
  display: block; width: 100%; min-height: 56px; margin: 10px 0 0; padding: 12px 18px;
  border: 0; border-radius: 14px; font: inherit; font-size: 1.2rem; font-weight: 800; cursor: pointer;
}
.btn.primary { background: var(--green); color: #fff; box-shadow: 0 4px 0 var(--green-dark); }
.btn.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--green-dark); }
.btn.ghost { background: transparent; color: var(--ink); border: 2px solid #d8cdbf; }
.btn.danger { background: var(--red); color: #fff; box-shadow: 0 4px 0 var(--red-dark); }
.btn.gold { background: var(--gold); color: var(--ink); box-shadow: 0 4px 0 #b8901f; }
.btn.small { display: inline-block; width: auto; min-height: 40px; margin: 0; padding: 6px 14px; font-size: 1rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 6px 12px; border-radius: 999px; background: #ece4d8; color: var(--muted); font-weight: 700; }
.chip.on { background: var(--green); color: #fff; }
.chip.on::before { content: '\25CF  '; color: #9cffb5; }

/* On the clock */
.clock { text-align: center; }
.clock .label { font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--red); }
.clock .name { font-family: var(--festive); font-weight: 700; font-size: 2.6rem; line-height: 1.1; }
.timer { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.timer.urgent { color: var(--red); animation: pulse 1s infinite; }
.clock.mine { background: linear-gradient(160deg, #fff3c4, #ffe08a); }
.clock.mine .label { font-size: 1.45rem; }
.flash { animation: flash 1.2s infinite; }
.clock.interlude { background: #eaf6ec; }
.clock.santa { background: linear-gradient(160deg, #eef5ff, #d6e7ff); }
.turn-line { font-weight: 800; color: var(--green-dark); }

/* Santa's sleigh crossing the screen during a no-show turn */
.sleigh-lane { position: fixed; inset: 0; z-index: 30; overflow: hidden; pointer-events: none; }
.sleigh {
  position: absolute; top: 14vh; left: 0; font-size: 3rem; white-space: nowrap;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.4)); animation: sleigh var(--dur, 10s) linear forwards;
}
.board .sleigh { font-size: 10vh; top: 12vh; }
@keyframes sleigh {
  0% { transform: translate(105vw, 0) rotate(-4deg); }
  25% { transform: translate(70vw, -2vh) rotate(3deg); }
  50% { transform: translate(35vw, 1vh) rotate(-3deg); }
  75% { transform: translate(5vw, -2vh) rotate(3deg); }
  100% { transform: translate(-70vw, 0) rotate(-4deg); }
}
@media (prefers-reduced-motion: reduce) { .sleigh-lane { display: none; } }
.announce { font-family: var(--festive); font-weight: 700; font-size: 1.8rem; line-height: 1.15; color: var(--green-dark); margin: 6px 0; }
.big-hint { font-size: 1.25rem; font-weight: 800; }

/* Draft order list */
.order { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.order li { display: flex; gap: 12px; align-items: center; padding: 8px 12px; border-radius: 12px; background: #f1e9dd; color: #b3a89b; font-weight: 800; }
.order li.shown { background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,.12); }
.order li.me { background: #fff1c9; }
.order li.pop { animation: pop .6s ease-out; }
.order .num { min-width: 2.4em; color: var(--red); }

/* The tree of presents */
.tree { --size: min(60px, calc((min(100vw, 560px) - 104px) / 5.4)); position: relative; padding: 2px 0 0; }
.tree::before {
  content: ''; position: absolute; left: 4%; right: 4%; top: calc(var(--size) * .6); bottom: calc(var(--size) * .35);
  background: linear-gradient(#2f8f4e, #1b5e32); clip-path: polygon(50% 0, 100% 100%, 0 100%); opacity: .22;
}
.star { position: relative; text-align: center; font-size: calc(var(--size) * .75); line-height: 1; animation: glow 2s infinite ease-in-out; filter: drop-shadow(0 0 8px rgba(244,197,66,.8)); }
.tree-row { position: relative; display: flex; justify-content: center; gap: calc(var(--size) * .18); }
.slot { display: flex; flex-direction: column; align-items: center; width: var(--size); }
.slot .who { min-height: 1.2em; max-width: calc(var(--size) * 1.35); font-size: .7rem; font-weight: 800; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trunk { position: relative; width: calc(var(--size) * .7); height: calc(var(--size) * .35); margin: 2px auto 0; background: #6d4c41; border-radius: 0 0 6px 6px; opacity: .55; }

/* One wrapped present. Colors come in as --wrap, --ribbon, --pc, --pattern, --psize. */
.present {
  position: relative; display: block; width: var(--size); height: calc(var(--size) * .78);
  margin-top: calc(var(--size) * .44); padding: 0; border: 0; background: none;
  font: inherit; color: inherit; -webkit-tap-highlight-color: transparent;
}
.present > .body, .present > .lid { background-color: var(--wrap); background-image: var(--pattern); background-size: var(--psize); }
.present > .body { position: absolute; inset: 0; border-radius: 4px; box-shadow: inset 0 -7px 0 rgba(0,0,0,.16), 0 5px 10px rgba(0,0,0,.28); }
.present > .lid {
  position: absolute; left: -8%; right: -8%; top: -16%; height: 26%; border-radius: 3px; box-shadow: 0 3px 0 rgba(0,0,0,.22);
  transition: transform .7s cubic-bezier(.2,1.4,.4,1), opacity .7s;
}
.present > .body::before, .present > .lid::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 50%; width: 16%; transform: translateX(-50%); background: var(--ribbon);
}
.present > .bow {
  position: absolute; left: 50%; top: -44%; width: 64%; height: 30%; transform: translateX(-50%);
  transition: transform .7s cubic-bezier(.2,1.4,.4,1), opacity .7s;
}
.present > .bow::before, .present > .bow::after {
  content: ''; position: absolute; bottom: 0; width: 50%; height: 100%;
  border: calc(var(--size) * .07) solid var(--ribbon); border-radius: 50%;
}
.present > .bow::before { left: 0; transform: rotate(-18deg); transform-origin: right bottom; }
.present > .bow::after { right: 0; transform: rotate(18deg); transform-origin: left bottom; }
.present > .bow > i {
  position: absolute; z-index: 1; left: 50%; bottom: -12%; width: 26%; aspect-ratio: 1;
  transform: translateX(-50%); border-radius: 50%; background: var(--ribbon); filter: brightness(.88);
}
.present.taken { opacity: .2; filter: grayscale(.8); }
.present.pickable { cursor: pointer; animation: wiggle 2.6s infinite ease-in-out; animation-delay: var(--d, 0s); }
.present.pickable > .body { outline: 3px solid var(--gold); outline-offset: 2px; }
.present.pickable:focus-visible > .body { outline-color: var(--ink); }
.present.shake { animation: shake .5s 3; }
.present.open > .lid { transform: translate(-6%, -190%) rotate(-24deg); opacity: 0; }
.present.open > .bow { transform: translate(-50%, -320%) rotate(30deg); opacity: 0; }

/* Overlay: confirm, hand-off, reveal */
#overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(4,10,26,.82); }
#overlay[hidden] { display: none; }
.modal {
  width: min(420px, 100%); max-height: 100%; overflow: auto; padding: 22px;
  background: var(--cream); color: var(--ink); border-radius: 22px; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.5); animation: pop .35s ease-out;
}
.modal .q { margin: 6px 0 4px; font-size: 1.35rem; font-weight: 800; }
.modal .emoji { font-size: 4rem; line-height: 1.1; }
.modal-present { display: flex; justify-content: center; }
.modal-present .present { --size: 120px; }
.reveal-name { display: none; margin: 8px 0; font-family: var(--festive); font-weight: 700; font-size: 3rem; line-height: 1.05; color: var(--red); }
.reveal .later { display: none; }
.reveal.opened .reveal-name { display: block; animation: pop .6s ease-out; }
.reveal.opened .later { display: block; }

/* Secret Santa cards */
.santa-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 10px 0; border-top: 1px dashed var(--line); }
.santa-row:first-of-type { border-top: 0; }
.santa-row .who { flex: 1 1 100%; font-size: .95rem; font-weight: 700; color: var(--muted); }
.secret { flex: 1; font-size: 1.4rem; font-weight: 800; }
.secret.shown { font-family: var(--festive); font-size: 2rem; color: var(--red); }

.log { list-style: none; margin: 0; padding: 0; }
.log li { padding: 8px 0; border-top: 1px dashed var(--line); }
.log li:first-child { border-top: 0; }
.log .num { margin-right: 6px; font-weight: 800; color: var(--red); }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 120; max-width: calc(100% - 32px); transform: translateX(-50%);
  padding: 12px 18px; border-radius: 12px; background: #222; color: #fff; font-weight: 700; box-shadow: 0 8px 20px rgba(0,0,0,.4);
}
.conn { position: fixed; top: 10px; right: 10px; z-index: 120; padding: 6px 12px; border-radius: 999px; background: var(--red); color: #fff; font-size: .85rem; font-weight: 800; }
.conn[hidden] { display: none; }

/* ---- Reindeer race ---- */
.race { --deer: 30px; --dw: calc(var(--deer) * 1.33); display: grid; gap: 6px; }
.race.tv { --deer: 5.4vh; gap: 1vh; }
.lane { display: grid; grid-template-columns: 1fr 2em; align-items: center; gap: 6px; }
.lane-label {
  position: absolute; top: 50%; left: calc(var(--rw) + 10px); transform: translateY(-50%); max-width: calc(100% - var(--rw) - 24px);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .74rem; font-weight: 800; color: rgba(31,26,23,.42);
}
.lane.me .lane-label { color: rgba(198,40,40,.75); }
.race.tv .lane { grid-template-columns: 20% 1fr 3.4em; gap: 1.2vw; }
.lane-name { font-size: .78rem; font-weight: 800; line-height: 1.15; overflow-wrap: anywhere; }
.race.tv .lane-name { font-size: 2.5vh; }
.lane.me .lane-name { color: var(--red); }
.track {
  --rw: calc(var(--dw) * (1 + .55 * (var(--n, 1) - 1))); /* runner width: one reindeer, or a team overlapping */
  position: relative; height: calc(var(--deer) + 6px); border-radius: 999px; overflow: hidden; background: linear-gradient(#f4f8ff, #dde8f5); box-shadow: inset 0 2px 4px rgba(0,0,0,.12); }
.lane.me .track { background: linear-gradient(#fff6d6, #ffe9a8); }
.finish { position: absolute; top: 0; right: 0; bottom: 0; width: 10px; opacity: .8; background: conic-gradient(#222 25%, #fff 0 50%, #222 0 75%, #fff 0) 0 0 / 10px 10px; }
.runner {
  /* Spans the whole travel distance and slides with transform, which phones animate
     without re-laying out the page on every tap. */
  position: absolute; top: 3px; left: 0; width: calc(100% - var(--rw) - 10px); display: flex;
  transform: translateX(calc(var(--p, 0) * 100%)); transition: transform .09s linear; will-change: transform;
}
.runner .deer { flex: none; width: var(--dw); height: var(--deer); transition: transform .06s; }
.runner .deer + .deer { margin-left: calc(var(--dw) * -.45); }
.deer .legs path { fill: none; stroke: #5d4037; stroke-width: 3.2; stroke-linecap: round; }
.deer .legs { transform-box: view-box; transition: transform .06s; }
.deer .legs-front { transform-origin: 40px 31px; transform: rotate(16deg); }
.deer .legs-back { transform-origin: 20px 31px; transform: rotate(-16deg); }
.runner.pose-b .legs-front { transform: rotate(-16deg); }
.runner.pose-b .legs-back { transform: rotate(16deg); }
.runner.pose-b .deer { transform: translateY(-1px); }
.place { font-size: 1.1rem; font-weight: 800; text-align: center; }
.race.tv .place { font-size: 3.6vh; }
.timer.countdown { font-size: 3.4rem; }
.race-banner { margin: 0 0 1.4vh; text-align: center; font-family: var(--festive); font-weight: 700; font-size: 6vh; line-height: 1.1; color: var(--red); }
.race-banner.count { font-size: 9vh; }
.race-banner.go { color: var(--green-dark); }
.race-banner.go.final { color: var(--red); animation: pulse .8s infinite; }
.board-sound {
  position: fixed; z-index: 60; right: 1.5vw; bottom: 1.5vh; padding: .6vh 1.4vh; border: 0; border-radius: 999px;
  background: rgba(255,255,255,.15); color: #fff; font: inherit; font-size: 2vh; font-weight: 800; cursor: pointer;
}
.race-banner span { font-family: 'Nunito', sans-serif; font-size: 3vh; color: var(--muted); }

.hooves { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.hooves.dock {
  position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; margin: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(6,15,34,.94);
}
.hoof {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 96px; border: 0; border-radius: 18px; color: #fff; font: inherit; font-size: 1.3rem; font-weight: 900;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.hooves.dock .hoof { min-height: 120px; }
.hoof .arrow { font-size: 1.8rem; line-height: 1; }
.hoof.left { background: var(--red); box-shadow: 0 6px 0 var(--red-dark); }
.hoof.right { background: var(--green); box-shadow: 0 6px 0 var(--green-dark); }
.hooves.dock, #app.docked { touch-action: manipulation; }
#app.docked { padding-bottom: 170px; }
.practice-time { min-height: 1.4em; margin-top: 10px; text-align: center; font-weight: 800; }
.practice > .btn { margin-top: 16px; }

/* Race bar: your place, what's happening, time left. Turns red for the final stretch. */
.race-hud {
  position: sticky; top: 6px; z-index: 35; display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px;
  margin: 10px 0; padding: 10px 14px; border-radius: 16px; background: var(--cream); color: var(--ink); box-shadow: 0 8px 20px rgba(0,0,0,.35);
}
.hud-place { min-width: 2.2em; font-family: var(--festive); font-weight: 700; font-size: 2.2rem; line-height: 1; color: var(--red); text-align: center; }
.hud-msg { font-weight: 900; font-size: 1rem; line-height: 1.2; }
.hud-time { font-weight: 900; font-size: 1.8rem; font-variant-numeric: tabular-nums; }
.hud-mute { padding: 4px; border: 0; background: none; font-size: 1.5rem; cursor: pointer; }
.race-hud.final { background: var(--red); color: #fff; animation: hudflash .7s infinite; }
.race-hud.final .hud-place { color: #fff; }
@keyframes hudflash { 50% { background: #8e1b1b; } }
.race-card { padding-top: 20px; }
.small { font-size: .85rem; }
.tip { margin: 10px 0 0; padding: 8px 12px; border-radius: 12px; background: #fff1c9; font-weight: 800; }
.reveal.opened .tip.later { display: block; }

/* ---- TV board ---- */
body.board { height: 100vh; overflow: hidden; font-size: 2.1vh; }
.board .lights { height: 4vh; }
.board .lights span { width: 1.4vh; height: 2.1vh; margin-top: .8vh; }
.board .title { font-size: 6vh; }
body.board #app.board-main { position: relative; z-index: 1; max-width: none; height: calc(100vh - 13vh); margin: 0; display: grid; gap: 3vw; padding: 1.5vh 3vw 2vh; }
.board-main.split { grid-template-columns: 1.15fr 1fr; align-items: center; }
.board-main.single { grid-template-columns: 1fr; align-items: center; }
.board-main.center { place-items: center; text-align: center; }
.board .card { margin: 0; padding: 3.6vh 3vh 2.6vh; border-radius: 2.2vh; }
.board .card::before { height: 1.2vh; }
.board .card h2 { font-size: 2.8vh; }
.board .tree { --size: min(8.2vh, 6vw); }
.board .slot .who { font-size: 1.8vh; }
.board .panel { display: flex; flex-direction: column; gap: 2vh; }
.board .clock .label { font-size: 3vh; }
.board .clock .name { font-size: 9vh; }
.board .timer { font-size: 10vh; }
.board .announce { font-size: 5.5vh; }
.board .upnext { font-size: 3vh; font-weight: 800; margin: 0; }
.board .log li { font-size: 2.5vh; }
.board .big { font-size: 9vh; color: var(--gold); text-shadow: 0 .5vh 0 rgba(0,0,0,.35); }
.board .hero .big { color: var(--red); text-shadow: none; }
.board .sub { font-size: 3.4vh; margin: 1.5vh 0; }
.lobby-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 1.5vh; max-width: 80vw; margin: 2vh auto; }
.board .chip { padding: 1vh 2.4vh; font-size: 3.2vh; }
.board .order { grid-template-columns: 1fr 1fr; }
.board .order li { padding: 1vh 1.5vh; font-size: 2.6vh; }
.spot { text-align: center; }
.spot .pos { font-size: 4.5vh; font-weight: 800; color: var(--gold); }
.spot .nm { font-family: var(--festive); font-weight: 700; font-size: 14vh; line-height: 1.05; color: #fff; text-shadow: 0 .6vh 0 rgba(0,0,0,.4); animation: pop .6s ease-out; }

/* ---- Commissioner ---- */
body.commish #app { max-width: 860px; }
.controls { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.controls .btn { margin: 0; }
.row-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.row-inline input { width: 6em; padding: 8px; border: 2px solid #d8cdbf; border-radius: 10px; font: inherit; }
.row-inline select { padding: 8px; border: 2px solid #d8cdbf; border-radius: 10px; background: #fff; font: inherit; }
.links { width: 100%; border-collapse: collapse; }
.links td { padding: 8px 6px; border-top: 1px dashed var(--line); vertical-align: middle; }
.links tr:first-child td { border-top: 0; }
.links .acts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.links .note { font-size: .85rem; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 50%; background: #c9bfb2; }
.dot.on { background: #2fbf5b; }
.small-timer { font-size: 1.4rem; }

@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.06); opacity: 1; } 100% { transform: scale(1); } }
@keyframes pulse { 50% { transform: scale(1.08); } }
@keyframes flash { 50% { color: var(--green); } }
@keyframes glow { 50% { filter: drop-shadow(0 0 16px rgba(244,197,66,1)); } }
@keyframes twinkle { 50% { opacity: .35; box-shadow: none; } }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-6deg); } 90% { transform: rotate(6deg); } 95% { transform: rotate(-3deg); } }
@keyframes shake { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-9deg) scale(1.03); } 75% { transform: rotate(9deg) scale(1.03); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
