:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --ink: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --soft: #f0f0ec;
  --accent: #4f46e5;
  --ok: #2f9e62;
  --bad: #e5484d;
  --a0: #e5484d;
  --a1: #3e63dd;
  --a2: #d98a0b;
  --a3: #2f9e62;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.05);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

/* ---------- Grundbausteine ---------- */

.wrap { max-width: 1080px; margin: 0 auto; padding: 24px 16px; }
.narrow { max-width: 420px; }
.center { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }

.logo { font-weight: 800; letter-spacing: -0.03em; font-size: 22px; text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; gap: 8px; }
.logo i { width: 22px; height: 22px; border-radius: 6px; display: inline-grid; grid-template-columns: 1fr 1fr; gap: 2px; overflow: hidden; }
.logo i b:nth-child(1) { background: var(--a0); } .logo i b:nth-child(2) { background: var(--a1); }
.logo i b:nth-child(3) { background: var(--a2); } .logo i b:nth-child(4) { background: var(--a3); }
.logo.big { font-size: 44px; } .logo.big i { width: 40px; height: 40px; border-radius: 10px; gap: 3px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 16px; font-weight: 600; cursor: pointer; text-decoration: none; transition: transform 0.08s, background 0.15s, opacity 0.15s; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #2e2e33; }
.btn.danger { color: var(--bad); }
.btn.lg { padding: 14px 22px; font-size: 18px; border-radius: 12px; }
.btn.block { width: 100%; }
.btn.icon { padding: 8px 10px; }

.input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 11px 14px; outline: none; transition: border-color 0.15s, box-shadow 0.15s; }
.input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.08); }
.input.lg { font-size: 22px; padding: 14px 16px; text-align: center; font-weight: 700; letter-spacing: 0.04em; }
textarea.input { resize: vertical; min-height: 80px; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }

