:root {
  color-scheme: light;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --bg: #f5f5f7;
  --bg-elevated: #ffffff;
  --bg-inset: #ececef;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --border: rgba(0, 0, 0, 0.10);
  --border-strong: rgba(0, 0, 0, 0.16);
  --shadow: rgba(0, 0, 0, 0.08);

  --accent: #0071e3;
  --accent-teams: #7c5cff;
  --accent-games: #007aff;
  --accent-points: #ff9500;
  --success: #248a3d;
  --warn: #b25000;
  --danger: #d70015;

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --bg-inset: #2c2c2e;
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --border: rgba(255, 255, 255, 0.12);
    --border-strong: rgba(255, 255, 255, 0.22);
    --shadow: rgba(0, 0, 0, 0.5);

    --accent: #0a84ff;
    --accent-teams: #9f7bff;
    --accent-games: #409cff;
    --accent-points: #ff9f0a;
    --success: #32d74b;
    --warn: #ffd60a;
    --danger: #ff453a;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --bg-elevated: #1c1c1e;
  --bg-inset: #2c2c2e;
  --text: #f5f5f7;
  --text-secondary: #98989d;
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.22);
  --shadow: rgba(0, 0, 0, 0.5);

  --accent: #0a84ff;
  --accent-teams: #9f7bff;
  --accent-games: #409cff;
  --accent-points: #ff9f0a;
  --success: #32d74b;
  --warn: #ffd60a;
  --danger: #ff453a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a { color: var(--accent); text-decoration: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 20px 60px;
  flex: 1;
}

@media (min-width: 768px) {
  .wrap { padding: 0 28px 64px; }
}

@media (min-width: 1024px) {
  .wrap { max-width: 1040px; padding: 0 32px 72px; }
}

/* --- Kopfzeile --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-elevated);
  background: color-mix(in srgb, var(--bg-elevated) 72%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .brand {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.topbar nav {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar .pill {
  background: var(--bg-inset);
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-weight: 600;
  font-size: 0.88rem;
  text-decoration: none;
}

.topbar a.pill {
  transition: background 0.15s ease;
}

.topbar a.pill:hover,
.topbar a.pill:focus-visible {
  background: var(--border);
}

.icon-btn {
  width: 38px;
  height: 38px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  background: var(--bg-inset);
  color: var(--text);
  box-shadow: none;
}

.nav-menu { position: relative; }

.nav-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px var(--shadow), 0 12px 32px var(--shadow);
  padding: 6px;
  flex-direction: column;
  gap: 2px;
  z-index: 30;
}

.nav-menu-panel[hidden] { display: none; }
.nav-menu-panel:not([hidden]) { display: flex; }

.nav-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  box-shadow: none;
}

.nav-menu-item:hover { background: var(--bg-inset); }

/* --- Buttons --- */
button, .btn {
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 13px 20px;
  min-height: 46px;
  cursor: pointer;
  background: var(--bg-inset);
  color: var(--text);
  box-shadow: none;
  transition: transform 0.12s ease, filter 0.15s ease, opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
}

button:hover, .btn:hover { filter: brightness(0.96); }
button:active, .btn:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
/* Ohne dieses Override gewinnt "display: inline-flex" oben gegen das UA-Standardverhalten
   von [hidden] (Autor-Regeln schlagen User-Agent-Regeln, unabhängig von der Spezifität) -
   ein Button mit hidden-Attribut würde trotzdem angezeigt. */
button[hidden], .btn[hidden] { display: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-warn { background: var(--danger); color: #fff; }
.btn-grape { background: var(--accent-teams); color: #fff; }
.btn-outline { background: transparent; border: 1.5px solid var(--border-strong); color: var(--text); }
.btn-block { width: 100%; }
.btn-lg { font-size: 1.1rem; padding: 18px 24px; min-height: 58px; }

/* --- Karten --- */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 2px var(--shadow), 0 8px 24px var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-inset);
  color: var(--text);
  font-weight: 700;
  overflow: hidden;
  vertical-align: middle;
  flex-shrink: 0;
}

.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.name-row { display: inline-flex; align-items: center; gap: 8px; }

.member-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 8px 0;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.avatar-preview {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-inset);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  font-weight: 700;
  margin: 0 auto 14px;
}

