:root {
  --bg: #0f1115;
  --bg-2: #161a21;
  --card: #1b2029;
  --card-2: #222834;
  --line: #2c3341;
  --text: #e8ebf1;
  --muted: #8c95a6;
  --accent: #5865f2;
  --accent-2: #7984ff;
  --ok: #3ccf7e;
  --warn: #f4b740;
  --err: #f0566a;
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f8;
    --bg-2: #ffffff;
    --card: #ffffff;
    --card-2: #f0f2f7;
    --line: #e1e4ec;
    --text: #151821;
    --muted: #677084;
    --accent: #4752e0;
    --accent-2: #5865f2;
    --ok: #18a35a;
    --warn: #c98a0b;
    --err: #d33a50;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.small { font-size: 13px; }

/* ---------- Login ---------- */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 22px;
  text-align: center;
}
.login-card img { width: 64px; height: 64px; }
.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 20px; }
.notice {
  text-align: left;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 18px;
  background: color-mix(in srgb, var(--err) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--err) 40%, transparent);
  font-size: 14px;
}
.notice code { word-break: break-all; }

/* ---------- Buttons & Inputs ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card-2);
  border-radius: 10px;
  padding: 9px 14px;
  min-height: 40px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  text-decoration: none;
  color: var(--text);
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--err); }
.btn.danger.solid { background: var(--err); border-color: var(--err); color: #fff; }
.btn.block { width: 100%; }
.btn.lg { min-height: 48px; font-weight: 600; font-size: 16px; }
.btn.sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  border-radius: 10px;
  outline: none;
}
.input:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 17px; margin: 0; flex: 1; }
.topbar .avatar { width: 30px; height: 30px; }
.live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.live-dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }

main {
  max-width: 820px;
  margin: 0 auto;
  padding: 14px 16px calc(var(--nav-h) + var(--safe-b) + 20px);
}
.view { display: none; }
.view.active { display: block; }

nav.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--bg-2);
  border-top: 1px solid var(--line);
}
nav.tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
  position: relative;
}
nav.tabs a svg { width: 23px; height: 23px; }
nav.tabs a.active { color: var(--accent-2); }
nav.tabs .badge {
  position: absolute;
  top: 7px;
  left: calc(50% + 6px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--err);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

@media (min-width: 900px) {
  nav.tabs {
    top: 0; bottom: 0; right: auto;
    width: 92px;
    height: auto;
    grid-template-columns: 1fr;
    grid-auto-rows: 74px;
    align-content: start;
    padding-top: 70px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }
  .topbar, main { margin-left: 92px; }
  main { padding-bottom: 30px; }
}

/* ---------- Cards ---------- */
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 18px 2px 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.section-title:first-child { margin-top: 2px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.card + .card { margin-top: 10px; }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stats { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  text-decoration: none;
  color: var(--text);
}
.stat .n { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); }
.status-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.status-head h3 { margin: 0; font-size: 16px; flex: 1; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--card-2);
  color: var(--muted);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.pill.err { color: var(--err); background: color-mix(in srgb, var(--err) 14%, transparent); }
.pill.plain::before { display: none; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 12px; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

/* ---------- Listen ---------- */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.item + .item { border-top: 1px solid var(--line); }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.item .actions { display: flex; gap: 6px; flex: none; }
.avatar { width: 40px; height: 40px; border-radius: 10px; flex: none; background: var(--card-2); image-rendering: pixelated; }
.avatar.round { border-radius: 50%; image-rendering: auto; }
.empty { padding: 26px 14px; text-align: center; color: var(--muted); }
.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--card-2);
  color: var(--muted);
  vertical-align: 1px;
}
.tag.accent { color: var(--accent-2); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.tag.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); }
.tag.err { color: var(--err); background: color-mix(in srgb, var(--err) 16%, transparent); }

.segmented {
  display: flex;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
  margin-bottom: 12px;
  overflow-x: auto;
}
.segmented button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  font-size: 14px;
}
.segmented button.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .15); }

/* ---------- Chat & Log ---------- */
.feed {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  height: calc(100dvh - 300px);
  min-height: 260px;
  overflow-y: auto;
  padding: 8px 0;
  overscroll-behavior: contain;
}
.line { padding: 3px 12px; font-size: 13.5px; overflow-wrap: anywhere; }
.line .t { color: var(--muted); font-size: 11px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.line.system { color: var(--text); }
.line.chat .who { color: var(--accent-2); }
.line.game_info { color: var(--muted); font-style: italic; }
.line.self { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.line.WARN { color: var(--warn); }
.line.ERROR { color: var(--err); }
.line .scope { color: var(--muted); margin-right: 6px; }
.composer {
  position: sticky;
  bottom: calc(var(--nav-h) + var(--safe-b) + 8px);
  margin-top: 10px;
}
@media (min-width: 900px) { .composer { bottom: 12px; } }
.chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 8px; scrollbar-width: none; }
.chips button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.jump {
  position: absolute;
  right: 12px;
  top: -44px;
}

/* ---------- Formulare ---------- */
.field { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 14px; }
.field + .field { border-top: 1px solid var(--line); }
.field label { flex: 1; font-size: 14px; }
.field .changed { color: var(--warn); font-size: 12px; display: block; }
.field input[type="number"] { width: 130px; text-align: right; }
.field.wide { flex-direction: column; align-items: stretch; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 14px; background: var(--line); transition: .15s; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
.sticky-actions {
  position: sticky;
  bottom: calc(var(--nav-h) + var(--safe-b) + 8px);
  margin-top: 14px;
  padding: 12px 0 4px;
  display: flex;
  gap: 8px;
  background: linear-gradient(to bottom, transparent, var(--bg) 35%);
}
@media (min-width: 900px) { .sticky-actions { bottom: 12px; } }

/* ---------- Dialog & Toast ---------- */
dialog {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  color: var(--text);
  padding: 20px;
  width: min(420px, calc(100% - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / .55); }
dialog h3 { margin: 0 0 8px; }
dialog p { margin: 0 0 14px; color: var(--muted); }
dialog .check { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
dialog .check input { width: 20px; height: 20px; }
dialog .row { justify-content: flex-end; }

.toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 14px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100% - 32px));
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--bg);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .25);
  animation: pop .18s ease-out;
}
.toast.err { background: var(--err); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 900px) { .toasts { bottom: 24px; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Abstände (keine Inline-Styles wegen CSP) ---------- */
.mb8 { margin-bottom: 8px; }
.mb12 { margin-bottom: 12px; }
.mt10 { margin: 10px 0 0; }
.ml6 { margin-left: 6px; }
.spacer { height: 10px; }
.stack { display: grid; gap: 8px; }
