*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: '';
  position: fixed; inset: 0;
  background: var(--board-deco), linear-gradient(160deg, var(--bg), var(--bg2));
  z-index: -2;
}
#stars { position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: 0; transition: opacity .8s; }
[data-tpl="space"] #stars { opacity: 1; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* ---------------- Kopfzeile ---------------- */
.top {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 22px 8px;
}
.top h1 {
  margin: 0; font-family: var(--font-display); font-weight: 400;
  font-size: clamp(18px, 2.4vw, 30px); letter-spacing: .04em;
  text-transform: uppercase; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip {
  padding: 7px 13px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  border: 1px solid var(--line); color: var(--muted);
  transition: transform .15s, color .15s, border-color .15s;
}
.chip:hover { transform: translateY(-2px); color: var(--text); border-color: var(--accent); }
.chip.on { color: var(--accent); border-color: var(--accent); }
#keyHint { opacity: .65; font-weight: 500; }
@media (max-width: 900px) { #keyHint { display: none; } }

/* ---------------- Tafel ---------------- */
#board {
  display: grid; gap: var(--gap);
  padding: 0 18px 8px;
  height: calc(100vh - 210px);
  align-content: stretch;
}
.cat {
  display: grid; place-items: center; text-align: center;
  background: var(--cat-bg); border: 1px solid var(--line);
  border-radius: var(--tile-radius); padding: 6px 8px;
  font-family: var(--font-display); font-weight: 400;
  letter-spacing: .05em; text-transform: uppercase;
  font-size: clamp(11px, 1.15vw, 20px); line-height: 1.15;
  animation: dropIn .5s cubic-bezier(.2, .9, .25, 1.2) backwards;
}
.tile {
  position: relative; overflow: hidden;
  background: var(--tile); border: 1px solid var(--line);
  border-radius: var(--tile-radius); box-shadow: var(--tile-shadow);
  color: var(--tile-text);
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(18px, 3.2vw, 46px); letter-spacing: .02em;
  display: grid; place-items: center;
  transition: transform .18s cubic-bezier(.2, .9, .25, 1.2), background .2s, filter .2s, opacity .35s;
  animation: dropIn .5s cubic-bezier(.2, .9, .25, 1.2) backwards;
}
.tile:hover:not(.used) { transform: translateY(var(--tile-hover-lift)) scale(1.02); background: var(--tile-hover); }
.tile:active:not(.used) { transform: translateY(0) scale(.98); }
.tile.used { opacity: .18; pointer-events: none; filter: grayscale(1); transform: none; }
.tile .dd { position: absolute; top: 6px; right: 8px; font-size: 12px; opacity: .0; }
.tile::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, .22) 50%, transparent 65%);
  transform: translateX(-120%); transition: transform .6s;
}
.tile:hover:not(.used)::after { transform: translateX(120%); }
@keyframes dropIn { from { opacity: 0; transform: translateY(-22px) scale(.94); } }

