:root {
  color-scheme: light dark;
  --bg: #ece5dd;
  --panel: #f7f7f7;
  --bubble-own: #dcf8c6;
  --bubble-other: #ffffff;
  --text: #111;
  --muted: #777;
  --accent: #075e54;
  --danger: #b00020;
  --shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b141a;
    --panel: #111b21;
    --bubble-own: #005c4b;
    --bubble-other: #202c33;
    --text: #e9edef;
    --muted: #8696a0;
    --accent: #00a884;
    --shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

/* HTML hidden-Attribut zwingend respektieren — sonst überschreiben Klassen
   wie .invite-banner mit display: flex die User-Agent-default-display:none. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.center-card {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.card {
  background: var(--panel);
  padding: 2rem;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  width: 100%;
  max-width: 360px;
}

.card h1 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
  color: var(--accent);
}

.card p { margin: 0.25rem 0 1rem; color: var(--muted); font-size: 0.9rem; }

input[type="text"] {
  width: 100%;
  padding: 0.75rem;
  margin: 0.5rem 0;
  border: 1px solid rgba(128, 128, 128, 0.3);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

button {
  width: 100%;
  padding: 0.85rem;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

button:disabled { opacity: 0.6; cursor: not-allowed; }

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 0.5rem;
  min-height: 1.2em;
}

/* Chat layout */
.chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.chat header {
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat header .header-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.chat header .header-btn {
  background: transparent;
  width: auto;
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  color: #fff;
  font-weight: 500;
}

.chat header .header-btn.danger {
  border-color: rgba(255, 180, 180, 0.6);
  color: #ffd6d6;
}

.invite-banner {
  background: #fff3cd;
  color: #5b4400;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  .invite-banner { background: #3a2f00; color: #ffe8a3; }
}

.invite-banner strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.05rem;
  letter-spacing: 0.1em;
}

.invite-expiry { color: var(--muted); margin-left: 0.5rem; font-size: 0.8rem; }

.invite-banner-actions { display: flex; gap: 0.4rem; }

.invite-btn {
  background: rgba(0, 0, 0, 0.08);
  border: 0;
  width: auto;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.85rem;
  color: inherit;
  font-weight: 500;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.bubble {
  max-width: 75%;
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  box-shadow: var(--shadow);
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 0.95rem;
  line-height: 1.3;
}

.bubble .ts {
  font-size: 0.7rem;
  color: var(--muted);
  margin-left: 0.5rem;
  float: right;
  margin-top: 0.25rem;
}

.bubble-own { background: var(--bubble-own); align-self: flex-end; border-bottom-right-radius: 2px; }
.bubble-other { background: var(--bubble-other); align-self: flex-start; border-bottom-left-radius: 2px; }

.system-msg {
  align-self: center;
  background: rgba(128, 128, 128, 0.15);
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border-radius: 12px;
  margin: 0.5rem 0;
}

/* Pergament-Hinweis nach Wipe — Marauder's-Map-Feeling */
.parchment {
  align-self: stretch;
  margin: 1rem 0.5rem;
  padding: 1.75rem 1.5rem;
  background:
    radial-gradient(ellipse at top left, rgba(120, 80, 40, 0.18), transparent 55%),
    radial-gradient(ellipse at bottom right, rgba(120, 80, 40, 0.15), transparent 55%),
    linear-gradient(to bottom, #f4e8cc, #e8d4a8);
  color: #3a2a14;
  font-family: 'Georgia', 'Garamond', 'Times New Roman', serif;
  font-style: italic;
  font-size: 1.02rem;
  line-height: 1.55;
  text-align: center;
  border-radius: 3px;
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.25),
    inset 0 0 60px rgba(120, 80, 40, 0.12),
    inset 0 0 2px rgba(120, 80, 40, 0.4);
  position: relative;
  overflow: hidden;
}

.parchment::before,
.parchment::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 12px;
  background: radial-gradient(ellipse at center, rgba(90, 60, 30, 0.25), transparent 70%);
  pointer-events: none;
}
.parchment::before { top: 0; }
.parchment::after { bottom: 0; transform: rotate(180deg); }

/* Im Dark-Mode gleiches Pergament — das Papier bleibt hell, das ist der Witz */

.day-divider {
  align-self: center;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0.6rem 0 0.2rem;
  padding: 0.15rem 0.6rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  .day-divider { background: rgba(255, 255, 255, 0.05); }
}

.composer {
  display: flex;
  padding: 0.5rem;
  background: var(--panel);
  gap: 0.5rem;
}

.composer input {
  flex: 1;
  padding: 0.7rem 0.9rem;
  border-radius: 20px;
  border: 1px solid rgba(128, 128, 128, 0.3);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.composer button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.connection {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  padding: 0.25rem;
  background: var(--panel);
}

.connection.bad { color: var(--danger); }