.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }

.team-card { border-left: 4px solid var(--accent-teams); }
.team-card-clickable { cursor: pointer; transition: transform 0.15s ease, box-shadow 0.15s ease; }
.team-card-clickable:hover { transform: translateY(-2px); }
.team-card-clickable details, .team-card-clickable summary, .team-card-clickable form { cursor: auto; }
.game-card {
  border-left: 4px solid var(--accent-games);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.game-card:hover { transform: translateY(-2px); }

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--bg-inset);
  color: var(--text);
}

.badge-status-PENDING { background: rgba(10, 132, 255, 0.14); color: var(--accent); }
.badge-status-RUNNING { background: rgba(50, 215, 75, 0.16); color: var(--success); }
.badge-status-FINISHED { background: rgba(255, 69, 58, 0.14); color: var(--danger); }

.points { font-size: 1.4rem; font-weight: 700; color: var(--accent-points); }

/* --- Formulare --- */
label { font-weight: 600; display: block; margin: 14px 0 6px; font-size: 0.92rem; }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-inset);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.25);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
textarea { min-height: 120px; font-family: inherit; }

.label-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 14px 0 6px; }
.label-row label { margin: 0; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 600; font-size: 0.8rem; color: var(--text-secondary); user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: var(--bg-inset);
  border: 1px solid var(--border-strong);
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-elevated);
  box-shadow: 0 1px 2px var(--shadow);
  transition: transform 0.15s ease;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.error-banner {
  background: rgba(255, 59, 48, 0.10);
  border: 1px solid rgba(255, 59, 48, 0.4);
  color: var(--danger);
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-weight: 600;
  scroll-margin-top: 90px;
}

.hint { color: var(--text-secondary); font-size: 0.9rem; }

/* --- Bereitschaft --- */
.ready-list { list-style: none; padding: 0; margin: 14px 0; }
.ready-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-weight: 600; }
.ready-list li.offline { opacity: 0.55; font-weight: 400; font-style: italic; }
.dot { font-size: 1.1rem; }

/* --- Spielreihenfolge (Drag & Drop) --- */
.reorder-list { list-style: none; padding: 0; margin: 14px 0; display: flex; flex-direction: column; gap: 6px; }
.reorder-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-inset);
  border-radius: var(--radius-sm);
  cursor: grab;
  user-select: none;
}
.reorder-list li.dragging { opacity: 0.4; }
.reorder-list li .drag-handle { flex: 0 0 auto; }
.reorder-list li input[type="text"] { flex: 1; width: auto; }
.reorder-list li .icon-btn { flex: 0 0 auto; width: 32px; height: 32px; }

/* --- Logo-Auswahl --- */
.logo-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0 14px;
}

.logo-option {
  font-size: 1.3rem;
  min-height: 42px;
  width: 42px;
  padding: 0;
  background: var(--bg-inset);
  box-shadow: none;
}

.logo-option.selected { background: var(--accent-teams); }

details summary {
  cursor: pointer;
  font-weight: 600;
  margin: 10px 0 4px;
  color: var(--accent-teams);
}

details.card > summary {
  color: var(--text);
}

/* --- Timer & Buzzer --- */
.timer {
  font-size: 2.8rem;
  font-weight: 700;
  text-align: center;
  color: var(--accent-games);
  margin: 10px 0;
}

.buzzer {
  width: 100%;
  max-width: 300px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--danger);
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--danger) 55%, white), var(--danger));
  color: #fff;
  font-size: 1.6rem;
  font-weight: 700;
  margin: 24px auto;
  display: flex;
  box-shadow: 0 10px 24px var(--shadow);
}

.buzzer:active { transform: scale(0.96); box-shadow: 0 6px 14px var(--shadow); }

