:root {
  --primary: #00B8A9;
  --primary-dark: #009689;
  --accent: #FF6F61;
  --bg: #F4F7F6;
  --bubble-me: #00B8A9;
  --bubble-them: #FFFFFF;
  --text-dark: #1E2A28;
  --text-muted: #6B7B79;
  --danger: #E85555;
  --border: #E3EAE9;
  /* --debug-safe-top ist trotz des Namens jetzt fest benötigt (nicht mehr nur Diagnose):
     updateAppHeight() in app.js liest ihn per JS aus - env() selbst kann JS nicht direkt
     auslesen, nur der Umweg über eine CSS-Variable macht den Wert für JS zugänglich. */
  --debug-safe-top: env(safe-area-inset-top, 0px);
  --debug-safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  width: 100%;
  touch-action: none;
}

body {
  font-family: -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  color: var(--text-dark);
}

.screen {
  /* Weder 100dvh noch 100% waren auf iOS zuverlässig (im Home-Bildschirm-Standalone-Modus blieb
     unten ein großer toter Rand). --app-height wird per JS aus window.innerHeight gesetzt (siehe
     app.js updateAppHeight()) - das spiegelt zuverlässig den tatsächlich sichtbaren Bereich wider:
     im normalen Safari-Tab kleiner (Safari-Leiste braucht Platz), in der installierten App der
     volle Bildschirm. 100% bleibt nur als Fallback, falls JS noch nicht gelaufen ist. */
  width: 100%;
  height: var(--app-height, 100%);
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Auf breiten Desktop-Fenstern: App bleibt in sinnvoller (Handy-ähnlicher) Breite, statt sich
   über das ganze Browserfenster zu strecken. Rest links/rechts bekommt einen Hintergrund, der
   mit dem Fenster mitwächst. */
@media (min-width: 700px) {
  body {
    background: linear-gradient(160deg, #0a2f2a 0%, #061c19 100%);
  }
  .screen {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.45);
  }
}

/* ---------- Generic layout ---------- */
.topbar {
  background: var(--primary);
  color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 16px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar .sub { font-size: 12px; opacity: 0.85; margin: 0; }
.topbar-icon-btn {
  background: rgba(255,255,255,0.18);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}

.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  position: relative;
}

/* Chat-Ansicht: Header + Composer bleiben fix, nur .messages scrollt (nicht die ganze .content-Box). */
.content.chat-mode {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  touch-action: none;
}

.bottom-nav {
  display: flex;
  background: #fff;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 6px);
}
.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 0 4px;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}
.bottom-nav button .icon { font-size: 20px; }
.bottom-nav button.active { color: var(--primary); font-weight: 600; }

/* ---------- Auth ---------- */
.auth-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 40px 28px;
  background: linear-gradient(160deg, var(--primary) 0%, #007F74 100%);
  color: #fff;
}
.auth-logo {
  width: 64px; height: 64px;
  background: #fff;
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
  margin-bottom: 18px;
}
.auth-screen h1 { font-size: 24px; margin: 0 0 4px; }
.auth-screen p.tagline { margin: 0 0 28px; opacity: 0.85; font-size: 13px; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.auth-tabs button {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.4);
  background: transparent;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}
.auth-tabs button.active { background: #fff; color: var(--primary-dark); font-weight: 600; border-color: #fff; }
.auth-form input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: none;
  margin-bottom: 10px;
  font-size: 14px;
}
.auth-form .captcha-box {
  background: rgba(255,255,255,0.12);
  border: 1px dashed rgba(255,255,255,0.5);
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
  margin-bottom: 14px;
  text-align: center;
  opacity: 0.9;
}
.btn-primary {
  width: 100%;
  padding: 13px;
  border-radius: 10px;
  border: none;
  background: #fff;
  color: var(--primary-dark);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

/* ---------- Pending ---------- */
.pending-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}
.pending-screen .emoji { font-size: 52px; margin-bottom: 18px; }
.pending-screen h2 { margin: 0 0 8px; font-size: 18px; }
.pending-screen p { color: var(--text-muted); font-size: 13px; line-height: 1.5; }

/* ---------- Chat list ---------- */
.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}
.avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 15px;
  flex-shrink: 0;
}
.chat-avatar-wrap { position: relative; flex-shrink: 0; }
.chat-type-badge {
  position: absolute;
  bottom: -3px;
  right: -3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  line-height: 1;
}
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-item-name { font-size: 14px; font-weight: 600; }
.chat-item-time { font-size: 11px; color: var(--text-muted); }
.chat-item-preview {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
  margin-left: 6px;
}
.section-label {
  padding: 10px 16px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg);
}

