/* Fluchsprüche Chat – Darkmode
   Tinte-Violett als Grund, Messing als einziges Signal (Siegel, Hauptaktionen). */

:root {
  --ink:        #16141d;
  --surface:    #201d29;
  --raised:     #2b2736;
  --line:       #3a3547;
  --text:       #ece7f3;
  --muted:      #a39cb3;
  --brass:      #d9a74a;
  --brass-deep: #9c7428;
  --brass-ink:  #1d1608;
  --plum:       #3d2c55;
  --plum-line:  #57407a;
  --danger:     #e06c75;
  --ok:         #6fc59b;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans:  system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brass); }

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Siegel (Markenzeichen) ---------- */

.seal {
  width: 64px; height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, #f0c46e, var(--brass) 45%, var(--brass-deep));
  box-shadow:
    0 0 0 3px var(--ink),
    0 0 0 4px var(--brass-deep),
    inset 0 -3px 6px rgba(0, 0, 0, .35);
  color: var(--brass-ink);
  font: italic 600 34px/1 var(--serif);
  flex: none;
}
.seal span { transform: translateY(1px); }

/* ---------- Buttons & Felder ---------- */

.btn {
  font: 600 15px/1 var(--sans);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 12px 18px;
  cursor: pointer;
  color: var(--text);
  background: var(--raised);
  transition: background-color .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .55; cursor: progress; }

.btn-primary { background: var(--brass); color: var(--brass-ink); }
.btn-primary:hover:not(:disabled) { background: #e6b65b; }

.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(224, 108, 117, .12); }

.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); padding: 9px 14px; }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.btn-link {
  background: none; border: 0; padding: 6px 0;
  color: var(--muted); font-weight: 500; text-decoration: underline; text-underline-offset: 3px;
}
.btn-link:hover { color: var(--text); }

.inline-form { display: inline; margin: 0; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; color: var(--muted); }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  width: 100%;
}
input:focus, textarea:focus { outline: none; border-color: var(--brass); box-shadow: 0 0 0 3px rgba(217, 167, 74, .18); }

.code-input {
  font: 600 26px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: .35em;
  text-align: center;
  padding: 14px 10px;
}

.stack { display: grid; gap: 16px; }

/* ---------- Anmelde-Seiten ---------- */

.auth-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 18px;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(87, 64, 122, .35), transparent 70%),
    var(--ink);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 36px 30px 26px;
  display: grid;
  gap: 18px;
  justify-items: stretch;
}
.auth-card--wide { max-width: 520px; }
.auth-card > .seal { justify-self: center; margin-bottom: 4px; }

.auth-title {
  margin: 0;
  text-align: center;
  font: 600 28px/1.15 var(--serif);
  letter-spacing: -.01em;
}
.auth-lead { margin: 0; color: var(--muted); text-align: center; }
.auth-card > .inline-form { justify-self: center; }

.alert {
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  background: rgba(224, 108, 117, .1);
  border: 1px solid rgba(224, 108, 117, .45);
  color: #f3b3b8;
}
.notice {
  margin: 0; padding: 12px 14px; border-radius: var(--r-sm);
  background: rgba(111, 197, 155, .1); border: 1px solid rgba(111, 197, 155, .4); color: #b6e6cf;
}
.hint { margin: 0; color: var(--muted); font-size: 14px; text-align: center; }

.setup-steps { margin: 0; padding-left: 22px; display: grid; gap: 22px; }
.setup-steps li::marker { color: var(--brass); font-weight: 700; }
.setup-steps p { margin: 0 0 10px; }

.qr-frame {
  display: inline-grid;
  background: #fff;
  border-radius: var(--r-md);
  padding: 4px;
  box-shadow: 0 0 0 1px var(--line);
}
.qr-frame img { display: block; max-width: 100%; height: auto; image-rendering: pixelated; }

.manual { margin-top: 12px; }
.manual summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.secret {
  display: block;
  margin: 10px 0 6px;
  padding: 12px;
  background: var(--ink);
  border: 1px dashed var(--line);
  border-radius: var(--r-sm);
  font: 600 15px/1.6 ui-monospace, Menlo, Consolas, monospace;
  word-break: break-all;
  user-select: all;
}
.manual .hint { text-align: left; }

.progress { display: flex; justify-content: center; gap: 10px; }
.progress-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line);
}
.progress-dot.is-done { background: var(--brass); border-color: var(--brass); }

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

.page-chat { overflow: hidden; }

.chat-app {
  height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  max-width: 980px;
  margin: 0 auto;
  border-inline: 1px solid var(--line);
  background: var(--surface);
  position: relative;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.chat-brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.chat-brand .seal { width: 42px; height: 42px; font-size: 22px; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--brass-deep), inset 0 -2px 4px rgba(0,0,0,.35); }
