/* LehreGPT — „helle Werkstatt": macOS-Anmutung (Sonoma/Sequoia).
   Helle Grundfläche + Frosted-Glass-Leisten; die Bühne bleibt als dunkles
   „Fenster" erhalten (wie ein Video-Player in einer hellen App). */

:root {
  /* Grundflächen (hell) */
  --bg: #f5f5f7;
  --surface: #ffffff;
  --glass: rgba(255, 255, 255, 0.72);
  --glass-popover: rgba(255, 255, 255, 0.82);
  --hairline: rgba(0, 0, 0, 0.09);
  --hairline-strong: rgba(0, 0, 0, 0.14);

  /* Text */
  --text: #1d1d1f;
  --text-2: #6e6e73;

  /* dunkles Glas für Elemente AUF der Bühne (macOS-Widgets auf Wallpaper) */
  --glass-dark: rgba(20, 25, 40, 0.55);
  --glass-dark-line: rgba(255, 255, 255, 0.14);
  --text-on-dark: #ebeef5;
  --text-dim-dark: rgba(235, 238, 245, 0.65);

  /* Akzente (auf Hell-Kontrast getrimmt) */
  --daimler: #2f6298;
  --benz: #a35c2e;
  --gold: #b8860b;
  --gold-text: #8a6206;      /* gold, dunkel genug für kleinen Text auf Weiß */
  --ok: #1d8a4a;
  --ok-text: #136c39;
  --err: #c93434;

  /* helle Varianten der Marken für die DUNKLE Bühne */
  --daimler-bright: #4a7fb5;
  --benz-bright: #b5764a;
  --warm: #ffb868;

  /* Geometrie & Schatten */
  --r-btn: 10px;
  --r-card: 14px;
  --r-pop: 16px;
  --shadow-bar: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.14);
  --focus-ring: 0 0 0 3px rgba(47, 98, 152, 0.28);
  --focus-ring-gold: 0 0 0 3px rgba(184, 134, 11, 0.28);

  --blur-glass: blur(20px) saturate(1.6);

  /* Systemschriften: modern, sofort da, keine Netz-Abhängigkeit */
  --font-display: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* hidden-Attribut gewinnt immer — auch gegen display:flex der Komponenten */
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* weiche Fokus-Ringe statt harter Outlines (macOS-typisch) */
:where(button, input, textarea, select):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ── Bühne: bleibt dunkel — das stimmungsvolle Fenster der hellen App ── */

#stage-section {
  position: relative;
  height: 45%;
  min-height: 220px;
  flex: 0 0 auto;
  overflow: hidden;
  background:
    radial-gradient(120% 95% at 50% 105%, rgba(255, 165, 80, 0.17), transparent 62%),
    radial-gradient(60% 50% at 25% 100%, rgba(74, 127, 181, 0.12), transparent 70%),
    linear-gradient(180deg, #080d1c 0%, #0d1326 65%, #15203c 100%);
  border-bottom: 1px solid rgba(0, 0, 0, 0.18); /* saubere Haarlinie zur hellen Fläche */
}

#stage-host {
  position: absolute;
  inset: 0;
}

#stage-host canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.stage-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 20px;
  pointer-events: none;
  z-index: 5;
}

.overlay-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.app-title {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(100deg, #f6e8c8, #e8b563);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.55));
}

.app-subtitle {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  font-style: normal;
  letter-spacing: 0.02em;
  color: var(--text-dim-dark);
  background: none;
  -webkit-background-clip: initial;
  background-clip: initial;
  -webkit-text-fill-color: var(--text-dim-dark);
}

/* Status-Pille — dunkles Frosted Glass auf der Bühne */

.status-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim-dark);
  background: var(--glass-dark);
  border: 1px solid var(--glass-dark-line);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ffd60a;
  flex: 0 0 auto;
}

.status-pill[data-state="ok"] .status-dot { background: #30d158; }
.status-pill[data-state="warn"] .status-dot { background: #ffd60a; }
.status-pill[data-state="err"] .status-dot { background: #ff453a; }
.status-pill[data-state="connecting"] .status-dot {
  background: #ffd60a;
  animation: pulse-dot 1.2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── HUD (Rang, XP, Streak, Abzeichen) — dunkles Glas auf der Bühne ── */

.overlay-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: auto;
}

.hud {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 230px;
  max-width: 300px;
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--glass-dark);
  border: 1px solid var(--glass-dark-line);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hud-rank {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 600;
  color: #f3e9d4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-streak {
  font-size: 12.5px;
  color: var(--warm);
  flex: 0 0 auto;
  cursor: default;
}

#logout-btn {
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-dark-line);
  color: var(--text-dim-dark);
  border-radius: 8px;
  padding: 2px 8px;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

#logout-btn:hover {
  color: var(--text-on-dark);
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.3);
}