/* ---------------- Punktestand ---------------- */
#teams {
  display: flex; gap: 10px; padding: 6px 18px 16px;
  overflow-x: auto; scrollbar-width: none;
}
#teams::-webkit-scrollbar { display: none; }
.team {
  flex: 1 1 0; min-width: 140px;
  background: var(--team-bg); color: var(--team-fg);
  border: 1px solid var(--line); border-top: 3px solid var(--tc);
  border-radius: var(--radius); padding: 8px 12px;
  display: flex; align-items: center; gap: 10px;
  transition: transform .2s, box-shadow .2s;
}
.team.lead { box-shadow: 0 0 0 2px var(--tc), 0 10px 26px color-mix(in srgb, var(--tc) 35%, transparent); }
.team .nm { font-weight: 600; font-size: 14px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team .sc { font-family: var(--font-display); font-size: 26px; color: var(--tc); font-variant-numeric: tabular-nums; }
.team .sc.bump { animation: bump .45s cubic-bezier(.2, .9, .25, 1.4); }
@keyframes bump { 40% { transform: scale(1.45); } }
.team .keycap {
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  border: 1px solid var(--line); color: var(--muted);
}
.team.buzzed { transform: translateY(-6px) scale(1.03); }

/* ---------------- Frage-Overlay ---------------- */
#overlay {
  position: fixed; inset: 0; z-index: 20;
  display: none; flex-direction: column;
  background: linear-gradient(160deg, var(--bg), var(--bg2));
  padding: 26px clamp(20px, 6vw, 90px) 20px;
}
#overlay.show { display: flex; }
#overlay::before { content: ''; position: absolute; inset: 0; background: var(--board-deco); pointer-events: none; }
.ov-head { display: flex; align-items: center; gap: 14px; position: relative; }
.ov-cat { font-family: var(--font-display); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); font-size: clamp(14px, 1.6vw, 22px); }
.ov-val { margin-left: auto; font-family: var(--font-display); font-size: clamp(20px, 2.6vw, 38px); color: var(--accent); }
.ov-body {
  flex: 1; display: grid; place-items: center; text-align: center; position: relative;
  gap: 18px; grid-auto-rows: min-content; align-content: center;
}
.ov-q { font-size: clamp(22px, 3.6vw, 56px); font-weight: 700; line-height: 1.25; max-width: 22ch; margin: 0 auto; }
.ov-a {
  font-family: var(--font-display); color: var(--accent);
  font-size: clamp(24px, 4.2vw, 62px); line-height: 1.15;
  opacity: 0; transform: translateY(18px) scale(.96); transition: opacity .45s, transform .55s cubic-bezier(.2, .9, .25, 1.3);
}
.ov-a.show { opacity: 1; transform: none; }
.ov-img { max-height: 34vh; max-width: 70vw; border-radius: 14px; box-shadow: var(--shadow); }
.ov-foot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; position: relative; }
.awd {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px;
  border-radius: 999px; border: 1px solid var(--tc); background: color-mix(in srgb, var(--tc) 12%, transparent);
  transition: transform .15s;
}
.awd:hover { transform: translateY(-3px); }
.awd b { font-weight: 600; font-size: 14px; }
.awd .pm { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: color-mix(in srgb, var(--tc) 28%, transparent); }
.awd .pm:hover { background: var(--tc); color: #08080c; }

.btn {
  padding: 11px 20px; border-radius: 999px; font-weight: 600; font-size: 15px;
  background: var(--accent); color: var(--on-accent); transition: transform .15s, filter .15s;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }

/* Timer */
#timer { position: relative; height: 6px; border-radius: 6px; background: color-mix(in srgb, var(--muted) 25%, transparent); overflow: hidden; margin-top: 10px; }
#timer i { position: absolute; inset: 0; transform-origin: left; background: linear-gradient(90deg, var(--accent2), var(--accent)); }
#timer.warn i { background: linear-gradient(90deg, #ff9f1c, #ff3b3b); }
[data-tpl="space"] #timer i::after {
  content: ''; position: absolute; right: -6px; top: -5px; width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle, #fff, var(--accent) 60%, transparent 70%);
}

/* ---- Aufdeck-Animationen je Vorlage ---- */
#overlay.show .ov-panel { animation: var(--revealAnim, zoomIn) .55s cubic-bezier(.2, .9, .25, 1.15) both; }
.ov-panel { display: contents; }
[data-tpl="classic"] { --revealAnim: zoomIn; }
[data-tpl="neon"] { --revealAnim: glitchIn; }
[data-tpl="paper"] { --revealAnim: flipIn; }
[data-tpl="space"] { --revealAnim: orbitIn; }
[data-tpl="tv"] { --revealAnim: curtainIn; }
[data-tpl="magma"] { --revealAnim: emberIn; }
[data-tpl="ocean"] { --revealAnim: waveIn; }
[data-tpl="comic"] { --revealAnim: popIn; }
[data-tpl="frost"] { --revealAnim: shatterIn; }
[data-tpl="slate"] { --revealAnim: slideIn; }
#overlay.show > .ov-head, #overlay.show > .ov-body, #overlay.show > .ov-foot {
  animation: var(--revealAnim, zoomIn) .5s cubic-bezier(.2, .9, .25, 1.15) both;
}
#overlay.show > .ov-body { animation-delay: .06s; }
#overlay.show > .ov-foot { animation-delay: .12s; }
@keyframes zoomIn { from { opacity: 0; transform: scale(.86); } }
@keyframes glitchIn {
  0% { opacity: 0; transform: translate(-14px, 6px) skewX(12deg); filter: hue-rotate(90deg); }
  35% { opacity: 1; transform: translate(10px, -4px) skewX(-8deg); }
  60% { transform: translate(-4px, 2px) skewX(3deg); }
  100% { opacity: 1; transform: none; filter: none; }
}
@keyframes flipIn { from { opacity: 0; transform: perspective(1200px) rotateX(-78deg); transform-origin: top center; } }
@keyframes orbitIn { from { opacity: 0; transform: perspective(1400px) rotateY(38deg) translateZ(-260px); } }
@keyframes curtainIn { from { opacity: 0; clip-path: inset(0 50% 0 50%); } to { opacity: 1; clip-path: inset(0 0 0 0); } }
@keyframes emberIn {
  0% { opacity: 0; transform: translateY(46px) scale(.94); filter: brightness(2.4) saturate(1.8) blur(5px); }
  55% { opacity: 1; filter: brightness(1.35) saturate(1.3) blur(0); }
  100% { opacity: 1; transform: none; filter: none; }
}
@keyframes waveIn {
  0% { opacity: 0; transform: translateY(52px); clip-path: inset(78% 0 0 0 round 40% 40% 0 0); }
  60% { opacity: 1; transform: translateY(-6px); clip-path: inset(0 0 0 0 round 12% 12% 0 0); }
  100% { opacity: 1; transform: none; clip-path: inset(0 0 0 0); }
}
@keyframes popIn {
  0% { opacity: 0; transform: scale(.4) rotate(-9deg); }
  55% { opacity: 1; transform: scale(1.09) rotate(3deg); }
  75% { transform: scale(.97) rotate(-1.5deg); }
  100% { opacity: 1; transform: none; }
}
@keyframes shatterIn {
  0% { opacity: 0; transform: scale(1.14); filter: blur(9px) brightness(1.7); clip-path: polygon(0 0, 34% 0, 26% 100%, 0 100%); }
  40% { opacity: 1; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); }
  60% { transform: scale(.985); filter: blur(0) brightness(1.12); }
  100% { opacity: 1; transform: none; filter: none; }
}
@keyframes slideIn { from { opacity: 0; transform: translateY(14px); } }

