/* ===== Grundlayout ===== */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #14161c; color: #e8eaf0; font-size: 15px;
}
.hidden { display: none !important; }
.muted { color: #9aa1b2; }
.small { font-size: 12px; }
.error { color: #ff7676; min-height: 1.2em; margin: 6px 0 0; }
.spacer { flex: 1; }
.row { display: flex; gap: 12px; align-items: center; margin-top: 16px; }

.screen { height: 100%; }
.screen.center { display: flex; align-items: center; justify-content: center; }

.card {
  background: #1e222c; border: 1px solid #2c3140; border-radius: 12px;
  padding: 28px; width: 380px; max-width: 94vw;
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.card.wide { width: 720px; }
.card h1 { margin: 0 0 16px; font-size: 22px; }

label { display: block; margin: 10px 0 4px; color: #b8bfd0; font-size: 13px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid #39405a;
  background: #12141a; color: #e8eaf0; font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #4f8cff55; border-color: #4f8cff; }

.btn {
  cursor: pointer; border: 1px solid #39405a; border-radius: 8px;
  background: #262b38; color: #e8eaf0; padding: 8px 14px; font: inherit; margin-top: 8px;
}
.btn:hover { background: #303748; }
.btn.primary { background: #3568d4; border-color: #3568d4; }
.btn.primary:hover { background: #4478e4; }
.btn.link { background: none; border: none; color: #9aa1b2; text-decoration: underline; }
.btn.small { padding: 4px 10px; font-size: 13px; margin: 0; }
.btn.big { font-size: 17px; padding: 12px 28px; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tab {
  flex: 1; padding: 8px; background: none; border: none; color: #9aa1b2;
  border-bottom: 2px solid transparent; cursor: pointer; font: inherit;
}
.tab.active { color: #fff; border-bottom-color: #4f8cff; }

/* ===== Lobby ===== */
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
#lobby-preview {
  width: 100%; aspect-ratio: 4/3; background: #000; border-radius: 8px; object-fit: cover;
  transform: scaleX(-1);
}
#mic-meter { height: 8px; background: #12141a; border-radius: 4px; margin-top: 8px; overflow: hidden; }
#mic-meter-fill { height: 100%; width: 0%; background: #43d17c; transition: width .08s linear; }
#avatar-preview { display: block; margin: 0 auto 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; display: flex; align-items: center; justify-content: center;
  font-size: 17px; background: #12141a;
}
.swatch.sel { border-color: #fff; }

/* ===== Welt ===== */
#screen-world { display: flex; flex-direction: column; }
#topbar {
  display: flex; align-items: center; gap: 12px; padding: 6px 12px;
  background: #1a1d26; border-bottom: 1px solid #2c3140; flex: 0 0 auto;
}
#topbar .brand { font-weight: 600; }
#topbar select { width: auto; }
#world-main { flex: 1; display: flex; min-height: 0; }

#stage { flex: 1; position: relative; display: flex; flex-direction: column; min-width: 0; }
#map-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  overflow: hidden; min-height: 0; padding: 8px;
}
#canvas { border-radius: 8px; max-width: 100%; max-height: 100%; }

#hint { text-align: center; padding: 2px 0 6px; flex: 0 0 auto; }

/* Videokacheln: Standard = Leiste oben über der Karte */
#video-grid {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; z-index: 5; max-width: 95%; flex-wrap: wrap; justify-content: center;
}
:root { --tile-scale: 1; }
.tile {
  position: relative; width: calc(200px * var(--tile-scale)); aspect-ratio: 4/3; background: #000;
  border-radius: 10px; overflow: hidden; border: 2px solid #2c3140;
  cursor: pointer; transition: width .15s ease;
}
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile.novideo video { display: none; }
.tile .tile-avatar {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: 700; color: #fff;
}
.tile.has-video .tile-avatar { display: none; }
.tile .tile-name {
  position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6);
  padding: 2px 8px; border-radius: 6px; font-size: 12px; z-index: 2;
}
.tile .tile-mic { position: absolute; right: 6px; bottom: 6px; font-size: 13px; z-index: 2; }
.tile.screen { width: calc(320px * var(--tile-scale)); aspect-ratio: 16/9; border-color: #4f8cff; }
.tile.screen video { object-fit: contain; }

/* Angeklickte Kachel → volle Breite; die übrigen rutschen als Leiste darunter */
#video-grid.has-expanded { inset: 8px 8px 64px 8px; position: absolute; transform: none; max-width: none; align-content: flex-start; }
#video-grid .tile.expanded {
  width: 100% !important; height: calc(100% - 170px); aspect-ratio: auto;
  order: -1; flex: 1 1 100%;
}
#video-grid .tile.expanded video { object-fit: contain; }
#video-grid.has-expanded .tile:not(.expanded) { width: calc(140px * var(--tile-scale)); }

/* Vereinfachte Ansicht: Videos groß, Karte klein unten rechts */
body.simplified #video-grid {
  position: absolute; inset: 8px 8px 64px 8px; transform: none;
  align-items: center; align-content: center; max-width: none;
}
/* Vereinfachte Ansicht: Höhe setzt das Auto-Layout (JS), Breite folgt dem
   Seitenverhältnis der Kachel (4:3 Kamera, 16:9 Bildschirm). */
body.simplified #video-grid .tile { width: auto; height: 200px; }
body.simplified #video-grid .tile.screen { width: auto; }
body.simplified #map-wrap {
  position: absolute; right: 12px; bottom: 64px; width: 260px; height: 170px;
  z-index: 6; padding: 0; background: #14161c; border: 1px solid #2c3140;
  border-radius: 8px; opacity: .92;
}
body.simplified #hint { visibility: hidden; }

/* Call-Leiste */
#callbar {
  position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; background: rgba(20,22,28,.85); padding: 8px 12px;
  border-radius: 999px; border: 1px solid #2c3140; z-index: 10;
}
.ctl {
  width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
  background: #262b38; font-size: 19px; color: #fff;
}
.ctl:hover { background: #303748; }
.ctl.off { background: #b33; }
.ctl.on { background: #2c7a4b; }
.ctl.active { background: #3568d4; }

/* ===== Sidebar ===== */
#sidebar {
  width: 320px; flex: 0 0 320px; display: flex; flex-direction: column;
  background: #1a1d26; border-left: 1px solid #2c3140; min-height: 0;
}
body.no-sidebar #sidebar { display: none; }

/* Ungelesen-Badge am Sidebar-Knopf */
#btn-sidebar { position: relative; }
.badge {
  position: absolute; top: -7px; right: -7px;
  background: #e05656; color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; line-height: 16px; text-align: center;
  border-radius: 8px; padding: 0 3px; pointer-events: none;
}
#participants { padding: 10px 12px; border-bottom: 1px solid #2c3140; max-height: 40%; overflow-y: auto; }
#participants h3, #chat h3 { margin: 0 0 8px; font-size: 14px; color: #b8bfd0; }
#participant-list { list-style: none; margin: 0; padding: 0; }
#participant-list li {
  display: flex; align-items: center; gap: 8px; padding: 5px 4px; border-radius: 6px;
}
#participant-list li:hover { background: #232836; }
.p-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.p-name { font-weight: 500; }
.p-zone { color: #9aa1b2; font-size: 12px; }
.p-actions { margin-left: auto; display: flex; gap: 4px; }
.p-actions button {
  background: none; border: none; cursor: pointer; font-size: 14px; padding: 2px 4px;
  border-radius: 4px;
}
.p-actions button:hover { background: #39405a; }

/* ===== Chat ===== */
#chat { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 10px 12px; }
.chat-head { display: flex; align-items: center; gap: 8px; }
.chat-head select { width: auto; flex: 1; padding: 4px 8px; font-size: 13px; }
#chat-messages { flex: 1; overflow-y: auto; margin: 8px 0; min-height: 0; }
.msg { margin-bottom: 8px; word-wrap: break-word; }
.msg .m-head { font-size: 12px; color: #9aa1b2; }
.msg .m-head b { color: #dfe3ee; }
.msg .m-body { white-space: pre-wrap; }
.msg.dm .m-head::after { content: " · privat"; color: #d49af5; }
.msg .m-body a { color: #7db1ff; }
.msg img.m-img { max-width: 100%; max-height: 220px; border-radius: 8px; display: block; margin-top: 4px; cursor: pointer; }
.msg .m-file {
  display: inline-block; margin-top: 4px; padding: 6px 10px; background: #262b38;
  border-radius: 8px; color: #7db1ff; text-decoration: none;
}
.msg .mention { background: #3568d455; border-radius: 4px; padding: 0 3px; }
.msg .m-delete {
  background: none; border: none; cursor: pointer; font-size: 11px; padding: 0 4px;
  opacity: 0; transition: opacity .15s;
}
.msg:hover .m-delete { opacity: .7; }
.msg .m-delete:hover { opacity: 1; }

/* Link-Vorschau-Karte */
.link-preview {
  display: flex; gap: 10px; margin-top: 6px; padding: 8px; text-decoration: none;
  background: #232836; border: 1px solid #39405a; border-left: 3px solid #4f8cff;
  border-radius: 8px; color: inherit; max-width: 100%;
}
.link-preview:hover { background: #2a3040; }
.link-preview img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; flex: 0 0 auto; }
.link-preview .lp-text { min-width: 0; }
.link-preview .lp-title { font-weight: 600; font-size: 13px; color: #dfe3ee; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.link-preview .lp-desc { font-size: 12px; color: #9aa1b2; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin-top: 2px; }
.link-preview .lp-site { font-size: 11px; color: #6d7489; margin-top: 3px; }
#chat-inputrow { display: flex; gap: 6px; align-items: flex-end; }
#chat-input { resize: none; max-height: 120px; }
#btn-attach, #btn-send {
  background: #262b38; border: 1px solid #39405a; border-radius: 8px; color: #fff;
  cursor: pointer; padding: 8px 10px; font-size: 15px; flex: 0 0 auto;
}
#btn-attach:hover, #btn-send:hover { background: #303748; }

/* ===== Toasts & Modal ===== */
#toasts { position: fixed; top: 14px; right: 14px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #262b38; border: 1px solid #39405a; border-left: 4px solid #4f8cff;
  padding: 10px 14px; border-radius: 8px; max-width: 340px; box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.toast.warn { border-left-color: #e0a13c; }
.toast .toast-actions { margin-top: 8px; display: flex; gap: 8px; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: #1e222c; border: 1px solid #2c3140; border-radius: 12px;
  padding: 24px; width: 640px; max-width: 94vw; max-height: 90vh; overflow-y: auto;
}
#admin-users { width: 100%; border-collapse: collapse; font-size: 13px; }
#admin-users td, #admin-users th { padding: 6px 8px; border-bottom: 1px solid #2c3140; text-align: left; }
#admin-users select { width: auto; padding: 3px 6px; }
#admin-invites { font-family: monospace; }
.modal-box.narrow { width: 420px; }

/* Einstellungs-Panel */
#settings-list h3 { margin: 16px 0 6px; font-size: 13px; color: #7db1ff; text-transform: uppercase; letter-spacing: .5px; }
.setting-row {
  display: flex; align-items: center; gap: 14px; padding: 8px 0;
  border-bottom: 1px solid #262b38;
}
.setting-row .setting-text { flex: 1; }
.setting-row label { margin: 0; color: #e8eaf0; font-size: 14px; }
.setting-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: #3568d4; flex: 0 0 auto; }
.setting-row input[type="range"] { width: 140px; flex: 0 0 auto; accent-color: #3568d4; }

/* Status-Emoji in der Teilnehmerliste */
.p-emoji { font-size: 13px; width: 16px; text-align: center; flex: 0 0 auto; }
