:root {
  --bg1: #0f3229;
  --bg2: #06140f;
  --card: #fff8ec;
  --ink: #1c2b26;
  --muted: #6b7a72;
  --red: #c8323a;
  --red-d: #96202a;
  --gold: #f2c14e;
  --green: #2f7d5b;
  --line: rgba(255, 255, 255, .14);
  --on-bg: #f6efe2;
  --on-bg-muted: #b3c6bb;
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--on-bg);
  background: radial-gradient(120% 80% at 50% 0%, var(--bg1), var(--bg2) 75%) fixed;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
button, input { font: inherit; color: inherit; }
h1, h2, p { margin: 0; }

#app {
  position: relative; z-index: 1;
  height: 100dvh; max-width: 540px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
body.tv #app { max-width: 1100px; font-size: 1.35rem; }

/* ---------- Schnee ---------- */
#snow { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
#snow i {
  position: absolute; top: -12px; width: var(--s); height: var(--s); border-radius: 50%;
  background: #fff; opacity: var(--o); left: var(--x);
  animation: snow var(--d) linear var(--dl) infinite;
}
@keyframes snow { to { transform: translate(var(--drift), 105vh); } }
@media (prefers-reduced-motion: reduce) { #snow { display: none; } }

/* ---------- Kopfzeile ---------- */
#top { display: flex; align-items: center; gap: 10px; padding: 12px 0 10px; flex: none; }
.brand { font-weight: 800; letter-spacing: .01em; }
.dots { display: flex; gap: 6px; margin-left: auto; }
.dots i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--gold); }
.dots i.on { background: var(--gold); }
.mechip { display: flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--on-bg-muted); max-width: 40%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

#main { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; padding-bottom: 16px; }

/* ---------- Bausteine ---------- */
.av {
  display: inline-grid; place-items: center; flex: none;
  width: 1.9em; height: 1.9em; border-radius: 50%;
  background: var(--c, #888); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .55), 0 2px 6px rgba(0, 0, 0, .3);
  line-height: 1;
}
.av > span { font-size: 1.15em; }
.card { background: var(--card); color: var(--ink); border-radius: var(--radius); padding: 18px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); }
.title { font-size: 1.5rem; font-weight: 800; line-height: 1.15; text-wrap: balance; }
.sub { color: var(--on-bg-muted); line-height: 1.4; }
.card .sub { color: var(--muted); }
.label { font-size: .78rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--gold); }
.card .label { color: var(--red); }

.btn {
  appearance: none; border: 0; border-radius: 14px; padding: 14px 18px; min-height: 50px;
  background: var(--red); color: #fff; font-weight: 800; font-size: 1.05rem; cursor: pointer;
  box-shadow: 0 4px 0 var(--red-d); transition: transform .06s, box-shadow .06s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--red-d); }
.btn:disabled { opacity: .45; }
.btn.ghost { background: transparent; color: inherit; box-shadow: inset 0 0 0 2px currentColor; opacity: .8; }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: .95rem; }
.btn.gold { background: var(--gold); color: var(--ink); box-shadow: 0 4px 0 #b98a1f; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }

.bar { height: 8px; border-radius: 8px; background: var(--line); overflow: hidden; flex: none; }
.bar > i { display: block; height: 100%; width: 100%; background: var(--gold); border-radius: 8px; transform-origin: left; }

#toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #000c; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .95rem;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Beitreten ---------- */
.join { display: flex; flex-direction: column; gap: 14px; text-align: center; }
.join .big { font-size: 3rem; line-height: 1; }
.join input {
  width: 100%; padding: 14px 16px; border-radius: 14px; border: 2px solid #d9cdb8; background: #fff; color: var(--ink);
  font-size: 1.15rem; text-align: center; -webkit-user-select: text; user-select: text;
}
.join input:focus { outline: 3px solid var(--gold); border-color: var(--gold); }

/* ---------- Lobby ---------- */
.hero { padding: 6px 0 2px; }
.hero .title { font-size: 2rem; }
.rounds { display: flex; flex-direction: column; gap: 10px; }
.round { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: var(--radius); background: rgba(255, 255, 255, .07); border: 1px solid var(--line); }
.round .ico { font-size: 1.9rem; flex: none; }
.round b { display: block; }
.round small { color: var(--on-bg-muted); line-height: 1.3; display: block; }
.round .won { display: flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--gold); font-weight: 700; flex: none; max-width: 42%; }
.round .won span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: flex; align-items: center; gap: 7px; padding: 5px 12px 5px 5px; border-radius: 99px; background: rgba(255, 255, 255, .09); font-weight: 600; }
.chip.off { opacity: .4; }
.chip .g { color: var(--gold); font-size: .85rem; }
.invite { display: flex; gap: 14px; align-items: center; }
.invite img { width: 104px; height: 104px; border-radius: 10px; flex: none; }
.invite .url { font-weight: 700; word-break: break-all; -webkit-user-select: text; user-select: text; }
body.tv .invite img { width: 260px; height: 260px; }

