:root {
  --bg: #0d1117;
  --tile: #161c25;
  --tile-hover: #1d2531;
  --line: #2a3340;
  --text: #f2f4f7;
  --muted: #9ba7b5;
  --accent: #f0a63a;
  --accent-ink: #1a1206;
  --ok: #3fb27f;
  --warn: #ef6a5f;
  --ai: #8ab4ff;
  --radius: 20px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 18px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

[hidden] { display: none !important; }

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 0.35em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  font: inherit;
  font-size: 0.85em;
  text-align: center;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--tile-hover); }
.btn:focus-visible, .tile:focus-visible, .seg button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.icon { padding: 0; width: 42px; font-size: 1.2rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #04130c; }
.btn.danger { color: var(--warn); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.big { min-height: 56px; padding: 0 24px; font-size: 1.1rem; border-radius: 14px; }

.pill.on { border-color: color-mix(in srgb, var(--ok) 60%, transparent); color: var(--ok); }
.pill.off { border-color: color-mix(in srgb, var(--warn) 60%, transparent); color: var(--warn); }
.pill::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; }

.count:not(:empty) {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--line);
  font-size: 0.85rem;
}
.count.alert { background: var(--warn); color: #fff; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button {
  min-width: 42px;
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--line); color: var(--text); }

/* ---------- Layout ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

.bar-title { flex: 1; display: flex; align-items: center; gap: 14px; min-width: 0; }
.bar-title h1 { margin: 0; font-size: 1.3rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats { flex: none; color: var(--muted); font-size: 1.15rem; font-weight: 600; white-space: nowrap; }
.bar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--warn); }
.dot.live { background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 2.4s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 70%, transparent); }
  70% { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 2), minmax(0, 1fr));
  gap: 20px;
  padding: 20px;
}

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
  padding: 0 20px 12px;
  color: var(--muted);
  font-size: 0.85rem;
}
.pager { display: flex; align-items: center; gap: 12px; font-size: 1rem; color: var(--text); }
.keys { margin-left: auto; }

/* ---------- Kacheln ---------- */
.tile {
  container-type: size;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: clamp(14px, 2.2vw, 28px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--tile);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.tile:hover { background: var(--tile-hover); border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.tile.enter { animation: enter 0.6s ease-out; }
.tile.enter::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 2px solid var(--accent);
  border-radius: inherit;
  animation: glow 4s ease-out forwards;
  pointer-events: none;
}
@keyframes enter { from { opacity: 0; transform: translateY(16px) scale(0.98); } }
@keyframes glow { from { opacity: 1; } to { opacity: 0; } }

.tile-head { display: flex; align-items: center; gap: 10px; margin-bottom: 0.6em; }
.target {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--line);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 45%;
}
.tile-head .grow { flex: 1; }
.target.all { background: transparent; border: 1px solid var(--line); color: var(--muted); }
/* Schnelles Löschen direkt auf der Kachel: erster Klick fragt, zweiter löscht */
.tile-del {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}
.tile-del:hover { color: var(--warn); border-color: var(--warn); }
.tile-del.confirm { background: var(--warn); border-color: var(--warn); color: #fff; }
.tile-del:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
/* Ansicht-Dropdown ersetzt den Titel: groß und so breit wie der freie Platz */
.view-select {
  flex: 1 1 auto;
  min-width: 12rem;
  min-height: 52px;
  padding: 0 52px 0 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--tile) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f0a63a' stroke-width='2.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 16px center / 26px;
  color: var(--text);
  font: inherit;
  font-size: 1.5rem; /* wird per JS verkleinert, wenn ein langer Name sonst nicht passt */
  font-weight: 700;
  text-overflow: ellipsis;
  appearance: none;
  cursor: pointer;
}
.view-select:hover { background-color: var(--tile-hover); }
.view-select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.view-select option { background: var(--bg); color: var(--text); font-size: 1.1rem; font-weight: 600; }
.speakers-help { color: var(--muted); font-size: 0.95rem; margin: 12px 0 16px; }
.speaker-rows { display: grid; gap: 10px; }
.speaker-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--tile); }
.speaker-row input, .speaker-add input {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: inherit;
  font: inherit;
}
.speaker-link { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.speaker-link a { color: var(--accent); }
.speaker-add { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 14px; }
.speaker-save { margin-top: 18px; display: flex; justify-content: flex-end; }
.badge {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--line);
  font-weight: 800;
}
.topic {
  flex-shrink: 1;
  padding: 3px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ai) 16%, transparent);
  color: var(--ai);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}