.hud-xpbar {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.hud-xp-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #c89a2e, #e8bc55);
  transition: width 0.6s ease;
}

.hud-xp-label {
  font-size: 11px;
  color: var(--text-dim-dark);
}

.hud-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.badge-chip {
  font-size: 14px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 8px;
  background: rgba(217, 164, 65, 0.16);
  border: 1px solid rgba(217, 164, 65, 0.4);
  cursor: default;
}

/* ── Themen-/Skripte-Knöpfe auf der Bühne — dunkles Glas ───────────── */

.doc-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  pointer-events: auto;
}

.topics-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 13px;
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  color: #ecd9ab;
  background: var(--glass-dark);
  border: 1px solid rgba(217, 164, 65, 0.4);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.topics-btn:hover {
  background: rgba(217, 164, 65, 0.18);
  border-color: rgba(217, 164, 65, 0.65);
}

.topics-btn:focus-visible { box-shadow: var(--focus-ring-gold); }

.topics-btn.has-error { border-color: rgba(255, 105, 97, 0.7); }

/* ── 2D-Portrait-Fallback (FR-5.5) — liegt auf der dunklen Bühne ──── */

.portrait-bar {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 48px;
  padding-top: 30px;
}

.portrait-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 26px;
  border-radius: var(--r-card);
  background: var(--glass-dark);
  border: 1px solid var(--glass-dark-line);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  transition: border-color 0.3s, opacity 0.3s;
}

.portrait-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  color: #fff;
}

.portrait-card.daimler .portrait-avatar { background: var(--daimler-bright); }
.portrait-card.benz .portrait-avatar { background: var(--benz-bright); }

.portrait-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-on-dark);
}
.portrait-role { font-size: 12px; color: var(--text-dim-dark); }
.portrait-status {
  font-size: 11.5px;
  color: var(--warm);
  min-height: 15px;
  font-style: italic;
}

.portrait-card[data-state="speaking"] { border-color: var(--warm); }
.portrait-card[data-state="speaking"] .portrait-avatar {
  animation: speak-pulse 1.1s ease-in-out infinite;
}
.portrait-card[data-state="listening"] { opacity: 0.7; }
.portrait-card[data-state="thinking"] .portrait-avatar {
  animation: pulse-dot 1.6s ease-in-out infinite;
}

@keyframes speak-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 184, 104, 0.55); }
  50% { box-shadow: 0 0 0 12px rgba(255, 184, 104, 0); }
}

/* ── Chat-Panel: helle Grundfläche ─────────────────────────────────── */

#chat-section {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px clamp(16px, 6vw, 90px);
  display: flex;
  flex-direction: column;
  /* kein scroll-behavior: smooth — die Animation läuft dem
     Per-Delta-Stick-to-Bottom-Check davon und bricht den Autoscroll */
}

.messages::-webkit-scrollbar { width: 9px; }
.messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
.messages::-webkit-scrollbar-track { background: transparent; }

/* ── Bubbles ───────────────────────────────────────────────────────── */

.msg {
  display: flex;
  gap: 10px;
  margin: 7px 0;
  max-width: 76%;
  align-items: flex-start;
}

.avatar {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  margin-top: 2px;
  box-shadow: var(--shadow-bar);
}

.bubble {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  padding: 10px 14px;
  line-height: 1.55;
  min-width: 0;
  box-shadow: var(--shadow-bar);
}

.segment-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.speaker-name {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 3px;
}

/* Daimler links, Benz rechts — weiße Bubbles mit Akzent-Haarlinie */

.msg.daimler { align-self: flex-start; }
.msg.daimler .avatar { background: var(--daimler); }
.msg.daimler .bubble {
  border-left: 3px solid var(--daimler);
  border-top-left-radius: 4px;
}
.msg.daimler .speaker-name { color: var(--daimler); }

