:root {
  color-scheme: dark;
  --bg: #101318;
  --surface: #1b2029;
  --tile: #252b36;
  --btn: #343b48;
  --btn-hover: #414a5a;
  --fg: #e8ebf0;
  --muted: #9aa4b2;
  --accent: #7fb0ff;
  --accent-ink: #0b1524;
  --danger: #e5484d;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
svg { width: 22px; height: 22px; fill: currentColor; display: block; }

/* ---------- Buttons ---------- */
.ctl {
  position: relative; flex: none;
  width: 48px; height: 48px;
  border: 0; border-radius: 50%;
  background: var(--btn);
  display: grid; place-items: center;
  transition: background .15s;
}
.ctl:hover { background: var(--btn-hover); }
.ctl.off { background: var(--danger); }
.ctl.active { background: var(--accent); color: var(--accent-ink); }
.ctl.leave { width: 68px; border-radius: 24px; background: var(--danger); }
.ctl:disabled { opacity: .4; cursor: not-allowed; }

.primary, .ghost, .small {
  border: 0; border-radius: 999px;
  padding: 10px 22px; font-weight: 600;
  display: inline-block; text-align: center; text-decoration: none; white-space: nowrap;
}
.primary:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.primary.danger { background: var(--danger); color: #fff; }
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover { filter: brightness(1.08); }
.ghost { background: transparent; color: var(--accent); }
.ghost:hover { background: rgba(127, 176, 255, .12); }
.small { padding: 8px 14px; font-size: 13px; background: var(--btn); color: var(--fg); }
.small:hover { background: var(--btn-hover); }
.small.danger { background: var(--danger); }

.icon-btn {
  border: 0; background: transparent; border-radius: 50%;
  width: 36px; height: 36px; flex: none; display: grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { background: var(--btn); color: var(--fg); }
.icon-btn svg { width: 18px; height: 18px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 8px 14px;
  background: var(--surface); font-size: 14px; color: var(--fg); text-decoration: none;
}
button.pill:hover, a.pill:hover { background: var(--btn); }
.pill svg { width: 18px; height: 18px; }

/* ---------- Vorraum ---------- */
#lobby {
  height: 100%;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: 48px; padding: 24px; overflow: auto;
}
.lobby-preview {
  /* schrumpft neben dem Chat, statt die Angaben zum Raum unter die Vorschau zu drängen */
  position: relative; flex: 1 1 320px; max-width: 640px;
  /* Bild und Hinweis (.preview-ask) liegen in derselben Rasterzelle übereinander. Das Bild gibt 16:9 vor;
     braucht der Hinweis mehr Platz (langer Text auf einem schmalen Handy), wächst die Fläche mit,
     statt ihn oben abzuschneiden. */
  display: grid; grid-template-columns: minmax(0, 1fr);
  background: var(--tile); border-radius: var(--radius); overflow: hidden;
}
.lobby-preview video { grid-area: 1 / 1; width: 100%; height: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.lobby-preview video.mirror { transform: scaleX(-1); }
.preview-off {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: 16px; text-align: center; text-wrap: balance;
  background: var(--tile); color: var(--muted); font-size: 18px;
}
/* im Vorraum über den Knöpfen bleiben, auch wenn der Text auf dem Handy mehrere Zeilen braucht */
.lobby-preview .preview-off { padding-bottom: 76px; font-size: clamp(15px, 4.2vw, 18px); }
/* Hinweis über dem laufenden Bild (der Weichzeichner lädt noch, die Kamera ist schon zu sehen) */
.preview-off.over-video { background: rgba(0, 0, 0, .6); color: #fff; }
.tile-note { padding: 8px; font-size: 14px; }
.preview-controls {
  position: absolute; left: 0; right: 0; bottom: 14px;
  display: flex; justify-content: center; gap: 14px;
}
.lobby-form { width: min(320px, 100%); display: flex; flex-direction: column; gap: 16px; }
.lobby-form h1 { font-size: 26px; font-weight: 500; margin: 0 0 4px; }
input:not([type="range"]), textarea, select {
  background: var(--surface); border: 1px solid #353d4b; border-radius: 10px;
  padding: 11px 13px; color: var(--fg); width: 100%;
}
input:not([type="range"]):focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
::placeholder { color: #8f99a8; opacity: 1; }
/* Tastaturbedienung: deutlich zeigen, wo man gerade ist */
:is(button, a, summary):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Nur für Vorleseprogramme */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
/* Knopf, der wie ein Link im Text aussieht */
.link { border: 0; padding: 0; background: none; color: var(--accent); text-decoration: underline; font-size: inherit; }
/* Felder auf einer Fläche (Karte, Dialog, Chat) heben sich dunkler ab */
.auth-card input, .card input, .card select, dialog input, #chat input, #chat textarea { background: var(--bg); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 0; width: auto; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.error { color: #ff8a8e; margin: 0; }
.hint { margin: 0; font-size: 13px; color: var(--muted); min-height: 1.4em; }

/* ---------- Anruf ---------- */
/* minmax(0, …): der Inhalt darf das Raster nicht über das Fenster hinaus aufweiten */
#call { height: 100%; display: grid; grid-template: minmax(0, 1fr) auto / minmax(0, 1fr); }
#main { display: flex; gap: 12px; padding: 12px 12px 4px; min-height: 0; }

/* Teilnehmerkacheln: ohne Bühne ein zentriertes 16:9-Raster; --cols und --tile-w berechnet app.js */
#people {
  flex: 1; min-width: 0; min-height: 0;
  display: grid; gap: 12px; place-content: center;
  grid-template-columns: repeat(var(--cols, 1), var(--tile-w, 320px));
  grid-auto-rows: calc(var(--tile-w, 320px) * 9 / 16);
}
.tile {
  position: relative; overflow: hidden; min-height: 0;
  background: var(--tile); border-radius: var(--radius);
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.mirror video { transform: scaleX(-1); }
.tile.cam-off video { visibility: hidden; }
.avatar {
  position: absolute; inset: 0; margin: auto;
  width: min(34%, 120px); aspect-ratio: 1; border-radius: 50%;
  background: #4b6aa8; color: #fff; font-weight: 600; font-size: clamp(18px, 4vw, 44px);
  display: none; place-items: center;
}
.tile.cam-off .avatar { display: grid; }
.tile-name {
  position: absolute; left: 10px; bottom: 8px; max-width: calc(100% - 20px);
  display: flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 8px;
  background: rgba(0, 0, 0, .55); font-size: 13px;
}
.tile-name .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-name .mic-off { color: #ff8a8e; }
.tile-name svg { width: 15px; height: 15px; }

/* Bühne: Bildschirmfreigaben und YouTube, standardmäßig nebeneinander */
#stage { display: none; flex: 1; min-width: 0; min-height: 0; gap: 12px; }
#call.has-stage #stage {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
#call.has-stage #people {
  flex: 0 0 210px;
  display: flex; flex-direction: column; place-content: normal; overflow-y: auto;
}
#call.has-stage .tile { flex: 0 0 auto; aspect-ratio: 16 / 9; }

/* Fokus: ein Element groß, die übrigen klein daneben – alles bleibt sichtbar */
#call.has-stage #stage.focus {
  grid-auto-flow: row;
  grid-template-columns: minmax(0, 3.2fr) minmax(0, 1fr);
  grid-template-rows: repeat(var(--side-count, 1), minmax(0, 1fr));
}
#stage.focus .stage-item.focused { grid-column: 1; grid-row: 1 / -1; }
#stage.focus .stage-item:not(.focused) { grid-column: 2; align-self: start; }

/* Hohe Bühne (.tall setzt app.js): übereinander statt nebeneinander, im Fokus die kleinen Elemente darunter */
#call.has-stage #stage.tall {
  grid-auto-flow: row;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: none; grid-auto-rows: minmax(0, 1fr);
}
#call.has-stage #stage.tall.focus {
  grid-auto-flow: column;
  grid-template-rows: minmax(0, 3fr) minmax(0, 1fr);
  grid-template-columns: repeat(var(--side-count, 1), minmax(0, 1fr));
}
#stage.tall.focus .stage-item.focused { grid-row: 1; grid-column: 1 / -1; }
#stage.tall.focus .stage-item:not(.focused) { grid-row: 2; grid-column: auto; align-self: center; }

/* Jedes Element ist so hoch wie sein 16:9-Inhalt, höchstens aber so hoch wie seine Rasterzelle */
.stage-item {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  align-self: center; max-height: 100%;
  background: #000; border-radius: var(--radius); overflow: hidden;
}
.stage-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px 6px 14px; min-height: 42px;
  background: var(--surface); font-size: 13px;
}
.stage-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-tools { display: flex; align-items: center; gap: 6px; }
.stage-tools input[type="range"] { width: 80px; accent-color: var(--accent); }
.stage-body { position: relative; flex: 1 1 auto; aspect-ratio: 16 / 9; min-height: 0; }
.stage-body video,
.stage-body iframe,
.yt-mount, .yt-shield {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0;
}
.stage-body video { object-fit: contain; background: #000; }
/* Zuschauer dürfen den Player nicht bedienen: transparente Abdeckung fängt Klicks ab */
.yt-shield { display: flex; align-items: flex-end; justify-content: center; padding-bottom: 24px; }
.stage-msg {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 24px; color: var(--muted); background: #000; pointer-events: none;
}
.stage-item.has-video .stage-msg.connecting { display: none; }
.stage-item:fullscreen { border-radius: 0; }

/* Leiste unten */
#bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 10px 18px 14px;
}
.bar-left { display: flex; gap: 10px; align-items: center; white-space: nowrap; overflow: hidden; }
.bar-left .sep { color: var(--muted); }
.bar-center { display: flex; gap: 12px; }
.bar-right { display: flex; gap: 8px; justify-content: flex-end; }

/* Dialog + Toasts */
dialog {
  border: 0; border-radius: 18px; padding: 24px; width: min(480px, calc(100vw - 32px));
  background: var(--surface); color: var(--fg);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 8px; font-size: 20px; font-weight: 500; }
dialog p { margin: 0 0 16px; color: var(--muted); }
dialog .error { color: #ff8a8e; margin: 8px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

#toasts {
  position: fixed; left: 18px; right: 18px; bottom: 86px; z-index: 10;
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; pointer-events: none;
}
.toast {
  max-width: min(480px, 100%); overflow-wrap: anywhere; /* auf dem Handy nicht über den Rand hinaus */
  background: #e8ebf0; color: #14181f; padding: 10px 16px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .4);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Anmeldung ---------- */
#auth { height: 100dvh; display: grid; place-items: center; padding: 24px; overflow: auto; }
.auth-card {
  width: min(400px, 100%); display: flex; flex-direction: column; gap: 16px;
  background: var(--surface); padding: 28px; border-radius: 18px;
}
.auth-card h1 { font-size: 26px; font-weight: 500; margin: 0; }
.auth-card form { display: flex; flex-direction: column; gap: 16px; }
.auth-card p { margin: 0; color: var(--muted); }
.auth-card p.error { color: #ff8a8e; }

/* ---------- Übersicht des Lehrers ---------- */
#dashboard { height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.dash-head {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 16px;
  padding: 12px 24px; border-bottom: 1px solid #262c37;
}
.dash-head h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 500; }
#dash-back { display: none; }
.dash-user { color: var(--muted); }
.dash-body { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 0; }
.dash-list {
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px; border-right: 1px solid #262c37; overflow-y: auto;
}
#student-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.student-item {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 10px 12px; border: 0; border-radius: 10px; background: transparent;
}
.student-item:hover { background: var(--surface); }
.student-item.selected { background: var(--btn); }
.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: #4a5362; }
.dot.on { background: #46c37b; }
.s-main { display: flex; flex-direction: column; min-width: 0; }
/* .s-name: Name eines Schülers (wird nie übersetzt); .nav-name: Eintrag der Übersicht */
.s-name, .nav-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-sub { font-size: 12.5px; color: var(--muted); }
.dash-empty { padding: 48px 24px; text-align: center; }
.dash-empty p { margin: 0 auto 8px; max-width: 420px; }
.dash-detail { overflow-y: auto; padding: 24px; }
.dash-detail > * { max-width: 760px; }
.dash-detail > * + * { margin-top: 16px; }
.detail-head { display: flex; align-items: center; gap: 16px; }
.detail-head h2 { flex: 1; min-width: 0; margin: 0; font-size: 26px; font-weight: 500; overflow-wrap: anywhere; }
.card {
  display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); border-radius: var(--radius); padding: 18px 20px;
}
.card h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card .hint { min-height: 0; }
.lesson-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.lesson-list li {
  display: flex; align-items: center; gap: 8px; min-height: 36px;
  border-bottom: 1px solid #2a313d; font-variant-numeric: tabular-nums;
}
.lesson-list li:last-child { border-bottom: 0; }
.lesson-list li span { flex: 1; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.lesson-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 10px; align-items: end; }
input[type="date"], input[type="time"] { min-height: 44px; }

