:root {
  --bg: #e8efdb;
  --panel: #f6f9ee;
  --text: #17301f;
  --muted: #5a7360;
  --border: #cbd9bc;
  --accent: #2c7a43;
  --accent-text: #ffffff;
  --hover: #dce8cc;
  --active: #cde2b6;
  --danger: #c0392b;
  --ok: #3aa956;
  --sun: #e9b92e;
  --serif: "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --leaf: 16px 3px 16px 3px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1810;
    --panel: #10241a;
    --text: #e0eed6;
    --muted: #8dac92;
    --border: #1e3a2a;
    --accent: #8fdc8a;
    --accent-text: #0a1810;
    --hover: #17321f;
    --active: #21452f;
    --danger: #ff8a80;
    --ok: #6fe38b;
    --sun: #f2c94c;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Anmeldung ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 28px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.06);
}
.card h1 { margin: 0; font-size: 28px; letter-spacing: -0.5px; }
.sub { margin: -8px 0 4px; color: var(--muted); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 10px; padding: 4px; }
.tab { border: 0; background: transparent; padding: 8px; border-radius: 8px; color: var(--muted); }
.tab.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, textarea {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.error { color: var(--danger); min-height: 1.3em; margin: 0; font-size: 13px; }
.primary {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 10px;
  padding: 10px 16px; font-weight: 600;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: 0.6; cursor: default; }
.primary.small { padding: 6px 12px; font-size: 13px; }
.ghost { background: transparent; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; font-size: 13px; color: var(--muted); }
.ghost:hover { background: var(--hover); color: var(--text); }
.icon-btn { background: transparent; border: 0; width: 28px; height: 28px; border-radius: 8px; font-size: 18px; line-height: 1; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ---------- App-Layout ---------- */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100dvh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; overflow-y: auto;
}
.brand { font-weight: 700; font-size: 20px; padding: 18px 18px 8px; letter-spacing: -0.3px; }
.brand span, .card h1 span { color: var(--accent); }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.list { list-style: none; margin: 0; padding: 0 8px; }
.room {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; text-align: left;
}
.room:hover { background: var(--hover); }
.room.active { background: var(--active); font-weight: 600; }
.room span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 7px; }
.new-room { display: flex; gap: 6px; padding: 0 12px 6px; }
.new-room input { flex: 1; min-width: 0; padding: 6px 10px; }
.online li { display: flex; align-items: center; gap: 8px; padding: 5px 10px; color: var(--muted); }
.online li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.dock { margin-top: auto; position: sticky; bottom: 0; background: var(--panel); }
.me { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--border); }
.me-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
}
.me .avatar { width: 32px; height: 32px; font-size: 14px; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.chat-head h2 { margin: 0; font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu { display: none; }
.status { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.status.on { background: var(--ok); }

.messages { flex: 1; overflow-y: auto; padding: 12px 18px; display: flex; flex-direction: column; }
.empty { margin: auto; color: var(--muted); text-align: center; }
.day { align-self: center; margin: 14px 0 6px; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 2px 12px; }
.msg { display: grid; grid-template-columns: 36px 1fr; gap: 10px; padding: 8px 0 0; }
.msg.grouped { padding-top: 2px; }
.msg .head { display: flex; align-items: baseline; gap: 8px; }
.msg .name { font-weight: 600; }
.msg.own .name { color: var(--accent); }
.msg .time { font-size: 12px; color: var(--muted); }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.typing { height: 22px; padding: 0 18px; font-size: 13px; color: var(--muted); }

.composer { display: flex; gap: 10px; padding: 10px 18px 16px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 140px; line-height: 1.4; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: 90vw;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

.backdrop { display: none; }

/* ---------- Sprachräume ---------- */
.count { font-size: 12px; color: var(--muted); flex: none; }
.vmembers { list-style: none; margin: 0 0 4px; padding: 0 0 0 22px; }
.vm { display: flex; align-items: center; gap: 8px; padding: 3px 10px; color: var(--muted); font-size: 14px; }
.vdot { width: 10px; height: 10px; border-radius: 50%; background: var(--border); flex: none; transition: box-shadow 0.12s, background 0.12s; }
.vm.speaking { color: var(--text); }
.vm.speaking .vdot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 35%, transparent); }
.vname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.vmuted { font-size: 12px; }
.voice-bar {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px;
  padding: 10px 14px; border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--ok) 9%, var(--panel));
}
.vb-info { min-width: 0; }
.voice-bar .ghost { white-space: nowrap; padding: 6px 10px; }
.vb-title { font-size: 13px; font-weight: 700; color: var(--ok); display: flex; align-items: center; gap: 6px; }
.vb-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.vb-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ghost.off { background: color-mix(in srgb, var(--danger) 15%, transparent); border-color: var(--danger); color: var(--danger); }
.ghost.danger:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }

/* ---------- Mobil ---------- */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 85vw); z-index: 20;
    transform: translateX(-100%); transition: transform 0.2s ease;
  }
  .app.open .sidebar { transform: none; }
  .app.open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 10; }
  .menu { display: inline-block; }
  .messages, .composer, .chat-head, .typing { padding-left: 12px; padding-right: 12px; }
}

/* ---------- Owner ---------- */
.owner-badge {
  display: inline-block; background: #dc2626; color: #fff; border-radius: 4px;
  font-size: 10px; font-weight: 800; letter-spacing: 0.06em; padding: 1px 6px; vertical-align: middle;
}
.msg .name.is-owner { color: #dc2626; }
.hidden { display: none !important; }

/* ---------- Nachrichten: Aktionen, Reaktionen, Erwähnungen ---------- */
.msg { position: relative; }
.msg:hover { background: color-mix(in srgb, var(--hover) 60%, transparent); }
.msg.mentioned { background: color-mix(in srgb, var(--accent) 10%, transparent); box-shadow: inset 3px 0 0 var(--accent); }
.mbody { min-width: 0; }
.msg .text a { color: var(--accent); text-decoration: underline; }
.mention { background: color-mix(in srgb, var(--accent) 16%, transparent); border-radius: 4px; padding: 0 3px; font-weight: 600; }
.mention.self { background: color-mix(in srgb, #f59e0b 35%, transparent); }
.edited { font-size: 12px; color: var(--muted); }
.reacts { display: flex; flex-wrap: wrap; gap: 4px; }
.reacts:not(:empty) { margin-top: 3px; }
.react { border: 1px solid var(--border); background: var(--panel); border-radius: 999px; padding: 1px 8px; font-size: 13px; }
.react:hover { background: var(--hover); }
.react.mine { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.actions {
  display: none; position: absolute; right: 4px; top: -6px; gap: 2px; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 2px; z-index: 5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.msg:hover .actions, .actions.picking { display: flex; }
.act-btn { background: transparent; border: 0; border-radius: 6px; padding: 2px 6px; font-size: 14px; line-height: 1.4; }
.act-btn:hover { background: var(--hover); }
.actions .pick { display: none; }
.actions.picking .pick { display: inline-flex; border-right: 1px solid var(--border); margin-right: 2px; padding-right: 2px; }
@media (hover: none) { .actions { display: flex; opacity: 0.75; top: 2px; } .actions .act-btn { padding: 2px 4px; } }
.edit-wrap textarea { width: 100%; resize: vertical; line-height: 1.4; }
.edit-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }

/* ---------- Emoji-Auswahl ---------- */
.composer { position: relative; }
.emoji-btn { width: 36px; height: 36px; font-size: 20px; flex: none; }
.emoji-pop {
  position: absolute; left: 18px; bottom: 62px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 8px; z-index: 30;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}
.emoji-pop button { background: transparent; border: 0; font-size: 20px; padding: 4px; border-radius: 8px; }
.emoji-pop button:hover { background: var(--hover); }
@media (max-width: 720px) { .emoji-pop { left: 12px; grid-template-columns: repeat(6, 1fr); } }

/* ---------- Dialoge ---------- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); display: grid; place-items: center; padding: 16px; z-index: 60; }
.modal-card {
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 20px;
}
.modal-card.wide { max-width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-card h4 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 14px; margin: 6px 0; }
.check input { width: auto; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.admin-list { display: flex; flex-direction: column; gap: 8px; }
.admin-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.admin-btns { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Sprachraum: Owner-Werkzeuge ---------- */
.rowwrap { display: flex; align-items: center; gap: 2px; }
.rowwrap .room { flex: 1; min-width: 0; }
.kick { width: 22px; height: 22px; font-size: 12px; margin-left: auto; }

/* Dock: Name oben, Knöpfe darunter */
.me { flex-wrap: wrap; }
.me-btns { flex: 0 0 100%; display: flex; align-items: center; gap: 6px; }
.me-btns #logoutBtn { margin-left: auto; }

/* =====================================================================
   Dschungel-Design
   ===================================================================== */
.brand, .card h1, .chat-head h2, .modal-head h3 { font-family: var(--serif); }
.logo { width: 1.05em; height: 1.05em; color: var(--accent); flex: none; vertical-align: -0.12em; margin-right: 0.3em; }
.brand { display: flex; align-items: center; font-size: 22px; }
.brand .logo { width: 28px; height: 28px; margin-right: 8px; }

/* Blatt-Ecken: zwei runde, zwei fast spitze Ecken */
.primary { border-radius: var(--leaf); }
.primary.small { border-radius: 12px 3px 12px 3px; }
.card { border-radius: 36px 6px 36px 6px; }
.modal-card { border-radius: 30px 6px 30px 6px; }
.avatar { border-radius: 50% 12% 50% 12%; }
.toast { border-radius: var(--leaf); }
.actions { border-radius: 12px 3px 12px 3px; }
.badge { border-radius: 10px 2px 10px 2px; }
.day { border-radius: 12px 3px 12px 3px; }

/* ---------- Seitenleiste: immer tiefes Waldgrün, Ranken hängen oben herein ---------- */
.sidebar {
  --bg: #0a2017; --panel: #0f2a1f; --text: #e3f1d8; --muted: #8fb094; --border: #1f4330;
  --hover: #18382a; --active: #245039; --accent: #a6e38a; --accent-text: #0a2017; --danger: #ff8a80; --ok: #7be495;
  background:
    url("vines.svg") top right / 175px auto no-repeat,
    linear-gradient(180deg, #0f2a1f 0%, #0a2017 100%);
  border-right: 1px solid #1f4330;
  color: var(--text);
}
.dock { background: color-mix(in srgb, #0a2017 90%, transparent); backdrop-filter: blur(6px); }
.room.active { box-shadow: inset 3px 0 0 var(--accent); }
.online li::before { box-shadow: 0 0 8px 2px color-mix(in srgb, var(--ok) 55%, transparent); }

/* ---------- Chat: ganz feines Blattmuster ---------- */
.messages { background: url("leaves-pattern.svg") 0 0 / 220px 220px; }
.chat-head { box-shadow: 0 1px 0 var(--border), 0 3px 0 -1px color-mix(in srgb, var(--accent) 35%, transparent); }
.msg.mentioned { background: color-mix(in srgb, var(--sun) 16%, transparent); box-shadow: inset 3px 0 0 var(--sun); }
.mention { background: color-mix(in srgb, var(--sun) 26%, transparent); }
.mention.self { background: color-mix(in srgb, var(--sun) 55%, transparent); }
.react.mine { border-color: var(--accent); }

/* ---------- Anmeldung: der Dschungel ---------- */
.auth {
  position: relative; overflow: hidden; isolation: isolate;
  background: radial-gradient(ellipse at 50% 38%, #1d5e3a 0%, #0e3322 52%, #06170e 100%);
}
.auth .card {
  position: relative; z-index: 2;
  background: color-mix(in srgb, var(--panel) 93%, transparent);
  backdrop-filter: blur(10px);
  border-color: color-mix(in srgb, #a6e38a 35%, transparent);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.5), 0 0 0 6px rgba(166, 227, 138, 0.07);
}
.card h1 { display: flex; align-items: center; }
.card h1 .logo { width: 34px; height: 34px; margin-right: 10px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.jungle { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.jungle svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.rays {
  position: absolute; inset: 0; mix-blend-mode: screen; opacity: 0.55;
  background:
    conic-gradient(from 148deg at 12% -12%,
      transparent 0 3deg, rgba(255, 240, 160, 0.20) 5deg, transparent 10deg,
      transparent 14deg, rgba(255, 240, 160, 0.14) 16deg, transparent 22deg,
      transparent 27deg, rgba(255, 240, 160, 0.17) 29deg, transparent 36deg, transparent 360deg);
}
.ff {
  position: absolute; left: var(--x); top: var(--y); width: var(--sz); height: var(--sz); border-radius: 50%;
  background: #f4f7a1; box-shadow: 0 0 10px 3px rgba(240, 247, 140, 0.75); opacity: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .sw { transform-box: fill-box; transform-origin: 50% 85%; animation: sway var(--d) ease-in-out var(--dl) infinite alternate; }
  .rays { animation: rays 9s ease-in-out infinite alternate; }
  .ff { animation: drift var(--s) ease-in-out var(--dl) infinite, glow calc(var(--s) / 2.4) ease-in-out var(--dl) infinite alternate; }
  @keyframes sway { from { transform: rotate(calc(var(--a) * -1)); } to { transform: rotate(var(--a)); } }
  @keyframes rays { from { opacity: 0.35; } to { opacity: 0.7; } }
  @keyframes drift {
    0% { transform: translate(0, 0); } 33% { transform: translate(24px, -30px); }
    66% { transform: translate(-18px, -14px); } 100% { transform: translate(0, 0); }
  }
  @keyframes glow { from { opacity: 0; } to { opacity: 0.95; } }
}
@media (prefers-reduced-motion: reduce) { .ff { opacity: 0.6; } }