.msg.benz {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.msg.benz .avatar { background: var(--benz); }
.msg.benz .bubble {
  border-right: 3px solid var(--benz);
  border-top-right-radius: 4px;
}
.msg.benz .speaker-name { color: var(--benz); }

/* FRAGE-Segment: hervorgehobene Karte mit Gold-Akzent */

.msg.frage .bubble {
  border: 1px solid rgba(184, 134, 11, 0.45);
  background: linear-gradient(180deg, rgba(184, 134, 11, 0.07), rgba(255, 255, 255, 0.97));
  box-shadow: 0 2px 10px rgba(184, 134, 11, 0.10);
}
.msg.frage.side-daimler { align-self: flex-start; margin-left: 44px; }
.msg.frage.side-benz { align-self: flex-end; margin-right: 44px; }
.msg.frage.side-daimler .bubble { border-left: 3px solid var(--daimler); }
.msg.frage.side-benz .bubble { border-right: 3px solid var(--benz); }

.frage-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--gold-text);
  margin-bottom: 5px;
}

/* Nutzer-Bubble: blau gefüllt, weiße Schrift */

.msg.user { align-self: flex-end; }
.msg.user .bubble {
  background: linear-gradient(180deg, #38709f, var(--daimler));
  border: none;
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 3px rgba(47, 98, 152, 0.3);
}

/* System-Notizen + Fehler */

.msg.system {
  align-self: center;
  max-width: 85%;
  font-size: 12.5px;
  color: var(--text-2);
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 5px 14px;
  text-align: center;
}

.msg.system.error {
  color: #a12c2c;
  background: rgba(201, 52, 52, 0.07);
  border-color: rgba(201, 52, 52, 0.35);
}

/* Tipp-Indikator */

.msg.typing { align-self: flex-start; }
.msg.typing .bubble {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 13px 16px;
}
.msg.typing .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #aeaeb2;
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.msg.typing .dot:nth-child(2) { animation-delay: 0.18s; }
.msg.typing .dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Quellen-Panel am Turn-Ende ────────────────────────────────────── */

.msg.sources-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 2px 0 10px 46px;
  max-width: 90%;
  font-size: 0.8rem;
}

.sources-label {
  color: var(--text-2);
  letter-spacing: 0.02em;
}

.source-chip {
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--text-2);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-family: var(--font-sans);
  cursor: pointer;
  box-shadow: var(--shadow-bar);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.source-chip:hover {
  background: rgba(47, 98, 152, 0.06);
  border-color: rgba(47, 98, 152, 0.45);
  color: var(--daimler);
}

/* ── Abbildungen aus den Skripten (FR-2.6) ─────────────────────────── */

.msg.figure-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 12px 46px;
  max-width: 90%;
}

.figure-row-label {
  flex: 0 0 100%;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 2px;
}

.figure-thumb-btn {
  position: relative;
  padding: 0;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-btn);
  background: #fff;
  cursor: zoom-in;
  overflow: hidden;
  box-shadow: var(--shadow-bar);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.figure-thumb-btn:hover {
  transform: scale(1.03);
  border-color: rgba(47, 98, 152, 0.5);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.10);
}

.figure-thumb {
  display: block;
  max-height: 120px;
  max-width: 220px;
  object-fit: contain;
}

.figure-page-tag {
  position: absolute;
  right: 5px;
  bottom: 5px;
  font-size: 10.5px;
  font-weight: 700;
  color: #fff;
  background: rgba(20, 25, 40, 0.78);
  border-radius: 6px;
  padding: 1px 6px;
  pointer-events: none;
}

/* Lightbox bleibt dunkel (Bild-Viewer) */

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(10, 12, 20, 0.86);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: zoom-out;
  padding: 4vh 4vw;
}

#lightbox img {
  max-width: 92vw;
  max-height: 84vh;
  border-radius: var(--r-btn);
  background: #fff;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6);
}

.lightbox-caption {
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.9rem;
}

/* ── Zitat-Badges ──────────────────────────────────────────────────── */

.cite-badge {
  display: inline-block;
  font: 600 11px/1.4 var(--font-sans);
  padding: 0 7px;
  margin: 0 2px;
  border-radius: 999px;
  color: #275a8e;
  background: rgba(47, 98, 152, 0.10);
  border: 1px solid rgba(47, 98, 152, 0.35);
  cursor: pointer;
  vertical-align: baseline;
  transition: background 0.15s;
}
.cite-badge:hover { background: rgba(47, 98, 152, 0.20); }

/* ── Quellen-Popover: helles schwebendes Panel ─────────────────────── */

