/* Wulfy: a wolf pack under the northern sky.
   Night-blue base, moonlight gold for identity and alerts, aurora teal→violet for your own messages. */

@font-face { font-family: "Bricolage"; src: url("/fonts/bricolage.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Manrope"; src: url("/fonts/manrope.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("/fonts/jetbrains-mono.woff2") format("woff2"); font-weight: 500; font-display: swap; }

:root {
  --bg: #10162B;            /* night sky */
  --bg-2: #141B33;          /* chat area */
  --panel: #19213D;         /* sidebar, dialogs */
  --glass: rgba(232, 237, 248, 0.06);
  --glass-strong: rgba(25, 33, 61, 0.72);
  --line: rgba(232, 237, 248, 0.10);
  --ink: #E8EDF8;
  --muted: #95A1C3;
  --received: #1E2748;
  --sent-a: #6656E8;        /* aurora violet */
  --sent-b: #2B78B8;        /* north-sea blue */
  --aurora-1: #3FD9B5;
  --aurora-2: #7C6CF5;
  --aurora-3: #2C8BD6;
  --moon: #F3D7A2;
  --moon-ink: #2B1E06;
  --primary: #6E5EF0;
  --primary-hover: #7F70FF;
  --link: #B4A9FF;
  --danger: #FF8691;
  --danger-bg: #D9465A;
  --good: #57DDB0;
  --focus: #F3D7A2;
  --field: rgba(232, 237, 248, 0.06);
  --shadow: 0 24px 60px rgba(4, 7, 20, 0.55);
  --radius-l: 28px;
  --radius-m: 18px;
  --radius-s: 12px;
  --display: "Bricolage", "Avenir Next", system-ui, sans-serif;
  --text: "Manrope", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
/* Dawn: follows the device, unless Night or Dawn is chosen in Settings */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #EDF0F8; --bg-2: #F4F6FB; --panel: #FFFFFF;
    --glass: rgba(255, 255, 255, 0.72); --glass-strong: rgba(255, 255, 255, 0.82);
    --line: rgba(21, 27, 48, 0.10); --ink: #151B30; --muted: #59637F; --received: #FFFFFF;
    --moon: #B87A12; --moon-ink: #FFFFFF; --primary: #5B4BE0; --primary-hover: #4C3CD3; --link: #5244D6;
    --danger: #C23547; --danger-bg: #C23547; --good: #13805B; --focus: #5B4BE0; --field: #FFFFFF;
    --shadow: 0 24px 60px rgba(30, 40, 80, 0.16);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
    --bg: #EDF0F8; --bg-2: #F4F6FB; --panel: #FFFFFF;
    --glass: rgba(255, 255, 255, 0.72); --glass-strong: rgba(255, 255, 255, 0.82);
    --line: rgba(21, 27, 48, 0.10); --ink: #151B30; --muted: #59637F; --received: #FFFFFF;
    --moon: #B87A12; --moon-ink: #FFFFFF; --primary: #5B4BE0; --primary-hover: #4C3CD3; --link: #5244D6;
    --danger: #C23547; --danger-bg: #C23547; --good: #13805B; --focus: #5B4BE0; --field: #FFFFFF;
    --shadow: 0 24px 60px rgba(30, 40, 80, 0.16);
    color-scheme: light;
}

*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--text); font-size: 1rem; line-height: 1.55; font-weight: 450;
  -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); margin: 0 0 10px; line-height: 1.1; letter-spacing: -0.02em; font-weight: 700; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.3rem; }
