/* Fonts are served from this site (no third-party font requests). SIL OFL 1.1, see fonts/OFL.txt. */
@font-face { font-family: "Cormorant"; src: url("fonts/cormorant-garamond-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Cormorant"; src: url("fonts/cormorant-garamond-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Inter"; src: url("fonts/inter-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Inter"; src: url("fonts/inter-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Inter"; src: url("fonts/inter-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }

/* Noir (default) */
:root {
  --bg: #08080a;
  --panel: #0f0f12;
  --panel-2: #16161a;
  --chat-bg: #0b0b0d;
  --text: #ece6da;
  --muted: #8a857b;
  --border: rgba(201, 169, 110, 0.13);
  --hover: #17171b;
  --gold: #c9a96e;
  --gold-hi: #e6cc94;
  --gold-lo: #8f6f3a;
  --accent: #c9a96e;
  --accent-strong: #e0c48f;
  --accent-text: #0b0b0c;
  --bubble-in: #18181c;
  --bubble-out: #2a2318;
  --bubble-out-text: #f3ead8;
  --tick-read: #e6cc94;
  --warn-bg: #2b2112;
  --warn-border: #7a5c2a;
  --error: #e3826f;
  --ok: #8fbf8a;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
  --radius: 12px;
  --serif: "Cormorant", "Cormorant Garamond", Garamond, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
/* Ivory */
:root[data-theme="light"] {
  --bg: #f4f1ea;
  --panel: #fbfaf6;
  --panel-2: #f0ece2;
  --chat-bg: #f2eee5;
  --text: #1c1a16;
  --muted: #7b756a;
  --border: rgba(143, 111, 58, 0.16);
  --hover: #f1ede4;
  --gold: #a8854a;
  --gold-hi: #c9a96e;
  --gold-lo: #7a5c2a;
  --accent: #9a7740;
  --accent-strong: #7f602f;
  --accent-text: #ffffff;
  --bubble-in: #ffffff;
  --bubble-out: #efe5cf;
  --bubble-out-text: #1c1a16;
  --tick-read: #9a7740;
  --warn-bg: #fbf0d9;
  --warn-border: #d8b46f;
  --error: #b3452f;
  --ok: #3f8a4a;
  --shadow: 0 1px 1px rgba(60, 45, 20, 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    --bg: #f4f1ea; --panel: #fbfaf6; --panel-2: #f0ece2; --chat-bg: #f2eee5; --text: #1c1a16; --muted: #7b756a;
    --border: rgba(143, 111, 58, 0.16); --hover: #f1ede4; --gold: #a8854a; --gold-hi: #c9a96e; --gold-lo: #7a5c2a;
    --accent: #9a7740; --accent-strong: #7f602f; --accent-text: #ffffff; --bubble-in: #ffffff; --bubble-out: #efe5cf;
    --bubble-out-text: #1c1a16; --tick-read: #9a7740; --warn-bg: #fbf0d9; --warn-border: #d8b46f; --error: #b3452f;
    --ok: #3f8a4a; --shadow: 0 1px 1px rgba(60, 45, 20, 0.08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  font: 15px/1.45 var(--sans);
  letter-spacing: -0.005em;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
::selection { background: color-mix(in srgb, var(--gold) 35%, transparent); }
.sprite { position: absolute; }
.ic { width: 22px; height: 22px; flex: none; fill: currentColor; }
h1, h2, h3 { margin: 0; font-weight: 600; }
/* SOTTO: widely spaced serif capitals. The negative margin keeps centred wordmarks optically centred. */
.wordmark { font-family: var(--serif); font-weight: 600; text-transform: uppercase; letter-spacing: 0.26em; margin-right: -0.26em; }
.eyebrow { font-size: 0.7em; letter-spacing: 0.28em; text-transform: uppercase; color: var(--gold); margin: 0; }

/* ---------- controls ---------- */
button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 999px;
}
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 1.5px solid var(--gold); outline-offset: 2px; }
.primary, .secondary { padding: 0.65em 1.3em; font-weight: 600; letter-spacing: 0.01em; }
.primary { background: linear-gradient(135deg, var(--gold-hi), var(--gold) 55%, var(--gold-lo)); color: var(--accent-text); }
:root[data-theme="light"] .primary { background: var(--accent); }
.primary:hover:not(:disabled) { filter: brightness(1.06); }
.secondary { border: 1px solid var(--border); color: var(--gold); }
.text { color: var(--gold); padding: 0.5em 0.8em; font-weight: 600; }
.big { padding: 0.85em 1.2em; font-size: 1em; }
.small { padding: 0.4em 1em; font-size: 0.88em; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
input, textarea, .select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7em 0.85em;
  width: 100%;
}
.select { width: auto; padding: 0.45em 0.6em; font-size: 0.88em; max-width: 46%; }
.hint { color: var(--muted); font-size: 0.84em; }
.hint.block { display: block; margin-top: 2px; line-height: 1.35; }
.muted { color: var(--muted); }
.error { color: var(--error); font-size: 0.9em; min-height: 0; margin: 0; }
.error:empty { display: none; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.pad { padding: 0 18px; margin: 0 0 8px; }
.e2e-note { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 0.76em; letter-spacing: 0.02em; margin: 0; }
.e2e-note .ic { width: 13px; height: 13px; color: var(--gold); }

/* ---------- avatars ---------- */
.avatar {
  --h: 40;
  width: 46px; height: 46px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  font: 600 1.3em/1 var(--serif);
  color: hsl(var(--h) 45% 82%);
  background: radial-gradient(circle at 30% 25%, hsl(var(--h) 22% 26%), hsl(var(--h) 18% 13%));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--gold) 35%, transparent);
  position: relative;
  text-transform: uppercase;
  user-select: none;
}
:root[data-theme="light"] .avatar { color: hsl(var(--h) 35% 30%); background: radial-gradient(circle at 30% 25%, hsl(var(--h) 35% 94%), hsl(var(--h) 25% 84%)); }
.avatar.sm { width: 36px; height: 36px; font-size: 1.1em; }
.avatar.xl { width: 68px; height: 68px; font-size: 2em; }
.avatar.xxl { width: 116px; height: 116px; font-size: 3.2em; }
.avatar.online::after {
  content: ""; position: absolute; right: 1px; bottom: 1px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--gold); border: 2px solid var(--panel);
}

/* ---------- onboarding ---------- */
.onboard {
  display: grid; place-items: center; height: 100%; padding: 16px; overflow-y: auto;
  background: radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--gold) 9%, transparent), transparent 60%), var(--bg);
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  padding: 40px 28px 26px;
  width: min(410px, 100%);
  display: grid; gap: 14px;
  text-align: center;
}
.card .logo { margin: 0 auto 4px; border-radius: 22px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); }
.card h1 { font-size: 2.6em; line-height: 1; }
.tagline { margin: 0; font-family: var(--serif); font-size: 1.2em; color: var(--muted); font-style: italic; }
.rule { border: 0; height: 1px; width: 60px; margin: 6px auto; background: linear-gradient(90deg, transparent, var(--gold), transparent); }
.card > p { margin: 0; }
.card form, .card .stack { text-align: left; }
.stack { display: grid; gap: 10px; }
.stack .hint { margin: 0; }
.notice { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.notice p { margin: 0 0 8px; }
#relay-form { border-top: 1px solid var(--border); padding-top: 14px; }

/* ---------- app lock ---------- */
.lock {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px;
  background: radial-gradient(ellipse at 50% 10%, color-mix(in srgb, var(--gold) 10%, transparent), transparent 55%), var(--bg);
}
.lock .logo { border-radius: 20px; margin-bottom: 6px; }
.lock h1 { font-size: 2em; }
.lock-prompt { margin: 6px 0 0; color: var(--muted); }
.dots { display: flex; gap: 16px; margin: 14px 0 4px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--gold); transition: background 0.12s; }
.dots i.on { background: var(--gold); }
.dots.shake { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }
.lock-error { color: var(--error); font-size: 0.86em; min-height: 1.3em; margin: 0; text-align: center; }
.lock-bio { margin-top: 18px; display: inline-flex; align-items: center; gap: 8px; background: none; border: 1px solid var(--border); color: var(--gold, #c9a96e); border-radius: 999px; padding: 10px 18px; font: inherit; }
.lock-bio .ic { width: 22px; height: 22px; }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px 26px; margin-top: 8px; }
.keypad button { width: 76px; height: 76px; font: 500 1.9em/1 var(--serif); border: 1px solid var(--border); background: var(--panel); }
.keypad button:active { background: var(--panel-2); border-color: var(--gold); }
.keypad .key-text { font: 500 0.9em var(--sans); border: 0; background: none; color: var(--muted); }
.veil { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: var(--bg); }
.veil img { border-radius: 22px; opacity: 0.9; }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: minmax(300px, 390px) 1fr; height: 100%; position: relative; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 2px; padding: 16px 8px 12px 18px; padding-top: max(16px, env(safe-area-inset-top)); }
.topbar .title { flex: 1; min-width: 0; }
.topbar h1 { font: 600 1.5em/1.1 var(--serif); text-transform: uppercase; letter-spacing: 0.26em; }
.circle-label { display: block; font: italic 600 0.95em var(--serif); color: var(--gold); margin-top: 2px; }
.conn { font-size: 0.78em; color: var(--muted); }
.conn.on { display: none; }

.banner { display: flex; align-items: center; gap: 10px; margin: 0 12px 10px; padding: 10px 6px 10px 12px; border-radius: var(--radius); background: var(--panel-2); border: 1px solid var(--border); font-size: 0.88em; }
.banner .ic { color: var(--gold); }
.banner .hint { display: block; }
.banner.update { border-color: var(--gold); }
.install-login { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.install-login .ic { width: 18px; height: 18px; }

.search { display: flex; align-items: center; gap: 8px; margin: 0 12px 8px; padding: 0 12px; background: var(--panel-2); border-radius: 999px; color: var(--muted); border: 1px solid transparent; }
.search:focus-within { border-color: var(--border); }
.search .ic { width: 18px; height: 18px; }
.search input { border: 0; background: none; padding: 0.6em 0; }
.search input:focus-visible { outline: none; }

.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-list button { width: 100%; display: flex; align-items: center; gap: 14px; padding: 11px 18px; border-radius: 0; text-align: left; }
.chat-list button:hover { background: var(--hover); }
.chat-list button.active { background: var(--panel-2); box-shadow: inset 2px 0 0 var(--gold); }
.chat-list .body { flex: 1; min-width: 0; border-bottom: 1px solid var(--border); padding-bottom: 11px; margin-bottom: -11px; }
.chat-list li:last-child .body { border-bottom: 0; }
.chat-list .line { display: flex; align-items: center; gap: 6px; }
.chat-list .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list .when { font-size: 0.74em; color: var(--muted); flex: none; }
.chat-list .when.unread { color: var(--gold); font-weight: 600; }
.chat-list .preview { flex: 1; color: var(--muted); font-size: 0.89em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 3px; }
.chat-list .preview span { overflow: hidden; text-overflow: ellipsis; }
.chat-list .preview.warn { color: var(--error); }
.chat-list .preview .ic { width: 14px; height: 14px; }
.badge { background: var(--gold); color: var(--accent-text); border-radius: 999px; font-size: 0.7em; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; flex: none; }
.shield { width: 15px; height: 15px; color: var(--gold); flex: none; }
.list-empty { padding: 36px 28px; text-align: center; color: var(--muted); }
.list-empty b { color: var(--text); font: 600 1.35em var(--serif); display: block; margin-bottom: 6px; }
.foot { padding: 12px 0 max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }

/* ---------- conversation ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--chat-bg); position: relative; }
.empty { margin: auto; padding: 24px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.empty img { border-radius: 24px; opacity: 0.95; }
.empty h2 { font-size: 2em; }
.empty p { margin: 0; }
#conversation { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-header { display: flex; align-items: center; gap: 4px; padding: 8px 12px 8px 8px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--border); }
.back { display: none; }
.peer-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 4px 8px; border-radius: var(--radius); text-align: left; }
.peer-info:hover { background: var(--hover); }
.who { display: grid; min-width: 0; }
.who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 5px; font-weight: 600; }
.who strong .ic { width: 15px; height: 15px; color: var(--gold); }
.status { font-size: 0.78em; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status.online { color: var(--gold); }

.warning { padding: 12px 16px; background: var(--warn-bg); border-bottom: 1px solid var(--warn-border); font-size: 0.9em; }
.warning p { margin: 0 0 10px; }

.messages { list-style: none; margin: 0; padding: 14px 6% 10px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; overscroll-behavior: contain; }
.messages > li { display: flex; }
.messages .sys { justify-content: center; margin: 10px 0; }
.messages .sys span { background: var(--panel); border: 1px solid var(--border); color: var(--muted); font-size: 0.76em; padding: 6px 12px; border-radius: 10px; text-align: center; max-width: 90%; display: inline-flex; gap: 6px; align-items: center; }
.messages .sys .ic { width: 13px; height: 13px; color: var(--gold); flex: none; }
.messages .sys.e2e span { color: var(--text); text-align: left; align-items: flex-start; cursor: pointer; line-height: 1.4; }
.messages .sys.e2e .ic { margin-top: 2px; }
.messages .day span { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.68em; border: 0; background: none; }
.bubble {
  max-width: min(78%, 560px);
  padding: 7px 9px 7px 12px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  position: relative;
}
.in .bubble { background: var(--bubble-in); border: 1px solid var(--border); }
.out { justify-content: flex-end; }
.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); border: 1px solid color-mix(in srgb, var(--gold) 22%, transparent); }
.messages .first { margin-top: 8px; }
.in.first .bubble { border-top-left-radius: 4px; }
.out.first .bubble { border-top-right-radius: 4px; }
.meta { float: right; display: inline-flex; align-items: center; gap: 3px; margin: 6px 0 -4px 10px; font-size: 0.68em; color: var(--muted); line-height: 1; white-space: nowrap; position: relative; top: 4px; }
.meta .ic { width: 11px; height: 11px; }
.out .meta { color: color-mix(in srgb, var(--bubble-out-text) 55%, transparent); }
.tick { width: 16px; height: 12px; }
.tick.read { color: var(--tick-read); }
.bad .bubble { background: var(--panel); border: 1px dashed var(--error); color: var(--error); font-size: 0.88em; }
.out.failed .bubble { cursor: pointer; }
.failed .meta { color: var(--error); }
.jump { position: absolute; right: 16px; bottom: 80px; width: 42px; height: 42px; background: var(--panel); border: 1px solid var(--border); color: var(--gold); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3); font-size: 1.1em; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--chat-bg); }
.field { flex: 1; min-width: 0; display: flex; align-items: flex-end; background: var(--panel); border: 1px solid var(--border); border-radius: 24px; padding: 0 4px; }
.field:focus-within { border-color: color-mix(in srgb, var(--gold) 45%, var(--border)); }
.composer textarea {
  resize: none; border: 0; background: none; padding: 12px 4px;
  max-height: 140px; line-height: 1.35;
}
.composer textarea:focus-visible { outline: none; }
.icon-btn.in-field { width: 40px; height: 46px; border-radius: 50%; }
.icon-btn.in-field.on { color: var(--gold); }

/* attachments waiting to be sent */
.tray { display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px 0; background: var(--chat-bg); }
.chip { position: relative; flex: none; width: 76px; height: 76px; border-radius: 12px; overflow: hidden; background: var(--panel); border: 1px solid var(--border); display: grid; place-items: center; text-align: center; font-size: 0.66em; color: var(--muted); padding: 4px; }
.chip img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.chip .ic { color: var(--gold); }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 68px; display: block; }
.chip button { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 12px; line-height: 1; }

/* emoji & GIF picker */
.picker { background: var(--panel); border-top: 1px solid var(--border); height: min(320px, 42dvh); display: flex; flex-direction: column; }
.picker-tabs { display: flex; gap: 4px; padding: 8px 10px 0; }
.picker-tabs button { padding: 6px 14px; font-size: 0.85em; color: var(--muted); }
.picker-tabs button.on { color: var(--gold); background: var(--panel-2); }
.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 8px 10px 0; gap: 8px; }
#emoji-search { padding: 0.5em 0.9em; border-radius: 999px; }
.emoji-cats { display: flex; gap: 2px; overflow-x: auto; flex: none; }
.emoji-cats button { font-size: 1.15em; padding: 4px 8px; border-radius: 8px; opacity: 0.55; }
.emoji-cats button.on { opacity: 1; background: var(--panel-2); }
.emoji-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); align-content: start; padding-bottom: 8px; }
.emoji-grid button { font-size: 1.6em; height: 44px; border-radius: 10px; }
.emoji-grid button:hover { background: var(--panel-2); }
.emoji-grid .label { grid-column: 1 / -1; font-size: 0.7em; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); padding: 8px 4px 2px; }
.gif-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; align-content: start; padding-bottom: 8px; }
.gif-grid button { padding: 0; border-radius: 10px; overflow: hidden; aspect-ratio: 1; background: var(--panel-2); }
.gif-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
#gif-pane .hint { margin: 0; }
#gif-pick { align-self: flex-start; }