#source-popover {
  position: fixed;
  z-index: 100;
  max-width: 300px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--glass-popover);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-pop);
  font-size: 13px;
  color: var(--text);
}
#source-popover .popover-title {
  font-weight: 600;
  margin-bottom: 3px;
  word-break: break-all;
}
#source-popover .popover-line { color: var(--text-2); }

/* ── Modusleiste: macOS-Segmented-Control ──────────────────────────── */

.mode-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px clamp(16px, 6vw, 90px) 0;
  border-top: 1px solid var(--hairline);
  background: var(--glass);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
}

.mode-group {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-btn);
  background: rgba(0, 0, 0, 0.05);
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  border: none;
  background: transparent;
  color: var(--text-2);
  border-radius: 8px;
  padding: 5px 14px 6px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
  white-space: nowrap;
  text-align: left;
}

.mode-btn .mode-name { font-size: 13px; font-weight: 600; }
.mode-btn .mode-desc { font-size: 11px; font-weight: 500; opacity: 0.85; }

.mode-btn:hover { color: var(--text); }

.mode-btn.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
}

.mode-btn.active:focus-visible {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), var(--focus-ring);
}

/* dezenter „antwortet…"-Indikator — Eingabe bleibt trotzdem frei */
.turn-indicator {
  display: none;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  margin-left: auto;
}

body.turn-running .turn-indicator { display: inline; }

.turn-indicator .ti-dots {
  display: inline-block;
  animation: ti-pulse 1.2s ease-in-out infinite;
}

@keyframes ti-pulse {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

.duell-status {
  font-size: 13px;
  font-weight: 600;
  color: var(--gold-text);
  white-space: nowrap;
}

.hint-btn {
  border: 1px solid rgba(184, 134, 11, 0.5);
  background: transparent;
  color: var(--gold-text);
  border-radius: 999px;
  padding: 6px 14px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.2s;
  white-space: nowrap;
}

.hint-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.hint-btn:not(:disabled):hover {
  background: rgba(184, 134, 11, 0.08);
  border-color: rgba(184, 134, 11, 0.75);
}
.hint-btn:focus-visible { box-shadow: var(--focus-ring-gold); }

/* ── Eingabezeile ──────────────────────────────────────────────────── */

.input-row {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 8px clamp(16px, 6vw, 90px) 16px;
  background: var(--glass);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
}

#chat-input {
  flex: 1 1 auto;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  padding: 11px 15px;
  border-radius: var(--r-btn);
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  outline: none;
  box-shadow: var(--shadow-bar);
  transition: border-color 0.15s, box-shadow 0.15s, opacity 0.2s;
}

#chat-input:focus {
  border-color: rgba(47, 98, 152, 0.55);
  box-shadow: var(--focus-ring);
}
#chat-input:disabled { opacity: 0.45; cursor: not-allowed; }
#chat-input::placeholder { color: var(--text-2); opacity: 0.9; }

.input-row button {
  flex: 0 0 auto;
  height: 44px;
  padding: 0 18px;
  border-radius: var(--r-btn);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, opacity 0.2s;
  white-space: nowrap;
}

.input-row button:disabled { opacity: 0.45; cursor: not-allowed; }
.input-row button:not(:disabled):hover { filter: brightness(1.08); }

#send-btn {
  background: linear-gradient(180deg, #3a73a8, var(--daimler));
  color: #fff;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(47, 98, 152, 0.35);
}

#send-btn:focus-visible {
  box-shadow: 0 1px 3px rgba(47, 98, 152, 0.35), var(--focus-ring);
}

/* ── Schwebende Popover ÜBER allem: Themenkarte & Skripte — HELL ───── */

.topic-panel {
  position: fixed;
  z-index: 150;
  top: 104px;
  left: 50%;
  transform: translateX(-50%);
  width: min(960px, 94vw);
  max-height: min(64vh, 560px);
  overflow-y: auto;
  padding: 16px 18px 20px;
  border-radius: var(--r-pop);
  background: var(--glass-popover);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-pop);
  color: var(--text);
}

.topic-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.topic-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.topic-close {
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 17px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.topic-close:hover { color: var(--text); background: rgba(0, 0, 0, 0.05); }

.topic-empty {
  font-size: 13px;
  font-style: italic;
  color: var(--text-2);
  padding: 8px 0 4px;
}

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

.topic-group {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 10px 12px;
}

.topic-group-title {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 8px;
}

.topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.topic-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px 4px 5px;
  border-radius: 999px;
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 12.5px;
  cursor: pointer;
  box-shadow: var(--shadow-bar);
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
}