/* ---------- Rennen ---------- */
.race { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; position: relative; }
.lanes { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 4px; overflow: hidden; }
.lane { flex: 1 1 0; min-height: 20px; max-height: 50px; position: relative; border-radius: 10px; background: rgba(255, 255, 255, .06); }
.lane.me { background: rgba(242, 193, 78, .2); box-shadow: inset 0 0 0 2px var(--gold); }
.lane .lname { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-size: .72rem; font-weight: 700; color: var(--on-bg-muted); max-width: 17%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; z-index: 0; }
.lane.me .lname { color: var(--gold); }
.lane .fin { position: absolute; left: 92%; top: 0; bottom: 0; border-left: 3px dashed rgba(255, 255, 255, .5); padding-left: 2px; display: grid; place-items: center; font-size: .95rem; }
.lane .sled { position: absolute; top: 50%; left: 30%; transform: translate(-100%, -50%); transition: left .12s linear; font-size: clamp(.6rem, 2.6vh, 1rem); z-index: 1; display: flex; align-items: center; }
.lane .sled::before { content: "🎁"; font-size: .9em; margin-right: -4px; opacity: .9; }
.lane .medal { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); font-size: 1rem; z-index: 2; }
.count-over {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 5;
  font-size: 6.5rem; font-weight: 900; color: var(--gold); text-shadow: 0 6px 30px #000;
}
.tapzone { flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px; padding-top: 4px; }
.tap {
  width: min(46vw, 180px); aspect-ratio: 1; border-radius: 50%; border: 0; cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #ef5d64, var(--red) 60%, var(--red-d));
  color: #fff; font-weight: 900; font-size: 1.7rem; letter-spacing: .04em;
  box-shadow: 0 8px 0 #6f1820, 0 14px 30px rgba(0, 0, 0, .5);
  touch-action: none;
}
.tap.idle { filter: grayscale(.7) brightness(.8); }
.rank { font-weight: 800; color: var(--gold); min-height: 1.3em; }