/* files in messages */
.bubble.has-media { padding: 4px 4px 6px; }
.bubble.has-media .caption { padding: 4px 6px 0; display: block; }
.media { display: block; position: relative; border-radius: 10px; overflow: hidden; background: var(--panel-2); max-width: min(300px, 70vw); cursor: pointer; }
.media img, .media video { display: block; width: 100%; height: 100%; object-fit: cover; }
.media img.thumb { filter: blur(8px); transform: scale(1.06); }
.media .over { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.35); color: #fff; font-size: 0.8em; text-align: center; padding: 8px; }
.media .gif-tag { position: absolute; left: 6px; bottom: 6px; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 0.65em; font-weight: 700; padding: 1px 6px; border-radius: 4px; }
.bubble audio { display: block; width: min(280px, 68vw); margin: 2px 0; }
.filecard { display: flex; align-items: center; gap: 10px; padding: 8px 8px; border-radius: 10px; background: color-mix(in srgb, var(--panel-2) 70%, transparent); min-width: 200px; max-width: min(300px, 70vw); cursor: pointer; text-align: left; }
.filecard .ic { width: 30px; height: 30px; color: var(--gold); }
.filecard .fname { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filecard .fsub { display: block; font-size: 0.75em; color: var(--muted); }
.filecard .grow { min-width: 0; }

/* full-screen viewer */
.viewer { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; }
.viewer-head { display: flex; align-items: center; gap: 8px; padding: 8px; padding-top: max(8px, env(safe-area-inset-top)); color: #fff; }
.viewer-head .icon-btn { color: #fff; }
.viewer-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9em; }
.viewer-body { flex: 1; min-height: 0; display: grid; place-items: center; padding-bottom: env(safe-area-inset-bottom); }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.drop-hint { outline: 2px dashed var(--gold); outline-offset: -8px; }
.send { width: 48px; height: 48px; flex: none; display: grid; place-items: center; background: linear-gradient(135deg, var(--gold-hi), var(--gold) 55%, var(--gold-lo)); color: var(--accent-text); }
.send:disabled { opacity: 1; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }

/* ---------- full-screen pages (settings, contact) ---------- */
.page { position: absolute; inset: 0; z-index: 5; background: var(--bg); display: flex; flex-direction: column; animation: slide-in 0.2s ease-out; }
@media (min-width: 801px) { .page { right: auto; width: min(430px, 100%); border-right: 1px solid var(--border); box-shadow: 8px 0 30px rgba(0, 0, 0, 0.25); } }
@keyframes slide-in { from { transform: translateX(-24px); opacity: 0; } }
.page-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--border); }
.page-head h2 { font: 600 1.5em var(--serif); }
.page-body { overflow-y: auto; flex: 1; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.profile { display: flex; align-items: center; gap: 16px; padding: 22px 18px; background: var(--panel); margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.profile.column { flex-direction: column; gap: 6px; text-align: center; }
.profile strong { font: 600 1.45em var(--serif); }
.big-name { font-size: 1.9em !important; margin-top: 8px; }
.group { background: var(--panel); margin-bottom: 8px; padding: 6px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.group h3 { font-size: 0.68em; color: var(--gold); font-weight: 600; letter-spacing: 0.2em; text-transform: uppercase; padding: 12px 18px 6px; }
.setting { display: flex; align-items: center; gap: 16px; padding: 12px 18px; width: 100%; text-align: left; border-radius: 0; cursor: pointer; }
.setting .ic { color: var(--muted); }
.setting.static { cursor: default; align-items: flex-start; }
.setting.action:hover, label.setting:hover { background: var(--hover); }
.setting.danger, .setting.danger .ic { color: var(--error); }
.verify { padding: 4px 18px 0; }
.verify p { margin: 6px 0; }
.verify .setting { padding: 12px 0; }
.safety {
  display: grid; grid-template-columns: repeat(5, auto); justify-content: center; gap: 10px 16px;
  font: 500 1.05em/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  padding: 16px; margin: 10px 0; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); letter-spacing: 0.06em; color: var(--gold-hi);
}
:root[data-theme="light"] .safety { color: var(--gold-lo); }
.inline-form { display: flex; gap: 8px; padding: 0 18px 8px; }
.inline-form input { flex: 1; }
.member-list { list-style: none; margin: 0; padding: 0; }
.member-list li { display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 18px; }
.member-list .email { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.invite-new { margin: 4px 18px 10px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-2); display: grid; gap: 10px; }
.invite-new p { margin: 0; }
.invite-code { font: 600 1.05em/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.06em; color: var(--gold-hi); text-align: center; overflow-wrap: anywhere; user-select: all; }
:root[data-theme="light"] .invite-code { color: var(--gold-lo); }
.sub { font-size: 0.68em; color: var(--muted); letter-spacing: 0.2em; text-transform: uppercase; padding: 14px 18px 4px; margin: 0; }
.member-list .meta-line { display: block; font-size: 0.8em; color: var(--muted); }
.colophon { font-family: var(--serif); font-style: italic; font-size: 1em; padding: 12px 0 4px; }

/* toggle switch */
.switch { appearance: none; width: 44px; height: 26px; padding: 0; border: 1px solid var(--border); border-radius: 999px; background: var(--panel-2); position: relative; cursor: pointer; flex: none; transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: transform 0.15s, background 0.15s; }
.switch:checked { background: color-mix(in srgb, var(--gold) 30%, var(--panel-2)); border-color: var(--gold); }
.switch:checked::after { transform: translateX(18px); background: var(--gold); }
.switch:disabled { opacity: 0.5; }

/* ---------- dialog & toast ---------- */
.dialog { border: 1px solid var(--border); border-radius: 18px; padding: 24px 22px 14px; width: min(380px, calc(100% - 32px)); background: var(--panel); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(3px); }
.dialog h2 { font: 600 1.45em/1.2 var(--serif); margin-bottom: 10px; }
.dialog p { margin: 0 0 18px; color: var(--muted); }
.dialog .primary.danger { background: var(--error); color: #fff; }
.toast {
  position: fixed; left: 50%; bottom: max(92px, calc(env(safe-area-inset-bottom) + 92px)); transform: translateX(-50%);
  z-index: 60; max-width: calc(100% - 32px);
  background: #1c1b1f; color: #ece6da; border: 1px solid rgba(201, 169, 110, 0.3);
  padding: 11px 18px; border-radius: 12px; font-size: 0.88em;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); animation: pop 0.15s ease-out;
}
@keyframes pop { from { transform: translate(-50%, 8px); opacity: 0; } }

/* ---------- phone layout: one screen at a time ---------- */
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .app.in-chat .sidebar { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .back { display: grid; }
  .messages { padding: 10px 10px 6px; }
  .bubble { max-width: 84%; }
}
@media (max-height: 640px) {
  .keypad { grid-template-columns: repeat(3, 64px); gap: 10px 22px; }
  .keypad button { width: 64px; height: 64px; }
  .lock .logo { display: none; }
}
@media (prefers-reduced-motion: reduce) { .page, .toast, .dots.shake { animation: none; } }

/* ---------- voice messages ---------- */
.voice { display: flex; align-items: center; gap: 6px; }
.voice > .ic { width: 20px; height: 20px; color: var(--gold); flex: none; }
.rec { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 24px; padding: 0 12px 0 4px; height: 48px; }
.rec .icon-btn { color: var(--error); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--error); animation: blink 1s infinite; flex: none; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }
@keyframes blink { 50% { opacity: 0.25; } }
.composer.recording .field { display: none; }

/* ---------- calls ---------- */
.call { position: fixed; inset: 0; z-index: 45; background: radial-gradient(ellipse at 50% 20%, #1f1c17, #050506 70%); color: #ece6da; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: max(48px, env(safe-area-inset-top)) 16px max(36px, env(safe-area-inset-bottom)); }
.remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.remote-video:not([data-on]) { display: none; }
.local-video { position: absolute; right: 14px; top: max(14px, env(safe-area-inset-top)); width: 104px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 14px; border: 1px solid rgba(201, 169, 110, 0.5); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); z-index: 2; transform: scaleX(-1); background: #111; }
.call-info { position: relative; z-index: 1; display: grid; justify-items: center; gap: 8px; margin-top: 8vh; text-align: center; }
.call.video-live .call-info { margin-top: 0; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8); }
.call.video-live .call-info .avatar { display: none; }
.call-name { font: 600 2em/1.1 var(--serif); letter-spacing: 0.04em; margin-top: 10px; }
.call-status { margin: 0; color: #b7ae9f; font-variant-numeric: tabular-nums; }
.call .e2e-note { color: #9a927f; }
.call-actions { position: relative; z-index: 1; display: flex; gap: 22px; justify-content: center; }
.round { width: 62px; height: 62px; display: grid; place-items: center; background: rgba(255, 255, 255, 0.12); color: #fff; backdrop-filter: blur(6px); }
.round .ic { width: 26px; height: 26px; }
.round.on { background: #ece6da; color: #0b0b0c; }
.round.end { background: #d84a3a; }
.round.end .ic { transform: rotate(0deg); }
.round.accept { background: linear-gradient(135deg, #e6cc94, #c9a96e 55%, #8f6f3a); color: #0b0b0c; }
.round.accept { animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(201, 169, 110, 0.6); } 100% { box-shadow: 0 0 0 22px rgba(201, 169, 110, 0); } }
.messages .sys.call span { cursor: pointer; }
@media (prefers-reduced-motion: reduce) { .round.accept, .rec-dot { animation: none; } }

/* ---------- operator: client circles ---------- */
.top-pad { padding-top: 14px; }
.client { margin: 0 12px 10px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-2); display: grid; gap: 6px; }
.client .top { display: flex; align-items: baseline; gap: 8px; }
.client .who { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.client .tag { font-size: 0.68em; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); flex: none; }
.client .tag.warn { color: var(--error); }
.client .line { font-size: 0.86em; color: var(--muted); overflow-wrap: anywhere; }
.client .line b { color: var(--text); font-weight: 600; }
.client .note { font-size: 0.86em; font-style: italic; color: var(--muted); }
.client .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; align-items: center; }
.client .actions .select { max-width: none; }
.client .code { font: 600 0.95em ui-monospace, Menlo, Consolas, monospace; color: var(--gold-hi); letter-spacing: 0.05em; user-select: all; overflow-wrap: anywhere; }
:root[data-theme="light"] .client .code { color: var(--gold-lo); }
.client details { font-size: 0.8em; color: var(--muted); }
.client details li { margin: 2px 0; }
.empty-note { padding: 4px 18px 12px; color: var(--muted); font-size: 0.88em; }

/* ======================================================================
   Craft: accent metals, engraved wallpapers, rosette, splash and motion
   ====================================================================== */

/* Accent metals (Gold is the default above). Dark first; Ivory variants after. */
:root[data-accent="platinum"] { --gold: #c3c8cf; --gold-hi: #eef1f5; --gold-lo: #8a9099; --accent: #c3c8cf; --accent-strong: #e1e5ea; --bubble-out: #23262b; --bubble-out-text: #eef1f5; --tick-read: #eef1f5; --border: rgba(195, 200, 207, 0.14); }
:root[data-accent="rose"] { --gold: #d6a191; --gold-hi: #f0c7b9; --gold-lo: #9a6455; --accent: #d6a191; --accent-strong: #ebbcad; --bubble-out: #2c201d; --bubble-out-text: #f6e4de; --tick-read: #f0c7b9; --border: rgba(214, 161, 145, 0.14); }
:root[data-accent="emerald"] { --gold: #6fb497; --gold-hi: #a7dcc4; --gold-lo: #3d7a62; --accent: #6fb497; --accent-strong: #8fcbb0; --bubble-out: #18271f; --bubble-out-text: #e2f3ea; --tick-read: #a7dcc4; --border: rgba(111, 180, 151, 0.14); }
:root[data-theme="light"][data-accent="platinum"] { --gold: #8d949e; --gold-hi: #b7bdc6; --gold-lo: #5f666f; --accent: #6f7782; --accent-strong: #5a616b; --bubble-out: #e7eaee; --bubble-out-text: #1c1f23; --tick-read: #6f7782; --border: rgba(95, 102, 111, 0.16); }
:root[data-theme="light"][data-accent="rose"] { --gold: #b9806f; --gold-hi: #d6a191; --gold-lo: #8a5446; --accent: #a7685a; --accent-strong: #8d5447; --bubble-out: #f3e1db; --bubble-out-text: #2a1c18; --tick-read: #a7685a; --border: rgba(138, 84, 70, 0.16); }
:root[data-theme="light"][data-accent="emerald"] { --gold: #4b977a; --gold-hi: #6fb497; --gold-lo: #2c6a52; --accent: #2f7d5f; --accent-strong: #256850; --bubble-out: #dcefe6; --bubble-out-text: #14261e; --tick-read: #2f7d5f; --border: rgba(44, 106, 82, 0.16); }
@media (prefers-color-scheme: light) {
  :root[data-theme="system"][data-accent="platinum"] { --gold: #8d949e; --gold-hi: #b7bdc6; --gold-lo: #5f666f; --accent: #6f7782; --accent-strong: #5a616b; --bubble-out: #e7eaee; --bubble-out-text: #1c1f23; --tick-read: #6f7782; }
  :root[data-theme="system"][data-accent="rose"] { --gold: #b9806f; --gold-hi: #d6a191; --gold-lo: #8a5446; --accent: #a7685a; --accent-strong: #8d5447; --bubble-out: #f3e1db; --bubble-out-text: #2a1c18; --tick-read: #a7685a; }
  :root[data-theme="system"][data-accent="emerald"] { --gold: #4b977a; --gold-hi: #6fb497; --gold-lo: #2c6a52; --accent: #2f7d5f; --accent-strong: #256850; --bubble-out: #dcefe6; --bubble-out-text: #14261e; --tick-read: #2f7d5f; }
}

/* Engraved chat wallpapers, printed in the accent metal. */
:root { --wp: none; --wp-size: auto; --wp-op: 0; }
:root[data-wallpaper="guilloche"] { --wp: url("art/wave.svg"); --wp-size: 120px 48px; --wp-op: .085; }
:root[data-wallpaper="clous"] { --wp: url("art/clous.svg"); --wp-size: 14px 14px; --wp-op: .07; }
:root[data-wallpaper="linen"] { --wp: url("art/linen.svg"); --wp-size: 32px 32px; --wp-op: .09; }
:root[data-wallpaper="monogram"] { --wp: url("art/monogram.svg"); --wp-size: 120px 120px; --wp-op: .12; }
.chat::before, .wp-sample::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 0;
  background: var(--gold); opacity: var(--wp-op);
  -webkit-mask: var(--wp) 0 0 / var(--wp-size) repeat; mask: var(--wp) 0 0 / var(--wp-size) repeat;
}
#conversation, .chat > .empty { position: relative; z-index: 1; }

/* Guilloché rosette turning slowly behind the welcome and lock screens. */
.onboard, .lock { position: relative; overflow: hidden; }
.onboard::before, .lock::before, .splash::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: min(150vw, 980px); aspect-ratio: 1;
  translate: -50% -50%; pointer-events: none; background: var(--gold); opacity: .13;
  -webkit-mask: url("art/rosette.svg") center / contain no-repeat; mask: url("art/rosette.svg") center / contain no-repeat;
  animation: turn 300s linear infinite;
}
.onboard > *, .lock > * { position: relative; z-index: 1; }
@keyframes turn { to { rotate: 360deg; } }

/* Opening splash: the emblem settles, then the app fades in. */
.splash { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: var(--bg); transition: opacity .45s ease, visibility .45s; }
.splash::before { width: min(110vw, 620px); opacity: .18; animation: turn 60s linear infinite; }
.splash img { position: relative; width: 96px; height: 96px; border-radius: 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .55); animation: settle .7s cubic-bezier(.2, .8, .2, 1) both; }
.splash.gone { opacity: 0; visibility: hidden; }
@keyframes settle { from { opacity: 0; transform: scale(.86); } }

/* Motion: messages glide in, chats open softly, buttons answer the touch. */
.messages li.fresh { animation: msg-in .26s cubic-bezier(.2, .8, .2, 1); }
.messages li.out.fresh { transform-origin: right bottom; }
.messages li.in.fresh { transform-origin: left bottom; }
@keyframes msg-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }
#conversation.enter { animation: chat-in .24s ease-out; }
@keyframes chat-in { from { opacity: 0; transform: translateX(14px); } }
button, .button { transition: transform .12s ease, filter .15s ease, background-color .15s ease; }
button:active:not(:disabled) { transform: scale(.96); }
.chat-list button:active, .setting:active { transform: none; background: var(--hover); }
.dialog[open] { animation: dlg-in .2s cubic-bezier(.2, .8, .2, 1); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.97); } }
.badge { animation: pop-badge .3s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop-badge { from { transform: scale(.4); } }

/* Customize: metals and wallpapers with a live preview. */
.swatches { display: flex; gap: 14px; padding: 6px 18px 14px; flex-wrap: wrap; }
.swatch { display: grid; justify-items: center; gap: 6px; font-size: .72em; color: var(--muted); padding: 0; background: none; }
.swatch i { width: 40px; height: 40px; border-radius: 50%; display: block; border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .2); }
.swatch[aria-pressed="true"] i { border-color: var(--text); }
.swatch[aria-pressed="true"] { color: var(--text); }
.swatch[data-v="gold"] i { background: linear-gradient(135deg, #f1dcaa, #c9a96e 55%, #8f6f3a); }
.swatch[data-v="platinum"] i { background: linear-gradient(135deg, #f4f6f8, #c3c8cf 55%, #7e858f); }
.swatch[data-v="rose"] i { background: linear-gradient(135deg, #f7d6cb, #d6a191 55%, #9a6455); }
.swatch[data-v="emerald"] i { background: linear-gradient(135deg, #c6ecd9, #6fb497 55%, #2f6b53); }
.wp-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; padding: 4px 18px 10px; }
.wp-tile { position: relative; aspect-ratio: 3 / 4; border-radius: 10px; overflow: hidden; background: var(--chat-bg); border: 1px solid var(--border); padding: 0; }
.wp-tile::before { content: ""; position: absolute; inset: 0; background: var(--gold); opacity: .22; -webkit-mask: var(--tile) 0 0 / var(--tile-size) repeat; mask: var(--tile) 0 0 / var(--tile-size) repeat; }
.wp-tile[data-v="none"]::before { display: none; }
.wp-tile[data-v="guilloche"] { --tile: url("art/wave.svg"); --tile-size: 60px 24px; }
.wp-tile[data-v="clous"] { --tile: url("art/clous.svg"); --tile-size: 8px 8px; }
.wp-tile[data-v="linen"] { --tile: url("art/linen.svg"); --tile-size: 16px 16px; }
.wp-tile[data-v="monogram"] { --tile: url("art/monogram.svg"); --tile-size: 50px 50px; }
.wp-tile span { position: absolute; left: 0; right: 0; bottom: 4px; font-size: .62em; color: var(--muted); text-align: center; }
.wp-tile[aria-pressed="true"] { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.wp-sample { position: relative; margin: 2px 18px 14px; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); background: var(--chat-bg); padding: 14px 12px; display: grid; gap: 6px; }
.wp-sample > * { position: relative; z-index: 1; }
.wp-sample .bubble { font-size: .85em; max-width: 80%; }
.wp-sample .in { justify-self: start; }
.wp-sample .out { justify-self: end; }

@media (prefers-reduced-motion: reduce) {
  .onboard::before, .lock::before, .splash::before, .splash img, .messages li.fresh, #conversation.enter, .dialog[open], .badge { animation: none; }
  button:active:not(:disabled) { transform: none; }
}

a.setting { color: inherit; text-decoration: none; }
.card .hint a { color: var(--muted); }
