:root {
  --bg: #0f1017;
  --surface: #181a24;
  --surface-2: #20232f;
  --surface-3: #2a2e3d;
  --line: #2f3345;
  --text: #eef0f6;
  --muted: #9aa0b4;
  --accent: #8b7bff;
  --accent-2: #b3a8ff;
  --imp: #ff4d6d;
  --imp-soft: rgba(255, 77, 109, 0.14);
  --crew: #34d6b0;
  --crew-soft: rgba(52, 214, 176, 0.13);
  --warn: #ffc857;
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background:
    radial-gradient(1200px 600px at 110% -10%, rgba(139, 123, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(255, 77, 109, 0.08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }

.boot { padding: 40px; text-align: center; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #9d8fff; }
.btn.danger { background: var(--imp); border-color: var(--imp); color: #fff; }
.btn.ghost { background: transparent; }
.btn.big { padding: 14px 26px; font-size: 1.08rem; border-radius: 12px; }
.btn.tiny { padding: 3px 8px; font-size: 0.8rem; border-radius: 7px; }

input[type="text"], textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 123, 255, 0.2); }
textarea { resize: vertical; min-height: 110px; font-size: 0.92rem; line-height: 1.5; }
input:disabled, textarea:disabled, textarea[readonly] { opacity: 0.7; }

label.field { display: block; font-size: 0.85rem; color: var(--muted); font-weight: 600; margin-bottom: 6px; }

/* ---------- Home ---------- */

.home {
  max-width: 440px;
  margin: 0 auto;
  padding: 10vh 16px 40px;
}
.logo {
  font-size: clamp(2.6rem, 11vw, 4rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  margin: 0;
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo .diamond { color: var(--imp); font-size: 0.7em; }
.tagline { color: var(--muted); margin: 10px 0 28px; font-size: 1.05rem; }
.home .panel { display: grid; gap: 14px; }
.or { text-align: center; color: var(--muted); font-size: 0.85rem; position: relative; }
.or::before, .or::after { content: ""; position: absolute; top: 50%; width: 38%; height: 1px; background: var(--line); }
.or::before { left: 0; }
.or::after { right: 0; }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; text-align: center; }
.joining { text-align: center; }
.joining .code { font-size: 2rem; }

/* ---------- Shell ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 16, 23, 0.75);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 900; letter-spacing: 0.12em; display: flex; align-items: center; gap: 8px; }
.brand .diamond { color: var(--imp); }
.top-meta { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.85rem;
  color: var(--muted);
}
.chip b { color: var(--text); letter-spacing: 0.1em; }
.chip.warn { color: var(--warn); border-color: rgba(255, 200, 87, 0.4); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 20px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 22px 20px 60px;
  align-items: start;
}
.stage { display: grid; gap: 18px; min-width: 0; }
.side { position: sticky; top: 76px; display: grid; gap: 14px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.panel h3 { margin: 0 0 12px; font-size: 0.95rem; letter-spacing: 0.02em; display: flex; justify-content: space-between; align-items: baseline; }

.stage-head h2 { margin: 2px 0 4px; font-size: clamp(1.5rem, 4vw, 2.1rem); line-height: 1.15; }
.stage-head p { margin: 0; color: var(--muted); }
.kicker { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.75rem; font-weight: 700; color: var(--accent-2); }
.stage-head.turn-me h2 { color: var(--warn); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions.center { justify-content: center; }
.host-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 12px;
}
.host-bar .label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-right: 4px; }

/* ---------- Spielerliste ---------- */

.plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.plist li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 9px;
  font-size: 0.95rem;
}
.plist li.me { background: var(--surface-2); }
.plist li.off { opacity: 0.5; }
.plist .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--crew); flex: none; }
.plist li.off .dot { background: var(--muted); }
.plist .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .score { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.plist .delta { font-size: 0.78rem; color: var(--crew); font-weight: 700; }
.plist .host-tools { display: none; gap: 3px; }
.plist li:hover .host-tools { display: flex; }
@media (hover: none) { .plist .host-tools { display: flex; } }
.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge.ok { background: var(--crew-soft); color: var(--crew); }
.badge.turn { background: rgba(255, 200, 87, 0.15); color: var(--warn); }
.badge.imp { background: var(--imp-soft); color: var(--imp); }

/* ---------- Lobby ---------- */

.invite { display: grid; gap: 12px; }
.invite-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.invite .code { font-size: 2.6rem; font-weight: 900; letter-spacing: 0.25em; line-height: 1; }
.invite .label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); display: block; margin-bottom: 6px; }
.link-row { display: flex; gap: 8px; }
.link-row input { font-size: 0.9rem; color: var(--muted); }
.alt-links { font-size: 0.82rem; color: var(--muted); }
.alt-links code { color: var(--text); background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }
.note { font-size: 0.85rem; padding: 10px 12px; border-radius: 10px; background: rgba(255, 200, 87, 0.08); border: 1px solid rgba(255, 200, 87, 0.3); color: #ffe2a8; }

.settings { display: grid; gap: 18px; }
.set-row { display: grid; gap: 8px; }
.set-row > .seg, .set-row > .stepper { justify-self: start; }
.set-row .set-label { font-weight: 700; font-size: 0.92rem; }
.set-row .set-help { font-size: 0.85rem; color: var(--muted); margin: 0; }
.set-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; }

