/* Anonymer Gruppenchat – PHP + HTMX + SQLite */

/* Schwarzweiß, ruhig: eine einzige Akzentfarbe – Schwarz –, alles andere
   sind Graustufen. Farbe entsteht nur durch Kontrast, nicht durch Buntheit. */
:root {
  --bg:      #f8f8fb;
  --app:     #ffffff;
  --ink:     #1e1e26;
  --muted:   #7b7b87;
  --line:    #ececf1;
  --accent:  #7671c8;
  --accent2: #918cd8;
  --mine:    #7570bd;
  --mine-ink:#ffffff;
  --other:   #f4f4f8;
  --ring:    rgba(118,113,200,.26);
  --shadow:  0 18px 50px rgba(30,30,60,.10);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #0b0b0b;
    --app:     #151515;
    --ink:     #f2f2f2;
    --muted:   #909090;
    --line:    #272727;
    --accent:  #a9a5e8;
    --accent2: #8f8ad6;
    --mine:    #dedcf2;
    --mine-ink:#111111;
    --other:   #1f1f1f;
    --ring:    rgba(169,165,232,.26);
    --shadow:  0 20px 60px rgba(0,0,0,.6);
  }
}


* { box-sizing: border-box; }
html { color-scheme: light dark; }

body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;              /* nur der Verlauf scrollt, nie die Seite */
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Vollbild: der Chat nimmt den ganzen Bildschirm ein. */
.app {
  width: 100%;
  height: 100dvh;
  background: var(--app);
  border: 0;
  border-radius: 0;
  overflow: hidden;
  display: flex;
}

/* ---------- Namens-Gate ---------- */
.gate {
  margin: auto;
  padding: 2rem;
  text-align: center;
  max-width: 380px;
}
.gate h1 { margin: 0 0 .4rem; font-size: 1.9rem; letter-spacing: -.03em; }
.gate .sub { color: var(--muted); margin: 0 0 1.4rem; font-size: 1.02rem; }

/* Vertrauens-Punkte auf der Startseite: linksbündig, ruhig, ohne Emojis */
.gate-points {
  list-style: none; margin: 0 0 1.4rem; padding: 0;
  display: flex; flex-direction: column; gap: .7rem; text-align: left;
}
.gate-points li {
  display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: .65rem;
  align-items: start; font-size: .84rem; color: var(--muted); line-height: 1.35;
}
.gate-points svg { width: 18px; height: 18px; margin-top: .15rem; color: var(--accent); }
.gate-points b { display: block; color: var(--ink); font-weight: 600; font-size: .9rem; }
.gate-form { display: flex; gap: .5rem; }
.field {
  flex: 1;
  padding: .75rem .9rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg);
  color: var(--ink);
  font-size: 1rem;
}
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring); }
.btn {
  border: 0; border-radius: 11px;
  padding: .75rem 1.2rem;
  background: var(--accent); color: #fff;
  font-weight: 600; font-size: 1rem; cursor: pointer;
  transition: filter .15s, transform .08s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.gate .hint { color: var(--muted); font-size: .82rem; margin-top: 1rem; }

/* ---------- Chat-Gerüst ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
  height: 58px; flex: none;
  padding: 0 1.1rem;
  border-bottom: 1px solid var(--line);
  background: var(--app);
  backdrop-filter: blur(6px);
}
.bar .title { font-weight: 700; letter-spacing: -.01em; }
.bar .me { font-size: .82rem; color: var(--muted); }
.bar .me strong { color: var(--ink); }
.link {
  border: 0; background: none; padding: 0;
  color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline;
}

/* ---------- Verlauf ---------- */
.feed {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  scroll-behavior: smooth;
}
.empty { margin: auto; color: var(--muted); text-align: center; }

.msg {
  display: flex;
  gap: .6rem;
  max-width: 82%;
  align-items: flex-end;
  animation: rise .18s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.msg.mine { margin-left: auto; flex-direction: row-reverse; }

.avatar {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: .85rem; font-weight: 700; color: #fff;
  background: hsl(0 0% calc(26% + var(--hue) * 0.09%));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.15);
}

.bubble {
  background: var(--other);
  border: 1px solid var(--line);
  padding: .5rem .7rem;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  min-width: 0;
}
.msg.mine .bubble {
  background: var(--mine);
  border-color: transparent;
  color: var(--mine-ink);
  border-radius: 14px;
  border-bottom-right-radius: 4px;
}
.meta { display: flex; gap: .5rem; align-items: baseline; margin-bottom: .1rem; }
.who  { font-size: .78rem; font-weight: 700; color: var(--accent2); }
.msg.mine .who { color: rgba(255,255,255,.85); }
.time { font-size: .68rem; color: var(--muted); }
.msg.mine .time { color: rgba(255,255,255,.6); }
.body { margin: .1rem 0 0; word-break: break-word; white-space: normal; }

.media {
  display: block;
  margin-top: .4rem;
  max-width: 100%;
  max-height: 320px;
  border-radius: 10px;
  background: rgba(0,0,0,.2);
}
.media-link { display: block; }

/* ---------- Eingabe ---------- */
.composer {
  border-top: 1px solid var(--line);
  padding: .6rem .7rem;
  background: var(--app);
}
.composer .row { display: flex; align-items: center; gap: .5rem; }
.file-label {
  display: block;
  font-size: .78rem;
  color: var(--accent);
  padding: 0 .3rem .4rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-label:empty { display: none; }

.attach {
  flex: none;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  cursor: pointer; font-size: 1.1rem;
  transition: background .15s, border-color .15s;
}
.attach:hover { border-color: var(--accent); }
.text {
  flex: 1; min-width: 0;
  padding: .7rem .85rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg);
  color: var(--ink);
  font-size: 1rem;
}
.text:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring); }
.send {
  flex: none;
  width: 40px; height: 40px;
  border: 0; border-radius: 11px;
  background: var(--accent); color: #fff;
  font-size: 1.05rem; cursor: pointer;
  transition: filter .15s, transform .08s;
}
.send:hover { filter: brightness(1.08); }
.send:active { transform: translateY(1px); }