.chat-title { margin: 0; font: 600 20px/1.2 var(--serif); }
.chat-members { margin: 2px 0 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-header-actions { display: flex; align-items: center; gap: 16px; font-size: 14px; color: var(--muted); }
.me strong { color: var(--text); font-weight: 600; }

.conn { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn.is-online .conn-dot { background: var(--ok); }
.conn.is-offline .conn-dot { background: var(--danger); }
.conn.is-online .conn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Beitrittsanfragen */
.requests {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(217, 167, 74, .09), rgba(217, 167, 74, .03));
  padding: 12px 20px;
  display: grid;
  gap: 10px;
}
.request {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 14px;
  border: 1px solid rgba(217, 167, 74, .35);
  border-left: 4px solid var(--brass);
  border-radius: var(--r-sm);
  background: var(--ink);
}
.request-line { margin: 0; }
.request-meta { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.request-actions { display: flex; gap: 8px; align-items: center; }
.request-actions .btn { padding: 9px 14px; font-size: 14px; }
.request-done { font-size: 13px; color: var(--muted); }

/* Nachrichtenliste */
.messages {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 20px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background:
    radial-gradient(700px 400px at 100% 0%, rgba(61, 44, 85, .25), transparent 70%),
    var(--ink);
}

.empty { margin: auto; color: var(--muted); text-align: center; font-family: var(--serif); font-style: italic; font-size: 18px; }

.day-sep {
  align-self: center;
  margin: 14px 0 8px;
  padding: 3px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.msg { display: flex; }
.msg--mine { justify-content: flex-end; }

.bubble {
  max-width: min(72%, 560px);
  padding: 8px 12px 6px;
  border-radius: var(--r-md);
  background: var(--raised);
  border: 1px solid var(--line);
  display: grid;
  gap: 4px;
}
.msg--theirs .bubble { border-bottom-left-radius: 4px; }
.msg--mine .bubble {
  background: var(--plum);
  border-color: var(--plum-line);
  border-bottom-right-radius: 4px;
}
.msg + .msg { margin-top: 2px; }
.msg--mine + .msg--theirs, .msg--theirs + .msg--mine { margin-top: 10px; }

.msg-author { font-size: 13px; font-weight: 600; color: var(--brass); }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-time { justify-self: end; font-size: 11px; color: var(--muted); }
.msg--mine .msg-time { color: #c3b4da; }

.att-img { display: block; margin: 2px -6px 0; }
.att-img img {
  display: block;
  max-width: 100%;
  max-height: 340px;
  border-radius: 10px;
  background: var(--ink);
}

.att-file {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, .22);
  color: var(--text);
  text-decoration: none;
  min-width: 200px;
}
.att-file:hover { background: rgba(0, 0, 0, .35); }
.att-icon {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--brass); color: var(--brass-ink); font-weight: 700;
}
.att-info { display: grid; min-width: 0; }
.att-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { font-size: 12px; color: var(--muted); }

/* Eingabe */
.composer {
  border-top: 1px solid var(--line);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--surface);
  display: grid;
  gap: 8px;
}
.composer-row { display: flex; align-items: flex-end; gap: 10px; }
.composer textarea {
  resize: none;
  min-height: 46px;
  max-height: 180px;
  line-height: 1.4;
  border-radius: var(--r-md);
}
.attach {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
}
.attach:hover, .attach:focus-within { color: var(--brass); border-color: var(--brass); }
.send { height: 46px; flex: none; border-radius: var(--r-md); }

.file-chip {
  display: inline-flex; align-items: center; gap: 8px;
  justify-self: start;
  max-width: 100%;
  padding: 6px 6px 6px 12px;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--line);
  font-size: 14px;
}
.file-chip[hidden] { display: none; }
.file-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip-remove {
  width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: var(--line); color: var(--text);
  font-size: 16px; line-height: 1; cursor: pointer;
}

.toast {
  position: absolute;
  left: 50%; bottom: 96px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  background: var(--text);
  color: var(--ink);
  border-radius: var(--r-sm);
  font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
}
.toast[hidden] { display: none; }

/* ---------- Klein ---------- */

@media (max-width: 640px) {
  .chat-app { border-inline: 0; }
  .chat-header { padding-inline: 14px; }
  .me { display: none; }
  .messages { padding-inline: 12px; }
  .bubble { max-width: 86%; }
  .requests { padding-inline: 12px; }
  .request-actions { width: 100%; }
  .request-actions .btn { flex: 1; }
  .composer { padding-inline: 10px; }
  .send { padding-inline: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
