:root {
  --bg: #0a0a0a;
  --card: #1a1a1a;
  --border: #2e2e2e;
  --text: #e4e4e4;
  --muted: #8a8a8a;
  --accent: #00c37a;
  --danger: #ff5a5a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  font-family: inherit;
  font-size: 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #202020;
  color: var(--text);
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #292929; border-color: #444; }
.btn-ghost { background: transparent; }
.btn-primary { background: var(--accent); color: #06150f; border-color: transparent; font-weight: 600; }
.btn-primary:hover { opacity: 0.88; background: var(--accent); }
.btn-icon { padding: 4px 9px; font-size: 0.95rem; line-height: 1; }

.exit-theater-btn {
  position: fixed;
  top: 10px; right: 10px;
  z-index: 1000;
  padding: 7px 13px;
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.65);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  opacity: 0;
  transition: opacity 0.2s, background 0.15s;
}
.exit-theater-btn:hover { opacity: 1; background: rgba(255,255,255,0.14); }
body.theater-mode .exit-theater-btn:not([hidden]) { opacity: 0.35; }
body.theater-mode .exit-theater-btn:not([hidden]):hover { opacity: 1; }

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  padding: 8px;
  min-height: 0;
}

.tile {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  min-height: 0;
}

.tile-form {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  z-index: 2;
}
/* Wichtig: NICHT über das HTML-"hidden"-Attribut steuern - ein "display"-Wert
   in einer Klassenregel gewinnt in der Kaskade immer gegen die
   User-Agent-Regel "[hidden]{display:none}", egal welche Spezifität.
   Ergebnis war: das Formular blieb trotz hidden=true sichtbar UND klickbar
   und hat jeden Klick auf das darunterliegende Video abgefangen - deshalb
   reagierten weder Ton-Button noch die YouTube-eigenen Regler. */
.tile.loaded .tile-form { display: none; }
.tile:not(.loaded) .tile-form { display: flex; }

.tile-form label {
  font-size: 0.78rem;
  color: var(--muted);
  max-width: 380px;
}

.tile-form-row {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 420px;
}

.tile-input {
  flex: 1;
  min-width: 0;
  background: #111;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.85rem;
}
.tile-input:focus { outline: none; border-color: var(--accent); }

/* Video/Website füllt die komplette Kachel aus - ebenfalls klassenbasiert
   statt über [hidden], aus demselben Grund wie bei .tile-form. */
.tile-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: none;
  transform-origin: 50% 50%;
}
.tile.loaded .tile-frame { display: block; }

/* Kontrollleiste liegt ÜBER dem iframe (Overlay), statt Platz wegzunehmen -
   und ist standardmäßig unsichtbar, nur bei Hover/Fokus eingeblendet.
   Bewusst als kompaktes Element oben LINKS statt als voller Balken: die
   nativen YouTube-Regler (Lautstärke/Einstellungen/CC/Vollbild) sitzen
   oben rechts - eine Leiste über die volle Breite hätte sie verdeckt.
   display wird über .loaded gesteuert, die Ein-/Ausblendung selbst nur
   noch über opacity (die immer neu berechnet wird, sobald der Klick auf
   "Laden" den Fokus korrekt verliert - siehe app.js: .blur()). */
.tile-bar {
  position: absolute;
  top: 8px; left: 8px;
  z-index: 3;
  display: none;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 70px);
  padding: 5px 8px;
  background: rgba(0,0,0,0.65);
  border-radius: 7px;
  font-size: 0.78rem;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
}
.tile.loaded .tile-bar { display: flex; }

.tile.loaded:hover .tile-bar,
.tile.loaded:focus-within .tile-bar {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.tile-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
  color: rgba(255,255,255,0.75);
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.tile-bar-actions { display: flex; gap: 6px; flex-shrink: 0; }
.tile-bar .btn-icon {
  background: rgba(20,20,20,0.75);
  border-color: rgba(255,255,255,0.15);
}
.tile-bar .btn-icon:hover { background: rgba(40,40,40,0.9); }
.tile-mute.is-unmuted { border-color: var(--accent); color: var(--accent); }

/* Theatermodus: kein Header, keine Abstände, keine Rahmen - reine Kachelwand */
body.theater-mode .topbar { display: none; }
body.theater-mode .grid { gap: 0; padding: 0; }
body.theater-mode .tile { border: none; border-radius: 0; }

@media (max-width: 700px) {
  .grid { grid-template-columns: 1fr; grid-template-rows: repeat(4, 1fr); }
}