/* ---------- Chat view ---------- */
.chat-header {
  background: var(--primary);
  color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 12px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.chat-header .back { background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; padding: 4px 6px; }
.chat-header .name { font-size: 15px; font-weight: 600; }
.chat-header .meta { font-size: 11px; opacity: 0.8; }

.messages { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.msg-row { display: flex; flex-direction: column; max-width: 78%; }
.msg-row.me { align-self: flex-end; align-items: flex-end; }
.msg-row.them { align-self: flex-start; align-items: flex-start; }
.msg-sender { font-size: 11px; color: var(--primary-dark); font-weight: 600; margin-bottom: 2px; padding: 0 4px; }
.bubble {
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.4;
  position: relative;
  box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}
.msg-row.me .bubble { background: var(--bubble-me); color: #fff; border-bottom-right-radius: 4px; }
.msg-row.them .bubble { background: var(--bubble-them); color: var(--text-dark); border-bottom-left-radius: 4px; }
.bubble img { max-width: 100%; border-radius: 10px; display: block; margin-top: 4px; }
.msg-time { font-size: 10px; color: var(--text-muted); margin-top: 3px; padding: 0 4px; }
.reactions {
  display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap;
  cursor: pointer;
}
.reactions .reaction-chip {
  display: flex; align-items: center; gap: 3px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 12px; padding: 2px 7px; font-size: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.reactions .reaction-chip.mine { background: #E9F7F5; border-color: var(--primary); }
.reactions .reaction-chip .count { color: var(--text-muted); font-size: 11px; }

.bubble { cursor: pointer; }
.reaction-picker {
  display: flex; gap: 2px; margin-top: 5px;
  background: #fff; border-radius: 20px; padding: 4px 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.reaction-picker button {
  background: none; border: none; font-size: 20px; padding: 4px 5px;
  border-radius: 50%; cursor: pointer; line-height: 1;
}
.reaction-picker button:active { background: var(--bg); }
.system-msg {
  align-self: center;
  font-size: 11.5px;
  color: var(--text-muted);
  background: #E9F2F1;
  padding: 5px 12px;
  border-radius: 10px;
}
.broadcast-lock {
  align-self: center;
  font-size: 11px;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 4px;
}

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: #fff;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.composer button.icon-btn {
  background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer;
}
.composer input[type=text] {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 13.5px;
  background: var(--bg);
}
.composer .send-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
}
.composer-blocked {
  padding: 14px 16px calc(env(safe-area-inset-bottom, 0px) + 14px);
  background: #fff;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
}

/* ---------- Admin ---------- */
.admin-card {
  background: #fff;
  margin: 10px 12px;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.admin-card-top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.admin-card-name { font-weight: 600; font-size: 14px; }
.admin-card-meta { font-size: 11.5px; color: var(--text-muted); }
.admin-actions { display: flex; gap: 8px; }
.admin-actions button {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: none;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-approve { background: var(--primary); color: #fff; }
.btn-reject { background: #F1E4E4; color: var(--danger); }

/* Einheitliche Admin-Aktionsbuttons (Freischalten/Ablehnen/Sperren/Entsperren/Passwort
   zurücksetzen/Löschen) - gleiche Form/Größe, Farbe zeigt die Schwere der Aktion an. */
.action-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 1;
  min-width: 128px;
  padding: 9px 10px;
  border-radius: 8px;
  border: none;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.action-btn .icon { font-size: 13px; }
.action-btn.tone-primary { background: var(--primary); color: #fff; }
.action-btn.tone-warn { background: #FFF3DE; color: #B8860B; }
.action-btn.tone-neutral { background: var(--bg); color: var(--text-dark); border: 1px solid var(--border); }
.action-btn.tone-danger { background: #FCEBEB; color: var(--danger); }
.role-pill {
  display: inline-block;
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-muted);
  margin-top: 4px;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- Extra: real-app additions (Fehler, Modal, Formulare) ---------- */
.error-box {
  background: #FCEBEB;
  color: var(--danger);
  border: 1px solid #F1CFCF;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  margin-bottom: 10px;
}
.info-box {
  background: #E9F2F1;
  color: var(--primary-dark);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  margin-bottom: 10px;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
.modal-sheet {
  background: #fff;
  width: 100%;
  border-radius: 18px 18px 0 0;
  padding: 18px 16px 24px;
  max-height: 80%;
  overflow-y: auto;
}
.modal-sheet h2 { margin: 0 0 12px; font-size: 16px; }
.modal-sheet label { display: block; font-size: 12px; color: var(--text-muted); margin: 10px 0 4px; }
.modal-sheet input[type=text], .modal-sheet select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13.5px;
}
.type-tabs { display: flex; gap: 6px; margin-top: 6px; }
.type-tabs button {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 12.5px;
  cursor: pointer;
}
.type-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.member-list { max-height: 180px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; margin-top: 4px; }
.member-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.member-row:last-child { border-bottom: none; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions button { flex: 1; }
.btn-secondary {
  padding: 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-dark);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.role-select {
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.admin-card-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.status-pill {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
}
.status-pill.aktiv { background: #E4F6EE; color: #1F9D5A; }
.status-pill.wartend { background: #FFF3DE; color: #B8860B; }
.status-pill.gesperrt { background: #FCEBEB; color: var(--danger); }
.composer input[type=file] { display: none; }
.msg-row .bubble { white-space: pre-wrap; word-break: break-word; }
.msg-delete {
  background: none; border: none; color: var(--text-muted); font-size: 10px; cursor: pointer; padding: 2px 4px;
}
.logout-btn {
  background: rgba(255,255,255,0.18);
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}
.spinner-line { text-align: center; padding: 20px; color: var(--text-muted); font-size: 12.5px; }

/* ---------- Online-Status ---------- */
.presence-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #C7D0CE;
  flex-shrink: 0;
  display: inline-block;
}
.presence-dot.online { background: #28C76F; }
.presence-line { font-size: 11px; color: var(--text-muted); }
.chat-header .meta .presence-dot { margin-right: 4px; vertical-align: middle; background: rgba(255,255,255,0.5); }
.chat-header .meta .presence-dot.online { background: #6CF0A4; }

/* ---------- Lesebestätigungen ---------- */
.receipt { margin-left: 4px; font-size: 10px; letter-spacing: -1px; }
.receipt.sent, .receipt.delivered { color: var(--text-muted); }
.receipt.read { color: #4C9EEB; font-weight: 700; letter-spacing: 0; }

/* ---------- Sende-Animation ---------- */
@keyframes bubble-pop { from { transform: scale(0.85); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }
.msg-row.sent-pop .bubble { animation: bubble-pop 0.22s ease-out; }

/* ---------- Registrierungs-Hinweis ---------- */
.auth-hint { color: rgba(255,255,255,0.85); font-size: 11.5px; margin: -4px 0 14px; line-height: 1.4; }

/* ---------- Avatare als Bild statt Initialen ---------- */
img.avatar { object-fit: cover; }

/* ---------- Wordle ---------- */
:root {
  --wordle-green: #6AAA64;
  --wordle-yellow: #C9B458;
  --wordle-gray: #787C7E;
  --wordle-border: #D3D6DA;
}

.wordle-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}

.wordle-banner {
  align-self: stretch;
  padding: 8px 12px;
  border-radius: 10px;
  background: #E9F2F1;
  color: var(--primary-dark);
  font-size: 12.5px;
  text-align: center;
}
.wordle-banner.win { background: #FFF3DE; color: #B8860B; }

.wordle-grid { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; }
.wordle-row { display: flex; gap: 6px; }
.wordle-tile {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  border: 2px solid var(--wordle-border);
  border-radius: 4px;
  color: var(--text-dark);
  background: #fff;
}
/* Kein text-transform:uppercase hier (bewusst!) - Wortliste/Guesses sind schon uppercase
   gespeichert, und CSS text-transform:uppercase würde 'ß' visuell zu "SS" machen (Chromium wendet
   die Unicode-Großschreibungsregel auch im Rendering an) - exakt dieselbe Falle wie bei
   JS .toUpperCase(), nur eine Ebene weiter oben. Siehe games/wordle.js für die JS-Seite davon. */
.wordle-tile.filled { border-color: #878A8C; } /* getippt, noch nicht abgeschickt */
.wordle-tile.correct { background: var(--wordle-green); border-color: var(--wordle-green); color: #fff; }
.wordle-tile.present { background: var(--wordle-yellow); border-color: var(--wordle-yellow); color: #fff; }
.wordle-tile.absent  { background: var(--wordle-gray); border-color: var(--wordle-gray); color: #fff; }

.wordle-keyboard {
  flex-shrink: 0;
  padding: 8px 6px calc(env(safe-area-inset-bottom, 0px) + 8px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #fff;
  border-top: 1px solid var(--border);
}
.wordle-kbd-row { display: flex; gap: 5px; justify-content: center; }
.wordle-key {
  flex: 1;
  max-width: 34px;
  height: 46px;
  border: none;
  border-radius: 6px;
  background: var(--wordle-border);
  color: var(--text-dark);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.wordle-key.wide { max-width: 64px; font-size: 11px; }
.wordle-key.key-correct { background: var(--wordle-green); color: #fff; }
.wordle-key.key-present { background: var(--wordle-yellow); color: #fff; }
.wordle-key.key-absent  { background: var(--wordle-gray); color: #fff; }
.wordle-key:disabled { opacity: 0.6; cursor: default; }

@keyframes wordle-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}
.wordle-row.shake { animation: wordle-shake 0.5s; }