.q {
  flex: 1;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  font-weight: 650;
  line-height: 1.22;
  white-space: pre-line;
  /* Startwert; presenter.js passt die Größe danach exakt an die Kachel an. */
  font-size: clamp(1rem, min(6cqi, 9cqb), 3rem);
}
.tile.checking .q { filter: blur(12px); opacity: 0.5; }
.q.clipped {
  -webkit-mask-image: linear-gradient(to bottom, #000 70%, transparent);
  mask-image: linear-gradient(to bottom, #000 70%, transparent);
}

.tile-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 0.7em;
  color: var(--muted);
  font-size: clamp(0.85rem, 3.2cqi, 1.15rem);
  white-space: nowrap;
}
.who { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.who.anon { color: var(--muted); font-style: italic; font-weight: 400; }
.ai-chip { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.ai-chip.done { color: var(--ai); }
.ai-chip.error { color: var(--warn); }
.ai-chip.flag { color: var(--accent); }
.more-hint { color: var(--accent); font-weight: 600; }

.spinner {
  width: 0.9em;
  height: 0.9em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Leerer Zustand ---------- */
.empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.empty p { margin: 0; color: var(--muted); font-size: 1rem; }

/* ---------- Detailansicht ---------- */
dialog { color: inherit; }
dialog::backdrop { background: rgb(3 6 10 / 0.75); backdrop-filter: blur(3px); }

.detail {
  width: min(1500px, 96vw);
  max-width: none;
  height: min(920px, 94dvh);
  max-height: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--bg);
}
.detail[open] { display: flex; flex-direction: column; animation: enter 0.2s ease-out; }

.detail-top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 1.1rem;
}
.detail-top .who { font-size: 1.25rem; }
.detail-top .spacer { flex: 1; }

.detail-main {
  flex: 1;
  min-height: 0;
  display: grid;
  /* Die KI-Hilfe bekommt den meisten Platz: Sie muss aus Abstand lesbar sein. */
  grid-template-columns: minmax(0, 0.72fr) minmax(0, 1.5fr);
  grid-template-rows: minmax(0, 1fr);
}

.detail-question {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  padding: clamp(20px, 3vw, 44px);
  overflow: auto;
}
.detail-summary {
  margin: 0;
  color: var(--accent);
  font-size: clamp(1rem, 1.5vw, 1.4rem);
  font-weight: 700;
}
.detail-q-text {
  flex: 1;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  font-size: clamp(1.1rem, 1.6vw, 1.8rem);
  font-weight: 600;
  line-height: 1.3;
  white-space: pre-line;
}
.detail-q-text.clipped { overflow: auto; }

.ai-panel {
  display: flex;
  flex-direction: column;
  gap: 0.9em;
  padding: clamp(18px, 2.4vw, 36px);
  overflow: auto;
  border-left: 1px solid var(--line);
  background: color-mix(in srgb, var(--ai) 5%, var(--bg));
  /* Grundgröße setzt presenter.js so groß wie möglich (alles in em skaliert mit). */
  font-size: 22px;
}
.ai-panel h2 { margin: 0; color: var(--ai); font-size: 0.7em; letter-spacing: 0.08em; text-transform: uppercase; }
.ai-panel h3 { margin: 0 0 0.4em; color: var(--muted); font-size: 0.62em; letter-spacing: 0.06em; text-transform: uppercase; }

.keywords { display: flex; flex-wrap: wrap; gap: 0.35em; margin: 0; padding: 0; list-style: none; }
.keywords li {
  padding: 0.25em 0.7em;
  border: 1px solid color-mix(in srgb, var(--ai) 40%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--ai) 12%, transparent);
  font-size: 1em;
  font-weight: 650;
}
.ai-hint { margin: 0; font-size: 1.45em; font-weight: 700; line-height: 1.3; }
.points { margin: 0; padding-left: 1.3em; font-size: 1.05em; line-height: 1.4; }
.points li + li { margin-top: 0.35em; }
.example, .caution { margin: 0.45em 0 0; font-size: 0.95em; line-height: 1.4; }
.example { font-style: italic; }
.caution { color: var(--accent); }
.ai-wait { display: flex; align-items: center; gap: 10px; margin: 0; color: var(--muted); font-size: 1em; }
.ai-error { margin: 0; color: var(--warn); }
.flag-box {
  padding: 12px 16px;
  border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}
.flag-box p { margin: 0; }

.detail-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--line);
}
/* „Beantwortet“ und „Ausblenden“ teilen sich die Breite neben den Pfeilen */
.detail-actions .act-main { flex: 3; min-height: 64px; font-size: 1.25rem; }
.detail-actions .act-side { flex: 1; min-height: 64px; }
.detail-actions kbd { margin-left: 6px; border-color: currentColor; opacity: 0.7; }

