:root {
  --bg-app:    #0e1015;
  --bg-rail:   #15171e;
  --bg-main:   #1a1c24;
  --bg-elev:   #21242e;
  --bg-input:  #0f1116;
  --border:    #2a2f3a;
  --border-soft:#20242e;
  --text:      #e7e9ef;
  --text-dim:  #98a0af;
  --text-faint:#666e7d;
  --accent:    #5b6ef5;
  --accent-hi: #7183f8;
  --success:   #3ba55d;
  --danger:    #e2504f;
  --radius:    10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg-app);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; cursor: pointer; color: var(--text); border: 0; background: none; }
input { font: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--text-dim); }
.error { color: var(--danger); font-size: 13px; min-height: 1.1em; margin: 0; }

.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #8a63f0);
  display: grid; place-items: center;
  font-weight: 700; font-size: 20px; color: #fff;
}
.brand-mark.sm { width: 28px; height: 28px; border-radius: 8px; font-size: 14px; }

/* ---------- Anmelde-Overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1c2030, var(--bg-app));
}
.login-card {
  width: min(380px, 100%);
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  display: flex; flex-direction: column; gap: 12px; align-items: stretch;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}
.login-card h1 { margin: 6px 0 0; font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
.login-card p { margin: 0 0 6px; font-size: 13.5px; }
.login-card input {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px 13px; color: var(--text); width: 100%;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.login-card button[type="submit"] {
  background: var(--accent); color: #fff; font-weight: 600;
  border-radius: var(--radius); padding: 11px 14px; transition: background 0.15s;
}
.login-card button[type="submit"]:hover { background: var(--accent-hi); }
.login-card button[disabled] { opacity: 0.6; cursor: progress; }

/* ---------- Shell ---------- */
.shell {
  height: 100vh; height: 100dvh;
  display: grid; grid-template-columns: 260px 1fr;
  background: var(--bg-main);
}

/* ---------- Rail ---------- */
.rail {
  background: var(--bg-rail);
  border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; min-height: 0;
}
.rail-head {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 16px; border-bottom: 1px solid var(--border-soft);
}
.rail-title { font-weight: 650; letter-spacing: -0.01em; }
.channels {
  flex: 1 1 auto; overflow-y: auto; min-height: 64px;
  padding: 12px 10px; display: flex; flex-direction: column; gap: 2px;
}
.channels button {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 8px; color: var(--text-dim); font-size: 14.5px;
}
.channels button:hover { background: var(--bg-elev); color: var(--text); }
.channels button[aria-current="true"] { background: var(--bg-elev); color: var(--text); font-weight: 600; }
.channels .ch-hash { color: var(--text-faint); }
.rail-presence {
  flex: 0 1 auto; overflow-y: auto; max-height: 36vh;
  padding: 12px 16px; border-top: 1px solid var(--border-soft);
}
.rail-h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-faint); margin: 0 0 8px; display: flex; gap: 6px; align-items: center;
}
.count { background: var(--bg-elev); border-radius: 999px; padding: 0 6px; font-size: 10px; }
.presence-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.presence-list li {
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px; color: var(--text-dim); min-width: 0;
}
.presence-list li span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-foot {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-top: 1px solid var(--border-soft); background: var(--bg-app);
}
.me-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; font-weight: 600; }
.ghost { color: var(--text-dim); font-size: 12.5px; padding: 6px 8px; border-radius: 6px; }
.ghost:hover { background: var(--bg-elev); color: var(--danger); }

.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700; flex: none;
}
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }

/* ---------- Content ---------- */
.content { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.topbar {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px; height: 52px;
  border-bottom: 1px solid var(--border-soft); background: var(--bg-main);
}
.topbar-hash { color: var(--text-faint); }
.topbar-channel { font-weight: 650; }
.spacer { flex: 1; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.dot.on { background: var(--success); }

.btn-voice {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 14px; font-size: 13.5px; font-weight: 600; color: var(--text);
}
.btn-voice:hover { border-color: var(--accent); }
.btn-voice.live { background: var(--success); border-color: transparent; color: #fff; }
.btn-voice[disabled] { opacity: 0.6; cursor: progress; }
.icon-btn {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 600; color: var(--text-dim);
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

.menu-btn {
  display: none; width: 34px; height: 34px; border-radius: 8px; position: relative;
  background: var(--bg-elev); border: 1px solid var(--border); flex: none;
}
.menu-btn span, .menu-btn span::before, .menu-btn span::after {
  content: ""; position: absolute; left: 8px; width: 16px; height: 2px;
  background: var(--text); border-radius: 2px;
}
.menu-btn span { top: 16px; }
.menu-btn span::before { top: -5px; }
.menu-btn span::after { top: 5px; }

/* ---------- Sprachkanal-Panel ---------- */
.voicepanel {
  flex: none;
  display: flex; flex-direction: column; max-height: 42vh;
  border-bottom: 1px solid var(--border-soft); background: var(--bg-main);
}
.vp-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px;
}
.vp-title { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-faint); }
.vp-controls { margin-left: auto; display: flex; gap: 8px; }
.vp-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px;
  background: var(--bg-elev); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 12.5px; font-weight: 600;
}
.vp-btn:hover { color: var(--text); border-color: var(--accent); }
.vp-btn svg { width: 15px; height: 15px; flex: none; }
.vp-btn.on {
  background: rgba(226, 80, 79, 0.14);
  border-color: var(--danger); color: var(--danger);
}
.vp-btn.danger { color: var(--danger); }
.vp-btn.danger:hover { background: rgba(226, 80, 79, 0.14); border-color: var(--danger); }

.vp-tiles {
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 4px 16px 16px; overflow-y: auto;
}
.tile {
  width: 100px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 6px; border-radius: 12px;
  background: var(--bg-elev); border: 1px solid var(--border-soft);
}
.tile-av {
  position: relative; width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-size: 22px; font-weight: 700;
  box-shadow: 0 0 0 0 rgba(59, 165, 93, 0); transition: box-shadow 0.12s ease;
}
.tile.speaking .tile-av { box-shadow: 0 0 0 3px var(--success); }
.tile.muted .tile-av { box-shadow: 0 0 0 2px var(--danger); }
.tile-badge {
  position: absolute; right: -2px; bottom: -2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--bg-elev);
  display: grid; place-items: center;
}
.tile-badge svg { width: 11px; height: 11px; stroke: #fff; }
.tile-name {
  font-size: 12.5px; color: var(--text); max-width: 96px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (max-width: 480px) {
  .vp-btn .lbl { display: none; }
}

/* ---------- Nachrichten ---------- */
.messages {
  flex: 1 1 auto;
  list-style: none; margin: 0; padding: 16px; overflow-y: auto; min-height: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.msg { display: grid; grid-template-columns: 38px 1fr; gap: 10px; padding: 1px 0; }
.msg.head { margin-top: 12px; }
.msg-body { min-width: 0; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-author { font-weight: 650; font-size: 14px; }
.msg-time { font-size: 11px; color: var(--text-faint); }
.msg-text { font-size: 14.5px; color: var(--text); overflow-wrap: anywhere; }
.msg-empty { margin: auto; color: var(--text-faint); font-size: 13.5px; text-align: center; }

/* ---------- Composer ---------- */
.composer {
  flex: none;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-soft); background: var(--bg-main);
}
.composer input {
  flex: 1; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 14px; color: var(--text);
}
.composer input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.composer button {
  background: var(--accent); color: #fff; font-weight: 600; border-radius: 10px; padding: 0 18px;
}
.composer button:hover { background: var(--accent-hi); }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 20; }

/* ---------- Einstellungen (Dialog) ---------- */
.iconbtn {
  flex: none; display: inline-flex; padding: 6px; border-radius: 6px;
  background: none; border: 0; color: var(--text-dim); cursor: pointer;
}
.iconbtn:hover { color: var(--text); background: var(--bg-elev); }
.iconbtn svg { width: 16px; height: 16px; }

.dlg {
  border: 0; padding: 0; background: transparent;
  max-width: 440px; width: calc(100% - 32px);
  color: var(--text);
}
.dlg::backdrop { background: rgba(0, 0, 0, 0.55); }
.dlg-inner {
  background: var(--bg-main); border: 1px solid var(--border); border-radius: 14px;
  padding: 22px; display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}
.dlg-head { display: flex; align-items: center; }
.dlg-head h2 { margin: 0; font-size: 16px; font-weight: 650; }
.dlg-x {
  margin-left: auto; background: none; border: 0; cursor: pointer;
  color: var(--text-dim); padding: 4px; border-radius: 6px;
}
.dlg-x:hover { color: var(--text); background: var(--bg-elev); }
.dlg-x svg { width: 18px; height: 18px; display: block; }

.fld { display: flex; flex-direction: column; gap: 6px; }
.fld-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-faint);
}
.dlg select {
  font: inherit; background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; width: 100%;
}
.dlg select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.dlg select:disabled { opacity: 0.5; }

.mictest { display: flex; align-items: center; gap: 10px; }
.mini-btn {
  flex: none; background: var(--bg-elev); border: 1px solid var(--border);
  color: var(--text-dim); border-radius: 8px; padding: 7px 12px;
  font-size: 12.5px; font-weight: 600; cursor: pointer; align-self: flex-start;
}
.mini-btn:hover { color: var(--text); border-color: var(--accent); }
.mini-btn.active { color: var(--success); border-color: var(--success); }
.meter {
  flex: 1; height: 8px; border-radius: 999px; overflow: hidden;
  background: var(--bg-input); border: 1px solid var(--border);
}
.meter-fill { height: 100%; width: 0%; background: var(--success); transition: width 0.06s linear; }
.fld-note { margin: 0; font-size: 12px; color: var(--text-faint); }

/* ---------- Mobil ---------- */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed; top: 0; bottom: 0; left: 0; width: 280px; z-index: 30;
    transform: translateX(-100%); transition: transform 0.22s ease;
    border-right: 1px solid var(--border);
  }
  .rail.open { transform: none; }
  .menu-btn { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  .rail, .tile-av, .meter-fill { transition: none; }
}