.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button {
  border: 0;
  background: transparent;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}
.seg button.on { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.seg button:disabled { cursor: default; }

.stepper { display: inline-flex; align-items: center; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.stepper button { width: 34px; height: 34px; border: 0; border-radius: 8px; background: var(--surface-2); cursor: pointer; font-size: 1.1rem; font-weight: 700; }
.stepper button:disabled { opacity: 0.35; cursor: default; }
.stepper .val { min-width: 3.2ch; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; }

.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 0.93rem; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.cats { display: flex; flex-wrap: wrap; gap: 7px; }
.cat {
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--muted);
  display: inline-flex;
  gap: 7px;
  align-items: baseline;
}
.cat small { font-weight: 500; opacity: 0.75; font-size: 0.75rem; }
.cat.on { border-color: var(--accent); color: var(--text); background: rgba(139, 123, 255, 0.14); }
.cat:disabled { cursor: default; }
.cat.empty { opacity: 0.4; }
.linkish { background: none; border: 0; color: var(--accent-2); cursor: pointer; padding: 0; font-size: 0.85rem; font-weight: 600; }

details.rules summary { cursor: pointer; font-weight: 700; font-size: 0.92rem; }
details.rules ul { margin: 10px 0 0; padding-left: 20px; color: var(--muted); font-size: 0.9rem; }

.start-area { display: grid; gap: 8px; justify-items: center; text-align: center; padding: 6px 0; }

/* ---------- Karte ---------- */

.card-wrap { display: flex; justify-content: center; }
.card {
  display: block;
  perspective: 1200px;
  width: min(380px, 100%);
  aspect-ratio: 3 / 2;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.card.small { width: min(250px, 100%); }
.card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transition: transform 0.55s cubic-bezier(0.2, 0.8, 0.2, 1);
  transform-style: preserve-3d;
}
.card.open .card-inner { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 18px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}
.front {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.035) 0 10px, transparent 10px 20px),
    linear-gradient(135deg, #2b2450, #1b1d2b 60%);
  border: 1px solid rgba(139, 123, 255, 0.35);
  color: var(--accent-2);
  font-weight: 700;
}
.front .card-logo { font-size: 2.4rem; color: var(--imp); line-height: 1; }
.front small { color: var(--muted); font-weight: 500; font-size: 0.78rem; }
.back {
  transform: rotateY(180deg);
  background: linear-gradient(160deg, #1d2a2a, #181a24 70%);
  border: 2px solid var(--crew);
}
.card.is-imp .back { background: linear-gradient(160deg, #3a1822, #181a24 70%); border-color: var(--imp); }
.back .role { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.16em; color: var(--muted); font-weight: 700; }
.back .word { font-size: clamp(1.5rem, 6vw, 2.3rem); font-weight: 900; line-height: 1.1; word-break: break-word; }
.card.small .back .word { font-size: 1.35rem; }
.card.is-imp .back .word { color: var(--imp); letter-spacing: 0.06em; }
.back .hint { font-size: 0.9rem; color: var(--muted); }
.back .hint b { color: var(--text); }
.card.spectator { cursor: default; }
.card.spectator .front { color: var(--muted); font-weight: 600; }

/* ---------- Assoziationen ---------- */

.clue-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 20px; align-items: start; }
.clue-main { display: grid; gap: 14px; min-width: 0; }
.input-row { display: flex; gap: 8px; }
.input-row input { font-size: 1.05rem; }
.my-turn { border-color: rgba(255, 200, 87, 0.5); box-shadow: 0 0 0 4px rgba(255, 200, 87, 0.08); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.clues { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.clues th, table.clues td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.clues tr:last-child td { border-bottom: 0; }
table.clues th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; background: var(--surface-2); }
table.clues td.num { color: var(--muted); width: 2.5em; font-variant-numeric: tabular-nums; }
table.clues td.pn { font-weight: 700; white-space: nowrap; }
table.clues td.cl { font-weight: 500; }
table.clues tr.current { background: rgba(255, 200, 87, 0.08); }
table.clues tr.current td.pn { color: var(--warn); }
table.clues tr.imp { background: var(--imp-soft); }
table.clues tr.imp td.pn { color: var(--imp); }
.typing { color: var(--warn); font-style: italic; font-size: 0.85rem; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- Abstimmung ---------- */

.vote-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.vote-card {
  text-align: left;
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  display: grid;
  gap: 4px;
  transition: border-color 0.15s, background 0.15s;
}
.vote-card:hover:not(:disabled) { border-color: var(--accent); }
.vote-card.on { border-color: var(--imp); background: var(--imp-soft); }
.vote-card:disabled { cursor: default; opacity: 0.55; }
.vote-card .vname { font-weight: 800; font-size: 1.05rem; }
.vote-card .vclues { font-size: 0.85rem; color: var(--muted); }
.vote-card .vcount { font-size: 0.8rem; color: var(--warn); font-weight: 700; }

/* ---------- Auflösung ---------- */

.banner {
  border-radius: 18px;
  padding: 26px 22px;
  text-align: center;
  border: 1px solid var(--line);
}
.banner h2 { margin: 6px 0; font-size: clamp(1.7rem, 5vw, 2.5rem); line-height: 1.1; }
.banner p { margin: 0; color: var(--muted); }
.banner.crew { background: linear-gradient(160deg, rgba(52, 214, 176, 0.2), rgba(24, 26, 36, 0.6)); border-color: rgba(52, 214, 176, 0.4); }
.banner.crew h2 { color: var(--crew); }
.banner.imp { background: linear-gradient(160deg, rgba(255, 77, 109, 0.22), rgba(24, 26, 36, 0.6)); border-color: rgba(255, 77, 109, 0.45); }
.banner.imp h2 { color: var(--imp); }
.banner.neutral { background: linear-gradient(160deg, rgba(139, 123, 255, 0.2), rgba(24, 26, 36, 0.6)); }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.fact { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.fact .label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); font-weight: 700; }
.fact .val { font-size: 1.35rem; font-weight: 900; line-height: 1.2; word-break: break-word; }
.fact .val.imp { color: var(--imp); }
.fact .val { display: block; }
.fact small { color: var(--muted); display: block; }

.reveal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.reveal-list li { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.reveal-list li.imp { background: var(--imp-soft); }
.reveal-list li.crew { background: var(--crew-soft); }
.reveal-list .grow { flex: 1; }

.votes-table { display: grid; gap: 6px; font-size: 0.92rem; }
.votes-table .vrow { display: grid; grid-template-columns: minmax(90px, 160px) 3ch 1fr; gap: 10px; align-items: baseline; }
.votes-table .vrow .n { font-weight: 800; color: var(--warn); text-align: right; }
.votes-table .vrow .who { color: var(--muted); }
.votes-table .vrow.imp .name { color: var(--imp); font-weight: 700; }

.points { display: flex; flex-wrap: wrap; gap: 8px; }
.points .pt { background: var(--surface-2); border-radius: 999px; padding: 4px 12px; font-size: 0.9rem; }
.points .pt b { color: var(--crew); }
.points .pt.zero b { color: var(--muted); }

/* ---------- Endstand ---------- */

.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: end; gap: 10px; max-width: 520px; margin: 0 auto; }
.podium .step { text-align: center; }
.podium .block { border-radius: 12px 12px 0 0; background: var(--surface-2); border: 1px solid var(--line); display: flex; align-items: flex-start; justify-content: center; padding-top: 10px; font-size: 1.8rem; font-weight: 900; }
.podium .p1 .block { height: 150px; background: linear-gradient(180deg, rgba(255, 200, 87, 0.35), var(--surface-2)); }
.podium .p2 .block { height: 110px; background: linear-gradient(180deg, rgba(180, 190, 210, 0.3), var(--surface-2)); }
.podium .p3 .block { height: 80px; background: linear-gradient(180deg, rgba(205, 127, 50, 0.3), var(--surface-2)); }
.podium .pn { font-weight: 800; margin-bottom: 4px; word-break: break-word; }
.podium .ps { color: var(--muted); font-size: 0.9rem; margin-bottom: 6px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--surface-3);
  border: 1px solid var(--line);
  padding: 11px 18px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
  z-index: 100;
  font-weight: 600;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(255, 77, 109, 0.6); }

.center-msg { max-width: 460px; margin: 18vh auto; text-align: center; padding: 0 16px; display: grid; gap: 14px; justify-items: center; }

/* ---------- Mobil ---------- */

@media (max-width: 1100px) {
  .clue-layout { grid-template-columns: 1fr; }
  .clue-layout .card-wrap { order: 2; }
}
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; padding: 16px 16px 50px; }
  .side { position: static; }
}
@media (max-width: 520px) {
  .topbar { padding: 10px 16px; }
  .brand .txt { display: none; }
  .invite .code { font-size: 2.1rem; }
  .link-row, .input-row, .join-row { flex-direction: column; }
  .votes-table .vrow { grid-template-columns: 1fr 3ch; }
  .votes-table .vrow .who { grid-column: 1 / -1; margin-top: -4px; }
}