/* ---------- Archiv ---------- */
.drawer {
  margin: 0 0 0 auto;
  width: min(640px, 100vw);
  max-width: none;
  height: 100dvh;
  max-height: none;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--bg);
}
.drawer[open] { display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0 auto 0 0; font-size: 1.3rem; }
.drawer-body { flex: 1; overflow: auto; padding: 8px 20px 24px; }
.drawer-body h3 { margin: 22px 0 10px; color: var(--muted); font-size: 0.85rem; letter-spacing: 0.06em; text-transform: uppercase; }
.drawer-body .none { color: var(--muted); margin: 0; }
.arch-item { padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--tile); }
.arch-item + .arch-item { margin-top: 10px; }
.arch-item strong { display: block; margin-bottom: 4px; color: var(--accent); }
.arch-item p { margin: 0 0 6px; overflow-wrap: anywhere; white-space: pre-line; }
.arch-meta { color: var(--muted); font-size: 0.85rem; }
.arch-reason { color: var(--accent); font-size: 0.9rem; }
.arch-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.arch-actions .btn { min-height: 36px; font-size: 0.85rem; }

/* ---------- QR-Dialog ---------- */
.qr-dialog {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--bg);
  text-align: center;
}
.qr-dialog img { width: min(70vh, 80vw); aspect-ratio: 1; background: #fff; padding: 16px; border-radius: 16px; }
.qr-url { margin: 16px 0; color: var(--accent); font-size: 1.4rem; font-weight: 700; word-break: break-all; }
.qr-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

/* ---------- Anmeldung & Toast ---------- */
.login { display: grid; place-items: center; height: 100dvh; padding: 16px; }
.login-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--tile);
}
.login-card h1 { margin: 0; }
.login-logo { display: block; align-self: flex-start; height: 44px; width: auto; margin-bottom: 4px; }
.login-back { color: var(--muted); font-size: 0.9rem; text-decoration: none; }
.login-back:hover { color: var(--text); }
.login-card p { margin: 0; color: var(--muted); }
.login-card input {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: inherit;
  font: inherit;
}
.login-error { color: var(--warn) !important; min-height: 1.4em; }

.toast.ok { background: var(--ok); color: #04130c; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--warn);
  color: #fff;
  font-weight: 600;
  z-index: 10;
}

@media (max-width: 1000px) {
  body { overflow: auto; }
  .detail-main { grid-template-columns: 1fr; grid-template-rows: none; overflow: auto; }
  .detail-question, .detail-q-text, .ai-panel { overflow: visible; height: auto; overflow-wrap: break-word; }
  .ai-panel { border-left: 0; border-top: 1px solid var(--line); }
  .keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
