:root {
  --pine: #0f3d2e;
  --pine-2: #15523d;
  --pine-3: #1d6b50;
  --red: #c8102e;
  --red-2: #e23a4f;
  --gold: #f5c542;
  --snow: #fbfaf5;
  --ink: #1b1b1b;
  --muted: #6b7a73;
  --grinch: #5fae3b;
  --card: #ffffff;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(120% 80% at 50% 0%, var(--pine-3), var(--pine) 60%);
  background-attachment: fixed;
  color: var(--snow);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(96px + var(--safe-bottom)); position: relative; z-index: 1; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 28px; }
h2 { font-size: 20px; margin-top: 8px; }
h3 { font-size: 16px; }
p { line-height: 1.45; }
a { color: var(--gold); }
.muted { color: #cfe0d8; opacity: .85; font-size: 14px; }
.loading { text-align: center; margin-top: 40vh; }

/* Snow */
#snow { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.flake { position: absolute; top: -10px; color: #fff; opacity: .8; animation: fall linear infinite; }
@keyframes fall { to { transform: translateY(105vh) translateX(30px) rotate(360deg); } }

/* Cards and forms */
.card { background: var(--card); color: var(--ink); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.card .muted { color: var(--muted); opacity: 1; }
.card h2 { margin-top: 0; }
label { display: block; font-size: 13px; font-weight: 600; margin: 10px 0 4px; color: var(--muted); }
input, textarea, select {
  width: 100%; padding: 12px; font-size: 16px; border: 1px solid #d9e2dd; border-radius: 12px; background: #fff; color: var(--ink);
}
textarea { min-height: 70px; resize: vertical; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 12px 18px; font-size: 16px; font-weight: 700; cursor: pointer;
  background: var(--red); color: #fff; text-decoration: none; transition: transform .1s ease;
}
button:active, .btn:active { transform: scale(.96); }
button.secondary { background: #eef3f0; color: var(--pine); }
button.ghost { background: transparent; color: var(--gold); padding: 8px 0; }
button.small { padding: 6px 12px; font-size: 14px; }
button.block { width: 100%; margin-top: 14px; }
button:disabled { opacity: .5; }
.error { color: var(--red); font-size: 14px; margin-top: 8px; }
.warning { color: #b7791f; font-size: 13px; }

/* Header */
.hero { text-align: center; padding: 24px 0 8px; }
.hero .big { font-size: 64px; animation: bob 2.4s ease-in-out infinite; display: inline-block; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-4deg); } }
.party-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.party-head .avatar { font-size: 36px; }
.countdown { background: rgba(255,255,255,.1); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }
.countdown b { color: var(--gold); }

/* Advent doors */
.doors { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 12px 0; perspective: 600px; }
.door { position: relative; aspect-ratio: 3 / 4; border-radius: 10px; background: var(--pine-2); border: 2px solid rgba(255,255,255,.15); text-align: center; font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; }
.door .emoji { font-size: 22px; }
.door .num { position: absolute; top: 3px; left: 6px; font-weight: 800; color: var(--gold); font-size: 12px; }
.door.done { background: var(--red); border-color: var(--gold); }
.door.done::after {
  content: ""; position: absolute; inset: 0; background: var(--pine-3); border-radius: 8px;
  transform-origin: left; transform: rotateY(-180deg); backface-visibility: hidden; animation: open 1.1s ease-out;
}
@keyframes open { from { transform: rotateY(0); opacity: 1; } }
.door.now { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(245,197,66,.35); animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 14px 4px rgba(245,197,66,.55); } }

/* Snow globe progress */
.globe-wrap { display: flex; align-items: center; gap: 16px; }
.globe { width: 92px; height: 92px; border-radius: 50%; position: relative; overflow: hidden; background: #7fb3d9; border: 4px solid #fff; flex: none; box-shadow: inset 0 0 0 3px rgba(0,0,0,.06); }
.globe .fill { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(#fff, #e6f2ff); transition: height 1.2s ease; }
.globe .tree { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 40px; }

/* Players */
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.player { text-align: center; font-size: 13px; padding: 8px 4px; border-radius: 12px; background: #f4f7f5; position: relative; }
.player .avatar { font-size: 30px; display: block; }
.player .badge { position: absolute; top: 4px; right: 6px; font-size: 14px; }
.player.grinch { background: #e5f5dc; }
.player.grinch .avatar { filter: hue-rotate(70deg) saturate(2); }
.player.pickable { cursor: pointer; border: 2px solid transparent; }
.player.pickable:active { border-color: var(--red); }

/* Avatar picker */
.avatars { display: flex; flex-wrap: wrap; gap: 8px; }
.avatars button { background: #f4f7f5; font-size: 26px; padding: 8px; width: 52px; height: 52px; }
.avatars button.on { background: var(--gold); transform: scale(1.08); }

/* Lists */
.item { border-top: 1px solid #edf1ef; padding: 10px 0; display: flex; gap: 10px; align-items: flex-start; }
.item:first-child { border-top: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 700; word-break: break-word; }
.item .price { color: var(--pine-3); font-weight: 700; white-space: nowrap; }
.item.chosen { background: #fff7dc; border-radius: 12px; padding: 10px; }
.vote { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; background: #f4f7f5; margin: 6px 0; cursor: pointer; }
.vote.on { background: #fff1c7; outline: 2px solid var(--gold); }
.vote .count { margin-left: auto; font-weight: 700; color: var(--muted); }
.mode-choices { display: grid; gap: 8px; }
.mode { padding: 12px; border-radius: 12px; background: #f4f7f5; cursor: pointer; }
.mode.on { background: #fff1c7; outline: 2px solid var(--gold); }
.mode b { display: block; }
.mode .muted { font-size: 13px; }

/* Code chip */
.code { display: inline-block; font-size: 28px; font-weight: 800; letter-spacing: 2px; background: var(--pine); color: var(--gold); padding: 8px 16px; border-radius: 12px; }

/* Notice */
.notice { background: var(--gold); color: var(--ink); border-radius: 12px; padding: 12px; display: flex; gap: 10px; align-items: center; margin: 10px 0; animation: pop .5s ease; }
.notice span { flex: 1; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }

/* Tabs */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: center; background: rgba(10,40,30,.95); backdrop-filter: blur(8px); padding: 6px 6px calc(6px + var(--safe-bottom)); }
#tabs button { flex: 1; max-width: 140px; flex-direction: column; gap: 2px; background: transparent; color: #cfe0d8; font-size: 11px; font-weight: 600; border-radius: 12px; padding: 6px 0; }
#tabs button .ico { font-size: 22px; }
#tabs button.on { color: var(--gold); background: rgba(255,255,255,.08); }

/* Overlay animations */
#overlay { position: fixed; inset: 0; z-index: 20; background: rgba(5,25,18,.92); display: flex; align-items: center; justify-content: center; padding: 24px; flex-direction: column; text-align: center; }
#overlay .close { position: absolute; top: 16px; right: 16px; }
.flip { width: 260px; height: 340px; perspective: 1000px; margin: 16px auto; }
.flip .inner { position: relative; width: 100%; height: 100%; transition: transform 1s cubic-bezier(.3,1.4,.5,1); transform-style: preserve-3d; }
.flip.turned .inner { transform: rotateY(180deg); }
.flip .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.flip .front { background: repeating-linear-gradient(45deg, var(--red), var(--red) 18px, var(--red-2) 18px, var(--red-2) 36px); font-size: 80px; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.flip .back { background: var(--snow); color: var(--ink); transform: rotateY(180deg); box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.flip .back .avatar { font-size: 64px; }
.flip .back .muted { color: var(--muted); opacity: 1; }
.flip .back .arrow { font-size: 22px; color: var(--muted); margin: 4px 0; }
.reveal-step { color: var(--gold); font-weight: 700; }

.grinch-show { animation: grinchIn 1s ease both; }
.grinch-show .big { font-size: 110px; display: block; animation: shake .5s ease-in-out 1s 3; }
@keyframes grinchIn { from { transform: scale(.3) rotate(-20deg); opacity: 0; } }
@keyframes shake { 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }


#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; z-index: 30; font-size: 14px; max-width: 90vw; text-align: center; }

.venue a { word-break: break-all; }
.list-plain { padding-left: 18px; margin: 6px 0; }
.list-plain li { margin: 4px 0; }
.right { text-align: right; }
.center { text-align: center; }

/* Home menu */
.menu { display: grid; gap: 14px; margin-top: 16px; }
.menu-btn { display: flex; align-items: center; gap: 16px; padding: 20px; border-radius: 20px; background: var(--card); color: var(--ink); text-decoration: none; box-shadow: 0 6px 20px rgba(0,0,0,.18); transition: transform .1s ease; }
.menu-btn:active { transform: scale(.97); }
.menu-btn .ico { font-size: 40px; }
.menu-btn b { display: block; font-size: 19px; }
.menu-btn small { color: var(--muted); font-size: 14px; }
.menu-btn.primary { background: var(--red); color: #fff; }
.menu-btn.primary small { color: #ffd9de; }

/* Create wizard */
.wiz-top { display: flex; align-items: center; gap: 12px; margin: 4px 0 8px; }
.wiz-top a { color: #cfe0d8; text-decoration: none; font-size: 22px; padding: 4px 8px; }
.wiz-top span { font-size: 13px; color: #cfe0d8; min-width: 32px; text-align: right; }
.candy { flex: 1; height: 12px; border-radius: 999px; background: rgba(255,255,255,.15); overflow: hidden; }
.candy div { height: 100%; border-radius: 999px; transition: width .5s ease;
  background: repeating-linear-gradient(-45deg, var(--red), var(--red) 8px, #fff 8px, #fff 16px); background-size: 22px 22px; animation: candy 1s linear infinite; }
@keyframes candy { to { background-position: 22px 0; } }
.wiz { padding-top: 16px; }
.wiz.slide { animation: slideIn .35s ease; }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } }
.wiz-emoji { font-size: 72px; text-align: center; animation: bob 2.4s ease-in-out infinite; }
.wiz-q { font-size: 28px; text-align: center; margin: 12px 0 6px; }
.wiz-hint { text-align: center; color: #cfe0d8; margin: 0 0 18px; font-size: 15px; }
.wiz-sub { color: #cfe0d8; font-size: 14px; margin: 16px 0 8px; text-align: center; }
.wiz-body input, .wiz-body textarea { font-size: 18px; padding: 16px; border-radius: 16px; border: 0; }
.wiz-body label { color: #cfe0d8; }
.wiz .error { color: #ffd0d6; text-align: center; font-weight: 600; min-height: 20px; }
.wiz-nav { display: flex; gap: 10px; margin-top: 18px; }
.wiz-nav button { flex: 1; padding: 16px; font-size: 18px; }
.wiz-nav button.secondary { flex: 0 0 34%; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 12px 0; }
.chip { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; font-size: 15px; padding: 10px 14px; border: 2px solid transparent; }
.chip.on { background: var(--gold); color: var(--ink); }
.avatars.big { justify-content: center; }
.avatars.big button { width: 60px; height: 60px; font-size: 32px; background: rgba(255,255,255,.12); }
.avatars.big button.on { background: var(--gold); transform: scale(1.12); }
.summary { background: var(--card); color: var(--ink); border-radius: var(--radius); padding: 6px 14px; }
.sum-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid #edf1ef; cursor: pointer; }
.sum-row:first-child { border-top: 0; }
.sum-row .e { font-size: 24px; }
.sum-row .grow { flex: 1; font-weight: 700; }
.sum-row small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.sum-row .edit { color: var(--red); font-size: 13px; font-weight: 700; }
.hero img.santa { width: 220px; height: 220px; display: block; margin: 0 auto -6px; filter: drop-shadow(0 8px 16px rgba(0,0,0,.25)); animation: laugh 2.6s ease-in-out infinite; transform-origin: 50% 85%; }
@keyframes laugh { 0%, 100% { transform: rotate(0); } 10% { transform: rotate(-4deg) translateY(-4px); } 20% { transform: rotate(3deg); } 30% { transform: rotate(-3deg) translateY(-3px); } 40% { transform: rotate(0); } }

/* 3D icons (see icons/ and iconize() in app.js) */
img.ic { width: 1.3em; height: 1.3em; object-fit: contain; vertical-align: -0.32em; display: inline-block; user-select: none; -webkit-user-drag: none; }
.avatars button img.ic { width: 100%; height: 100%; vertical-align: middle; }
.avatars button { padding: 4px; }
.menu-btn .ico img.ic, .hero .big img.ic, .grinch-show .big img.ic, .wiz-emoji img.ic, .flip .front img.ic, .flip .back .avatar img.ic { filter: drop-shadow(0 6px 10px rgba(0,0,0,.35)); }
.grinch-show .big img.ic { width: 1.6em; height: 1.6em; }
.door .emoji img.ic { width: 1.5em; height: 1.5em; }
#tabs button .ico img.ic { width: 1.35em; height: 1.35em; }
.code img.ic { vertical-align: -0.28em; margin-right: 4px; }
body::before { content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(15,61,46,.55), rgba(10,40,30,.88) 60%), url(/icons/bg-forest.webp) center top / cover no-repeat; }

/* Sign in / sign up */
.auth { max-width: 420px; margin: 0 auto; }
.auth-hero { text-align: center; font-size: 96px; line-height: 1; margin-top: 4px; animation: bob 2.4s ease-in-out infinite; }
.auth-hero img.ic { filter: drop-shadow(0 8px 14px rgba(0,0,0,.35)); }
.auth h1 { margin: 10px 0 4px; }
.auth .card a:not(.btn) { color: var(--red); font-weight: 700; }
.muted-dark { color: var(--muted); font-size: 14px; }
.socials { display: flex; flex-direction: column; gap: 10px; }
.btn.social { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; font-weight: 700; text-decoration: none; }
.btn.social.google { background: #fff; color: #1f1f1f; border: 1px solid #dadce0; }
.btn.social.facebook { background: #1877f2; color: #fff; }
.btn.social .fb { width: 22px; height: 22px; border-radius: 50%; background: #fff; color: #1877f2; font: 900 18px/24px Arial, sans-serif; text-align: center; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 16px 0 4px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: #e2e8e4; }
.account-bar { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.1); border-radius: 999px; padding: 6px 8px 6px 12px; margin: -6px 0 14px; font-size: 14px; }
.account-bar span { flex: 1; }
.account-bar img.ic { width: 28px; height: 28px; }
