:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181d;
  --muted: #646a76;
  --border: #dde0e6;
  --accent: #2f6df6;
  --accent-text: #ffffff;
  --danger: #d33a3a;
  --warn: #b7791f;
  --mine: #2f6df6;
  --mine-text: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 8px 24px rgb(0 0 0 / 0.06);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --text: #e8eaee;
    --muted: #9399a5;
    --border: #2b3039;
    --accent: #5b8cff;
    --mine: #3a6ae0;
    --danger: #ef5b5b;
    --warn: #e0a84a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.noscript { padding: 16px; text-align: center; }

/* ---------- Bausteine ---------- */

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.logo {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  position: relative;
}
.logo::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px solid #fff;
  border-radius: 3px;
  border-top-width: 5px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .link:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible, .nick:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }
#dlg-destroy .btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.wide { width: 100%; padding: 12px; }

.link {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
}

.pill {
  font-size: 0.8rem;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
}
.pill.muted { color: var(--muted); }
.pill.warn { color: var(--warn); }

.error { color: var(--danger); margin: 12px 0 0; font-size: 0.92rem; }

/* ---------- Zentrierte Karten ---------- */

.view.center {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}
.card.small { max-width: 280px; text-align: center; }
.card h1 { font-size: 1.45rem; line-height: 1.25; margin: 18px 0 12px; letter-spacing: -0.02em; }
.card p { color: var(--muted); }
.card .btn.wide { margin-top: 8px; }

.facts { list-style: none; padding: 0; margin: 0 0 22px; color: var(--muted); font-size: 0.95rem; }
.facts li { padding-left: 22px; position: relative; margin: 6px 0; }
.facts li::before { content: '✓'; position: absolute; left: 0; color: var(--accent); font-weight: 700; }

.field { display: grid; gap: 6px; margin-bottom: 14px; font-size: 0.9rem; color: var(--muted); }
select, input[type='text'] {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  width: 100%;
  min-width: 0;
}

.spinner {
  width: 28px;
  height: 28px;
  margin: 4px auto 12px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Chat ---------- */

.view.chat {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 860px;
  margin: 0 auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.chat-head .meta { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; min-width: 0; }
.chat-head .actions { display: flex; gap: 8px; }

.share {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
  font-size: 0.92rem;
}
.share p { margin: 0 0 10px; color: var(--muted); }
.share p strong { color: var(--text); }
.share-row { display: flex; gap: 8px; margin-bottom: 8px; }
.share-row input { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 0.82rem; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
}

.empty { color: var(--muted); text-align: center; margin: auto; max-width: 360px; font-size: 0.92rem; }

.msg {
  --h: 220;
  max-width: min(80%, 560px);
  align-self: flex-start;
  background: var(--surface-2);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  padding: 7px 12px 9px;
}
.msg.mine {
  align-self: flex-end;
  background: var(--mine);
  color: var(--mine-text);
  border-radius: var(--radius) 4px var(--radius) var(--radius);
}
.msg.broken { color: var(--muted); font-style: italic; font-size: 0.88rem; }
.msg-head { display: flex; gap: 10px; align-items: baseline; font-size: 0.78rem; margin-bottom: 2px; }
.msg-name { font-weight: 700; color: hsl(var(--h) 60% 45%); }
.msg.mine .msg-name { color: inherit; opacity: 0.85; }
.msg-head time { color: var(--muted); }
.msg.mine .msg-head time { color: inherit; opacity: 0.7; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }

@media (prefers-color-scheme: dark) {
  .msg-name { color: hsl(var(--h) 70% 68%); }
}

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 12px;
  max-height: 160px;
  line-height: 1.4;
}
.nick {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  padding: 10px 4px;
  cursor: pointer;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nick:hover { color: var(--text); }

/* ---------- Dialoge & Hinweise ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(420px, calc(100% - 32px));
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dlg { padding: 22px; }
.dlg h2 { margin: 0 0 8px; font-size: 1.15rem; }
.dlg p { margin: 0 0 16px; color: var(--muted); font-size: 0.93rem; }
.dlg input { margin-bottom: 16px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100% - 32px);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 560px) {
  .card { padding: 22px 18px; }
  .chat-head { padding: 10px 12px; }
  .chat-head .brand { display: none; }
  .chat-head .actions { width: 100%; }
  .chat-head .actions .btn { flex: 1; }
  .view.chat { border: 0; }
  .msg { max-width: 88%; }
  .share-row { flex-wrap: wrap; }
  .share-row input { flex-basis: 100%; }
  .share-row .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  .toast { transition: none; }
}