/* Vorhang für TV */
#curtain { position: fixed; inset: 0; z-index: 30; pointer-events: none; display: none; }
#curtain b {
  position: absolute; top: 0; bottom: 0; width: 52%;
  background: linear-gradient(90deg, #5c0a20, #a01a3c 60%, #6d0f27);
  box-shadow: inset -30px 0 60px rgba(0, 0, 0, .5);
}
#curtain b:first-child { left: 0; transform: translateX(-100%); }
#curtain b:last-child { right: 0; transform: translateX(100%); }
#curtain.play { display: block; }
#curtain.play b:first-child { animation: cl .75s ease-in-out both; }
#curtain.play b:last-child { animation: cr .75s ease-in-out both; }
@keyframes cl { 0% { transform: translateX(-100%); } 45% { transform: translateX(0); } 100% { transform: translateX(-100%); } }
@keyframes cr { 0% { transform: translateX(100%); } 45% { transform: translateX(0); } 100% { transform: translateX(100%); } }

/* Daily Double */
#dd { position: fixed; inset: 0; z-index: 25; display: none; place-items: center; background: rgba(0, 0, 0, .78); backdrop-filter: blur(6px); }
#dd.show { display: grid; }
#dd .card { text-align: center; padding: 34px 40px; border-radius: 22px; background: var(--panel); border: 1px solid var(--accent); box-shadow: var(--shadow); animation: ddPop .6s cubic-bezier(.2, .9, .25, 1.5) both; }
#dd h2 { font-family: var(--font-display); font-size: clamp(30px, 5vw, 64px); margin: 0 0 6px; color: var(--accent); letter-spacing: .06em; }
#dd input { width: 180px; text-align: center; font-size: 26px; padding: 8px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, .3); color: var(--text); font-family: var(--font-display); }
@keyframes ddPop { from { opacity: 0; transform: scale(.6) rotate(-6deg); } }