.topic-chip:hover {
  border-color: rgba(184, 134, 11, 0.55);
  background: rgba(184, 134, 11, 0.06);
}
.topic-chip:focus-visible { box-shadow: var(--focus-ring-gold); }

/* Fortschrittsringe: Spur dezent, Füllung Gold */

.topic-ring {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.topic-ring .ring-bg {
  fill: none;
  stroke: rgba(0, 0, 0, 0.1);
  stroke-width: 4;
}

.topic-ring .ring-fg {
  fill: none;
  stroke: var(--gold);
  stroke-width: 4;
  stroke-linecap: round;
}

/* Skripte-Panel (gleiches helles Popover, schmaler) */

.docs-panel {
  max-width: 460px;
}

.panel-head {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 10px;
}

.docs-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--hairline);
  font-size: 13px;
}

.docs-row:last-child { border-bottom: none; }

.docs-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.docs-meta {
  flex: 0 0 auto;
  color: var(--text-2);
  font-size: 12px;
}

.docs-row[data-status="error"] .docs-meta { color: var(--err); }
.docs-empty { color: var(--text-2); font-size: 13px; padding: 6px 2px; }

.chip-icon { flex: 0 0 auto; }
.docs-row[data-status="indexed"] .chip-icon { color: var(--ok); }
.docs-row[data-status="error"] .chip-icon { color: var(--err); }
.docs-row[data-status="processing"] .chip-icon {
  color: var(--gold);
  display: inline-block;
  animation: spin 1.4s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ── Widget-Karten im Nachrichtenfluss (v2) ────────────────────────── */

.msg.widget-row {
  display: block;
  align-self: flex-start;
  width: 100%;
  max-width: 620px;
  margin: 8px 0 10px 46px;
}

.widget-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  padding: 14px 16px;
  box-shadow: var(--shadow-bar);
}

.widget-card.widget-error {
  border-color: rgba(201, 52, 52, 0.4);
  background: rgba(201, 52, 52, 0.04);
}

.widget-kind {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 6px;
}

.widget-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.45;
  margin-bottom: 10px;
}

.widget-text {
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 10px;
}

/* Antwort-Optionen (quiz + zuordnen) */

.widget-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.widget-option {
  position: relative;
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 34px 8px 12px;
  border-radius: var(--r-btn);
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.widget-option:not(:disabled):hover {
  border-color: rgba(47, 98, 152, 0.45);
  background: rgba(47, 98, 152, 0.04);
}

.widget-option.selected {
  border-color: var(--daimler);
  background: rgba(47, 98, 152, 0.10);
  box-shadow: inset 0 0 0 1px var(--daimler);
}

.widget-option.correct {
  border-color: var(--ok);
  background: rgba(29, 138, 74, 0.10);
  box-shadow: inset 0 0 0 1px var(--ok);
}

.widget-option.wrong {
  border-color: var(--err);
  background: rgba(201, 52, 52, 0.08);
  box-shadow: inset 0 0 0 1px var(--err);
}

.widget-option:disabled { cursor: default; opacity: 0.6; }
.widget-option.selected:disabled,
.widget-option.correct:disabled,
.widget-option.wrong:disabled { opacity: 1; }

.widget-card.submitted .widget-option { cursor: default; }

/* Bestätigen-Knopf */

.widget-submit {
  display: inline-block;
  margin-top: 2px;
  padding: 7px 18px;
  border: none;
  border-radius: var(--r-btn);
  background: linear-gradient(180deg, #3a73a8, var(--daimler));
  color: #fff;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(47, 98, 152, 0.3);
  transition: filter 0.15s, opacity 0.2s;
}

.widget-submit:not(:disabled):hover { filter: brightness(1.08); }
.widget-submit:disabled { opacity: 0.45; cursor: not-allowed; }
.widget-submit:focus-visible {
  box-shadow: 0 1px 3px rgba(47, 98, 152, 0.3), var(--focus-ring);
}

/* Schieberegler (schaetzen + schieber) */

.widget-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}

.widget-slider-name {
  flex: 0 0 auto;
  min-width: 56px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.widget-slider-row input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  accent-color: var(--daimler);
}

.widget-slider-row input[type="range"].correct { accent-color: var(--ok); }
.widget-slider-row input[type="range"].wrong { accent-color: var(--err); }

.widget-slider-value {
  flex: 0 0 auto;
  min-width: 76px;
  text-align: right;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--daimler);
}