/* ---------- Lehrraum: Vorraum/Anruf links, Chat rechts ---------- */
#room { height: 100dvh; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr) auto; }
#room-main { min-width: 0; min-height: 0; }
.lobby-form .back { text-decoration: none; font-size: 13px; }
.lobby-form .primary { align-self: flex-start; }
.lobby-lesson { margin: 0; font-size: 16px; }
.lobby-form h2 { margin: 8px 0 4px; font-size: 13px; font-weight: 600; color: var(--muted); }

#chat {
  width: 340px; min-height: 0;
  /* minmax(0, …) auch für die Spalte: Eine lange angepinnte Nachricht (eine Zeile, wird mit … gekürzt) weitete
     sie sonst über den Rand hinaus – Senden- und Schließen-Knopf lagen dann außerhalb des Bildschirms. */
  display: grid; grid-template: auto minmax(0, 1fr) auto / minmax(0, 1fr);
  background: var(--surface); border-left: 1px solid #262c37;
}
#room.chat-closed #chat { display: none; }
.chat-head { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px 10px; }
.chat-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.chat-head input { padding: 8px 12px; }
.chat-head .hint { min-height: 0; }
#chat-list {
  display: flex; flex-direction: column; gap: 10px;
  padding: 6px 14px 14px; overflow-y: auto; overscroll-behavior: contain;
}
.msg { max-width: 88%; align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.msg-meta { margin-bottom: 2px; font-size: 12px; color: var(--muted); }
.msg.mine .msg-meta { text-align: right; }
.msg-text {
  padding: 8px 12px; border-radius: 14px; background: var(--tile);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.mine .msg-text { background: #2b4a7d; }
.msg-text a { color: #cfe0ff; }
#chat-list.searching .msg { cursor: pointer; }
.msg.flash .msg-text { animation: flash 1.8s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 2px var(--accent); } 100% { box-shadow: 0 0 0 2px transparent; } }
mark { background: #f2c94c; color: #14181f; border-radius: 3px; }
/* Marker im Verlauf: Tageswechsel dezent, Unterrichtstermine als deutliche Trennlinie */
.chat-marker { align-self: center; font-size: 12px; color: var(--muted); text-align: center; }
.chat-marker.empty { margin: auto; }
.chat-marker.lesson {
  align-self: stretch; display: flex; align-items: center; gap: 10px;
  margin-top: 10px; color: var(--accent); font-weight: 600;
}
.chat-marker.lesson::before, .chat-marker.lesson::after {
  content: ""; flex: 1; height: 1px; background: currentColor; opacity: .35;
}
.chat-older { align-self: center; flex: none; }
/* Rückfrage vor dem Laden von YouTube */
.yt-consent {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  gap: 14px; padding: 24px; text-align: center; background: #000; color: var(--muted); overflow-y: auto;
}
/* Mittig, solange Platz ist; reicht er nicht (Handy mit offenem Chat), beginnt der Text oben und lässt sich
   scrollen – „justify-content: center“ schnitte ihn oben und unten ab, samt dem Knopf. */
.yt-consent > :first-child { margin-top: auto; }
.yt-consent > :last-child { margin-bottom: auto; flex: none; }
.yt-consent p { margin: 0; max-width: 420px; }
/* YouTube spielt das Video hier nicht ab: Meldung mit Ausweg, über dem (leeren) Player */
.yt-fallback {
  position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center;
  gap: 12px; padding: 24px; text-align: center; background: #000; color: var(--muted); overflow-y: auto;
}
.yt-fallback > :first-child { margin-top: auto; }
.yt-fallback > :last-child { margin-bottom: auto; flex: none; justify-content: center; }
.yt-fallback p { margin: 0; max-width: 460px; }
.yt-fallback p:first-child { color: var(--fg); }
.yt-fallback a.small { text-decoration: none; }
#account-dialog form + form { margin-top: 22px; }
#account-dialog h3 { margin: 0; font-size: 15px; font-weight: 600; }
#account-dialog .error { margin-top: 14px; }
.dialog-actions { align-items: center; }
#chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px 14px; }
#chat-input { resize: none; min-height: 42px; max-height: 120px; padding: 10px 13px; }
#chat-send { width: 42px; height: 42px; background: var(--accent); color: var(--accent-ink); }
/* Punkt am Chat-Knopf: ungelesene Nachrichten */
.ctl.unread::before {
  content: ""; position: absolute; top: 4px; right: 4px;
  width: 11px; height: 11px; border-radius: 50%;
  background: #f2c94c; border: 2px solid var(--bg);
}

/* ---------- Einstieg, Vorraum: Erklärung vor der Kamera-Rückfrage, Gerätewahl, Pegel ---------- */
#login-box summary { cursor: pointer; color: var(--accent); font-size: 14px; }
#invite-who { color: var(--fg); font-size: 16px; overflow-wrap: anywhere; }
.auth-card #invite-other { color: #f2c94c; overflow-wrap: anywhere; }
#invite-form .primary { align-self: flex-start; }
#login-box form { margin-top: 14px; }
.auth-card strong { color: var(--fg); }
.preview-ask {
  grid-area: 1 / 1; position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  /* unten bleibt Platz für die Knöpfe für Mikrofon und Kamera */
  gap: 14px; padding: 20px 20px 76px; text-align: center; background: var(--tile);
}
.preview-ask p { margin: 0; max-width: 440px; }
.preview-controls { z-index: 2; }
.devices { padding-top: 4px; }
.meter { height: 8px; border-radius: 4px; background: var(--btn); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: #46c37b; transition: width .1s linear; }
.devices .hint, .lobby-form .hint { min-height: 0; }
#lobby-upcoming-box .small { margin-top: 10px; }

/* ---------- Anruf: Beschriftung der Knöpfe, Hinweiszeile, Stundenuhr ---------- */
#call { position: relative; }
#bar { padding-bottom: 30px; }
.bar-center .ctl::after {
  content: attr(data-label); position: absolute; top: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  font-size: 11px; line-height: 1.2; color: var(--muted); white-space: nowrap; pointer-events: none;
}
.call-notice {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 3; max-width: calc(100% - 24px);
  padding: 8px 16px; border-radius: 10px; background: #f2c94c; color: #14181f; font-size: 14px; text-align: center;
}
/* Uhr und Stundenuhr bleiben immer lesbar; wird es eng, kürzt sich der Raumname */
.bar-left > * { flex: none; }
#room-code { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.lesson-timer { padding: 2px 9px; border-radius: 999px; background: var(--surface); font-size: 13px; }
.lesson-timer.soon { background: #f2c94c; color: #14181f; }

/* ---------- Chat: „Neu“-Marke, Löschen ---------- */
.chat-marker.new {
  align-self: stretch; display: flex; align-items: center; gap: 10px; color: #f2c94c; font-weight: 600;
}
.chat-marker.new::before, .chat-marker.new::after { content: ""; flex: 1; height: 1px; background: currentColor; opacity: .5; }
.msg-meta { display: flex; align-items: center; gap: 4px; }
.msg.mine .msg-meta { justify-content: flex-end; }
.msg-action {
  border: 0; background: none; padding: 2px; border-radius: 50%; color: var(--muted); display: grid; opacity: 0;
}
.msg-action svg { width: 14px; height: 14px; }
.msg:hover .msg-action, .msg-action:focus-visible, .msg.pinned .msg-pin, .chat-pinned .msg-action { opacity: 1; }
.msg-del:hover { color: #ff8a8e; }
.msg-pin:hover, .msg.pinned .msg-pin { color: #f2c94c; }
.msg.pinned .msg-text { box-shadow: inset 3px 0 0 #f2c94c; }

/* Dateien: Bilder direkt, alles andere als Zeile zum Herunterladen */
.msg-image img { display: block; max-width: 100%; max-height: 240px; border-radius: 8px; }
.msg-file { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; }
.msg-file span { text-decoration: underline; overflow-wrap: anywhere; }
.msg-file small { flex: none; color: var(--muted); }
.msg-file svg { flex: none; width: 20px; height: 20px; }
#chat-attach { align-self: center; }

/* Suche und Terminsprung; angepinnte Nachrichten */
.chat-tools { display: flex; flex-direction: column; gap: 8px; }
#chat-tools-toggle { display: none; }
#chat-jump { padding: 7px 10px; font-size: 13px; background: var(--bg); }
.chat-pinned summary { font-size: 13px; color: #f2c94c; }
#chat-pinned-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 108px; overflow-y: auto; }
#chat-pinned-list li { display: flex; align-items: center; gap: 4px; }
.pinned-item {
  flex: 1; min-width: 0; border: 0; background: none; padding: 4px 0; text-align: left; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pinned-item:hover { text-decoration: underline; }
.chat-marker.lesson.call { color: #9ad6b0; }
.chat-marker.flash { animation: flash 1.8s ease-out; border-radius: 6px; }

/* Kamerabild einer Person groß auf die Bühne holen */
.tile-pin { position: absolute; top: 8px; right: 8px; background: rgba(0, 0, 0, .55); color: #fff; opacity: 0; }
.tile:hover .tile-pin, .tile-pin:focus-visible { opacity: 1; }

/* Übersicht: Archiv, Hinweiszeile, Benachrichtigungs-Schalter, Sprachwahl */
#archive-box summary { padding: 6px 2px; }
#archive-list { list-style: none; margin: 4px 0 0; padding: 0; }
#archive-list .student-item { color: var(--muted); padding: 8px 12px; }
.notice {
  margin: 0; padding: 12px 16px; border-radius: var(--radius); background: var(--surface);
  border-left: 3px solid #f2c94c; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--fg); }
.check input { width: auto; }
.push-toggle { display: inline-flex; align-items: center; gap: 6px; }
.push-toggle svg { width: 16px; height: 16px; }
.push-toggle.on { color: #46c37b; }
/* Einladung als QR-Code; Materialliste */
.invite-qr { display: flex; align-items: center; gap: 16px; }
#invite-qr { flex: none; width: 148px; line-height: 0; }
#invite-qr svg { width: 100%; height: auto; border-radius: 8px; }
.material-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) auto auto; gap: 10px; align-items: end; }
#btn-material { margin-top: -10px; }
.lesson-list li .doc-link { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-host { flex: none !important; font-size: 13px; color: var(--muted); }
#material-dialog { width: min(560px, calc(100vw - 32px)); }

/* Sprachwahl: steht am Ende von Einstiegskarte, Schülerliste bzw. Vorraum */
.lang-switch { align-self: flex-start; margin-top: auto; }
.lang-switch select { width: auto; padding: 5px 8px; font-size: 13px; }
.dialog-actions { flex-wrap: wrap; }
#confirm-text { white-space: pre-line; overflow-wrap: anywhere; }

/* ---------- Übersicht: Plan, ungelesene Nachrichten ---------- */
#btn-plan { border-bottom: 1px solid #262c37; border-radius: 10px 10px 0 0; padding-bottom: 14px; }
#student-search { padding: 8px 12px; }
.student-item .s-main { flex: 1; }
.badge {
  flex: none; min-width: 22px; padding: 2px 7px; border-radius: 999px; text-align: center;
  background: #f2c94c; color: #14181f; font-size: 12px; font-weight: 700;
}
.plan-time { flex: none !important; width: 108px; color: var(--muted); }
.lesson-list li .link { flex: none; font-weight: 600; text-decoration: none; }
.lesson-list li .link:hover { text-decoration: underline; }
.plan-note { font-size: 13px; color: var(--muted); }
.plan-note.warn { color: #f2c94c; }

/* Finger statt Maus: größere Flächen, und was sonst erst beim Überfahren erscheint, ist immer da */
@media (pointer: coarse) {
  .small { padding: 12px 16px; }
  .icon-btn { width: 44px; height: 44px; }
  .msg-action { opacity: 1; padding: 8px; }
  .tile-pin { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Wird die Leiste des Anrufs eng (Tablet, Handy, kleines Fenster mit offenem Chat), stehen Uhr, Stundenuhr,
   Material und Notizen in einer eigenen Zeile über den Knöpfen. Nebeneinander wurden sie abgeschnitten oder
   überlagerten die Knöpfe – und auf Handy und Tablet im Hochformat fehlten sie früher ganz. */
@media (max-width: 1100px) {
  #bar { grid-template: auto auto / minmax(0, 1fr) auto; row-gap: 0; }
  .bar-left { grid-area: 1 / 1; }
  .bar-right { grid-area: 1 / 2; }
  .bar-center { grid-area: 2 / 1 / 3 / 3; justify-self: center; }
  .bar-left > *, .bar-right > * { margin-bottom: 8px; }
  .bar-right .pill { padding: 6px 12px; font-size: 13px; }
}

/* Schmale Fenster: Bühne oben, Teilnehmer als Streifen darunter; Chat unter dem Bild, Übersicht einspaltig */
@media (max-width: 900px) {
  /* Der Chat nimmt die untere Hälfte ein – das Bild der Gegenseite bleibt darüber sichtbar. */
  #room { grid-template: minmax(0, 1fr) auto / minmax(0, 1fr); }
  #chat { width: auto; height: 46dvh; border-left: 0; border-top: 1px solid #262c37; }
  /* Suche und Terminsprung sind hier eingeklappt; die Lupe im Kopf des Chats klappt sie aus. */
  #chat-tools-toggle { display: grid; }
  .chat-tools { display: none; }
  #chat.tools-open .chat-tools { display: flex; }
  #chat.tools-open #chat-tools-toggle { color: var(--accent); }
  #dashboard { height: auto; min-height: 100dvh; display: block; }
  body:has(#dashboard:not([hidden])) { overflow: auto; }
  /* Kopfzeile in zwei Zeilen: Titel, Konto und Abmelden – darunter der Schalter für Benachrichtigungen */
  .dash-head { padding: 8px 12px; gap: 2px 6px; }
  .dash-head .ghost { padding: 8px 12px; }
  .dash-head .push-toggle { order: 1; }
  .dash-user { display: none; }
  /* Plan und Terminlisten: Zeit (und Name) mit den Knöpfen in einer Zeile, der Hinweis („läuft gerade“,
     „Serie“, „nicht stattgefunden“ …) darunter – nebeneinander bliebe für das Datum kaum Platz. */
  .lesson-list li:has(> .plan-note) { flex-wrap: wrap; row-gap: 0; padding-block: 6px; }
  .plan-note { order: 1; flex: 1 1 100% !important; }
  .plan-note:empty { display: none; }
  .plan-time { width: auto; }
  .plan-time ~ .small { margin-left: auto; }
  /* Entweder die Liste oder das Gewählte: Nach dem Antippen eines Schülers stünde er sonst unter der ganzen Liste. */
  #dashboard.detail-open .dash-list { display: none; }
  #dashboard.detail-open #dash-back { display: inline-block; }
  #dashboard.detail-open .dash-head h1 { display: none; }
  #dashboard.detail-open #dash-back { margin-right: auto; }
  .detail-head { flex-wrap: wrap; gap: 8px 12px; }
  .dash-body { display: block; }
  .dash-list { border-right: 0; border-bottom: 1px solid #262c37; overflow: visible; }
  .dash-detail { overflow: visible; padding: 16px; }
  .lesson-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .material-form { grid-template-columns: minmax(0, 1fr); }
  .invite-qr { flex-direction: column; align-items: flex-start; }
  .lesson-form button { grid-column: 1 / -1; }
  #main { flex-direction: column; }
  #call.has-stage #people { flex: 0 0 96px; flex-direction: row; overflow: auto hidden; scrollbar-width: none; }
  #call.has-stage .tile { height: 100%; }
  /* Auf dem Handy bleiben in der Zeile über den Knöpfen nur Stundenuhr, Material und Notizen. */
  #bar { padding-inline: 8px; }
  #clock, .bar-left .sep, #room-code, #people-pill { display: none; }
  .yt-consent { gap: 8px; padding: 10px 14px; font-size: 13px; }
  .yt-fallback { gap: 8px; padding: 10px 14px; font-size: 13px; }
  .yt-consent .primary { padding: 8px 18px; }
  /* sechs Knöpfe müssen auch auf ein 320 px breites Handy passen */
  .bar-center { gap: clamp(6px, 2vw, 12px); }
  .bar-center .ctl { width: clamp(40px, 12.5vw, 48px); height: clamp(40px, 12.5vw, 48px); }
  .bar-center .ctl.leave { width: clamp(54px, 17vw, 68px); }
}

/* ---------- Einstellungen (Geräte, Bildqualität, Hintergrund) ---------- */
#settings-dialog { max-height: calc(100dvh - 32px); overflow-y: auto; }
#settings-dialog select { background: var(--bg); padding: 9px 12px; }
#settings-dialog .hint { min-height: 0; margin-top: -6px; }
#settings-dialog .hint:empty { display: none; }
dialog h3 { margin: 6px 0 0; font-size: 15px; font-weight: 600; }
.settings-preview {
  position: relative; width: min(100%, 320px); aspect-ratio: 16 / 9; margin: 8px auto 18px;
  background: var(--tile); border-radius: 12px; overflow: hidden;
}
.settings-preview video { display: block; width: 100%; height: 100%; object-fit: cover; }
.settings-preview video.mirror { transform: scaleX(-1); }
.settings-preview .preview-off { font-size: 14px; padding: 12px; text-align: center; }
.pill.icon-only { padding: 8px; }
@media (max-width: 1100px) {
  .bar-right .pill.icon-only { padding: 6px; }
}
/* „Fertig“ bleibt erreichbar, auch wenn der Dialog höher ist als das Fenster */
#settings-dialog .dialog-actions {
  position: sticky; bottom: -24px; margin: 8px -24px -24px; padding: 12px 24px 20px;
  background: var(--surface); border-top: 1px solid #262c37;
}

/* ---------- Seite „Impressum und Datenschutz“ (rechtliches.html) ---------- */
body.legal-page { overflow: auto; }
.legal { max-width: 720px; margin: 0 auto; padding: 24px 20px 64px; line-height: 1.55; }
.legal-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.legal-top .back { text-decoration: none; font-size: 13px; }
.legal-top .lang-switch { margin: 0; align-self: auto; }
.legal h1 { font-size: 26px; font-weight: 500; margin: 20px 0 0; }
.legal h2 { font-size: 19px; font-weight: 600; margin: 32px 0 8px; }
.legal h3 { font-size: 15px; font-weight: 600; margin: 24px 0 6px; }
.legal p { margin: 0 0 10px; }
.legal ul { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.legal li, .legal p { overflow-wrap: anywhere; }
/* Texte des Anbieters: Zeilenumbrüche bleiben, wie er sie eingegeben hat */
.legal-text { white-space: pre-line; }
.legal-link { font-size: 13px; color: var(--muted); }
.legal-link:hover { color: var(--accent); }
#account-dialog textarea, #account-dialog select { background: var(--bg); }
#account-dialog textarea { resize: vertical; }
@media (pointer: coarse) {
  .bar-right .pill.icon-only { padding: 11px; }
}

/* ---------- Kalender, Terminanfragen, Nachweis, Moderation, Chat-Ergänzungen ---------- */
/* Navigation der Übersicht: Plan, Kalender, Nachweis, Material als eine Gruppe */
.dash-nav { display: flex; flex-direction: column; gap: 2px; padding-bottom: 12px; border-bottom: 1px solid #262c37; }
.dash-nav #btn-plan { border-bottom: 0; border-radius: 10px; padding-bottom: 10px; }
.dash-nav #btn-material { margin-top: 0; }
.dash-detail.wide > * { max-width: 1100px; }
/* Namen und Worte von Nutzern, die nie übersetzt werden (siehe i18n.js) – ohne eigenes Aussehen */
.plain { unicode-bidi: isolate; }

/* Wochenkalender (calendar.js) */
.cal { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.cal-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cal-title { margin-left: 6px; font-weight: 600; }
.cal-extra { margin-left: auto; display: flex; gap: 6px; }
.cal-scroll { border: 1px solid #2a313d; border-radius: 12px; overflow: hidden; background: var(--bg); }
.cal-head, .cal-allday, .cal-body { display: grid; grid-template-columns: 52px repeat(var(--cal-days, 7), minmax(0, 1fr)); }
.cal-head, .cal-allday { border-bottom: 1px solid #2a313d; }
.cal-dayhead {
  display: flex; flex-direction: column; align-items: center; padding: 6px 4px;
  border-left: 1px solid #2a313d; font-size: 12.5px; color: var(--muted);
}
.cal-dayhead strong { font-size: 14px; color: var(--fg); font-variant-numeric: tabular-nums; }
.cal-dayhead.today strong { color: var(--accent); }
.cal-alldaycell { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 3px; border-left: 1px solid #2a313d; }
.cal-body { max-height: min(60dvh, 620px); overflow-y: auto; overscroll-behavior: contain; }
.cal-gutter { position: relative; }
.cal-gutter span {
  position: absolute; right: 6px; transform: translateY(-50%);
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.cal-gutter span:first-child { transform: translateY(2px); }
.cal-day {
  position: relative; border-left: 1px solid #2a313d; cursor: pointer;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour) - 1px), #232a35 calc(var(--hour) - 1px), #232a35 var(--hour));
}
.cal-day.today { background-color: rgba(127, 176, 255, .05); }
.cal-item {
  position: absolute; left: 0; right: 0; z-index: 1; overflow: hidden;
  display: flex; flex-direction: column; padding: 3px 6px; border: 0; border-radius: 6px;
  font-size: 12px; line-height: 1.25; text-align: left; color: var(--fg); background: #2b4a7d;
}
button.cal-item:hover { filter: brightness(1.15); }
/* Ist der Eintrag zu niedrig für alle Zeilen, fällt unten etwas weg – nicht der Titel (er ließe sich sonst auf null stauchen). */
.cal-item > * { flex: none; }
.cal-item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-item-time, .cal-item-sub { font-size: 11px; opacity: .85; white-space: nowrap; }
.cal-item.lesson { box-shadow: inset 3px 0 0 var(--accent); }
.cal-item.past { opacity: .6; }
.cal-item.cancelled { background: var(--bg); box-shadow: inset 0 0 0 1px #5a6577; color: var(--muted); }
.cal-item.cancelled .cal-item-title { text-decoration: line-through; }
.cal-item.request { background: #3a3520; box-shadow: inset 0 0 0 1px #f2c94c; color: #f7dc85; }
/* Flächen hinter den Terminen: nicht buchbar, belegt, abwesend */
.cal-item.area { z-index: 0; border-radius: 0; padding: 2px 6px; color: var(--muted); }
.cal-item.closed { background: rgba(0, 0, 0, .34); }
.cal-item.busy { background: rgba(154, 164, 178, .2); }
.cal-item.absence { background: repeating-linear-gradient(45deg, rgba(154, 164, 178, .24) 0 6px, rgba(154, 164, 178, .1) 6px 12px); }
.cal-item.chip { position: static; padding: 2px 6px; border-radius: 4px; }
.cal-now { position: absolute; left: 0; right: 0; z-index: 2; height: 2px; background: var(--danger); pointer-events: none; }
.cal-card { gap: 14px; }
.cal-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--muted); }
.cal-legend li { display: flex; align-items: center; gap: 6px; }
.swatch { flex: none; width: 14px; height: 14px; border-radius: 4px; }
.swatch.lesson { background: #2b4a7d; box-shadow: inset 3px 0 0 var(--accent); }
.swatch.cancelled { box-shadow: inset 0 0 0 1px #5a6577; }
.swatch.request { background: #3a3520; box-shadow: inset 0 0 0 1px #f2c94c; }
.swatch.absence { background: repeating-linear-gradient(45deg, rgba(154, 164, 178, .5) 0 3px, rgba(154, 164, 178, .15) 3px 6px); }
.swatch.busy { background: rgba(154, 164, 178, .35); }
.swatch.closed { background: #0a0c10; box-shadow: inset 0 0 0 1px #2a313d; }

/* Plan und Terminlisten: laufender Termin, abgesagte Termine, Anfragen */
.lesson-list li.now { margin-inline: -8px; padding-inline: 8px; border-radius: 8px; border-bottom-color: transparent; background: rgba(127, 176, 255, .14); }
.lesson-list li.cancelled > span:first-child, .lesson-list li.cancelled > .link { text-decoration: line-through; color: var(--muted); }
.primary.compact { padding: 8px 14px; font-size: 13px; }
.request-list .link { margin-right: 4px; }
.quote { margin: 0; padding: 6px 12px; border-left: 3px solid #3a4558; color: var(--fg); overflow-wrap: anywhere; }
dialog p.quote { margin-bottom: 0; color: var(--fg); }
.absence-title { flex: 0 1 auto !important; font-weight: 600; overflow-wrap: anywhere; }

/* Checkliste für den ersten Start */
.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.checklist li { display: flex; align-items: flex-start; gap: 10px; }
.check-mark { flex: none; width: 22px; height: 22px; margin-top: 1px; border: 2px solid #4a5362; border-radius: 50%; display: grid; place-items: center; }
.check-mark svg { width: 14px; height: 14px; }
.checklist li.done .check-mark { border-color: #46c37b; background: #46c37b; color: #0b1524; }
.check-body { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.checklist li.done strong { font-weight: 500; color: var(--muted); }
.checklist .link { font-weight: 600; }

/* Dialoge: Eintragen, Einstellungen des Kalenders, Auswahl */
dialog textarea, dialog select, .card textarea { background: var(--bg); }
dialog textarea, .card textarea { resize: vertical; }
.segmented { display: flex; padding: 3px; border-radius: 999px; background: var(--bg); }
.segmented label { flex: 1; flex-direction: row; gap: 0; }
.segmented input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.segmented span { flex: 1; padding: 7px 12px; border-radius: 999px; text-align: center; font-size: 14px; color: var(--fg); cursor: pointer; }
.segmented input:checked + span { background: var(--btn); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.segmented input:disabled + span { opacity: .4; cursor: not-allowed; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 10px; align-items: end; }
#entry-info { display: flex; flex-direction: column; gap: 2px; }
#calsettings-dialog, #calendar-dialog, #entry-dialog { max-height: calc(100dvh - 24px); overflow-y: auto; }
#calsettings-dialog { width: min(620px, calc(100vw - 24px)); }
#calsettings-dialog > * + * { margin-top: 22px; padding-top: 18px; border-top: 1px solid #2a313d; }
#calsettings-dialog > .dialog-actions { margin-top: 12px; }
#calsettings-dialog .hint { min-height: 0; }
#calsettings-dialog .hint.error { color: #ff8a8e; }
.hours-grid { display: flex; flex-direction: column; gap: 6px; }
.hours-row { display: grid; grid-template-columns: minmax(96px, 1fr) minmax(0, 108px) minmax(0, 108px); gap: 8px; align-items: center; }
.hours-row input[type="time"] { min-height: 38px; padding: 6px 10px; }
.hours-row input:disabled { opacity: .35; }
.guide { margin: 10px 0 8px; padding-left: 20px; display: grid; gap: 8px; font-size: 13.5px; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; }
.sheet-actions button { width: 100%; }
#sheet-title { overflow-wrap: anywhere; }
#calendar-dialog { width: min(980px, calc(100vw - 16px)); padding: 20px; }
#calendar-dialog > * + * { margin-top: 14px; }
#calendar-dialog #request-form { padding: 14px 16px; border-radius: var(--radius); background: var(--tile); }
#device-qr { width: 190px; margin: 0 auto 16px; line-height: 0; }
#device-qr svg { width: 100%; height: auto; border-radius: 8px; }
#device-dialog .invite-qr { justify-content: center; }

/* Nachweis: Monatsübersicht */
.table-wrap { overflow-x: auto; }
.report-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.report-table th, .report-table td { padding: 8px 10px; border-bottom: 1px solid #2a313d; text-align: right; white-space: nowrap; }
.report-table th:first-child { text-align: left; font-weight: 600; }
.report-table thead th { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.report-table tfoot th, .report-table tfoot td { border-bottom: 0; font-weight: 700; }
.report-table td.report-empty { text-align: center; white-space: normal; color: var(--muted); }

/* Meldungen zum Anklicken */
.toast.clickable { border: 0; text-align: left; font: inherit; font-size: 14px; cursor: pointer; pointer-events: auto; }
.toast.clickable:hover { filter: brightness(1.06); }

/* Chat: Statuszeile (Upload, Aufnahme, Berichtigen), automatische Meldungen, „Gelesen“, Ton */
.chat-status { display: flex; align-items: center; gap: 8px; padding: 8px 14px 0; font-size: 13px; color: var(--muted); }
.chat-status > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-status .meter { flex: 0 0 64px; }
.chat-status .small { padding: 6px 12px; }
.small.primary-small { background: var(--accent); color: var(--accent-ink); }
.msg.event { align-self: center; max-width: 96%; }
.msg.event .msg-meta { justify-content: center; }
.msg-event {
  display: flex; flex-direction: column; gap: 2px; padding: 8px 14px;
  border: 1px solid #3a4558; border-radius: 12px; font-size: 13.5px; text-align: center; overflow-wrap: anywhere;
}
.msg-event span { font-size: 12.5px; color: var(--muted); }
.msg .msg-event .msg-text { padding: 0; border-radius: 0; background: none; font-style: italic; quotes: "„" "“"; }
.msg-seen { margin-top: 2px; font-size: 11.5px; color: var(--muted); text-align: right; }
.msg-edit:hover { color: var(--accent); }
.msg-audio { display: flex; flex-direction: column; gap: 6px; min-width: min(240px, 60vw); }
.msg-audio audio { width: 100%; height: 36px; }
#chat-voice { align-self: center; }

/* Anruf: Hinweis für den, der allein wartet; Moderation und Kamerawechsel auf den Kacheln; Zuschauer eines Videos */
.call-waiting {
  position: absolute; left: 50%; bottom: 112px; z-index: 2; transform: translateX(-50%);
  margin: 0; max-width: calc(100% - 24px); padding: 8px 16px; border-radius: 16px;
  background: rgba(27, 32, 41, .94); box-shadow: 0 4px 18px rgba(0, 0, 0, .4); font-size: 14px; text-align: center; text-wrap: balance;
}
.tile-flip, .tile-mod { position: absolute; top: 8px; left: 8px; z-index: 1; }
.tile-flip, .tile-mod .icon-btn { background: rgba(0, 0, 0, .55); color: #fff; }
.tile-mod { display: flex; gap: 6px; opacity: 0; }
.tile:hover .tile-mod, .tile-mod:focus-within { opacity: 1; }
.stage-viewers { flex: 0 1 auto; max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: var(--muted); }
#lobby-pinned-box .pinned-item { white-space: normal; overflow-wrap: anywhere; }
#lobby-requests .small { flex: none; }
#lobby-upcoming .plan-note { flex: none; }
@media (pointer: coarse) {
  .tile-mod { opacity: 1; }
}
@media (max-width: 1100px) {
  .call-waiting { bottom: 150px; }
}
@media (max-width: 900px) {
  /* Zu zweit auf dem Handy: die andere Person füllt die Fläche, das eigene Bild sitzt klein in der Ecke. */
  #call:not(.has-stage) #people.duo { display: block; position: relative; }
  #call:not(.has-stage) #people.duo .tile { position: absolute; inset: 0; }
  #call:not(.has-stage) #people.duo .tile[data-key="me"] {
    inset: auto 8px 8px auto; z-index: 2; width: min(32%, 150px); aspect-ratio: 3 / 4;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .55);
  }
  #call:not(.has-stage) #people.duo .tile[data-key="me"] .tile-name { left: 6px; bottom: 6px; font-size: 11px; }
  #call:not(.has-stage) #people.duo ~ * .call-waiting, .call-waiting { bottom: 158px; }
  .cal-head, .cal-allday, .cal-body { grid-template-columns: 44px repeat(var(--cal-days, 7), minmax(0, 1fr)); }
  #calendar-dialog { padding: 14px; }
}

/* ---------- Geräteliste, Absage durch Schüler, Monatsübersicht ---------- */
.warn-text, dialog p.warn-text, .hint.warn-text { color: #f2c94c; }
.devices-list:empty { display: none; }
.devices-list .device { flex-wrap: wrap; row-gap: 0; padding-block: 7px; }
.device-main { flex: 1 1 auto !important; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; min-width: 0; }
.device-main strong { font-weight: 600; }
.device-badge { flex: none !important; padding: 1px 8px; border-radius: 999px; background: var(--btn); font-size: 12px; }
.device-note { order: 1; flex: 1 1 100% !important; display: flex; flex-wrap: wrap; gap: 0 12px; }
.device-note span { flex: none; }
#devices-dialog .dialog-actions { justify-content: flex-start; }

/* Umschalter Woche | Monat */
.cal-mode { display: inline-flex; padding: 2px; border-radius: 999px; background: var(--bg); }
.cal-mode .small { padding: 6px 12px; background: transparent; }
.cal-mode .small.selected { background: var(--btn); }
.cal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-monthhead { padding: 6px 4px; border-bottom: 1px solid #2a313d; text-align: center; font-size: 12.5px; color: var(--muted); }
.cal-cell {
  min-width: 0; min-height: 98px; padding: 4px; display: flex; flex-direction: column; gap: 2px;
  border-left: 1px solid #2a313d; border-bottom: 1px solid #2a313d; cursor: pointer;
}
.cal-cell:nth-child(7n + 1) { border-left: 0; }
.cal-cell:hover { background-color: rgba(127, 176, 255, .07); }
.cal-cell.blocked { background-image: repeating-linear-gradient(45deg, rgba(154, 164, 178, .15) 0 6px, rgba(154, 164, 178, .05) 6px 12px); }
.cal-cell-day {
  align-self: flex-start; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 999px;
  display: grid; place-items: center; font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.cal-cell.other .cal-cell-day { opacity: .4; }
.cal-cell.today .cal-cell-day { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.cal-chip {
  display: flex; gap: 4px; min-width: 0; padding: 1px 5px; border: 0; border-radius: 4px; overflow: hidden;
  font: inherit; font-size: 11.5px; line-height: 1.4; text-align: left; white-space: nowrap; color: var(--fg); background: #2b4a7d;
}
.cal-chip > span { overflow: hidden; text-overflow: ellipsis; }
.cal-chip-time { flex: none; opacity: .85; font-variant-numeric: tabular-nums; }
.cal-chip.past { opacity: .6; }
.cal-chip.cancelled { background: transparent; box-shadow: inset 0 0 0 1px #5a6577; color: var(--muted); text-decoration: line-through; }
.cal-chip.request { background: #3a3520; box-shadow: inset 0 0 0 1px #f2c94c; color: #f7dc85; }
.cal-chip.absence, .cal-chip.busy { background: rgba(154, 164, 178, .25); color: var(--muted); }
button.cal-chip { cursor: pointer; }
button.cal-chip:hover { filter: brightness(1.15); }
.cal-more { padding-left: 5px; font-size: 11px; color: var(--muted); }
.cal-dots { display: flex; flex-wrap: wrap; gap: 3px; padding: 2px; }
.cal-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.cal-dot.cancelled { background: #5a6577; }
.cal-dot.request { background: #f2c94c; }
.cal.narrow .cal-cell { min-height: 54px; align-items: center; }
.cal.narrow .cal-cell-day { align-self: center; }
.cal.narrow .cal-chip { display: none; }

/* Abrechnung: Übersicht, Entwurf, Belege */
.wide-dialog { width: min(760px, calc(100vw - 16px)); max-height: calc(100dvh - 24px); overflow-y: auto; }
#roombill-dialog { width: min(560px, calc(100vw - 16px)); max-height: calc(100dvh - 24px); overflow-y: auto; }
.billing-table th, .billing-table td, .draft-table th, .draft-table td { text-align: left; }
.billing-table td:nth-last-child(3) { text-align: right; }
#billing-open td:nth-last-child(2) { text-align: right; }
#billing-open td:nth-child(2) { white-space: normal; color: var(--muted); }
#billing-open td:nth-child(4) { font-weight: 600; }
.billing-table td:last-child { text-align: right; }
.billing-table td.report-empty { text-align: center; }
.billing-table .link { font-weight: 600; text-decoration: none; }
.billing-table .link:hover, .billing-table th a:hover { text-decoration: underline; }
.billing-table th a { color: var(--accent); text-decoration: none; }
.billing-table tr.cancelled th a, .billing-table tr.cancelled td:not(.status):not(.billing-actions) { color: var(--muted); text-decoration: line-through; }
.billing-table tr.cancelled td.status { color: var(--muted); }
.billing-actions { display: flex; justify-content: flex-end; gap: 6px; }
.billing-actions .small { padding: 5px 10px; font-size: 12.5px; }
.billing-table th, .billing-table td { padding-inline: 8px; }
.report-table td.warn-text { color: #f2c94c; }
.draft-table th, .draft-table td { padding: 6px 8px; font-weight: 400; }
.draft-table th:first-child, .draft-table td:first-child { width: 28px; padding-right: 0; }
.draft-table input[type="checkbox"] { width: 18px; height: 18px; margin: 0; }
.draft-table select { min-height: 36px; padding: 4px 8px; width: auto; max-width: 100%; }
.draft-table input.amount { width: 84px; min-height: 36px; padding: 4px 8px; text-align: right; font-variant-numeric: tabular-nums; }
.draft-table td:last-child { text-align: right; }
.draft-table thead th:last-child { text-align: right; }
.draft-table tr.excluded th, .draft-table tr.excluded td { color: var(--muted); }
.draft-table tr.excluded input.amount, .draft-table tr.excluded select { opacity: .45; }
.draft-sum { margin: 0; text-align: right; font-size: 16px; color: var(--fg); }
dialog p.draft-sum { color: var(--fg); }
.draft-sum span:first-child { font-size: 13px; color: var(--muted); }
.draft-sum strong { font-size: 19px; font-variant-numeric: tabular-nums; }
#billing-dialog h3, #draft-dialog h3 { margin-top: 10px; }
.pay-grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); } /* die IBAN braucht Platz */
#billing-dialog details > .stack { margin-top: 10px; }
#billing-rules span, #roombill-rules span, #rate-hint span { display: inline; }
.rate-form { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.rate-form label { flex: 1 1 220px; }
.receipt-list li strong { flex: none; font-variant-numeric: tabular-nums; }
.receipt-list li a { flex: 1; color: var(--accent); text-decoration: none; white-space: nowrap; }
.receipt-list li a:hover { text-decoration: underline; }
.receipt-list li.cancelled a, .receipt-list li.cancelled strong { color: var(--muted); text-decoration: line-through; }
.receipt-list li.receipt-sum { font-weight: 600; }
.receipt-list .plan-note { flex: none; }
.roombill-month h3 { margin: 14px 0 4px; }
#roombill-dialog > h3 { margin: 18px 0 4px; }
.msg-event a { color: var(--accent); font-size: 13px; }
@media (max-width: 640px) {
  /* Schmal: nur das Nötige – der Name öffnet den Entwurf, Monat und Datum stehen auf dem Beleg selbst */
  #billing-open th:nth-child(3), #billing-open td:nth-child(3), #billing-open th:nth-child(5), #billing-open td:nth-child(5) { display: none; }
  #billing-receipts th:nth-child(3), #billing-receipts td:nth-child(3) { display: none; }
  .billing-table th, .billing-table td { padding-inline: 5px; }
  .billing-table td { white-space: normal; }
  .wide-dialog { padding: 16px; }
  /* Entwurf: jede Zeile als kleiner Block – oben Häkchen, Termin und Dauer, darunter Art und Betrag */
  .draft-table, .draft-table tbody { display: block; }
  .draft-table thead { display: none; }
  .draft-table tr { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 6px 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid #2a313d; }
  .draft-table th, .draft-table td { padding: 0; border: 0; white-space: normal; }
  .draft-table th:first-child, .draft-table td:first-child { grid-row: 1; grid-column: 1; width: auto; }
  .draft-table tbody th { grid-row: 1; grid-column: 2; text-align: left; }
  .draft-table td:nth-child(4) { grid-row: 1; grid-column: 3; font-size: 13px; color: var(--muted); }
  .draft-table td:nth-child(3) { grid-row: 2; grid-column: 2; }
  .draft-table td:nth-child(5) { grid-row: 2; grid-column: 3; }
  .draft-table select { width: 100%; }
  .billing-actions { flex-direction: column; align-items: stretch; }
  .receipt-list li { flex-wrap: wrap; row-gap: 0; }
  .receipt-list li .plan-note { order: 1; flex: 1 1 100%; }
}

/* ---------- Handy im Querformat (flacher Bildschirm) ---------- */
/* Hier ist die Höhe knapp. Mit Teilnehmerleiste unter der Bühne und zweizeiliger Knopfleiste blieben für ein
   geteiltes Bild keine 100 Pixel – mit offenem Chat gar nichts. Deshalb: Bühne und Teilnehmer nebeneinander,
   die Knöpfe in einer niedrigen Zeile ohne Beschriftung, der Chat neben dem Bild statt darunter. */
@media (orientation: landscape) and (max-height: 540px) {
  #room { grid-template: minmax(0, 1fr) / minmax(0, 1fr) auto; }
  #chat { width: min(44vw, 340px); height: auto; border-top: 0; border-left: 1px solid #262c37; }

  #main { flex-direction: row; gap: 8px; padding: 6px 8px 2px; }
  #stage { gap: 8px; }
  #call.has-stage #people {
    flex: 0 0 clamp(92px, 15vw, 132px);
    flex-direction: column; overflow: hidden auto; scrollbar-width: none;
  }
  #call.has-stage .tile { height: auto; }
  #call.has-stage .tile-name { left: 4px; bottom: 4px; max-width: calc(100% - 8px); padding: 2px 6px; font-size: 11px; }
  #call.has-stage .tile-name svg { width: 12px; height: 12px; }
  /* Die Knöpfe auf den kleinen Kacheln (vergrößern, Kamera wechseln, Moderation) dürfen sie nicht zudecken. */
  #call.has-stage .tile .icon-btn { width: 28px; height: 28px; }
  #call.has-stage .tile .icon-btn svg { width: 15px; height: 15px; }
  #call.has-stage .tile-pin { top: 3px; right: 3px; }
  #call.has-stage .tile-flip, #call.has-stage .tile-mod { top: 3px; left: 3px; gap: 3px; }
  /* Der Kopf über dem geteilten Bild: so niedrig wie möglich */
  .stage-head { min-height: 34px; padding: 2px 4px 2px 10px; font-size: 12.5px; }
  .stage-head .icon-btn { width: 34px; height: 34px; }
  .stage-tools .small { padding: 6px 10px; font-size: 12.5px; }
  /* Zu zweit ohne Bühne: das eigene Bild quer statt hochkant in der Ecke */
  #call:not(.has-stage) #people.duo .tile[data-key="me"] { width: min(24%, 150px); aspect-ratio: 4 / 3; }

  /* Leiste: eine Zeile – links die Stundenuhr, in der Mitte die Knöpfe, rechts Material, Notizen, Einstellungen */
  /* (Die Knöpfe stehen mittig, solange rechts und links gleich viel Platz ist; wird es eng, weicht die linke Seite.) */
  #bar { grid-template: auto / minmax(0, 1fr) auto minmax(max-content, 1fr); gap: 0 8px; padding: 4px 10px 6px; }
  .bar-left { grid-area: 1 / 1; }
  .bar-center { grid-area: 1 / 2; justify-self: center; gap: 8px; }
  .bar-right { grid-area: 1 / 3; }
  .bar-left > *, .bar-right > * { margin-bottom: 0; }
  .bar-center .ctl { width: 40px; height: 40px; }
  .bar-center .ctl.leave { width: 56px; }
  .bar-center .ctl::after { content: none; }
  #clock, .bar-left .sep, #room-code, #people-pill { display: none; }
  .bar-right .pill { padding: 6px 10px; font-size: 12.5px; }
  .call-waiting, #call:not(.has-stage) #people.duo ~ * .call-waiting { bottom: 58px; }
  /* Mit offenem Chat ist der Platz neben ihm schmal: Stundenuhr und Material stehen dann wieder über den Knöpfen. */
  #room:not(.chat-closed) #call.has-stage #people { flex-basis: 88px; }
  #room:not(.chat-closed) #bar { grid-template: auto auto / minmax(0, 1fr) auto; }
  #room:not(.chat-closed) .bar-right { grid-area: 1 / 2; }
  #room:not(.chat-closed) .bar-center { grid-area: 2 / 1 / 3 / 3; }
  #room:not(.chat-closed) .bar-left > *, #room:not(.chat-closed) .bar-right > * { margin-bottom: 4px; }
}

/* ---------- Führung durch eine Ansicht (tour.js) ---------- */
/* Ein durchsichtiger Dialog über der ganzen Seite: darin der Rahmen um das erklärte Element – sein riesiger
   Schatten dunkelt alles andere ab – und die Karte mit der Erklärung. */
#tour {
  position: fixed; inset: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border-radius: 0; background: transparent; overflow: hidden;
}
#tour::backdrop { background: transparent; }
.tour-hole {
  position: absolute; border-radius: 10px;
  outline: 2px solid var(--accent);
  box-shadow: 0 0 0 200vmax rgba(8, 10, 14, .7);
  transition: left .24s ease, top .24s ease, width .24s ease, height .24s ease;
}
#tour.centered .tour-hole { outline: 0; }
.tour-card {
  position: absolute; box-sizing: border-box; width: min(360px, calc(100vw - 24px));
  padding: 16px 18px 14px; border-radius: 16px;
  background: var(--surface); color: var(--fg);
  box-shadow: 0 12px 44px rgba(0, 0, 0, .6), 0 0 0 1px #2f3745;
  transition: left .24s ease, top .24s ease;
}
.tour-count { margin: 0 0 4px; font-size: 12px; color: var(--muted); }
dialog p.tour-count { margin: 0 0 4px; }
#tour h2 { margin: 0 34px 6px 0; font-size: 17px; font-weight: 600; }
dialog p.tour-text { margin: 0 0 12px; font-size: 14.5px; line-height: 1.5; color: var(--fg); }
.tour-close { position: absolute; top: 8px; right: 8px; }
/* Läuft die Führung von allein, füllt sich der Balken bis zum nächsten Schritt. */
.tour-progress { height: 3px; margin: 0 0 10px; border-radius: 2px; background: #2a313d; overflow: hidden; visibility: hidden; }
#tour.playing .tour-progress { visibility: visible; }
#tour-bar { display: block; width: 0; height: 100%; background: var(--accent); }
#tour-bar.running { transition: width linear; }
.tour-actions { display: flex; align-items: center; gap: 8px; }
.tour-actions .primary, .tour-actions .ghost { padding: 9px 16px; }
.tour-keys { font-size: 12px; color: var(--muted); white-space: nowrap; }
@media (pointer: coarse) {
  .tour-keys { display: none; }
}
/* Knopf, der die Führung startet */
.tour-btn { display: inline-flex; align-items: center; gap: 6px; }
.tour-icon { display: inline-flex; }
.tour-icon svg { width: 18px; height: 18px; }
@media (max-width: 900px) {
  .tour-btn > span:not(.tour-icon) { display: none; }
}