/* Handy-Buzzer */
#buzzerBox { position: fixed; inset: 0; z-index: 27; display: none; place-items: center; background: rgba(0, 0, 0, .82); backdrop-filter: blur(8px); padding: 20px; }
#buzzerBox.show { display: grid; }
#buzzerBox .card {
  position: relative; width: min(880px, 100%); padding: 28px 32px 30px;
  border-radius: 24px; background: var(--panel); border: 1px solid var(--accent);
  box-shadow: var(--shadow); animation: ddPop .45s cubic-bezier(.2, .9, .25, 1.4) both;
}
#buzzerBox h2 { font-family: var(--font-display); font-size: clamp(22px, 3vw, 38px); margin: 0 0 18px; color: var(--accent); letter-spacing: .05em; }
.closeX { position: absolute; top: 14px; right: 16px; font-size: 20px; color: var(--muted); padding: 6px 10px; border-radius: 10px; }
.closeX:hover { background: rgba(255, 255, 255, .1); color: var(--text); }
.bz-grid { display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: start; }
@media (max-width: 720px) { .bz-grid { grid-template-columns: 1fr; } }
.bz-qr { text-align: center; }
.bz-qr svg { display: block; border-radius: 12px; background: #fff; padding: 8px; width: 230px; height: 230px; }
.bz-code {
  font-family: var(--font-display); font-size: 44px; letter-spacing: .22em;
  margin-top: 12px; color: var(--accent); text-indent: .22em;
}
.bz-url { font-size: 12.5px; color: var(--muted); word-break: break-all; margin-top: 2px; }
.bz-how { line-height: 1.9; font-size: 15.5px; margin: 0 0 16px; color: var(--text); }
.bz-how b { color: var(--accent); }
.bz-status { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.bz-status.ok { color: var(--accent); }
.bz-players { display: flex; flex-wrap: wrap; gap: 7px; max-height: 190px; overflow: auto; }
.bz-chip {
  padding: 5px 12px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--pc); background: color-mix(in srgb, var(--pc) 18%, transparent);
  animation: tileIn .35s cubic-bezier(.2, .9, .25, 1.4) backwards;
}
@keyframes tileIn { from { opacity: 0; transform: translateY(10px) scale(.9); } }

/* Wer war zuerst */
#winner { position: fixed; inset: 0; z-index: 40; display: none; place-items: center; pointer-events: none; }
#winner.show { display: grid; }
#winner .w-burst {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--wc) 85%, transparent) 0%, color-mix(in srgb, var(--wc) 45%, transparent) 35%, transparent 70%);
  animation: burst .9s cubic-bezier(.15, .8, .3, 1) both;
}
@keyframes burst { from { opacity: 0; transform: scale(.35); } 60% { opacity: 1; } to { opacity: .92; transform: scale(1.15); } }
#winner .w-inner { position: relative; text-align: center; }
#winner .w-team {
  font-family: var(--font-display); text-transform: uppercase; letter-spacing: .06em;
  font-size: clamp(38px, 9vw, 130px); line-height: 1;
  color: #fff; text-shadow: 0 8px 40px rgba(0, 0, 0, .6);
  animation: wPop .5s cubic-bezier(.2, .9, .25, 1.7) both .06s;
}
#winner .w-name { font-size: clamp(16px, 2.4vw, 30px); font-weight: 600; color: rgba(255, 255, 255, .9); margin-top: 8px; animation: wPop .5s cubic-bezier(.2, .9, .25, 1.6) both .18s; }
@keyframes wPop { from { opacity: 0; transform: scale(.5) rotate(-4deg); } }
#winner.out { animation: wOut .45s ease-in both; }
@keyframes wOut { to { opacity: 0; transform: scale(1.08); } }

/* Finalrunde */
#fin { position: fixed; inset: 0; z-index: 26; display: none; place-items: center; background: rgba(0, 0, 0, .82); backdrop-filter: blur(8px); padding: 20px; }
#fin.show { display: grid; }
#fin .card { text-align: center; padding: 30px 36px; border-radius: 22px; width: min(620px, 100%); background: var(--panel); border: 1px solid var(--accent); box-shadow: var(--shadow); animation: ddPop .5s cubic-bezier(.2, .9, .25, 1.4) both; }
#fin h2 { font-family: var(--font-display); font-size: clamp(26px, 4vw, 48px); margin: 0 0 10px; color: var(--accent); letter-spacing: .06em; }
.bet { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-radius: 12px; border: 1px solid var(--line); }
.bet b { flex: 1; text-align: left; font-weight: 600; }
.bet small { color: var(--muted); }
.bet input { width: 110px; text-align: center; padding: 6px; border-radius: 9px; border: 1px solid var(--line); background: rgba(0, 0, 0, .3); color: var(--text); }
.bet .yn { display: flex; gap: 6px; }
.bet .yn button { width: 34px; height: 30px; border-radius: 8px; border: 1px solid var(--line); font-weight: 700; }
.bet .yn button.pick { background: var(--accent); color: #0b0b12; }

/* Endbildschirm */
#end { position: fixed; inset: 0; z-index: 28; display: none; place-items: center; background: linear-gradient(160deg, var(--bg), var(--bg2)); }
#end.show { display: grid; }
.podium { display: flex; align-items: flex-end; gap: 16px; }
.pod { width: clamp(90px, 12vw, 160px); border-radius: 16px 16px 0 0; background: var(--pc); display: grid; align-content: end; justify-items: center; padding: 10px; color: #0b0b12; font-weight: 700; animation: rise .8s cubic-bezier(.2, .9, .25, 1.2) both; }
@keyframes rise { from { transform: scaleY(0); transform-origin: bottom; opacity: 0; } }
#confetti { position: fixed; inset: 0; z-index: 29; pointer-events: none; display: none; }

/* Kurzmeldung unten */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 160%);
  background: color-mix(in srgb, var(--panel) 92%, #000);
  border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 11px 22px; font-size: 14.5px; z-index: 45;
  box-shadow: var(--shadow); max-width: 90vw; text-align: center;
  transition: transform .45s cubic-bezier(.2, .9, .25, 1.4);
}
.toast.show { transform: translate(-50%, 0); }
.chip[disabled] { opacity: .35; pointer-events: none; }

/* Buzzer-Anzeige */
#buzzWin { font-weight: 700; padding: 6px 14px; border-radius: 999px; }

@media (max-width: 720px) {
  #board { height: calc(100vh - 250px); }
  .team { min-width: 110px; }
}