/* Toleranzband-Skala (schaetzen) + Verlaufsgraph (schieber) */

.widget-scale { margin: 4px 0 8px; }

.widget-graph {
  display: block;
  width: 100%;
  max-width: 360px;
  height: auto;
  margin: 8px 0;
  border-radius: var(--r-btn);
  background: rgba(0, 0, 0, 0.03);
}

/* JS setzt Präsentationsattribute für die dunkle Bühne —
   CSS gewinnt gegen Attribute und tönt die Grafik für helle Karten um. */
.widget-graph .graph-axis { stroke: rgba(0, 0, 0, 0.28); }
.widget-graph .graph-label { fill: var(--text-2); }
.widget-graph .graph-line { stroke: var(--benz); }
.widget-graph .graph-target { stroke: var(--ok); }
.widget-graph .graph-band { fill: rgba(29, 138, 74, 0.16); }
.widget-graph .graph-guess { stroke: #ffffff; }
.widget-graph .graph-point { fill: var(--ok); stroke: #ffffff; }

.widget-result {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--daimler);
  margin: 6px 0;
}

/* Zuordnen: zwei Spalten + nummerierte Paar-Chips */

.widget-pairs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.widget-pair-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.widget-pair {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  /* Hintergrundfarbe setzt JS pro Paar */
}

/* Lückentext */

.widget-gaptext {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 2.1;
  color: var(--text);
}

.widget-gap {
  display: inline-block;
  margin: 0 3px;
  padding: 4px 9px;
  border-radius: 8px;
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.widget-gap:focus {
  border-color: rgba(47, 98, 152, 0.55);
  box-shadow: var(--focus-ring);
}

.widget-gap.correct {
  border-color: var(--ok);
  background: rgba(29, 138, 74, 0.08);
}

.widget-gap.wrong {
  border-color: var(--err);
  background: rgba(201, 52, 52, 0.07);
}

/* Auswertung / Erklärung */

.widget-feedback {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--r-btn);
  border: 1px solid var(--hairline);
  background: rgba(0, 0, 0, 0.03);
  font-size: 13px;
  line-height: 1.5;
}

.widget-feedback.ok {
  border-color: rgba(29, 138, 74, 0.35);
  background: rgba(29, 138, 74, 0.07);
}

.widget-feedback.bad {
  border-color: rgba(201, 52, 52, 0.35);
  background: rgba(201, 52, 52, 0.05);
}

.widget-feedback-head {
  font-weight: 700;
  margin-bottom: 3px;
}

.widget-feedback.ok .widget-feedback-head { color: var(--ok-text); }
.widget-feedback.bad .widget-feedback-head { color: #a12c2c; }

.widget-feedback-text {
  color: var(--text);
  margin-bottom: 3px;
}

.widget-feedback-line {
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

/* ── XP-Flug, Level-Up, Konfetti (v2) ──────────────────────────────── */

.xp-fly {
  position: fixed;
  z-index: 260;
  pointer-events: none;
  font-weight: 800;
  font-size: 15px;
  color: var(--gold-text);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8), 0 2px 8px rgba(255, 255, 255, 0.6);
  opacity: 1;
  transform: translate(0, 0) scale(1);
  transition: transform 0.85s cubic-bezier(0.45, -0.05, 0.7, 0.4),
    opacity 0.85s ease-in;
}

.xp-fly.xp-neg { color: var(--err); }

.msg.levelup {
  align-self: center;
  width: 100%;
  max-width: 520px;
}

.levelup-card {
  width: 100%;
  text-align: center;
  padding: 18px 22px;
  border-radius: var(--r-card);
  border: 1px solid rgba(184, 134, 11, 0.5);
  background: linear-gradient(180deg, rgba(184, 134, 11, 0.10), rgba(255, 255, 255, 0.95));
  box-shadow: 0 4px 18px rgba(184, 134, 11, 0.18);
}

.levelup-head {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--gold-text);
}

.levelup-sub {
  font-size: 12.5px;
  color: var(--text-2);
  margin-top: 4px;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 255;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -24px;
  border-radius: 2px;
  opacity: 0;
  animation: confetti-fall 2.2s ease-in forwards;
}

@keyframes confetti-fall {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  85% { opacity: 1; }
  100% {
    transform: translate(var(--drift, 0px), 108vh) rotate(var(--rot, 540deg));
    opacity: 0;
  }
}

/* ── Onboarding-Karte ──────────────────────────────────────────────── */

.msg.onboarding { max-width: 620px; }

.onboarding-card {
  width: 100%;
  border: 1px solid rgba(184, 134, 11, 0.35);
  border-radius: var(--r-card);
  background: linear-gradient(160deg, rgba(184, 134, 11, 0.06), rgba(255, 255, 255, 0.95));
  padding: 16px 18px;
  box-shadow: var(--shadow-bar);
}

.onboarding-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}

