:root {
  --bg: #0e1116;
  --panel: #1a212b;
  --text: #e8edf4;
  --muted: #93a1b3;
  --accent: #3ddc84;
  --danger: #e0564f;
  --border: #2b3646;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

h1 { font-size: 1.25rem; flex-shrink: 0; }

.chip {
  font-size: 0.8rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  white-space: nowrap;
  max-width: 55vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

main, section {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 18px;
}

/* Zuschauer-Modus: volle Fensterbreite und -höhe fürs Grid */
#viewUI {
  max-width: none;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px 12px;
}

#viewUI[hidden] { display: none; }

#viewLive {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#viewLive[hidden] { display: none; }

.intro { color: var(--muted); margin-bottom: 18px; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  touch-action: manipulation;
}

button:active { transform: scale(0.98); }

button.big {
  display: block;
  width: 100%;
  padding: 20px;
  font-size: 1.2rem;
  margin-bottom: 14px;
  text-align: left;
}

button.big small {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

button.go { background: #14351f; border-color: #2c6e43; text-align: center; }
button.danger { background: #3a1a18; border-color: #7a332e; }

.btnrow {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin: 12px 0;
}

.row { margin-bottom: 14px; }

label { display: block; color: var(--muted); font-size: 0.9rem; margin-bottom: 6px; }
label.inline { display: flex; align-items: center; gap: 8px; font-size: 1rem; color: var(--text); }
input[type="checkbox"] { width: 20px; height: 20px; }

input[type="text"],
input[type="password"],
select {
  font: inherit;
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 220, 132, 0.15);
}

input::placeholder { color: #56657a; }

/* --- Login-Karte --- */
#loginUI {
  display: flex;
  justify-content: center;
  padding-top: max(4vh, 18px);
}

#loginUI[hidden] { display: none; }

.logincard {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, #1d2530, var(--panel));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 26px 22px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.45);
}

.loginhead { text-align: center; margin-bottom: 22px; }

.loginhead .loginicon {
  font-size: 2.6rem;
  line-height: 1;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 14px rgba(61, 220, 132, 0.35));
}

.loginhead h2 { font-size: 1.35rem; letter-spacing: 0.02em; }

.loginhead p { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }

.logincard .row { margin-bottom: 16px; }

.logincard input { background: #10161e; }

#loginCode {
  text-align: center;
  font-size: 1.35rem;
  letter-spacing: 0.45em;
  font-variant-numeric: tabular-nums;
}

#loginCode::placeholder { letter-spacing: 0.45em; }

.pwwrap { position: relative; }

.pwwrap input { padding-right: 50px; }

.pweye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  padding: 6px 10px;
  font-size: 1.05rem;
  opacity: 0.7;
}

.pweye:hover, .pweye.aktiv { opacity: 1; }

.loginbtn {
  text-align: center;
  margin-top: 4px;
  background: linear-gradient(180deg, #1b4a2b, #14351f);
  border-color: #2c6e43;
  box-shadow: 0 6px 18px rgba(61, 220, 132, 0.15);
}

.loginbtn:hover { border-color: var(--accent); }

#loginError { text-align: center; min-height: 1.2em; margin-top: 12px; }

.status { color: var(--muted); font-size: 0.95rem; margin: 10px 0; }

.help { margin-top: 24px; color: var(--muted); }
.help summary { cursor: pointer; padding: 8px 0; }
.help ul { padding: 8px 0 0 20px; display: grid; gap: 8px; font-size: 0.92rem; }

#camPreview {
  width: 100%;
  max-height: 60vh;
  background: #000;
  border-radius: 12px;
  border: 1px solid var(--border);
}

#grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr; /* wird von relayout() je nach Kamera-Anzahl gesetzt */
  gap: 10px;
  margin-top: 4px;
}

.tile {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; }

.tile .label {
  position: absolute;
  left: 8px; top: 8px;
  background: rgba(0,0,0,0.55);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
}

.tile .state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 12px;
  color: var(--muted);
  background: rgba(14,17,22,0.85);
  font-size: 0.9rem;
}

.tile .state[hidden] { display: none; }

.tile .tools {
  position: absolute;
  right: 8px; bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.tile .tileinfo {
  position: absolute;
  right: 8px; top: 8px;
  background: rgba(0, 0, 0, 0.55);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.tile .tileinfo[hidden] { display: none; }
.tile .tileinfo.ok::before { content: '● '; color: var(--accent); }
.tile .tileinfo.mid::before { content: '● '; color: #e8b34b; }
.tile .tileinfo.bad::before { content: '● '; color: var(--danger); }

.tile .tools button { padding: 6px 10px; font-size: 0.9rem; background: rgba(0,0,0,0.55); touch-action: none; user-select: none; -webkit-user-select: none; }

.tile .tools button.talking {
  background: var(--danger);
  border-color: #ff8a80;
  box-shadow: 0 0 10px rgba(224, 86, 79, 0.7);
}

.tile .tools button.torch-on {
  background: #6b5b1e;
  border-color: #e8b34b;
  box-shadow: 0 0 10px rgba(232, 179, 75, 0.6);
}

/* Einheitlicher Aktiv-Zustand für alle Schalter (grün = an) —
   Ausnahmen: Taschenlampe leuchtet gelb (torch-on), Sprechen rot (talking) */
button.wide-on,
button.on {
  background: #14351f;
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(61, 220, 132, 0.45);
}

.tile .tools select.qsel {
  font: inherit;
  font-size: 0.85rem;
  width: auto;
  padding: 5px 6px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,12,16,0.96);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  padding: 24px;
  z-index: 50;
}

.overlay[hidden] { display: none; }

#blackout {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 40px;
}

#blackout[hidden] { display: none; }

#blackout p { color: #222; font-size: 0.85rem; }

.warn { color: #e8b34b; }
.ok { color: var(--accent); }

.settingsH { font-size: 1.05rem; margin: 26px 0 6px; }
#settingsUI a { color: var(--accent); word-break: break-all; }
#settingsUI button { margin-top: 4px; }

code {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 6px;
  word-break: break-all;
}