.msg { padding: 10px 14px; border-radius: 10px; background: #fdecec; color: #a3262a; font-size: 14px; }
.msg.info { background: var(--soft); color: var(--ink); }

/* ---------- Antwort-Kacheln ---------- */

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { --c: var(--a0); background: var(--c); color: #fff; border: 0; border-radius: var(--radius); padding: 16px; display: flex; align-items: center; gap: 12px; min-height: 76px; font-weight: 700; font-size: 18px; text-align: left; position: relative; transition: transform 0.1s, opacity 0.2s, filter 0.2s; }
button.tile { cursor: pointer; }
button.tile:hover { filter: brightness(1.05); }
button.tile:active { transform: scale(0.97); }
.tile svg { width: 28px; height: 28px; flex: none; fill: #fff; }
.tile.c0 { --c: var(--a0); } .tile.c1 { --c: var(--a1); } .tile.c2 { --c: var(--a2); } .tile.c3 { --c: var(--a3); }
.tile.dim { opacity: 0.28; }
.tile.selected { outline: 4px solid var(--ink); outline-offset: 3px; }
.tile .check { margin-left: auto; width: 28px; height: 28px; border-radius: 50%; background: rgba(255, 255, 255, 0.25); display: grid; place-items: center; font-size: 16px; }
.tile .count { margin-left: auto; font-size: 22px; font-variant-numeric: tabular-nums; }

/* ---------- Spieler ---------- */

.player { min-height: 100dvh; display: flex; flex-direction: column; }
.player header { color: var(--ink); display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); font-weight: 600; font-size: 14px; }
.player main { flex: 1; display: flex; flex-direction: column; padding: 16px; gap: 14px; max-width: 720px; width: 100%; margin: 0 auto; }
.player .qtext { font-size: 20px; font-weight: 700; line-height: 1.3; text-align: center; }
.player .qimg { max-height: 30dvh; margin: 0 auto; border-radius: 12px; object-fit: contain; }
.player .tiles { flex: 1; align-content: end; }
.player .tile { min-height: 84px; }
.player.big-tiles .tiles .tile { min-height: 120px; }

.status { flex: 1; display: grid; place-items: center; text-align: center; }
.status h2 { font-size: 28px; margin: 12px 0 6px; letter-spacing: -0.02em; }
.status .big { font-size: 56px; line-height: 1; }
.result-ok { background: var(--ok); color: #fff; }
.result-bad { background: var(--bad); color: #fff; }
.result-ok .muted, .result-bad .muted { color: rgba(255, 255, 255, 0.85); }
.pill { display: inline-block; padding: 6px 12px; border-radius: 999px; background: var(--soft); font-weight: 700; font-size: 14px; }
.result-ok .pill, .result-bad .pill { background: rgba(255, 255, 255, 0.2); }

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

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.pop { animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Host ---------- */

.host { min-height: 100dvh; display: flex; flex-direction: column; }
.host .topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; gap: 12px; }
.host .stage { flex: 1; display: flex; flex-direction: column; padding: 8px 20px 20px; gap: 16px; max-width: 1280px; width: 100%; margin: 0 auto; }

.join-banner { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; }
.join-banner .pin { font-size: clamp(56px, 10vw, 112px); font-weight: 800; letter-spacing: 0.06em; line-height: 1; font-variant-numeric: tabular-nums; }
.join-banner .qr { background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--line); }
.join-banner .qr img, .join-banner .qr svg { width: 150px; height: 150px; image-rendering: pixelated; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-weight: 600; cursor: pointer; animation: pop 0.3s; }
.chip:hover { border-color: var(--bad); color: var(--bad); text-decoration: line-through; }
.chip.off { opacity: 0.45; }

.host .qtitle { font-size: clamp(24px, 3.4vw, 44px); font-weight: 800; text-align: center; letter-spacing: -0.02em; line-height: 1.2; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 24px; }
.host .qmid { flex: 1; display: grid; grid-template-columns: 120px 1fr 120px; align-items: center; gap: 16px; min-height: 200px; }
.host .qmid img { max-height: 42dvh; margin: 0 auto; border-radius: 12px; object-fit: contain; }
.host .tile { min-height: 92px; font-size: clamp(18px, 2vw, 26px); }
.timer { width: 104px; height: 104px; border-radius: 50%; display: grid; place-items: center; font-size: 40px; font-weight: 800; background: var(--surface); border: 1px solid var(--line); font-variant-numeric: tabular-nums; position: relative; }
.timer svg { position: absolute; inset: -1px; width: 106px; height: 106px; transform: rotate(-90deg); }
.timer circle { fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: round; transition: stroke-dashoffset 0.25s linear; }
.counter { text-align: center; font-weight: 700; }
.counter b { display: block; font-size: 40px; }

.chart { display: grid; grid-template-columns: repeat(var(--n, 4), 1fr); gap: 16px; align-items: end; height: 100%; min-height: 180px; padding: 0 10%; }
.chart .col { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; font-weight: 800; font-size: 22px; }
.chart .col i { width: 100%; border-radius: 8px 8px 0 0; background: var(--c); min-height: 6px; transition: height 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }
.chart .col.dim { opacity: 0.3; }

.board { display: flex; flex-direction: column; gap: 10px; max-width: 760px; width: 100%; margin: 0 auto; }
.board .entry { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; font-size: 22px; font-weight: 700; animation: slide 0.4s both; }
.board .entry .r { color: var(--muted); }
.board .entry .d { color: var(--ok); font-size: 15px; margin-left: 8px; }
@keyframes slide { from { transform: translateY(14px); opacity: 0; } }

.podium { display: flex; justify-content: center; align-items: flex-end; gap: 16px; flex: 1; padding-top: 40px; }
.podium .place { display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(240px, 28vw); }
.podium .place .name { font-size: clamp(18px, 2.4vw, 30px); font-weight: 800; text-align: center; word-break: break-word; }
.podium .place .block { width: 100%; border-radius: 12px 12px 0 0; display: grid; place-items: start center; padding-top: 14px; font-size: 48px; font-weight: 800; color: #fff; transform-origin: bottom; animation: rise 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.podium .p1 .block { height: 300px; background: #c9a227; animation-delay: 1.6s; }
.podium .p2 .block { height: 220px; background: #9aa0a6; animation-delay: 0.8s; }
.podium .p3 .block { height: 160px; background: #b0703c; animation-delay: 0s; }
.podium .p1 .name, .podium .p1 .pts { animation: fade 0.5s 2.3s both; }
.podium .p2 .name, .podium .p2 .pts { animation: fade 0.5s 1.5s both; }
.podium .p3 .name, .podium .p3 .pts { animation: fade 0.5s 0.7s both; }
@keyframes rise { from { transform: scaleY(0); } }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Editor ---------- */

.lib { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.lib .card { display: flex; flex-direction: column; gap: 10px; }
.lib h3 { margin: 0; font-size: 18px; letter-spacing: -0.01em; word-break: break-word; }

.editor { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.qlist { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 16px; max-height: calc(100dvh - 32px); overflow: auto; padding: 2px; }
.qitem { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; display: grid; grid-template-columns: 24px 1fr; gap: 8px; font-size: 14px; text-align: left; }
.qitem.active { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.qitem .n { font-weight: 800; color: var(--muted); }
.qitem .t { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.qitem.warn .n { color: var(--bad); }
.answers-edit { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.aedit { display: flex; align-items: center; gap: 10px; border-radius: 12px; padding: 8px 10px 8px 14px; background: var(--c); }
.aedit svg { width: 22px; height: 22px; fill: #fff; flex: none; }
.aedit input[type="text"] { flex: 1; min-width: 0; background: rgba(255, 255, 255, 0.95); border: 0; border-radius: 8px; padding: 10px 12px; outline: none; }
.aedit .ok { width: 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.8); background: transparent; color: #fff; cursor: pointer; font-weight: 800; flex: none; }
.aedit .ok.on { background: #fff; color: var(--ok); border-color: #fff; }
.imgbox { border: 1px dashed var(--line); border-radius: 12px; padding: 12px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; background: var(--surface); }
.imgbox img { max-height: 160px; border-radius: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

dialog { border: 0; border-radius: var(--radius); padding: 24px; max-width: 440px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2); }
dialog::backdrop { background: rgba(24, 24, 27, 0.4); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; z-index: 50; animation: fade 0.2s; }

@media (max-width: 760px) {
  .editor { grid-template-columns: 1fr; }
  .qlist { position: static; max-height: none; flex-direction: row; overflow-x: auto; }
  .qitem { min-width: 160px; }
  .answers-edit, .grid3 { grid-template-columns: 1fr; }
  .host .qmid { grid-template-columns: 1fr; }
  .host .qmid > :first-child, .host .qmid > :last-child { justify-self: center; }
  .join-banner { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: 1fr; }
  .player .tiles { grid-template-columns: 1fr 1fr; }
}