.compare-options { display: flex; gap: 16px; margin: 20px 0; }
.compare-options button { flex: 1; font-size: 1.2rem; padding: 28px 16px; }
/* Multiple-Choice hat 4 statt 2 Optionen - als 2x2-Raster statt einer engen Reihe. */
.compare-options.mc-options { flex-wrap: wrap; }
.compare-options.mc-options button { flex: 1 1 calc(50% - 8px); }

/* Sortier-Quiz: Auf-/Ab-Buttons statt Drag&Drop (auf Touchgeräten zuverlässiger). */
.sorting-list { list-style: none; padding: 0; margin: 20px 0; display: flex; flex-direction: column; gap: 8px; }
.sorting-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-inset);
}
.sorting-rank { font-weight: 700; color: var(--text-secondary); min-width: 1.6em; }
.sorting-text { flex: 1; font-size: 1.05rem; }
.sorting-controls { display: flex; gap: 4px; flex: 0 0 auto; }
.sorting-controls button { width: 42px; height: 42px; min-height: 0; padding: 0; border-radius: 50%; font-size: 1.1rem; }
.sorting-list.sorting-revealed li { justify-content: flex-start; }

/* --- Quiz Vollbild --- */
body.quiz-fullscreen-active { overflow: hidden; }

#quiz-container .card.quiz-maximized {
  position: fixed;
  inset: 0;
  z-index: 200;
  margin: 0;
  max-width: none;
  border-radius: 0;
  overflow-y: auto;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}

#quiz-container .card.quiz-maximized > .flex-between:first-child {
  position: sticky;
  top: -20px;
  margin: -20px -20px 12px;
  padding: 20px 20px 12px;
  background: var(--bg-elevated);
  z-index: 1;
}

/* --- Tabs (Admin) --- */
.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  background: var(--bg-inset);
  padding: 4px;
  border-radius: var(--radius);
}
.tabs button {
  background: transparent;
  padding: 9px 16px;
  min-height: 38px;
  font-size: 0.9rem;
  box-shadow: none;
  border-radius: calc(var(--radius) - 4px);
}
.tabs button:hover { filter: none; }
.tabs button.active { background: var(--bg-elevated); color: var(--text); box-shadow: 0 1px 3px var(--shadow); }

table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--text-secondary); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; }

.center { text-align: center; }
.mt { margin-top: 20px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

.top-right-fixed {
  position: sticky;
  top: 70px;
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
  z-index: 10;
}

/* --- Fragen-Karussell --- */
.questions-section { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.questions-section h3 { margin: 0 0 4px; }
.carousel-nav { margin: 12px 0; }
.carousel-slide { background: var(--bg-inset); border-radius: var(--radius); padding: 4px 16px 16px; }
.q-add-area { margin-top: 16px; }
.q-create-panel { background: var(--bg-inset); border-radius: var(--radius); padding: 16px; margin-top: 12px; }
.q-create-panel textarea { min-height: 200px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem; }

/* --- Fragen-Übersicht (Suche über alle Quizzes) --- */
.q-overview-item { padding: 14px 20px; }
.q-overview-item summary { margin: 0; list-style-position: outside; }
.q-overview-item summary strong { display: block; margin-top: 8px; font-size: 1rem; color: var(--text); }
.q-overview-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.q-overview-preview { margin: 4px 0 0; }
.q-overview-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.q-overview-filters select { width: auto; flex: 1 1 170px; }
.q-overview-filters button { flex: 0 0 auto; }

/* --- Format-Auswahl (Fragen anlegen) --- */
.segmented { display: flex; background: var(--bg-inset); border: 1px solid var(--border-strong); border-radius: var(--radius-pill); padding: 3px; gap: 2px; }
.segmented button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.segmented button.active { background: var(--bg-elevated); color: var(--text); box-shadow: 0 1px 2px var(--shadow); }

@media (min-width: 768px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}

@media (max-width: 480px) {
  .topbar { padding: 10px 14px; }
  .topbar .brand { font-size: 1.05rem; }
  .compare-options { flex-direction: column; }
}