.onboarding-point {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 13.5px;
  color: var(--text);
  margin-bottom: 7px;
  line-height: 1.5;
}

.onboarding-icon { flex: 0 0 52px; text-align: center; }

.onboarding-ok {
  margin-top: 8px;
  border: none;
  border-radius: var(--r-btn);
  background: linear-gradient(135deg, #e2b258, #c08b2d);
  color: #271c06;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 700;
  padding: 8px 16px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(184, 134, 11, 0.3);
}

.onboarding-ok:hover { filter: brightness(1.05); }
.onboarding-ok:focus-visible {
  box-shadow: 0 1px 3px rgba(184, 134, 11, 0.3), var(--focus-ring-gold);
}

/* ── Login-Overlay: weiße Karte auf abgedunkeltem Hintergrund-Blur ── */

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(28, 30, 38, 0.38);
  backdrop-filter: blur(22px) saturate(1.4);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
}

.auth-card {
  width: min(420px, 94vw);
  padding: 28px 30px 26px;
  border-radius: var(--r-pop);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  border: 1px solid var(--hairline);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
  color: var(--text);
}

.auth-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  text-align: center;
}

.auth-sub {
  margin: 6px 0 18px;
  text-align: center;
  font-size: 13px;
  color: var(--text-2);
}

/* Tabs als macOS-Segmented-Control */

.auth-tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-btn);
  background: rgba(0, 0, 0, 0.05);
  margin-bottom: 18px;
}

.auth-tab {
  flex: 1 1 0;
  padding: 8px 0;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.auth-tab:hover { color: var(--text); }

.auth-tab.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
}

.auth-tab.active:focus-visible {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), var(--focus-ring);
}

.auth-label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 12px;
}

.auth-label input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px 13px;
  border-radius: var(--r-btn);
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-label input:focus {
  border-color: rgba(47, 98, 152, 0.55);
  box-shadow: var(--focus-ring);
}

.auth-hint {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-2);
}

.auth-error {
  min-height: 18px;
  margin: 2px 0 10px;
  font-size: 12.5px;
  color: #a12c2c;
}

.auth-submit {
  width: 100%;
  height: 44px;
  border: none;
  border-radius: var(--r-btn);
  background: linear-gradient(180deg, #3a73a8, var(--daimler));
  color: #fff;
  font-family: var(--font-sans);
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(47, 98, 152, 0.35);
  transition: filter 0.15s, opacity 0.2s;
}

.auth-submit:not(:disabled):hover { filter: brightness(1.08); }
.auth-submit:disabled { opacity: 0.5; cursor: wait; }
.auth-submit:focus-visible {
  box-shadow: 0 1px 3px rgba(47, 98, 152, 0.35), var(--focus-ring);
}

/* ── Responsive ────────────────────────────────────────────────────── */

@media (max-width: 1023px) {
  #stage-section { height: 30%; min-height: 170px; }
  .app-title { font-size: 19px; }
  .app-subtitle { display: block; font-size: 12.5px; }
  .msg { max-width: 92%; }
  .doc-row { max-width: 100%; }
  .messages, .input-row, .mode-row { padding-left: 12px; padding-right: 12px; }
  .portrait-bar { gap: 20px; padding-top: 16px; }
  .portrait-card { padding: 10px 16px; }
  .portrait-avatar { width: 44px; height: 44px; font-size: 21px; }
  .hud { min-width: 190px; max-width: 240px; padding: 7px 10px; }
  .hud-rank { font-size: 12.5px; }
  .topic-panel { top: 70px; max-height: 72vh; }
  .msg.widget-row { margin-left: 0; max-width: 100%; }
  .msg.levelup { max-width: 92%; }
  .mode-btn, .hint-btn { padding: 5px 10px; font-size: 12px; }
  .widget-pairs { grid-template-columns: 1fr; }
}