p { margin: 0 0 12px; }
.mono, code { font-family: var(--mono); font-size: 0.94em; letter-spacing: 0.02em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hint { color: var(--muted); font-size: 0.86rem; }
.err { color: var(--danger); font-size: 0.92rem; font-weight: 600; }
.ok { color: var(--good); font-size: 0.92rem; font-weight: 600; }
.warn { background: color-mix(in srgb, var(--moon) 14%, transparent); border: 1px solid color-mix(in srgb, var(--moon) 35%, transparent); border-radius: var(--radius-s); padding: 11px 14px; font-size: 0.92rem; }

/* ---------- The sky (sign-in and lock screens) ---------- */
.sky { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.aurora { position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%; filter: blur(70px); opacity: 0.32; animation: drift 26s ease-in-out infinite alternate; }
.a1 { left: -25vmax; top: -38vmax; background: radial-gradient(circle, var(--aurora-1), transparent 62%); }
.a2 { right: -30vmax; top: -30vmax; background: radial-gradient(circle, var(--aurora-2), transparent 62%); animation-duration: 32s; animation-direction: alternate-reverse; }
.a3 { left: 10vmax; bottom: -55vmax; background: radial-gradient(circle, var(--aurora-3), transparent 60%); opacity: 0.18; animation-duration: 38s; }
.stars {
  position: absolute; inset: 0; opacity: 0.55;
  background-image:
    radial-gradient(1px 1px at 12% 18%, #fff, transparent), radial-gradient(1px 1px at 28% 72%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 44% 32%, #fff, transparent), radial-gradient(1px 1px at 61% 12%, #fff, transparent),
    radial-gradient(1px 1px at 77% 58%, #fff, transparent), radial-gradient(1.5px 1.5px at 89% 26%, #fff, transparent),
    radial-gradient(1px 1px at 8% 88%, #fff, transparent), radial-gradient(1px 1px at 53% 91%, #fff, transparent),
    radial-gradient(1px 1px at 69% 81%, #fff, transparent), radial-gradient(1px 1px at 35% 49%, #fff, transparent);
  background-size: 520px 520px;
}
@keyframes drift { from { transform: translate3d(0, 0, 0) scale(1); } to { transform: translate3d(6vmax, 4vmax, 0) scale(1.12); } }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .aurora { opacity: 0.22; } :root:not([data-theme="dark"]) .stars { display: none; } }
:root[data-theme="light"] .aurora { opacity: 0.22; }
:root[data-theme="light"] .stars { display: none; }
.app:not([hidden]) ~ .sky, body:has(.app:not([hidden])) .sky, body:has(.admin:not([hidden])) .sky { display: none; }

/* Crescent moon: a transparent circle whose offset shadow forms the crescent. */
.moon { display: inline-block; width: 0.42em; height: 0.42em; border-radius: 50%; margin-left: 0.28em; vertical-align: 0.5em; box-shadow: -0.11em 0.05em 0 0 var(--moon); }
.hero-moon { width: 76px; height: 76px; border-radius: 50%; margin: 0 0 26px 22px; box-shadow: -20px 9px 0 0 var(--moon); filter: drop-shadow(0 0 28px color-mix(in srgb, var(--moon) 55%, transparent)); }
.hero-moon.small { width: 54px; height: 54px; margin: 0 auto 20px; box-shadow: -14px 6px 0 0 var(--moon); transform: translateX(7px); }

/* ---------- Buttons and fields ---------- */
button {
  font: inherit; font-weight: 700; cursor: pointer; border: 0; border-radius: 999px;
  padding: 13px 22px; background: var(--primary); color: #FFFFFF; letter-spacing: 0.005em;
  transition: background-color 0.15s, transform 0.1s;
}
button:hover { background: var(--primary-hover); }
button:active { transform: scale(0.98); }
button.secondary { background: var(--glass); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
button.secondary:hover { background: color-mix(in srgb, var(--ink) 10%, transparent); }
button.link { background: none; color: var(--link); padding: 8px 4px; font-weight: 600; }
button.link:hover { background: none; text-decoration: underline; text-underline-offset: 3px; }
button.link.danger { color: var(--danger); }
button.danger-btn { background: var(--danger-bg); color: #FFFFFF; }
button.danger-btn:hover { background: color-mix(in srgb, var(--danger-bg) 85%, #000); }
button.small { padding: 7px 15px; font-size: 0.86rem; }
button:disabled { opacity: 0.55; cursor: progress; transform: none; }
:is(button, input, textarea, select, summary, [tabindex]):focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

label { display: block; font-weight: 700; font-size: 0.9rem; margin: 16px 0 7px; }
label input, label select { display: block; width: 100%; margin-top: 7px; font-weight: 500; }
input, textarea, select {
  font: inherit; font-size: 1rem; font-weight: 500; color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: 13px 16px; min-width: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 25%, transparent); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }
select { width: 100%; }
details { font-size: 0.9rem; color: var(--muted); margin: 6px 0; }
summary { cursor: pointer; font-weight: 600; }

/* ---------- Screens (welcome, sign-up steps, sign-in, unlock) ---------- */
.screen { position: relative; z-index: 1; min-height: 100%; display: grid; place-items: center; padding: 32px 20px; }
.card {
  width: 100%; max-width: 440px; padding: 30px 28px;
  background: var(--glass-strong); border: 1px solid var(--line); border-radius: var(--radius-l);
  box-shadow: var(--shadow); -webkit-backdrop-filter: blur(20px) saturate(1.2); backdrop-filter: blur(20px) saturate(1.2);
}
#welcome .card, #loading .card { background: none; border: 0; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; padding: 0; }
.card.center { text-align: center; }
.wordmark { font-family: var(--display); font-weight: 800; letter-spacing: -0.04em; font-size: 1.6rem; line-height: 1; }
.wordmark.big { font-size: clamp(3.2rem, 15vw, 5.2rem); margin-bottom: 18px; font-variation-settings: "opsz" 96; }
.lede { font-size: 1.12rem; color: var(--muted); margin-bottom: 34px; max-width: 34ch; line-height: 1.6; }
.stack { display: grid; gap: 12px; }
.stack button { width: 100%; padding: 15px 22px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 24px; }
.row.end { justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; justify-content: flex-end; }
.step { color: var(--moon); font-weight: 700; font-size: 0.86rem; margin-bottom: 8px; letter-spacing: 0.01em; }
.meter { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 10px; }
.meter span { display: block; height: 100%; width: 0; background: var(--danger); border-radius: 3px; transition: width 0.25s, background-color 0.25s; }
.meter span.mid { background: var(--moon); }
.meter span.strong { background: linear-gradient(90deg, var(--aurora-1), var(--aurora-2)); }
.idbox { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--field); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px 18px; margin-bottom: 16px; }
.idbox code { font-size: clamp(1rem, 4.6vw, 1.3rem); font-weight: 500; letter-spacing: 0.04em; flex: 1; color: var(--moon); white-space: nowrap; }
.qr { display: grid; place-items: center; background: #FFFFFF; border-radius: var(--radius-m); padding: 14px; width: max-content; margin: 10px auto 14px; }
.secret { display: block; word-break: break-all; margin-top: 8px; color: var(--ink); }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 22px; background: var(--field); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px 18px 16px 40px; font-size: 1.05rem; }

/* Lock screen PIN */
.pinwrap { position: relative; width: max-content; margin: 18px auto 10px; }
.pin-dots { display: flex; gap: 16px; padding: 10px 6px; cursor: text; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); transition: background-color 0.12s, border-color 0.12s, transform 0.12s; }
.pin-dots i.on { background: var(--moon); border-color: var(--moon); transform: scale(1.08); }
.pin-dots.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
input.pin { position: absolute; inset: 0; width: 100%; opacity: 0; font-size: 16px; caret-color: transparent; cursor: text; }
.pinwrap:focus-within .pin-dots i:not(.on) { border-color: var(--ink); }
#locked .stack { margin-top: 22px; }

/* ---------- App shell ---------- */
.app { position: relative; z-index: 1; height: 100%; display: grid; grid-template-columns: 340px 1fr; background: var(--bg); }
.side { background: var(--bg); display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 20px 16px 8px 22px; }
.side-actions { display: flex; gap: 6px; }
button.icon { width: 42px; height: 42px; padding: 0; display: grid; place-items: center; font-size: 1.2rem; font-weight: 600; background: var(--glass); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
button.icon:hover { background: color-mix(in srgb, var(--ink) 12%, transparent); }
.me { margin: 4px 22px 14px; font-size: 0.82rem; color: var(--muted); }
.me code { color: var(--moon); }
.convos { list-style: none; margin: 0; padding: 4px 10px 16px; overflow-y: auto; flex: 1; }
.convos li + li { margin-top: 2px; }
.convos button {
  width: 100%; text-align: left; background: transparent; color: var(--ink); border-radius: var(--radius-m);
  padding: 11px 12px; display: grid; grid-template-columns: auto 1fr auto; gap: 1px 12px; align-items: center; font-weight: 500;
}
.convos button:hover { background: var(--glass); }
.convos button[aria-current="true"] { background: var(--glass); box-shadow: inset 3px 0 0 var(--aurora-1); }
.convos .avatar { grid-row: span 2; }
.convos .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convos .time { font-size: 0.75rem; color: var(--muted); }
.convos .preview { font-size: 0.86rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--moon); color: var(--moon-ink); border-radius: 999px; font-size: 0.72rem; font-weight: 800; padding: 2px 8px; justify-self: end; }
.side .empty { color: var(--muted); font-size: 0.92rem; padding: 18px 14px; line-height: 1.6; }

/* Avatars: a gradient chosen from the ID, so every member has a look without a photo or name. */
.avatar { width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 800; font-size: 0.82rem; color: #FFFFFF; letter-spacing: 0.02em; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }
.avatar.h0 { background: linear-gradient(135deg, #3FD9B5, #2C78B8); }
.avatar.h1 { background: linear-gradient(135deg, #7C6CF5, #C25FD6); }
.avatar.h2 { background: linear-gradient(135deg, #F0B35A, #D9465A); }
.avatar.h3 { background: linear-gradient(135deg, #2C8BD6, #6656E8); }
.avatar.h4 { background: linear-gradient(135deg, #57C47A, #2C8BA6); }
.avatar.h5 { background: linear-gradient(135deg, #E86F9A, #7C6CF5); }
.avatar.h6 { background: linear-gradient(135deg, #9AA7C7, #4A5578); }
.avatar.h7 { background: linear-gradient(135deg, #E9C46A, #3FA59B); }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: radial-gradient(120% 70% at 100% 0%, color-mix(in srgb, var(--aurora-2) 9%, transparent), transparent 60%), var(--bg-2); }
.chat-top { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--glass-strong); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.chat-title h2 { font-size: 1.15rem; margin: 0; letter-spacing: -0.01em; }
.chat-title .link { padding: 0; font-size: 0.8rem; }
.back { display: none; background: none; color: var(--ink); padding: 4px 10px 4px 0; font-size: 1.8rem; line-height: 1; }
.back:hover { background: none; }
.thread { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.placeholder, .thread .empty { color: var(--muted); margin: auto; text-align: center; max-width: 30ch; line-height: 1.6; }
.day { align-self: center; font-size: 0.74rem; font-weight: 700; color: var(--muted); background: var(--glass); border-radius: 999px; padding: 3px 12px; margin: 10px 0; }
.msg { max-width: min(76%, 560px); padding: 9px 14px 6px; border-radius: 20px; word-wrap: break-word; line-height: 1.45; }
.msg p { margin: 0; white-space: pre-wrap; }
.msg small { display: block; text-align: right; font-size: 0.68rem; opacity: 0.72; margin-top: 2px; font-weight: 600; }
.msg.out { align-self: flex-end; background: linear-gradient(135deg, var(--sent-a), var(--sent-b)); color: #FFFFFF; border-bottom-right-radius: 6px; box-shadow: 0 6px 18px color-mix(in srgb, var(--sent-a) 25%, transparent); }
.msg.in { align-self: flex-start; background: var(--received); border: 1px solid var(--line); border-bottom-left-radius: 6px; cursor: pointer; }
.msg + .msg.out, .msg + .msg.in { margin-top: 0; }
.msg.locked p { font-style: italic; opacity: 0.8; }
.msg p.scrambling { font-family: var(--mono); font-size: 0.88rem; color: var(--aurora-1); }
.msg-actions { align-self: flex-start; margin: -1px 0 6px; }
.msg-actions button { font-size: 0.8rem; padding: 6px 14px; }
.ttl-note { align-self: center; font-size: 0.78rem; font-weight: 600; color: var(--muted); border: 1px dashed var(--line); border-radius: 999px; padding: 4px 14px; margin-bottom: 4px; }
.composer { display: flex; align-items: flex-end; gap: 8px; margin: 0 16px 16px; padding: 6px 6px 6px 8px; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.composer textarea { flex: 1; resize: none; max-height: 140px; border: 0; background: transparent; padding: 11px 10px; border-radius: 20px; }
.composer textarea:focus, .composer textarea:focus-visible { box-shadow: none; outline: none; }
.composer:focus-within { border-color: color-mix(in srgb, var(--primary) 70%, transparent); box-shadow: var(--shadow), 0 0 0 4px color-mix(in srgb, var(--primary) 22%, transparent); }
.composer button { padding: 11px 20px; }
.banner { background: color-mix(in srgb, var(--moon) 16%, var(--bg-2)); font-size: 0.86rem; font-weight: 600; padding: 9px 18px; }
.announce { background: linear-gradient(90deg, color-mix(in srgb, var(--aurora-1) 22%, var(--bg-2)), color-mix(in srgb, var(--aurora-2) 22%, var(--bg-2))); font-size: 0.88rem; font-weight: 600; padding: 10px 18px; }

/* Safety code changed */
.key-alert { border: 1px solid color-mix(in srgb, var(--moon) 45%, transparent); background: color-mix(in srgb, var(--moon) 12%, var(--bg-2)); border-radius: var(--radius-m); padding: 14px 16px; margin-bottom: 10px; font-size: 0.92rem; }
.key-alert p { margin: 0; }
.verified { font-family: var(--text); font-size: 0.72rem; font-weight: 800; color: var(--good); background: color-mix(in srgb, var(--good) 16%, transparent); border-radius: 999px; padding: 2px 8px; vertical-align: 0.15em; letter-spacing: 0; }
.typing { display: block; font-size: 0.8rem; font-weight: 700; color: var(--aurora-1); }
.typing:not([hidden]) + .link { display: none; }

/* Replies and reactions */
.quote-in { font-size: 0.82rem; line-height: 1.35; padding: 6px 10px; margin: 0 0 6px; border-left: 3px solid currentColor; border-radius: 8px; background: rgba(0, 0, 0, 0.16); opacity: 0.9; cursor: pointer; overflow-wrap: anywhere; }
.msg.in .quote-in { background: var(--glass); border-left-color: var(--aurora-2); }
.reactions { display: flex; gap: 4px; margin: -4px 8px 4px; }
.reactions.out { align-self: flex-end; }
.reactions.in { align-self: flex-start; }
.reactions .chip { font-size: 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.reactions .chip.mine { border-color: var(--aurora-2); }
.msg-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 8px; max-width: 100%; }
.msg-actions.out { align-self: flex-end; justify-content: flex-end; }
.msg-actions.in { align-self: flex-start; }
.msg-actions button.emoji { background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); padding: 5px 9px; font-size: 1.1rem; line-height: 1; }
.msg-actions button.emoji.on { box-shadow: inset 0 0 0 2px var(--aurora-2); }
.msg.pending { opacity: 0.6; }
.reply-bar { display: flex; align-items: center; gap: 10px; margin: 0 16px -6px; padding: 10px 14px 16px; background: var(--panel); border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; font-size: 0.86rem; }
.reply-bar div { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.reply-bar b { color: var(--aurora-1); margin-right: 6px; }
.qr-link { font-size: 0.78rem; word-break: break-all; color: var(--muted); text-align: center; }
#infoQrBtn { margin-top: 4px; }

/* Photos and voice notes */
.composer button.tool { background: none; color: var(--ink); padding: 8px; font-size: 1.2rem; line-height: 1; border-radius: 50%; flex: none; }
.composer button.tool:hover { background: var(--glass); }
.media { display: inline-block; vertical-align: top; border-radius: 14px; overflow: hidden; margin: -3px -8px 4px; }
.media img { display: block; width: min(300px, 62vw); height: auto; max-height: 380px; object-fit: cover; cursor: zoom-in; border-radius: 14px; }
.media audio { display: block; width: min(280px, 64vw); height: 40px; }
.media .loading { display: grid; place-items: center; width: 220px; height: 140px; font-size: 0.86rem; background: rgba(0, 0, 0, 0.16); border-radius: 14px; }
.media.voice { display: flex; align-items: center; gap: 8px; margin: 2px 0 4px; overflow: visible; }
.media .dur { font-family: var(--mono); font-size: 0.78rem; opacity: 0.85; white-space: nowrap; }
.recording { display: flex; align-items: center; gap: 12px; margin: 0 16px 16px; padding: 10px 10px 10px 18px; background: var(--glass-strong); border: 1px solid color-mix(in srgb, var(--danger) 50%, transparent); border-radius: 28px; }
.recording #recTime { font-family: var(--mono); font-weight: 600; }
.recording .muted { flex: 1; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
dialog.viewer { width: auto; max-width: calc(100vw - 24px); padding: 12px; background: var(--panel); }
dialog.viewer img { display: block; max-width: calc(100vw - 48px); max-height: calc(100vh - 140px); border-radius: 12px; }

/* Backup words and transfer codes */
.btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.words { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 14px; background: var(--field); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px 16px 16px 40px; font-size: 1rem; }
.bigcode { font-size: 2.2rem; text-align: center; letter-spacing: 0.08em; color: var(--moon); margin: 10px 0; }
#bkInput { width: 100%; resize: vertical; margin-top: 7px; }
@media (max-width: 420px) { .words { grid-template-columns: repeat(2, 1fr); } }

/* Hide chats when the app is in the background (app switcher previews) */
body.veiled .app, body.veiled .admin, body.veiled dialog { filter: blur(28px); }

/* ---------- Dialogs ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 26px; padding: 26px; width: min(460px, calc(100% - 28px));
  background: var(--panel); color: var(--ink); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(6, 9, 22, 0.6); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
dialog section { border-top: 1px solid var(--line); padding: 14px 0; }
dialog section p { margin-bottom: 8px; }
.quote { margin: 10px 0 6px; padding: 11px 15px; border-left: 3px solid var(--moon); background: var(--field); border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; max-height: 180px; overflow: auto; }
.devices { list-style: none; margin: 8px 0 0; padding: 0; }
.devices li { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-top: 1px solid var(--line); }
.devices li div { flex: 1; min-width: 0; }
.devices b { display: block; }
.devices span { color: var(--muted); font-size: 0.85rem; }
.devices button { font-size: 0.85rem; padding: 7px 14px; }
.switch { display: flex; align-items: center; gap: 12px; font-weight: 700; margin: 0; }
.switch input { width: 20px; height: 20px; margin: 0; accent-color: var(--primary); display: inline-block; }
.switch.check { font-weight: 600; margin-top: 16px; }

/* ---------- Admin ---------- */
.admin { position: relative; z-index: 1; height: 100%; overflow-y: auto; background: var(--bg); }
.admin-top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; padding: 14px 20px; background: var(--glass-strong); border-bottom: 1px solid var(--line); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.admin-top .wordmark { margin: 0; font-size: 1.4rem; text-align: center; }
.admin-top .link { justify-self: start; }
.admin-lock { justify-self: end; display: flex; align-items: center; gap: 10px; }
.admin-unlock { margin: 56px auto; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 12px 16px 0; border-bottom: 1px solid var(--line); max-width: 1100px; margin: 0 auto; }
.tabs button { background: none; color: var(--muted); border-radius: 12px 12px 0 0; padding: 11px 15px; white-space: nowrap; font-weight: 700; border-bottom: 3px solid transparent; }
.tabs button:hover { color: var(--ink); background: none; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--moon); }
.admin-body { max-width: 1100px; margin: 0 auto; padding: 22px 20px 48px; }
.admin-body h2 { font-size: 1.3rem; margin: 26px 0 14px; }
.admin-body h2:first-child { margin-top: 4px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px 18px; }
.stat b { display: block; font-family: var(--display); font-size: 2rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat span { color: var(--muted); font-size: 0.86rem; font-weight: 600; }
.stat.alert b { color: var(--danger); }
.chart { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px; overflow-x: auto; }
.chart svg { display: block; width: 100%; min-width: 520px; height: auto; }
.chart .bar { fill: var(--aurora-2); }
.chart .bar2 { fill: var(--moon); }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--text); }
.chart .grid { stroke: var(--line); }
.legend { display: flex; gap: 16px; font-size: 0.86rem; color: var(--muted); margin-top: 8px; font-weight: 600; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.legend .l1 { background: var(--aurora-2); } .legend .l2 { background: var(--moon); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input { flex: 1 1 220px; }
.toolbar select { width: auto; margin: 0; }
.list { display: grid; gap: 10px; }
.item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px 18px; }
.item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item-head code { font-weight: 500; font-size: 1rem; }
.item-meta { color: var(--muted); font-size: 0.86rem; margin: 6px 0 0; }
.item-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.item-actions button { font-size: 0.85rem; padding: 7px 15px; }
.tag { font-size: 0.72rem; font-weight: 800; padding: 2px 9px; border-radius: 999px; background: var(--glass); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.tag.admin { background: var(--moon); color: var(--moon-ink); box-shadow: none; }
.tag.blocked { background: var(--danger-bg); color: #FFFFFF; box-shadow: none; }
.tag.online { background: color-mix(in srgb, var(--good) 22%, transparent); color: var(--good); box-shadow: none; }
.tag.warn { color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); background: none; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px; margin-bottom: 14px; }
.panel textarea { width: 100%; min-height: 84px; resize: vertical; margin-top: 6px; }
.log { list-style: none; margin: 0; padding: 0; }
.log li { display: grid; grid-template-columns: 160px 1fr; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; }
.empty-note { color: var(--muted); padding: 28px 0; text-align: center; }

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app[data-view="list"] .chat { display: none; }
  .app[data-view="chat"] .side { display: none; }
  .side { border-right: 0; }
  .back { display: inline-block; }
  .composer { margin: 0 10px 10px; }
  .reply-bar { margin: 0 10px -6px; }
  .recording { margin: 0 10px 10px; }
  .thread { padding: 14px 12px; }
  .msg { max-width: 84%; }
  .card { padding: 26px 22px; }
  #welcome { align-items: end; padding-bottom: 48px; }
}
@media (max-width: 600px) {
  .log li { grid-template-columns: 1fr; gap: 2px; }
  .admin-top { grid-template-columns: auto 1fr auto; }
  .admin-top .wordmark { font-size: 1.15rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- More themes (Settings → Appearance). Each sets the full palette. ---------- */
/* Midnight: true black for OLED screens */
:root[data-theme="midnight"] {
  --bg: #000000; --bg-2: #000000; --panel: #0E0E12; --glass: rgba(255, 255, 255, 0.06); --glass-strong: rgba(14, 14, 18, 0.86);
  --line: rgba(255, 255, 255, 0.10); --ink: #EDEDF2; --muted: #8E8E99; --received: #17171D;
  --sent-a: #5B4BE0; --sent-b: #2B6CB0; --moon: #F3D7A2; --moon-ink: #2B1E06; --primary: #6E5EF0; --primary-hover: #7F70FF; --link: #B4A9FF;
  --danger: #FF8691; --danger-bg: #D9465A; --good: #57DDB0; --focus: #F3D7A2; --field: rgba(255, 255, 255, 0.06);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.7); color-scheme: dark;
}
/* Forest: light, calm greens, warm chat background */
:root[data-theme="forest"] {
  --bg: #EEF3EC; --bg-2: #E8EEE2; --panel: #FFFFFF; --glass: rgba(255, 255, 255, 0.75); --glass-strong: rgba(255, 255, 255, 0.88);
  --line: rgba(22, 40, 28, 0.10); --ink: #15241A; --muted: #5A6B5F; --received: #FFFFFF;
  --sent-a: #2E8B57; --sent-b: #226F45; --moon: #A9701A; --moon-ink: #FFFFFF; --primary: #2C7A4F; --primary-hover: #236842; --link: #23714A;
  --danger: #B93648; --danger-bg: #B93648; --good: #1E7A52; --focus: #2C7A4F; --field: #FFFFFF;
  --aurora-1: #8FD3A8; --aurora-2: #B9DFA1; --aurora-3: #9CC9B3;
  --shadow: 0 20px 50px rgba(30, 60, 40, 0.14); color-scheme: light;
}
/* Ocean: light, clean whites, blue sent bubbles */
:root[data-theme="ocean"] {
  --bg: #F3F6FA; --bg-2: #FFFFFF; --panel: #FFFFFF; --glass: rgba(255, 255, 255, 0.8); --glass-strong: rgba(255, 255, 255, 0.9);
  --line: rgba(20, 32, 46, 0.10); --ink: #13202D; --muted: #586677; --received: #EEF1F5;
  --sent-a: #2C66D8; --sent-b: #2C66D8; --moon: #A9701A; --moon-ink: #FFFFFF; --primary: #2C66D8; --primary-hover: #2457BD; --link: #2459C4;
  --danger: #C23547; --danger-bg: #C23547; --good: #1C7C56; --focus: #2C66D8; --field: #FFFFFF;
  --aurora-1: #9CC3F5; --aurora-2: #B7C7F2; --aurora-3: #A5D3EE;
  --shadow: 0 20px 50px rgba(20, 40, 80, 0.12); color-scheme: light;
}
/* Graphite: neutral greys, very minimal */
:root[data-theme="graphite"] {
  --bg: #1C1C1E; --bg-2: #202022; --panel: #2A2A2D; --glass: rgba(255, 255, 255, 0.06); --glass-strong: rgba(42, 42, 45, 0.9);
  --line: rgba(255, 255, 255, 0.10); --ink: #ECECEF; --muted: #9C9CA3; --received: #2E2E32;
  --sent-a: #3F6FD1; --sent-b: #3A62B8; --moon: #D8C7A0; --moon-ink: #241B08; --primary: #3F6FD1; --primary-hover: #4A7AE0; --link: #8FB0F5;
  --danger: #FF8691; --danger-bg: #C9424F; --good: #6FD1A6; --focus: #D8C7A0; --field: rgba(255, 255, 255, 0.06);
  --aurora-1: #6B6B75; --aurora-2: #55555E; --aurora-3: #5E6470;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.5); color-scheme: dark;
}
:root:is([data-theme="forest"], [data-theme="ocean"]) .stars { display: none; }
:root:is([data-theme="forest"], [data-theme="ocean"]) .aurora { opacity: 0.35; }
:root:is([data-theme="midnight"], [data-theme="graphite"]) .aurora { opacity: 0.16; }
:root[data-theme="graphite"] .stars { opacity: 0.25; }

/* ---------- Chat wallpaper (Settings → Appearance) ---------- */
:root[data-wall="plain"] .chat { background: var(--bg-2); }
:root[data-wall="stars"] .thread {
  background-image:
    radial-gradient(1px 1px at 12% 18%, color-mix(in srgb, var(--ink) 45%, transparent), transparent), radial-gradient(1px 1px at 68% 34%, color-mix(in srgb, var(--ink) 35%, transparent), transparent),
    radial-gradient(1.5px 1.5px at 38% 62%, color-mix(in srgb, var(--ink) 40%, transparent), transparent), radial-gradient(1px 1px at 84% 78%, color-mix(in srgb, var(--ink) 35%, transparent), transparent),
    radial-gradient(1px 1px at 22% 88%, color-mix(in srgb, var(--ink) 30%, transparent), transparent), radial-gradient(1.5px 1.5px at 56% 8%, color-mix(in srgb, var(--moon) 60%, transparent), transparent);
  background-size: 260px 260px;
}
:root[data-wall="dots"] .thread {
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 9%, transparent) 1.2px, transparent 1.4px);
  background-size: 22px 22px;
}
:root[data-wall="paws"] .thread {
  background-image:
    radial-gradient(circle at 50% 62%, color-mix(in srgb, var(--ink) 7%, transparent) 5px, transparent 5.5px),
    radial-gradient(circle at 38% 44%, color-mix(in srgb, var(--ink) 7%, transparent) 2.4px, transparent 2.9px),
    radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--ink) 7%, transparent) 2.4px, transparent 2.9px),
    radial-gradient(circle at 62% 44%, color-mix(in srgb, var(--ink) 7%, transparent) 2.4px, transparent 2.9px);
  background-size: 64px 64px;
}

/* ---------- Text size (Settings → Appearance) ---------- */
:root[data-text="s"] { font-size: 14.5px; }
:root[data-text="l"] { font-size: 18px; }
:root[data-text="xl"] { font-size: 20px; }

/* ---------- Ticks, unread, trust dots, timer, swipe, phone tabs ---------- */
.tick { margin-left: 4px; letter-spacing: -0.18em; font-weight: 800; }
.tick.read { color: #7FE3FF; }
:root:is([data-theme="light"], [data-theme="forest"], [data-theme="ocean"]) .msg.out .tick.read { color: #CFF3FF; }
.convos button.unread .name, .convos button.unread .preview { color: var(--ink); font-weight: 800; }
.trust { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-left: 6px; vertical-align: 0.1em; flex: none; box-shadow: inset 0 0 0 1.5px var(--muted); }
.trust.t1 { background: var(--moon); box-shadow: none; }
.trust.t2 { background: var(--good); box-shadow: none; }
.chat-timer { font-size: 0.85rem; margin-left: 6px; color: var(--muted); font-family: var(--text); }
.msg { touch-action: pan-y; transition: transform 0.15s; }
.msg.swiping { transition: none; }
.swipe-hint { position: absolute; left: -26px; top: 50%; transform: translateY(-50%); opacity: 0; font-size: 1rem; }
.tabbar, .fab { display: none; }
@media (max-width: 760px) {
  .side { position: relative; }
  .side-actions { display: none; }
  .tabbar { display: flex; border-top: 1px solid var(--line); background: var(--glass-strong); padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)); }
  .tabbar button { flex: 1; background: none; color: var(--muted); padding: 8px; border-radius: 12px; font-size: 0.82rem; display: grid; justify-items: center; gap: 2px; }
  .tabbar button span { font-size: 1.2rem; }
  .tabbar button[aria-current="true"] { color: var(--ink); background: var(--glass); }
  .fab { display: grid; place-items: center; position: absolute; right: 18px; bottom: 82px; width: 58px; height: 58px; padding: 0; border-radius: 18px; font-size: 1.6rem; box-shadow: var(--shadow); }
}

/* ---------- Settings groups, My ID card, contact profile ---------- */
h4.group { margin: 22px 0 4px; font-family: var(--display); font-size: 0.95rem; letter-spacing: 0.02em; color: var(--moon); }
.idcard { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; align-items: center; padding: 16px; margin: 6px 0 4px; border-radius: var(--radius-m);
  background: linear-gradient(135deg, color-mix(in srgb, var(--sent-a) 22%, var(--panel)), color-mix(in srgb, var(--sent-b) 16%, var(--panel))); border: 1px solid var(--line); }
.idcard .avatar { width: 54px; height: 54px; font-size: 1rem; }
.idcard-text p { margin: 0; }
.idcard-id { display: block; font-size: 1.1rem; font-weight: 600; color: var(--ink); letter-spacing: 0.04em; white-space: nowrap; }
.idcard .btn-row { grid-column: 1 / -1; margin-top: 6px; }
dialog.profile .profile-head { text-align: center; padding-bottom: 8px; }
.avatar.big { width: 76px; height: 76px; font-size: 1.4rem; margin: 0 auto 10px; }
dialog.profile h3 { margin: 0 0 2px; }
.trust-line { display: flex; justify-content: center; align-items: center; gap: 4px; font-size: 0.85rem; color: var(--muted); margin: 8px 0 0; }
.codes-pair { display: flex; justify-content: space-between; gap: 10px; margin: 0 0 4px; }
.chat-title h2 { cursor: pointer; }
#chatVerified { display: none !important; }
.avatar.self { background: linear-gradient(135deg, var(--moon), color-mix(in srgb, var(--moon) 55%, var(--sent-a))); color: var(--moon-ink); font-size: 1.1rem; }

/* ---------- Secure Notes ---------- */
dialog.notes { width: min(640px, calc(100% - 20px)); }
.notes-top { margin-top: 0; }
.notes-top h3 { margin: 0; }
.note-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 60vh; overflow-y: auto; }
.note-list button { width: 100%; text-align: left; background: var(--field); color: var(--ink); border-radius: var(--radius-s); padding: 12px 14px; box-shadow: inset 0 0 0 1px var(--line); font-weight: 500; display: grid; gap: 2px; }
.note-list button:hover { background: var(--glass); }
.note-list b { font-weight: 700; }
.note-list span { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#ntEdTitle { width: 100%; font-weight: 700; font-size: 1.1rem; margin-bottom: 8px; }
#ntEdBody { width: 100%; resize: vertical; min-height: 220px; }