/* ---------- Päckli zählen ---------- */
.sky { flex: 1; min-height: 220px; position: relative; overflow: hidden; border-radius: var(--radius); background: linear-gradient(#0a2a3d, #123d35); border: 1px solid var(--line); }
.item { position: absolute; left: 0; top: 0; font-size: var(--s); line-height: 1; will-change: transform; animation: fall var(--d) cubic-bezier(.4, 0, .9, .65) var(--dl) both; }
@keyframes fall {
  0% { transform: translate(var(--x0), -70px) rotate(0deg); opacity: 1; }
  88% { opacity: 1; }
  100% { transform: translate(var(--x1), var(--y1)) rotate(var(--r)) scale(.5); opacity: 0; }
}
.sack { position: absolute; left: 50%; bottom: -8%; width: 46%; max-width: 230px; aspect-ratio: 1 / .95; transform: translateX(-50%); z-index: 3; }
.sack::before { content: ""; position: absolute; inset: 14% 0 0; border-radius: 42% 42% 46% 46% / 30% 30% 60% 60%; background: radial-gradient(circle at 35% 30%, #b0552f, #7c3418 70%); box-shadow: inset 0 -14px 30px rgba(0, 0, 0, .35); }
.sack::after { content: ""; position: absolute; left: 12%; right: 12%; top: 6%; height: 16%; border-radius: 50%; background: #3d170a; box-shadow: 0 0 0 5px #c9703f; }
.sky .msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; font-size: 1.5rem; font-weight: 800; z-index: 4; text-shadow: 0 3px 16px #000; }
.sky .msg b { display: block; font-size: 5rem; color: var(--gold); }

.num { font-size: 5.5rem; font-weight: 900; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; color: var(--red); }
.guess { display: flex; flex-direction: column; gap: 16px; }
.guess input[type=range] { width: 100%; accent-color: var(--red); height: 34px; }
.step { flex: 1; min-height: 50px; border-radius: 12px; border: 2px solid #d9cdb8; background: #fff; color: var(--ink); font-weight: 800; font-size: 1.05rem; }
.step:active { background: #f1e6d2; }
.pile { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; font-size: 1.15rem; line-height: 1; min-height: 60px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px; background: rgba(255, 255, 255, .07); }
.li.me { box-shadow: inset 0 0 0 2px var(--gold); }
.li.first { background: rgba(242, 193, 78, .22); }
.li .pos { width: 1.6em; font-weight: 800; color: var(--gold); text-align: center; flex: none; }
.li .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.li .val { font-variant-numeric: tabular-nums; font-weight: 800; }
.li .dv { font-size: .82rem; color: var(--on-bg-muted); width: 4.6em; text-align: right; flex: none; }

/* ---------- Roulette ---------- */
.strip { display: flex; flex-wrap: wrap; gap: 6px; font-size: .9rem; }
.strip .av.out { filter: grayscale(1); opacity: .35; }
/* Innenabstand, damit Markierung und «Deins»-Schild am Rand nicht abgeschnitten werden */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; perspective: 900px; padding: 12px 8px 10px; }
.box { position: relative; aspect-ratio: 1; border: 0; padding: 0; background: none; cursor: pointer; }
.box .flip { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.3, 1.4, .5, 1); }
.box.open .flip { transform: rotateY(180deg); }
.box .front, .box .back { position: absolute; inset: 0; border-radius: 16px; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.box .front { background: var(--bc); box-shadow: inset 0 -10px 0 rgba(0, 0, 0, .18), 0 6px 14px rgba(0, 0, 0, .35); overflow: hidden; }
.box .front::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 18%; transform: translateX(-50%); background: var(--rc); }
.box .front::after { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 18%; transform: translateY(-50%); background: var(--rc); }
.box .bow { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 1.9rem; z-index: 1; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .3)); }
.box .back { transform: rotateY(180deg); background: var(--card); color: var(--ink); display: grid; place-items: center; align-content: center; font-size: 2.4rem; }
.box .back small { font-size: .7rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.box.coal .back { background: #2a2a2e; }
.box.coal .back small { color: #bbb; }
.box.sel .front { outline: 4px solid var(--gold); outline-offset: 3px; }
.box.sel::after { content: "Deins"; position: absolute; top: -9px; right: -4px; background: var(--gold); color: var(--ink); font-size: .68rem; font-weight: 800; padding: 2px 7px; border-radius: 99px; z-index: 3; }
.box .who { position: absolute; left: 0; right: 0; bottom: -8px; display: flex; justify-content: center; flex-wrap: wrap; gap: 2px; font-size: .62rem; z-index: 2; }
.box.open.coal .who .av { filter: grayscale(1); opacity: .6; }
.verdict { min-height: 1.6em; font-weight: 800; font-size: 1.15rem; text-align: center; color: var(--gold); text-wrap: balance; }

/* ---------- Siegerbanner ---------- */
.banner { text-align: center; position: relative; overflow: hidden; animation: pop .5s cubic-bezier(.3, 1.5, .5, 1) both; flex: none; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.banner .gift { font-size: 3.2rem; line-height: 1; }
.banner .who { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 1.9rem; font-weight: 900; margin: 6px 0 2px; overflow-wrap: anywhere; }
.banner .ctl { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -30px; left: var(--x); font-style: normal; font-size: 1.2rem; animation: conf var(--d) linear var(--dl) both; }
@keyframes conf { to { transform: translateY(420px) rotate(var(--r)); opacity: 0; } }

/* ---------- Regie ---------- */
.regie .li { cursor: pointer; }
.regie .li.tgt { background: rgba(242, 193, 78, .25); box-shadow: inset 0 0 0 2px var(--gold); }
.regie .x { border: 0; background: none; font-size: 1.2rem; opacity: .6; padding: 4px 8px; }
.mono { font-family: ui-monospace, monospace; font-size: .85rem; word-break: break-all; -webkit-user-select: text; user-select: text; }

/* ---------- Winternacht-Szene ---------- */
.scene { position: relative; flex: none; aspect-ratio: 400 / 220; max-height: 38vh; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, .4); background: #071a33; }
.scene svg { display: block; width: 100%; height: 100%; }
.scene .tw { fill: #fff; animation: sc-tw 3s ease-in-out infinite; }
.scene circle.tw[fill] { fill: #ffe9a8; }
@keyframes sc-tw { 0%, 100% { opacity: .15; } 50% { opacity: 1; } }
.scene .bulb { animation: sc-bulb 1.8s steps(1) infinite; filter: drop-shadow(0 0 3px currentColor); }
@keyframes sc-bulb { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
.scene .pulse { animation: sc-pulse 5s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes sc-pulse { 50% { transform: scale(1.12); opacity: .7; } }
.scene .star { animation: sc-star 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; filter: drop-shadow(0 0 5px #ffd84d); }
@keyframes sc-star { 50% { transform: scale(1.25) rotate(12deg); } }
.scene .bob { animation: sc-bob .55s ease-in-out infinite; }
@keyframes sc-bob { 50% { transform: translateY(-2.5px); } }
.scene .nose { animation: sc-tw .9s ease-in-out infinite; filter: drop-shadow(0 0 3px #ff3b3b); }
.scene .win { animation: sc-win 4s steps(1) infinite; }
@keyframes sc-win { 0%, 100% { opacity: 1; } 46% { opacity: .55; } 52% { opacity: 1; } 80% { opacity: .7; } }
.scene .smoke { animation: sc-smoke 3s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes sc-smoke { 0% { transform: translate(0, 0) scale(.6); opacity: .8; } 100% { transform: translate(10px, -26px) scale(2); opacity: 0; } }
.scene .drop { animation: sc-drop 7.6s linear infinite; }
@keyframes sc-drop {
  0% { transform: translate(var(--x), -40px) rotate(-8deg); opacity: 1; }
  20% { transform: translate(calc(var(--x) + 6px), calc(var(--y) * .3)) rotate(8deg); }
  40% { transform: translate(calc(var(--x) - 5px), calc(var(--y) * .62)) rotate(-7deg); }
  62% { transform: translate(var(--x), var(--y)) rotate(0deg); }
  92% { transform: translate(var(--x), var(--y)); opacity: 1; }
  100% { transform: translate(var(--x), var(--y)); opacity: 0; }
}
.scene .chute { animation: sc-chute 7.6s linear infinite; }
@keyframes sc-chute { 0%, 60% { opacity: 1; } 66%, 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .scene * { animation: none !important; } }
.scene .replay {
  position: absolute; right: 8px; bottom: 8px; width: 38px; height: 38px; border-radius: 50%; border: 0; padding: 0;
  background: rgba(7, 26, 51, .6); color: #fff; font-size: 1.25rem; line-height: 1; cursor: pointer;
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .55);
}
.scene .replay:active { background: rgba(7, 26, 51, .9); }
