:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #15171c;
  --muted: #646a78;
  --border: #e1e4ec;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --mine: #4f46e5;
  --mine-text: #ffffff;
  --theirs: #eef0f6;
  --danger: #d92d3a;
  --ok: #16a34a;
  --shadow: 0 6px 24px rgba(20, 22, 40, 0.08);
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #222632;
    --text: #eceef3;
    --muted: #9aa1b2;
    --border: #2a2f3b;
    --accent: #7c74ff;
    --mine: #6359f0;
    --theirs: #242936;
    --danger: #ff5d68;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

.screen { min-height: 100dvh; }

/* ---------- entry ---------- */
.entry { display: grid; place-items: center; padding: 24px 16px; }
.entry-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 24px; padding: 28px 22px; box-shadow: var(--shadow);
}
.logo { font-size: 40px; line-height: 1; }
h1 { margin: 12px 0 6px; font-size: 28px; letter-spacing: -0.02em; }
.lead { margin: 0 0 22px; color: var(--muted); }
.field { display: grid; gap: 6px; margin-bottom: 16px; font-weight: 600; font-size: 14px; }
.field input, .composer input, select, textarea {
  width: 100%; font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface-2); border: 1px solid transparent; border-radius: 12px;
  padding: 12px 14px; outline: none;
}
.field input:focus, .composer input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }
.rules { font-size: 13px; color: var(--muted); margin: 14px 0 18px; }
.error { color: var(--danger); font-size: 14px; margin: -6px 0 14px; }
.legal-links { margin-top: 18px; text-align: center; font-size: 13px; color: var(--muted); }
.legal-links a, .legal a { color: inherit; }

/* ---------- Impressum / Datenschutz ---------- */
.legal { max-width: 720px; margin: 0 auto; padding: 24px 16px 48px; line-height: 1.55; }
.legal h1 { font-size: 26px; }
.legal h2 { font-size: 18px; margin: 26px 0 8px; }
.legal p, .legal li { color: var(--text); }
.legal .muted { color: var(--muted); font-size: 14px; }
.legal .back { display: inline-block; margin-bottom: 8px; font-size: 14px; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; cursor: pointer;
  background: var(--surface-2); transition: transform .05s, opacity .15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.wide, #join-btn { width: 100%; }
.btn.small { padding: 7px 11px; font-size: 14px; }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.danger { color: var(--danger); }
.btn.danger-bg { background: var(--danger); }
.icon-btn { border: 0; background: transparent; font-size: 24px; width: 38px; height: 38px; border-radius: 10px; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- app ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
}
.brand { font-weight: 800; letter-spacing: -0.02em; font-size: 20px; }
.me { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }
.pill { background: var(--surface-2); border-radius: 99px; padding: 3px 10px; font-size: 13px; }
.pill::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 6px; vertical-align: 1px; }
.banner { margin: 0 16px 8px; padding: 10px 12px; border-radius: 12px; background: var(--danger); color: #fff; font-size: 14px; }

.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 10px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 99px;
  padding: 7px 14px; font-size: 14px; font-weight: 600; cursor: pointer; position: relative; max-width: 160px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tab[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.tab.unread::after { content: ""; position: absolute; top: 4px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.tab.ended { opacity: .55; }

.view { flex: 1; min-height: 0; }
.people { overflow-y: auto; padding: 4px 16px 24px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; }
.people-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.people-list:empty { display: none; }
.person { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--border); cursor: pointer; }
.person:first-child { border-top: 0; }
.person:hover { background: var(--surface-2); }
.avatar { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; }
.person .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .go { color: var(--accent); font-weight: 600; font-size: 14px; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }

.chat { display: flex; flex-direction: column; background: var(--surface); border-top: 1px solid var(--border); }
.chat-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.chat-peer { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 14px 12px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 80%; padding: 9px 13px; border-radius: 18px; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; }
.bubble.theirs { align-self: flex-start; background: var(--theirs); border-bottom-left-radius: 6px; }
.bubble.mine { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 6px; }
.bubble.pending { opacity: .6; }
.notice { align-self: center; font-size: 13px; color: var(--muted); background: var(--surface-2); padding: 5px 12px; border-radius: 99px; text-align: center; max-width: 90%; }
.notice.bad { color: var(--danger); }
.composer { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.composer input { flex: 1; }

/* ---------- dialog + toast ---------- */
.dialog { border: 0; border-radius: 20px; padding: 22px; width: min(92vw, 380px); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog h3 { margin: 0 0 6px; }
.dialog .muted { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.dialog select, .dialog textarea { margin-bottom: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px); z-index: 10;
}

/* ---------- admin ---------- */
.admin { max-width: 900px; margin: 0 auto; padding: 20px 16px 40px; }
.admin h1 { font-size: 24px; }
.admin .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.admin .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.admin .row .grow { flex: 1; min-width: 160px; }
.admin .meta { color: var(--muted); font-size: 13px; }
.admin .lines { margin: 10px 0; padding: 10px; background: var(--surface-2); border-radius: 10px; font-size: 14px; list-style: none; }
.admin .lines li { padding: 2px 0; }
.admin .handled { opacity: .55; }
.admin input[type=password] { width: 100%; font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); margin-bottom: 10px; }
.admin .toolbar { margin-bottom: 12px; }

/* ---------- online count, chat hour, empty room ---------- */
.room-info { margin: -8px 0 20px; padding: 12px 14px; background: var(--surface-2); border-radius: 12px; display: grid; gap: 4px; }
.room-info p { margin: 0; }
.online-now { font-weight: 600; }
.online-now::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 8px; vertical-align: 1px; }
.online-now.live::before { background: var(--ok); }
.next-hour { font-size: 14px; color: var(--muted); }
.next-hour.on { color: var(--ok); font-weight: 600; }
.empty p { margin: 0 0 10px; }
.share { display: flex; gap: 8px; max-width: 420px; margin: 0 auto; }
.share input { flex: 1; min-width: 0; font: inherit; font-size: 14px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; }