/* Scrollbar dezent */
.feed::-webkit-scrollbar { width: 9px; }
.feed::-webkit-scrollbar-thumb { background: var(--line); border-radius: 20px; border: 2px solid var(--app); }

/* ---------- Vollbild: Inhalte in lesbarer Spalte mittig halten ---------- */
:root { --col: 1100px; }
.feed,
.composer > .row,
.composer > .file-label {
  padding-left:  max(1rem, calc((100% - var(--col)) / 2));
  padding-right: max(1rem, calc((100% - var(--col)) / 2));
}
.msg { max-width: min(82%, 760px); }

/* ---------- Emoji-Auswahl im Eingabefeld ---------- */
.composer { position: relative; }
.emoji-panel {
  display: none;
  position: absolute;
  bottom: calc(100% + .4rem);
  left: max(1rem, calc((100% - var(--col)) / 2));
  width: min(330px, calc(100% - 2rem));
  max-height: 230px;
  overflow-y: auto;
  background: var(--app);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: .5rem;
  gap: .15rem;
  grid-template-columns: repeat(auto-fill, minmax(2.1rem, 1fr));
  z-index: 20;
}
.emoji-panel.open { display: grid; }
.emoji-panel button {
  border: 0; background: none; cursor: pointer;
  font-size: 1.25rem; line-height: 1; padding: .3rem; border-radius: 8px;
}
.emoji-panel button:hover { background: var(--bg); }

