:root {
  --bg: #0f0d1f;
  --bg2: #1b1633;
  --fg: #f5f3ff;
  --muted: #aaa3c4;
  --accent: #8b5cf6;
  --accent2: #ec4899;
  --ok: #22c55e;
  --err: #ef4444;
  --card: #1a1633cc;
  --opt-a: #ef4444;
  --opt-b: #3b82f6;
  --opt-c: #f59e0b;
  --opt-d: #22c55e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  color: var(--fg);
  background:
    radial-gradient(at 20% 10%, #2a1a55 0%, transparent 50%),
    radial-gradient(at 80% 90%, #4c1d95 0%, transparent 50%),
    var(--bg);
  background-attachment: fixed;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.logo {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--fg);
  text-decoration: none;
}
.logo span {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logo.small { font-size: 1.4rem; }

.subtitle { color: var(--muted); margin-top: -0.5rem; }

.status {
  font-size: 0.9rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.score-badge {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1;
  box-shadow: 0 2px 8px #0006, 0 0 0 0 transparent;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.score-badge .score-unit {
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.75;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.score-badge.bump {
  animation: score-bump 0.6s ease;
}
@keyframes score-bump {
  0%   { transform: scale(1);    box-shadow: 0 2px 8px #0006, 0 0 0 0 var(--accent2); }
  40%  { transform: scale(1.18); box-shadow: 0 4px 14px #0008, 0 0 0 8px #ffd60033; }
  100% { transform: scale(1);    box-shadow: 0 2px 8px #0006, 0 0 0 0 transparent; }
}

.card {
  background: var(--card);
  backdrop-filter: blur(10px);
  border: 1px solid #ffffff15;
  border-radius: 18px;
  padding: 1.5rem;
  box-shadow: 0 10px 40px #0008;
}

.center { text-align: center; }
.hidden { display: none !important; }

.landing main {
  max-width: 440px;
  margin: 4rem auto;
}

.join-box h2,
.landing h2 { margin-top: 0; }

form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

input {
  background: #ffffff10;
  border: 1px solid #ffffff20;
  border-radius: 12px;
  padding: 0.9rem 1rem;
  font-size: 1rem;
  color: var(--fg);
  outline: none;
}
input:focus {
  border-color: var(--accent);
}
#code {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-weight: 700;
  text-align: center;
}

.btn {
  display: inline-block;
  padding: 0.9rem 1.4rem;
  border-radius: 12px;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: transform 0.05s ease, opacity 0.2s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  color: #fff;
}
.btn.secondary {
  background: #ffffff15;
  color: var(--fg);
  border: 1px solid #ffffff25;
}
.btn.big {
  width: 100%;
  margin-top: 1rem;
  padding: 1.1rem;
  font-size: 1.1rem;
}

.sep {
  border: none;
  border-top: 1px solid #ffffff20;
  margin: 1.5rem 0;
}

.error { color: var(--err); min-height: 1.2em; }
.hint { color: var(--muted); }

.room-code {
  font-size: 4rem;
  font-weight: 900;
  letter-spacing: 0.3em;
  text-align: center;
  margin: 1rem 0;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.player-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
  margin: 1rem 0;
}
.player-list li {
  background: #ffffff10;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  text-align: center;
  font-weight: 600;
  border: 1px solid #ffffff15;
}

.qmeta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.timer {
  background: var(--accent);
  color: #fff;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-weight: 700;
  min-width: 2.5rem;
  text-align: center;
}
#q-text {
  font-size: 1.5rem;
  margin: 0.5rem 0 1.2rem;
}

.q-image {
  display: block;
  width: 100%;
  max-height: 40vh;
  object-fit: contain;
  margin: 0.5rem 0 0.8rem;
  border-radius: 12px;
  background: #00000040;
  cursor: zoom-in;
}

/* Lightbox-Overlay (Klick auf .q-image vergroessert das Bild). */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  cursor: zoom-out;
  animation: lightbox-in 0.18s ease-out;
}
.lightbox-img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 40px #000c;
}
@keyframes lightbox-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.qtable-thumb {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.img-preview {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  margin-top: 0.5rem;
  padding: 0.6rem;
  background: #ffffff08;
  border: 1px solid #ffffff15;
  border-radius: 10px;
}
.img-preview img {
  max-width: 140px;
  max-height: 100px;
  object-fit: contain;
  border-radius: 6px;
}
.img-preview code {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  word-break: break-all;
  margin-bottom: 0.3rem;
}

.options {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin: 0;
}
.options.player {
  grid-template-columns: 1fr 1fr;
}

.opt {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1rem;
  border-radius: 14px;
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  border: none;
  cursor: pointer;
  text-align: left;
  min-height: 70px;
  transition: opacity 0.2s, transform 0.1s, outline 0.2s;
}
.opt:active { transform: translateY(1px); }
.opt-a { background: var(--opt-a); }
.opt-b { background: var(--opt-b); }
.opt-c { background: var(--opt-c); }
.opt-d { background: var(--opt-d); }
.opt .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  background: #00000040;
  font-weight: 800;
}
.opt.dim { opacity: 0.4; }
.opt.picked { outline: 4px solid #ffffffcc; }
.opt.correct { outline: 4px solid #fff; box-shadow: 0 0 0 6px #22c55e80; }
.opt.wrong { opacity: 0.35; }

.scoreboard {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}
.scoreboard li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #ffffff10;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  margin-bottom: 0.4rem;
  font-weight: 600;
  border: 1px solid #ffffff15;
}
.scoreboard li.me {
  border-color: var(--accent);
  background: #8b5cf625;
}
.scoreboard.final li:first-child {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border: none;
  font-size: 1.15rem;
}

.big-points {
  font-size: 3rem;
  font-weight: 900;
  margin: 0.5rem 0;
  color: var(--ok);
}

.copy-row {
  text-align: center;
  margin: -0.5rem 0 0.8rem;
}
.copy-btn {
  background: #ffffff15;
  border: 1px solid #ffffff25;
  color: var(--fg);
  padding: 0.35rem 0.8rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.copy-btn:hover { background: #ffffff25; }
.copy-btn:active { transform: translateY(1px); }
.copy-btn.small {
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  margin-left: 0.4rem;
}
.copy-btn.copied {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}

.reveal-correct {
  font-size: 1.1rem;
  margin: 0.2rem 0 0.8rem;
  padding: 0.6rem 0.9rem;
  background: #22c55e20;
  border: 1px solid #22c55e60;
  border-radius: 10px;
  color: #c6f6d5;
}

.role-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

details.qm-info {
  margin: 1rem 0;
  background: #ffffff10;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  border: 1px solid #ffffff15;
}
details.qm-info summary {
  cursor: pointer;
  color: var(--muted);
}
details.qm-info code {
  background: #00000040;
  padding: 0.1em 0.3em;
  border-radius: 4px;
  word-break: break-all;
}

.config {
  display: grid;
  gap: 0.5rem;
  margin: 1rem 0;
  padding: 1rem;
  background: #ffffff08;
  border: 1px solid #ffffff15;
  border-radius: 12px;
}
.config label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.95rem;
}
.config label.checkbox {
  justify-content: flex-start;
  gap: 0.5rem;
}
.config input[type="number"],
.config select {
  width: 8rem;
  padding: 0.4rem 0.6rem;
}

.qm-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 1rem 0;
}
.qm-controls .btn { flex: 1; min-width: 120px; }

li.offline { opacity: 0.5; }

.reveal-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 1rem;
}
.reveal-list .reveal-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  background: #ffffff08;
  border: 1px solid #ffffff15;
  margin-bottom: 0.3rem;
  font-size: 0.95rem;
}
.reveal-list .reveal-row.correct {
  border-color: #22c55e80;
  background: #22c55e15;
}
.reveal-list .reveal-row.wrong {
  border-color: #ef444460;
  background: #ef444410;
}
.reveal-list .rl-pick {
  font-weight: 700;
  min-width: 1.5rem;
  text-align: center;
  background: #00000040;
  border-radius: 6px;
  padding: 0.1rem 0.4rem;
}
.reveal-list .rl-status {
  font-weight: 600;
  min-width: 4rem;
  text-align: right;
}

#q-state-badge,
#state-label {
  font-weight: 600;
  color: var(--accent2);
}

/* Admin */
.container.wide { max-width: 1100px; }
.tabs { display: flex; gap: 0.3rem; }
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid #ffffff20;
  border-radius: 999px;
  padding: 0.4rem 1rem;
  cursor: pointer;
  font-weight: 600;
}
.tab.active {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  color: #fff;
  border-color: transparent;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.qtable {
  width: 100%;
  border-collapse: collapse;
}
.qtable th,
.qtable td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #ffffff15;
  text-align: left;
  vertical-align: top;
}
.qtable th { color: var(--muted); font-weight: 600; }
.qtable td.ellipsis {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn.small {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}
.btn.danger {
  background: var(--err);
  color: #fff;
}

.modal {
  position: fixed;
  inset: 0;
  background: #000a;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-card {
  background: var(--bg2);
  border-radius: 16px;
  border: 1px solid #ffffff20;
  padding: 1.5rem;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card form { gap: 0.8rem; }
.modal-card label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.modal-card textarea {
  background: #ffffff10;
  border: 1px solid #ffffff20;
  border-radius: 10px;
  padding: 0.6rem;
  color: var(--fg);
  font-family: inherit;
  font-size: 1rem;
  resize: vertical;
}
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.result {
  background: #00000040;
  padding: 0.8rem;
  border-radius: 8px;
  white-space: pre-wrap;
  font-size: 0.85rem;
  color: var(--muted);
}

.scoreboard li small { color: var(--muted); font-weight: 400; }

/* Admin-Highscores: Meta-Block (Name+Score) und Action-Box
   (Loesch-Button) optisch trennen — Delete-Button hat eigene Box
   rechts neben dem Daten-Block, mit Trennlinie. */
.scoreboard li .hs-meta {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.scoreboard li .hs-actions {
  margin-left: 1rem;
  padding-left: 1rem;
  border-left: 1px solid #ffffff20;
  display: flex;
  align-items: center;
}

@media (max-width: 480px) {
  .room-code { font-size: 2.8rem; }
  #q-text { font-size: 1.2rem; }
  .opt { font-size: 0.95rem; padding: 0.8rem; min-height: 60px; }
}

/* --- Spielshow-Ansicht (show.html, read-only) --- */

.show-container {
  max-width: 1400px;
  /* Fester Viewport-Container — kein Page-Scroll. Frage und Tiles
     leben in einem Grid mit fester Tile-Reihe unten. So kann ein
     Bild in der Frage die Tiles nicht mehr nach unten verschieben. */
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#view-show {
  flex: 1 1 auto;
  min-height: 0; /* erlaubt overflow:auto im Kind */
  display: grid;
  /* Frage nimmt verfuegbaren Platz, Tiles ihre natuerliche Hoehe. */
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 1.2rem;
}

.status .show-room { margin-left: 0.5rem; color: var(--fg); }
.status .show-room strong { color: var(--accent2); letter-spacing: 0.05em; }

.show-question {
  position: relative;
  text-align: center;
  padding: 1.5rem 1.5rem 1.2rem;
  /* Fragen-Box scrollt intern wenn der Inhalt den verfuegbaren
     Grid-Slot sprengt — Tiles bleiben dadurch an ihrer Position. */
  min-height: 0;
  overflow-y: auto;
}
/* Bild auf Show-Seite enger gedeckelt, damit Frage + Optionen + Tiles
   in den Viewport passen ohne Scrollbalken. Lightbox bleibt zugaenglich. */
.show-question .q-image {
  max-height: 25vh;
}
.show-q-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
}
.show-q-meta .timer {
  font-size: 1.1rem;
  padding: 0.3rem 0.8rem;
}
#show-text {
  font-size: 1.8rem;
  margin: 0.3rem 0 1rem;
}
.show-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.show-options .opt {
  padding: 0.8rem 1rem;
  min-height: 56px;
  font-size: 1rem;
  cursor: default;
  pointer-events: none;
}

.show-tiles {
  /* Position kommt jetzt vom #view-show-Grid (zweite Reihe = auto).
     Tiles haben eine feste Hoehe und sitzen unabhaengig von der
     Fragen-Box-Hoehe immer am gleichen Pixel. */
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  /* Alle Reihen gleich hoch — verhindert dass ein Pick-Badge in einer
     Kachel den Rest der Reihe mitwachsen laesst. */
  grid-auto-rows: 1fr;
}
.show-tiles[data-count="1"],
.show-tiles[data-count="2"]   { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.show-tiles[data-count="3"]   { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.show-tiles[data-count="4"]   { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.show-tiles[data-count="5"],
.show-tiles[data-count="6"]   { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.show-tiles[data-count="7"],
.show-tiles[data-count="8"]   { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.show-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  font-style: italic;
  padding: 2rem;
}

.candidate-tile {
  --tile-color: var(--accent);
  background: var(--card);
  backdrop-filter: blur(10px);
  border: 2px solid var(--tile-color);
  border-radius: 16px;
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  /* space-between haelt den Pick-Slot konstant unten, auch wenn er leer ist */
  justify-content: space-between;
  gap: 0.5rem;
  box-shadow: 0 4px 12px #0007, inset 0 0 0 1px #ffffff10;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}
.candidate-tile.acc-1 { --tile-color: #ef4444; }
.candidate-tile.acc-2 { --tile-color: #3b82f6; }
.candidate-tile.acc-3 { --tile-color: #f59e0b; }
.candidate-tile.acc-4 { --tile-color: #22c55e; }
.candidate-tile.acc-5 { --tile-color: #a855f7; }
.candidate-tile.acc-6 { --tile-color: #ec4899; }
.candidate-tile.acc-7 { --tile-color: #14b8a6; }
.candidate-tile.acc-8 { --tile-color: #f97316; }

.candidate-tile.correct {
  border-color: var(--ok);
  box-shadow: 0 0 0 3px #22c55e40, 0 4px 14px #0008;
}
.candidate-tile.wrong { opacity: 0.55; }
.candidate-tile.offline { opacity: 0.4; }

.cam-slot {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background:
    repeating-linear-gradient(135deg, #ffffff08 0 8px, transparent 8px 16px),
    linear-gradient(180deg, #00000060, #00000020);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #ffffff20;
}
.cam-icon {
  font-size: 2rem;
  opacity: 0.5;
}

.tile-name {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--fg);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-score {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 0.3rem;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--tile-color);
}
.tile-score .tile-unit {
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.75;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* Reservierter Slot fuer den Live-Pick-Badge — bleibt auch leer
   bestehen, damit das Erscheinen eines Picks kein Layout-Shift in der
   Kachel ausloest. */
.tile-pick {
  min-height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pick-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  padding: 0.25rem 0.7rem;
  border-radius: 8px;
  font-weight: 800;
  font-size: 1.1rem;
  color: #fff;
  box-shadow: 0 2px 8px #0008;
}
.pick-badge.opt-a { background: var(--opt-a); }
.pick-badge.opt-b { background: var(--opt-b); }
.pick-badge.opt-c { background: var(--opt-c); }
.pick-badge.opt-d { background: var(--opt-d); }

@media (max-width: 600px) {
  .show-tiles,
  .show-tiles[data-count="3"],
  .show-tiles[data-count="4"],
  .show-tiles[data-count="5"],
  .show-tiles[data-count="6"],
  .show-tiles[data-count="7"],
  .show-tiles[data-count="8"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #show-text { font-size: 1.3rem; }
}