/* ---------- Antwort-Zitat in der Bubble ---------- */
.quote {
  display: block;
  margin: .1rem 0 .3rem;
  padding: .3rem .5rem;
  border-left: 3px solid var(--accent2);
  border-radius: 6px;
  background: rgba(127,127,127,.12);
  font-size: .82rem;
  color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.quote .qwho { display: block; font-weight: 700; color: var(--accent2); font-size: .76rem; }
.msg.mine .quote { border-left-color: rgba(255,255,255,.7); color: rgba(255,255,255,.85); background: rgba(255,255,255,.14); }
.msg.mine .quote .qwho { color: #fff; }

/* ---------- Reaktionen unter der Bubble ---------- */
.reactions { display: flex; flex-wrap: wrap; gap: .25rem; }
.reactions:empty { display: none; }
.reactions { margin-top: .35rem; }
.rx {
  display: inline-flex; align-items: center; gap: .2rem;
  border: 1px solid var(--line);
  background: var(--app);
  color: var(--ink);
  border-radius: 999px;
  padding: .1rem .4rem;
  font-size: .85rem; line-height: 1.3; cursor: pointer;
}
.rx span { font-size: .72rem; font-weight: 700; color: var(--muted); }
.rx:hover { border-color: var(--accent); }

/* ---------- Aktionen an der Bubble ---------- */
.acts {
  display: flex; gap: .2rem; align-self: center;
  opacity: 0; transition: opacity .15s;
}
.msg:hover .acts, .acts:focus-within { opacity: 1; }
@media (hover: none) { .acts { opacity: .55; } }   /* Touch: dauerhaft sichtbar */
.act {
  width: 26px; height: 26px;
  border: 1px solid var(--line); background: var(--app);
  border-radius: 50%; cursor: pointer;
  font-size: .8rem; line-height: 1; padding: 0;
  display: grid; place-items: center; color: var(--ink);
}
.act:hover { border-color: var(--accent); }

/* Schnellauswahl für Reaktionen */
.quick {
  display: none; position: fixed; z-index: 40;
  background: var(--app); border: 1px solid var(--line);
  border-radius: 999px; box-shadow: var(--shadow);
  padding: .25rem .35rem; gap: .1rem;
}
.quick.open { display: flex; }
.quick button {
  border: 0; background: none; cursor: pointer;
  font-size: 1.2rem; line-height: 1; padding: .25rem; border-radius: 50%;
}
.quick button:hover { background: var(--bg); transform: scale(1.15); }

/* ---------- Antwort-Leiste über der Eingabe ---------- */
.reply-bar { display: none; }
.reply-bar.open {
  display: flex; align-items: center; gap: .5rem;
  margin: 0 0 .4rem;
  padding: .35rem .6rem;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--bg);
  font-size: .82rem;
}
.reply-bar .rwho { font-weight: 700; color: var(--accent); flex: none; }
.reply-bar .rtxt { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar #reply-x { margin-left: auto; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: .9rem; }

/* ---------- Sprachnachricht ---------- */
#voice-btn.rec {
  background: #e5484d; color: #fff; border-color: #e5484d;
  font-size: .78rem; font-weight: 700;
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 50% { filter: brightness(1.25); } }
@media (prefers-reduced-motion: reduce) { #voice-btn.rec { animation: none; } }

/* ---------- Eigener Sprachnachrichten-Player ---------- */
.voice {
  display: flex; align-items: center; gap: .55rem;
  margin-top: .45rem;
  width: min(250px, 100%);
  padding: .4rem .55rem;
  border-radius: 999px;
  background: rgba(127,127,127,.14);
}
.msg.mine .voice { background: rgba(255,255,255,.20); }
.voice audio { display: none; }
.vplay {
  flex: none; width: 30px; height: 30px;
  border: 0; border-radius: 50%;
  background: var(--accent); color: #fff;
  cursor: pointer; font-size: .72rem; line-height: 1;
  display: grid; place-items: center;
}
.msg.mine .vplay { background: #fff; color: var(--accent); }
.vbar {
  flex: 1; height: 4px; min-width: 0;
  border-radius: 999px;
  background: rgba(127,127,127,.35);
  cursor: pointer;
}
.msg.mine .vbar { background: rgba(255,255,255,.45); }
.vbar i { display: block; height: 100%; width: 0%; border-radius: 999px; background: var(--accent); transition: width .1s linear; }
.msg.mine .vbar i { background: #fff; }
.vtime { flex: none; font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.msg.mine .vtime { color: rgba(255,255,255,.85); }

/* Aufnahme verwerfen */
#voice-cancel { place-items: center; color: #e5484d; border-color: #e5484d; font-weight: 700; }
#voice-cancel:hover { background: rgba(229,72,77,.12); }

/* ---------- Suche in der Kopfzeile ---------- */
.qbox { display: flex; align-items: center; gap: .3rem; flex: 1; max-width: 420px; margin: 0 auto; }
.qbox input {
  flex: 1; min-width: 0;
  padding: .4rem .7rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg); color: var(--ink); font-size: .88rem;
}
.qbox input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.q-count { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: center; }
.qbox button {
  flex: none; width: 26px; height: 26px;
  border: 1px solid var(--line); background: var(--app); color: var(--ink);
  border-radius: 8px; cursor: pointer; font-size: .7rem; line-height: 1;
  display: grid; place-items: center;
}
.qbox button:hover { border-color: var(--accent); }

/* Angesprungener Treffer */
.msg.hit .bubble {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  animation: hitflash 1.1s ease;
}
@keyframes hitflash { 0% { background: color-mix(in srgb, var(--accent) 35%, transparent); } }
@media (prefers-reduced-motion: reduce) { .msg.hit .bubble { animation: none; } }

/* Vom Speicher-Wächter entfernte Datei */
.gone {
  margin-top: .4rem; padding: .35rem .55rem;
  border: 1px dashed var(--line); border-radius: 8px;
  font-size: .78rem; color: var(--muted); font-style: italic;
}
.msg.mine .gone { color: rgba(255,255,255,.8); border-color: rgba(255,255,255,.4); }

@media (max-width: 720px) { .qbox { max-width: none; } .bar .me { display: none; } }

/* ---------- Kurzmeldung (z. B. Rate-Limit) ---------- */
.toast {
  position: fixed; left: 50%; bottom: 5.2rem; transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: var(--app);
  padding: .55rem .9rem; border-radius: 999px;
  font-size: .85rem; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 60; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Suchleiste standardmäßig zu – öffnet per ⌘F/Strg+F oder Lupe */
.qbox { display: none; }
.qbox.open { display: flex; }
.icon-btn {
  flex: none; width: 32px; height: 32px;
  border: 1px solid var(--line); background: var(--app); color: var(--muted);
  border-radius: 9px; cursor: pointer;
  display: grid; place-items: center;
  transition: color .15s, border-color .15s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Ältere Nachrichten nachladen ---------- */
/* Schwebt über dem Verlauf statt Platz zu belegen: taucht nur auf, wenn man
   oben an der Kante des geladenen Verlaufs angekommen ist. */
.feed-top {
  position: absolute; left: 0; right: 0; top: .5rem; z-index: 12;
  display: flex; justify-content: center; pointer-events: none;
  opacity: 0; transform: translateY(-6px); transition: opacity .18s, transform .18s;
}
.feed-top.show { opacity: 1; transform: none; pointer-events: auto; }
#load-older {
  border: 1px solid var(--line); background: var(--app); color: var(--muted);
  border-radius: 999px; padding: .3rem .8rem; font-size: .78rem; cursor: pointer;
  box-shadow: var(--shadow);
}
#load-older:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Räume-Seitenleiste ---------- */
.rooms {
  flex: none; width: 240px;
  border-right: 1px solid var(--line);
  background: var(--panel-2, var(--bg));
  display: flex; flex-direction: column; min-height: 0;
}
.rooms-head {
  display: flex; align-items: center; justify-content: space-between;
  height: 58px; flex: none;
  padding: 0 1rem; border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: .9rem;
  background: var(--app);
}
.rooms-head button {
  width: 26px; height: 26px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--app); color: var(--accent);
  font-size: 1rem; line-height: 1; display: grid; place-items: center;
}
.rooms-head button:hover { border-color: var(--accent); }
.rooms-list { flex: 1; overflow-y: auto; padding: .5rem; display: flex; flex-direction: column; gap: .15rem; }
.rooms-sub { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: .7rem .6rem .25rem; }
.room {
  display: flex; align-items: center; gap: .4rem;
  padding: .45rem .6rem; border-radius: 9px;
  color: var(--ink); text-decoration: none; font-size: .88rem;
}
.room:hover { background: var(--app); }
.room.active { background: var(--accent); color: #fff; font-weight: 600; }
.room .rname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room .rlock { font-size: .7rem; opacity: .7; }

/* Auf dem Handy ausgeblendet, per Menüknopf einblendbar */
#rooms-toggle { display: none; margin-right: .6rem; }
/* Verdunkelung hinter der ausgeklappten Raumleiste – nur am Smartphone.
   Ohne sie liegt der Menüknopf unter der Leiste und man kommt nicht mehr raus. */
.rooms-backdrop { display: none; }
.rooms-head-btns { display: flex; gap: .35rem; }
#rooms-close { display: none; }

@media (max-width: 820px) {
  .rooms {
    position: absolute; left: 0; top: 0; bottom: 0; z-index: 40;
    transform: translateX(-100%); transition: transform .2s;
    box-shadow: var(--shadow);
  }
  body.rooms-open .rooms { transform: none; }
  .rooms-backdrop {
    display: block; position: absolute; inset: 0; z-index: 35;
    background: rgba(0,0,0,.45);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  body.rooms-open .rooms-backdrop { opacity: 1; pointer-events: auto; }
  #rooms-toggle { display: grid; }
  #rooms-close { display: grid; }
  .app { position: relative; }
}

/* ---------- Dialog: neuen Raum anlegen ---------- */
.roomdlg {
  display: none; position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,.45); place-items: center; padding: 1rem;
}
.roomdlg.open { display: grid; }
.roomdlg form {
  background: var(--app); border: 1px solid var(--line); border-radius: 14px;
  padding: 1.2rem; width: min(400px, 100%);
  display: flex; flex-direction: column; gap: .6rem; box-shadow: var(--shadow);
}
.roomdlg h3 { margin: 0 0 .2rem; font-size: 1.05rem; }
.roomdlg .chk { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--muted); }
.roomdlg .row { display: flex; gap: .5rem; margin-top: .2rem; }
.btn.ghost { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.roomlink { display: block; margin-top: .4rem; word-break: break-all; color: var(--accent); font-size: .8rem; }

/* Löschen nur bei eigenen Nachrichten anbieten */
.act-del { display: none; }
.msg.mine .act-del { display: grid; }
.act-del:hover { border-color: #e5484d; color: #e5484d; }

/* Selbstlöschung im Eingabefeld */
.ttl {
  flex: none; height: 40px; padding: 0 .4rem;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--bg); color: var(--muted);
  font-size: .8rem; cursor: pointer;
}
.ttl:focus { outline: none; border-color: var(--accent); }
@media (max-width: 560px) { .ttl { display: none; } }

/* ---------- Reiter + Filter in der Raumleiste ---------- */
.rooms-tabs { display: flex; gap: .25rem; padding: .55rem .6rem 0; }
.rtab {
  flex: 1; padding: .35rem .5rem;
  border: 1px solid var(--line); background: var(--app); color: var(--muted);
  border-radius: 9px; font-size: .8rem; font-weight: 600; cursor: pointer;
}
.rtab:hover { border-color: var(--accent); }
.rtab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.room-filter {
  margin: .5rem .6rem .2rem; padding: .4rem .65rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--app); color: var(--ink); font-size: .82rem;
}
.room-filter:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.rooms-empty { padding: .9rem .7rem; font-size: .8rem; color: var(--muted); text-align: center; }
#roomdlg-ok { margin-top: .7rem; width: 100%; }

/* Ranking in der Raumliste */
.rrank {
  flex: none; min-width: 1.5em; text-align: right;
  font-size: .72rem; font-weight: 700; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.room.active .rrank { color: rgba(255,255,255,.8); }
.rcount {
  flex: none; font-size: .68rem; color: var(--muted);
  background: var(--bg); border-radius: 999px; padding: .05rem .35rem;
  font-variant-numeric: tabular-nums;
}
.room.active .rcount { background: rgba(255,255,255,.22); color: #fff; }
.rdel {
  flex: none; width: 18px; height: 18px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer;
  font-size: .7rem; line-height: 1; display: none; place-items: center;
}
.room:hover .rdel { display: grid; }
.rdel:hover { background: rgba(229,72,77,.15); color: #e5484d; }
.room.active .rdel { color: rgba(255,255,255,.85); }
.rsub {
  flex: none; width: 18px; height: 18px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer;
  font-size: .8rem; line-height: 1; display: grid; place-items: center;
}
.rsub.on { color: #eab308; }
.rsub:hover { color: var(--accent); }
.room.active .rsub { color: rgba(255,255,255,.85); }
/* Abo-Haken: umrandet = nicht abonniert, gefüllt = abonniert */
.rsub { border: 1.5px solid var(--line); background: var(--app); color: transparent; width: 20px; height: 20px; }
.rsub:hover { border-color: var(--accent); color: var(--accent); }
.rsub.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.room.active .rsub { border-color: rgba(255,255,255,.6); }
.room.active .rsub.on { background: #fff; border-color: #fff; color: var(--accent); }
/* SVG-Icons an der Bubble */
.act svg { display: block; }

/* Abo-Haken dezent statt als Kreis (überschreibt die frühere Fassung) */
.rsub {
  width: 18px; height: 18px;
  border: 0 !important;
  background: transparent !important;
  color: var(--line) !important;
  opacity: .55;
  transition: color .15s, opacity .15s;
}
.room:hover .rsub { opacity: 1; }
.rsub:hover { color: var(--accent) !important; }
.rsub.on { color: var(--accent) !important; opacity: 1; }
.room.active .rsub { color: rgba(255,255,255,.55) !important; }
.room.active .rsub.on { color: #fff !important; }
/* Links in Nachrichten */
.body a { color: inherit; text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
.body a:hover { opacity: .8; }
.msg.mine .body a { color: #fff; }

/* Links klar erkennbar – auf hellem wie auf indigo Grund */
.body a { color: var(--accent2) !important; text-decoration: underline; text-underline-offset: 2px; }
.msg.mine .body a { color: #fff !important; text-decoration-color: rgba(255,255,255,.65); }
.body a:hover { text-decoration-thickness: 2px; }

/* ---------- Datei-Anhang ---------- */
.filechip {
  display: flex; align-items: center; gap: .5rem;
  margin-top: .45rem; padding: .5rem .65rem;
  border-radius: 10px; text-decoration: none;
  background: rgba(127,127,127,.14); color: inherit;
  max-width: 100%;
}
.msg.mine .filechip { background: rgba(255,255,255,.20); }
.filechip:hover { background: rgba(127,127,127,.24); }
.msg.mine .filechip:hover { background: rgba(255,255,255,.30); }
.filechip svg { flex: none; opacity: .85; }
.fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; }
.fdl { flex: none; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; opacity: .7; }

/* ---------- Kamera ---------- */
.camdlg { display: none; position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.85); place-items: center; padding: 1rem; }
.camdlg.open { display: grid; }
.camwrap { width: min(560px, 100%); display: flex; flex-direction: column; gap: .8rem; align-items: center; }
#camvid { width: 100%; max-height: 65dvh; border-radius: 14px; background: #000; object-fit: cover; }
.camrow { display: flex; align-items: center; gap: 1rem; }
.camshot {
  width: 60px; height: 60px; border-radius: 50%;
  border: 4px solid #fff; background: rgba(255,255,255,.25);
  cursor: pointer; transition: transform .08s, background .15s;
}
.camshot:hover { background: rgba(255,255,255,.45); }
.camshot:active { transform: scale(.93); }
.camdlg .hint { color: #fff; font-size: .85rem; text-align: center; margin: 0; min-height: 1.2em; }

/* ---------- Smartphone-Optimierung ---------- */
.attach svg, .send svg { display: block; }

@media (max-width: 640px) {
  /* Eingabezeile: kompakter, damit alle Knöpfe nebeneinander passen */
  .composer { padding: .45rem .5rem calc(.45rem + env(safe-area-inset-bottom)); }
  .composer .row { gap: .3rem; }
  .attach, .send { width: 36px; height: 36px; border-radius: 10px; }
  .attach svg, .send svg { width: 17px; height: 17px; }
  .text { padding: .6rem .7rem; font-size: 16px; }  /* 16px verhindert Zoom beim Fokus in iOS */
  .bar { padding: .6rem .8rem; }
  .bar .title { font-size: .95rem; }
  .msg { max-width: 88%; }
  .avatar { width: 28px; height: 28px; font-size: .75rem; }
  .feed { gap: .5rem; }
  /* Aktionen sind auf Touch dauerhaft sichtbar, aber kleiner */
  .act { width: 24px; height: 24px; }
  .act svg { width: 13px; height: 13px; }
  .rooms { width: min(80vw, 300px); }
  .qbox { gap: .2rem; }
  .q-count { min-width: 2.6em; font-size: .68rem; }
}

/* Sehr schmale Geräte: Emoji-Knopf weicht (Auswahl gibt es per Tastatur) */
@media (max-width: 380px) {
  #emoji-btn { display: none; }
}

/* ---------- Marke ---------- */
.brand { flex: none; display: grid; place-items: center; margin-right: .45rem; }
.brand .logo, .gate-logo .logo { border-radius: 7px; }
.brand .logo { display: block; }
.gate-logo { display: grid; place-items: center; color: var(--accent); margin-bottom: .6rem; }
.gate-logo .logo { width: 56px; height: 56px; border-radius: 13px; }
@media (max-width: 640px) { .brand { display: none; } }

/* Kopfzeilen hell; der Raumname sitzt direkt neben dem Zeichen. */
.bar .title { margin-right: auto; }

/* Suche bleibt kompakt statt über die halbe Leiste zu laufen */
.qbox { max-width: 300px; margin: 0 0 0 .6rem; flex: 0 1 300px; }
@media (max-width: 720px) { .qbox { flex: 1 1 auto; max-width: none; } }
.gate-pass { width: 100%; margin-top: .5rem; font-size: .9rem; }
.gate-err {
  margin: 0 0 .8rem; padding: .55rem .75rem; border-radius: 10px;
  background: color-mix(in srgb, #e5484d 12%, transparent);
  color: #c0343a; font-size: .85rem; text-align: left;
}

/* ---------- Indigo-Schimmer auf den Sprechblasen ----------
   Das Schwarzweiß bleibt die Grundlage; Farbe kommt nur als leiser Schleier
   und ein langsam durchlaufendes Glanzlicht dazu. */
.msg .bubble { position: relative; overflow: hidden; }

.msg.mine .bubble {
  background:
    linear-gradient(135deg, rgba(129,131,255,.22), rgba(129,131,255,.04) 55%),
    var(--mine);
  box-shadow: 0 1px 0 rgba(255,255,255,.06) inset,
              0 6px 18px rgba(79,70,229,.16);
}
.msg:not(.mine) .bubble {
  background:
    linear-gradient(135deg, rgba(99,102,241,.10), rgba(99,102,241,0) 60%),
    var(--other);
}

/* Glanzlicht: läuft alle paar Sekunden einmal durch. */
.bubble::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(115deg,
    transparent 34%, rgba(160,162,255,.16) 48%, transparent 62%);
  transform: translateX(-130%);
  animation: sheen 7s ease-in-out infinite;
}
.msg:not(.mine) .bubble::after { opacity: .5; animation-delay: 1.4s; }
@keyframes sheen {
  0%, 72% { transform: translateX(-130%); }
  100%    { transform: translateX(130%); }
}
@media (prefers-reduced-motion: reduce) { .bubble::after { animation: none; opacity: 0; } }

/* Zeichen und Raumname gehören zusammen: der grosse Abstand der Kopfzeile
   liess das Logo ohne Bezug dazwischen schweben. */
.bar { gap: .55rem; }
.bar .brand { margin-right: 0; }
.bar .title { margin-left: .1rem; }
.bar .icon-btn { margin-left: .45rem; }

/* Marke sitzt oben links in der Raumleiste und trägt die Akzentfarbe. */
.rooms-head { gap: .55rem; justify-content: flex-start; }
.rooms-head > span:nth-child(2) { flex: 1; }
.rooms-head .brand { display: grid; place-items: center; color: var(--accent); flex: none; }
.rooms-head .logo { width: 30px; height: 30px; }

/* Ohne Zeichen davor klebt der Raumname an der Trennlinie – etwas einrücken,
   damit er auf einer Flucht mit den Raumeinträgen darunter steht. */
.bar .title { margin-left: .55rem; }

/* ---------- Man selbst vs. das Gegenüber ----------
   Eigene Nachrichten tragen die Akzentfarbe der App. Alle anderen bekommen
   ihre eigene, aus dem Namen abgeleitete Farbe – so erkennt man auf einen
   Blick, wer spricht, ohne dass es bunt wird. */
.msg.mine .avatar { background: var(--accent); }
.msg:not(.mine) .avatar { background: hsl(var(--hue) 42% 46%); }
.msg:not(.mine) .who { color: hsl(var(--hue) 46% 38%); }
.msg:not(.mine) .bubble {
  background:
    linear-gradient(135deg, hsl(var(--hue) 52% 95%), hsl(var(--hue) 40% 97.5%));
  border-color: hsl(var(--hue) 34% 90%);
}
.msg:not(.mine) .bubble::after {
  background: linear-gradient(115deg,
    transparent 34%, hsl(var(--hue) 70% 88% / .55) 48%, transparent 62%);
}
@media (prefers-color-scheme: dark) {
  .msg:not(.mine) .avatar { background: hsl(var(--hue) 38% 42%); }
  .msg:not(.mine) .who    { color: hsl(var(--hue) 55% 72%); }
  .msg:not(.mine) .bubble {
    background: linear-gradient(135deg, hsl(var(--hue) 22% 20%), hsl(var(--hue) 16% 16%));
    border-color: hsl(var(--hue) 20% 26%);
  }
}

/* ============================================================
   Smartphone-Feinschliff
   ============================================================ */

/* Nichts darf die Seite seitlich schieben – ein einziges zu breites Element
   macht den ganzen Chat horizontal scrollbar und damit unbrauchbar. */
html, body { max-width: 100%; overflow-x: hidden; overscroll-behavior: none; }
.bubble, .body, .msg { min-width: 0; }
.body a { word-break: break-word; overflow-wrap: anywhere; }

/* Randlose Geräte: Kopfzeile unter die Kamera-Insel, Eingabe über die
   Home-Leiste. Ohne das liegt beides im Vollbildmodus unter der Systemleiste. */
.bar, .rooms-head { padding-top: env(safe-area-inset-top); height: calc(58px + env(safe-area-inset-top)); }
.rooms { padding-bottom: env(safe-area-inset-bottom); }

@media (max-width: 820px) {
  /* Fingerkuppen brauchen Fläche: Apple und Google nennen 44 px als Minimum.
     Die Trefferfläche wächst, das Symbol bleibt klein. */
  .act { width: 34px; height: 34px; }
  .act::before { content: ""; position: absolute; inset: -6px; }
  .act { position: relative; }
  .attach, .send, .icon-btn { width: 44px; height: 44px; }
  .attach svg, .send svg, .icon-btn svg { width: 20px; height: 20px; }
  .rtab { padding: .6rem .5rem; }          /* Reiter „Meine/Alle“ */
  .room { padding: .7rem .6rem; }          /* Raumzeilen */
  .rooms-head button { width: 38px; height: 38px; }

  /* Selbstlöschung war unter 560 px komplett ausgeblendet – damit gab es die
     Funktion am Telefon gar nicht. Jetzt sitzt sie unter der Eingabezeile. */
  .ttl { display: block !important; width: 100%; height: 34px; margin-top: .4rem; }
  .composer .row { flex-wrap: wrap; }
  .text { flex: 1 1 100%; order: -1; margin-bottom: .4rem; }

  /* Lange Raumnamen dürfen die Leiste nicht sprengen. */
  .room .rname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .rooms { width: min(86vw, 320px); }

  /* Blasen dürfen breiter werden, der Platz ist knapp. */
  .msg { max-width: 90%; }
  .media { max-height: 46vh; }
}

@media (max-width: 480px) {
  /* Der Hinweis „Du bist X“ frisst die halbe Kopfzeile – der Name steht
     ohnehin an jeder eigenen Nachricht. */
  .bar .me { display: none; }
  .bar .title { font-size: 1rem; }
}

/* Kein Wackeln beim Tippen: iOS zoomt bei Feldern unter 16 px hinein. */
@media (max-width: 820px) {
  .text, .field, .room-filter, #q { font-size: 16px; }
}

/* Kamera- und Dialogflächen im Vollbild statt in einem winzigen Kasten. */
@media (max-width: 560px) {
  .roomdlg form { width: 100%; max-height: 88dvh; overflow-y: auto; }
  .emoji-panel { width: calc(100% - 1rem); left: .5rem; max-height: 40dvh; }
}
