/* Теми задаються змінними на [data-theme]: на <html> для всієї сторінки
   і на картках вибору, щоб кожна картка показувала свою тему.
   Типова — «Нічна латунь»: майже чорний графіт, золото, заголовки із засічками. */

[data-theme="brass"] {
  color-scheme: dark;
  --bg: #0e1116;
  --bg-image: none;
  --bg-size: auto;
  --bg-position: 0 0;
  --surface: #161a21;
  --field: #1d222b;
  --nav: #12161c;
  --text: #eee9df;
  --muted: #8d8a83;
  --line: #222832;
  --bar: #0e1116;
  --bar-text: #f3ead7;
  --bar-image: none;
  --accent: #d4ad62;
  --accent-image: linear-gradient(180deg, #e0bd78, #b38a45);
  --accent-text: #15110a;
  --mine: #cfa95f;
  --mine-text: #17120a;
  --mine-border: #cfa95f;
  --theirs: #1c2129;
  --theirs-text: #e9e4da;
  --theirs-border: #1c2129;
  --check-color: #3b2c10;
  --font: Roboto, "Noto Sans", "Segoe UI", system-ui, sans-serif;
  --title-font: "Noto Serif", Georgia, "Times New Roman", serif;
  --radius: 16px;
  --bubble-radius: 16px 16px 16px 4px;
  --avatar-radius: 50%;
  --online: #6fcf7f;
  --mine-radius: 16px 16px 4px 16px;
  --theirs-border-width: 0;
  --theirs-shadow: none;
  --ticks: none;
  --title-transform: none;
  --title-spacing: .02em;
  --error: #ff8a7a;
}

[data-theme="kids"] {
  --bg: #dff1ff;
  --bg-image: url("img/kids.svg");
  --bg-size: auto;
  --bg-position: 0 0;
  --surface: #ffffff;
  --text: #1d3a5c;
  --muted: #5d7c9c;
  --line: #b9dcf7;
  --bar: #2f7fd0;
  --bar-text: #ffffff;
  --bar-image: radial-gradient(circle at 12% 30%, rgba(255,255,255,.25) 0 5px, transparent 6px),
               radial-gradient(circle at 78% 70%, rgba(255,255,255,.2) 0 7px, transparent 8px),
               radial-gradient(circle at 46% 20%, rgba(255,255,255,.18) 0 4px, transparent 5px);
  --accent: #e8483f;
  --accent-text: #ffffff;
  --mine: #3a8fd9;
  --mine-text: #ffffff;
  --mine-border: #3a8fd9;
  --theirs: #ffffff;
  --theirs-text: #1d3a5c;
  --theirs-border: #9ccdf3;
  --font: "Comic Sans MS", "Comic Neue", "Chalkboard SE", "Trebuchet MS", sans-serif;
  --title-font: var(--font);
  --radius: 22px;
  --bubble-radius: 22px;
  --avatar-radius: 50% 50% 18% 18%;
  --online: #4cbf5a;
  --mine-radius: 22px;
  --theirs-border-width: 1.5px;
  --theirs-shadow: none;
  --ticks: none;
  --title-transform: none;
  --title-spacing: 0;
}

[data-theme="artist"] {
  --bg: #f4ecdd;
  /* --artist-bg задає сторінка, коли вибрано фото своєї картини. */
  --bg-image: var(--artist-bg, url("img/artist.svg"));
  --bg-size: var(--artist-bg-size, auto);
  --bg-position: center;
  --surface: #fdf9f1;
  --text: #3b2a1e;
  --muted: #8a735c;
  --line: #e2d4bc;
  --bar: #3b2a1e;
  --bar-text: #f8eedc;
  --bar-image: radial-gradient(ellipse 40px 14px at 88% 80%, rgba(214,69,47,.55), transparent 70%),
               radial-gradient(ellipse 26px 10px at 70% 20%, rgba(242,182,50,.45), transparent 70%),
               radial-gradient(ellipse 34px 12px at 96% 35%, rgba(47,95,179,.5), transparent 70%);
  --accent: #c2412b;
  --accent-text: #fff8ee;
  --mine: #2f5fb3;
  --mine-text: #fdf9f1;
  --mine-border: #2f5fb3;
  --theirs: #fffdf8;
  --theirs-text: #3b2a1e;
  --theirs-border: #e0c48f;
  --font: Georgia, "Noto Serif", "Times New Roman", serif;
  --title-font: Georgia, "Noto Serif", serif;
  --radius: 14px;
  --bubble-radius: 18px 18px 18px 4px;
  --avatar-radius: 58% 42% 55% 45% / 48% 60% 40% 52%;
  --online: #3d8b4f;
  --mine-radius: 18px 18px 4px 18px;
  --theirs-border-width: 0 0 0 4px;
  --theirs-shadow: 0 1px 2px rgba(59,42,30,.15);
  --ticks: none;
  --title-transform: none;
  --title-spacing: .01em;
}

/* Креслярський аркуш: білий і відтінки сірого, сітка міліметрівки. */
[data-theme="architect"] {
  --bg: #eeeff0;
  --bg-image: linear-gradient(rgba(0,0,0,.08) 1px, transparent 1px),
              linear-gradient(90deg, rgba(0,0,0,.08) 1px, transparent 1px),
              linear-gradient(rgba(0,0,0,.035) 1px, transparent 1px),
              linear-gradient(90deg, rgba(0,0,0,.035) 1px, transparent 1px);
  --bg-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
  --bg-position: 0 0;
  --surface: #ffffff;
  --text: #2b2d2f;
  --muted: #74787c;
  --line: #c4c7ca;
  --bar: #3a3d40;
  --bar-text: #ffffff;
  --bar-image: none;
  --accent: #3a3d40;
  --accent-text: #ffffff;
  --mine: #55595d;
  --mine-text: #ffffff;
  --mine-border: #3a3d40;
  --theirs: #ffffff;
  --theirs-text: #2b2d2f;
  --theirs-border: #8d9195;
  --font: "Roboto Mono", Consolas, "DejaVu Sans Mono", monospace;
  --title-font: var(--font);
  --radius: 0;
  --bubble-radius: 0;
  --avatar-radius: 0;
  --online: #4caf50;
  --mine-radius: 0;
  --theirs-border-width: 1.5px;
  --theirs-shadow: none;
  --ticks: block;
  --title-transform: uppercase;
  --title-spacing: .12em;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.4 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.view {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background-color: var(--bg);
  background-image: var(--bg-image);
  background-size: var(--bg-size, auto);
  background-position: var(--bg-position, 0 0);
}

/* ---------- Заголовок */
.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 6px 12px;
  padding-top: max(6px, env(safe-area-inset-top));
  background-color: var(--bar);
  background-image: var(--bar-image);
  color: var(--bar-text);
  flex: none;
}
[data-theme="architect"] .bar { border-bottom: 1px solid var(--line); }
.bar h1 {
  margin: 0;
  font: 600 20px/1.2 var(--title-font);
  text-transform: var(--title-transform);
  letter-spacing: var(--title-spacing);
}
.grow { flex: 1; min-width: 0; }
.icon {
  border: 0;
  background: none;
  color: inherit;
  font-size: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.icon.back { font-size: 34px; line-height: 1; padding-bottom: 4px; }
.icon:active { background: rgba(255,255,255,.18); }
/* «немає зв’язку…» в заголовку списку чатів: сторінка працює й без сервера. */
.conn { font-size: 13px; opacity: .85; }
.peer { display: flex; flex-direction: column; }
.peer b, .peer small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer small { opacity: .8; }

/* ---------- Аватари */
.avatar {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--avatar-radius);
  background: hsl(var(--hue, 200) 60% 55%);
  color: #fff;
  font-weight: 700;
  position: relative;
}
.bar .avatar { width: 38px; height: 38px; }
[data-theme="kids"] .avatar {
  background: radial-gradient(circle at 24% 16%, #fff 0 2.5px, transparent 3.5px),
              radial-gradient(circle at 78% 18%, #fff 0 2px, transparent 3px),
              hsl(var(--hue, 0) 70% 56%);
}
[data-theme="architect"] .avatar {
  background: var(--surface);
  border: 1.5px solid var(--text);
  color: var(--text);
}
/* Знак стану: зелений — у застосунку, жовтий — застосунок згорнуто, червоний —
   телефон заблоковано (стан повідомляє застосунок; браузер — лише зелений/жовтий). */
.avatar.online.away::after { background: #e0b84c; }
.avatar.online.locked::after { background: #e5534b; }
.avatar.online::after {
  content: "";
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--online);
  border: 2px solid var(--surface);
}

/* ---------- Список чатів */
.contacts { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.contacts li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.contacts li:active { filter: brightness(.96); }
[data-theme="kids"] .contacts li { margin: 8px 10px 0; border: 2px solid var(--line); border-radius: var(--radius); }
[data-theme="architect"] .contacts li { background: transparent; }
.contact-main { flex: 1; min-width: 0; }
.contact-top { display: flex; gap: 8px; align-items: baseline; }
.contact-top b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-top time { font-size: 12px; color: var(--muted); }
.contact-last { color: var(--muted); font-size: 14px; display: flex; gap: 8px; }
.contact-last span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  flex: none;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
[data-theme="architect"] .badge { border-radius: 0; }

/* ---------- Повідомлення */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; max-width: 280px; }
[data-theme="kids"] .messages > .empty::before {
  content: "";
  display: block;
  width: 160px;
  height: 200px;
  margin: 0 auto 8px;
  background: url("img/smurfette.png") center / contain no-repeat;
}
/* Смурфетта виглядає з правого нижнього кута списку чатів. */
[data-theme="kids"] .contacts {
  background: url("img/smurfette.png") right 10px bottom 10px / auto 150px no-repeat;
  padding-bottom: 170px;
}
.day {
  align-self: center;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  padding: 2px 10px;
  border-radius: 10px;
  margin: 8px 0 2px;
}
[data-theme="architect"] .day { background: transparent; border-top: 1px solid var(--line); border-radius: 0; padding-top: 4px; }
.msg {
  max-width: 80%;
  padding: 7px 11px 5px;
  border-radius: var(--bubble-radius);
  background: var(--theirs);
  color: var(--theirs-text);
  border: 1.5px solid var(--theirs-border);
  border-width: var(--theirs-border-width);
  box-shadow: var(--theirs-shadow);
  align-self: flex-start;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  position: relative;
}
.msg.mine {
  align-self: flex-end;
  background: var(--mine);
  color: var(--mine-text);
  border-color: var(--mine-border, var(--mine));
  border-width: 1.5px;
  border-radius: var(--mine-radius);
  box-shadow: none;
}
/* Вигляд бульбашок задають змінні теми, а не правила [data-theme] .msg: так картки
   вибору в налаштуваннях не переймають оформлення поточної теми.
   Креслярські засічки в кутах (--ticks: block лише в «Архітекторі»). */
.msg::before,
.msg::after {
  content: "";
  display: var(--ticks);
  position: absolute;
  width: 7px;
  height: 7px;
  border: 0 solid var(--theirs-border);
}
.msg.mine::before,
.msg.mine::after { border-color: var(--mine-border); }
.msg::before { left: -5px; top: -5px; border-width: 1px 0 0 1px; }
.msg::after { right: -5px; bottom: -5px; border-width: 0 1px 1px 0; }
.meta { display: block; text-align: right; font-size: 11px; margin-top: 2px; }
.meta .time { opacity: .7; }
.msg.failed .meta { color: #ff6b5b; }
.msg.failed .meta .time { opacity: 1; }
/* Галочки: жирні (обведені своїм кольором) і більші за час. */
.check {
  font-size: 15px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -3px;
  padding-right: 3px;
  color: var(--check-color, inherit);
  -webkit-text-stroke: .7px currentColor;
}
.msg { font-family: var(--msg-font, inherit); font-size: var(--msg-size, inherit); }
/* Довге натискання відкриває меню повідомлення, тож без виділення тексту
   (скопіювати — пунктом «Копіювати»). */
.messages .msg { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* ---------- Вибрані файли перед надсиланням (над полем введення) */
.attach-tray {
  display: flex;
  gap: 8px;
  padding: 8px 10px 4px;
  overflow-x: auto;
  background: var(--surface);
  border-top: 1px solid var(--line);
  flex: none;
}
.attach-tray[hidden] { display: none; }
.attach-item {
  position: relative;
  flex: none;
  width: 76px;
  height: 76px;
  border-radius: 12px;
  background: var(--field, var(--bg));
  border: 1.5px solid var(--line);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
.attach-item img { width: 100%; height: 100%; object-fit: cover; }
.attach-item .icon { font-size: 26px; }
.attach-item .name { max-width: 70px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 3px; }
.attach-item button {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 12px;
  line-height: 22px;
  padding: 0;
}
.msg .caption { display: block; margin-top: 4px; white-space: pre-wrap; }
.msg.file .caption { padding: 0 6px; }

/* ---------- Редагування свого повідомлення (над полем введення) */
.edit-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 14px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  flex: none;
}
.edit-bar span { display: flex; flex-direction: column; min-width: 0; }
.edit-bar b { color: var(--accent); font-size: 13px; }
.edit-bar small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.edit-bar button { border: 0; background: none; color: var(--muted); font-size: 18px; padding: 6px; }

/* ---------- Меню повідомлення: аркуш знизу */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, .45);
}
.sheet[hidden] { display: none; }
.sheet-card {
  width: min(100%, 480px);
  padding: 8px 12px max(12px, env(safe-area-inset-bottom));
  background: var(--surface);
  color: var(--text);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sheet-title { margin: 6px 4px 4px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.sheet-card button {
  border: 0;
  border-radius: 12px;
  padding: 14px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  text-align: left;
}
.sheet-card button:active { background: var(--field, var(--line)); }
.sheet-card button.danger { color: #e5534b; }
.sheet-card button.cancel { margin-top: 4px; text-align: center; color: var(--muted); border-top: 1px solid var(--line); border-radius: 0; }

/* ---------- Поле введення */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  flex: none;
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  outline: none;
}
[data-theme="architect"] .composer textarea { background: transparent; }
.composer textarea:focus { border-color: var(--accent); }
.send {
  flex: none;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent-image, var(--accent));
  color: var(--accent-text);
  font-size: 20px;
  display: grid;
  place-items: center;
}
[data-theme="kids"] .send { border-radius: 50%; }

/* ---------- Вхід */
.login { align-items: center; justify-content: center; padding: 20px 16px; overflow-y: auto; }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
}
.logo { width: 110px; height: 110px; }
.login h1 {
  margin: 4px 0 16px;
  font: 600 26px/1.2 var(--title-font);
  text-transform: var(--title-transform);
  letter-spacing: var(--title-spacing);
}
.login form { display: grid; gap: 12px; text-align: left; }
.login label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.login input {
  padding: 11px 12px;
  border: 1.5px solid var(--line);
  border-radius: calc(var(--radius) / 2);
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
}
[data-theme="architect"] .login input { background: transparent; }
.primary, .settings button {
  padding: 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent-image, var(--accent));
  color: var(--accent-text);
  font-weight: 700;
}
.error { color: var(--error, #d83a2e); min-height: 1.4em; margin: 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; }
.theme-chips { display: flex; justify-content: center; gap: 10px; margin-top: 8px; }
.login .scan {
  width: 100%;
  margin-top: 14px;
  padding: 11px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-weight: 600;
}
.theme-chips button {
  width: 52px;
  height: 52px;
  padding: 6px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--bar);
}
.theme-chips button[aria-pressed="true"] { border-color: var(--accent); }
.theme-chips svg { width: 100%; height: 100%; }

/* ---------- Налаштування */
.settings { padding: 8px 16px 24px; overflow-y: auto; flex: 1; }
.settings h2 {
  font: 600 15px/1.2 var(--title-font);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 18px 0 10px;
}
.settings > button { display: block; width: 100%; margin-top: 10px; }
.photo-box { margin-top: 12px; }
.photo-box p { margin: 0 0 4px; color: var(--muted); font-size: 14px; }
.photo-box button { display: block; width: 100%; margin-top: 8px; }
.settings button.secondary { background: transparent; color: var(--text); border: 1.5px solid var(--line); }
.settings > p { margin: 6px 0; }
.theme-cards { display: grid; gap: 12px; }
.theme-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background-color: var(--bg);
  background-image: var(--bg-image);
  background-size: var(--bg-size, auto);
  background-position: var(--bg-position, 0 0);
  color: var(--text);
  font-family: var(--font);
  cursor: pointer;
}
.theme-card input { position: absolute; opacity: 0; pointer-events: none; }
.theme-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.theme-card .emblem { flex: none; width: 56px; height: 56px; padding: 6px; background: var(--bar); border-radius: var(--radius); }
.theme-card .emblem svg { width: 100%; height: 100%; }
.theme-card .sample { flex: 1; display: grid; gap: 4px; min-width: 0; }
.theme-card b { font-family: var(--title-font); text-transform: var(--title-transform); letter-spacing: var(--title-spacing); }
.theme-card small { color: var(--muted); }
.theme-card .msg { max-width: 100%; font-size: 13px; padding: 3px 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Вкладення */
.attach {
  flex: none;
  width: 38px;
  height: 46px;
  border: 0;
  background: none;
  font-size: 22px;
  padding: 0;
}
.attach:active { opacity: .6; }
.msg.file { padding: 4px 4px 4px; }
.msg.file .meta { padding: 0 6px 1px; }
.msg .photo {
  display: block;
  /* Без відсотків: інакше бульбашка розтягується під справжню ширину фото. */
  max-width: 240px;
  max-height: 300px;
  border-radius: calc(var(--radius) * .6);
  cursor: zoom-in;
}
.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 10px 2px 6px;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  font: inherit;
}
.file-icon { font-size: 30px; line-height: 1; }
.file-info { display: grid; min-width: 0; }
.file-info b { overflow-wrap: anywhere; font-weight: 600; }
.file-info small { opacity: .75; }
.progress { font-variant-numeric: tabular-nums; }

.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .92);
}
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.viewer-bar button {
  border: 0;
  border-radius: 20px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  font-size: 16px;
}

/* ---------- Групи */
/* Друга «картка» позаду аватара: видно, що це група. */
.avatar.group { box-shadow: 5px -5px 0 -1px var(--surface), 5px -5px 0 0 hsl(var(--hue, 200) 55% 70%); }
.bar .avatar.group { box-shadow: 4px -4px 0 -1px var(--bar), 4px -4px 0 0 hsl(var(--hue, 200) 55% 70%); }
.msg .author {
  display: block;
  font-size: 13px;
  margin-bottom: 1px;
  color: hsl(var(--hue, 200) 55% 40%);
}
[data-theme="architect"] .msg .author { color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-size: 11px; }

/* ---------- Голосові */
.composer.recording .attach,
.composer.recording textarea { display: none; }
.recording-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 4px 0 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}
[data-theme="architect"] .recording-bar { background: transparent; }
.recording-bar .grow { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e53935;
  animation: rec-blink 1s ease-in-out infinite;
}
@keyframes rec-blink { 50% { opacity: .25; } }
.rec-cancel {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 20px;
  width: 40px;
  height: 40px;
}
.msg.voice {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  column-gap: 10px;
  min-width: 210px;
}
.msg.voice .author,
.msg.voice .meta { grid-column: 1 / -1; }
.voice-play {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 16px;
  padding: 0;
}
.msg.mine .voice-play { background: var(--mine-text); color: var(--mine); }
[data-theme="architect"] .voice-play { border-radius: 0; }
[data-theme="architect"] .msg.mine .voice-play { background: #fff; color: #3a3d40; }
.voice-play:disabled { opacity: .4; }
.voice-bar {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: color-mix(in srgb, currentColor 22%, transparent);
  cursor: pointer;
  overflow: hidden;
}
.voice-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); }
.msg.mine .voice-fill { background: var(--mine-text); }
.voice-time { font-size: 13px; font-variant-numeric: tabular-nums; opacity: .8; }

/* ---------- QR-запрошення */
#inviteBox button { display: block; width: 100%; margin-top: 12px; }
.settings label.field { display: grid; gap: 4px; margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.settings label.field input,
.settings label.field select {
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: calc(var(--radius) / 2);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
}
.invite-card {
  width: min(92vw, 380px);
  padding: 18px;
  border-radius: 16px;
  background: #fff;
  color: #222;
  text-align: center;
  display: grid;
  gap: 10px;
}
.invite-card img { width: 100%; image-rendering: pixelated; }
.invite-card .hint { color: #666; margin: 0; }

/* ---------- Аватар групи (картинка), вікно «Про розмову», нова група */
[data-theme] .avatar.photo {
  background-color: var(--surface);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
#peerAvatar, #peerInfo { cursor: pointer; }
.info-head { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 14px 0 6px; }
.avatar.big { width: 112px; height: 112px; font-size: 44px; }
.info-name { font: 600 20px/1.3 var(--title-font); text-align: center; overflow-wrap: anywhere; }
.settings .row { display: flex; gap: 8px; margin-top: 10px; align-items: stretch; }
.settings .row button { flex: 1; }
.settings .row select {
  min-width: 0;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: calc(var(--radius) / 2);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
}
#addBox button { flex: none; }
.members { list-style: none; margin: 0; padding: 0; }
.members li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.members li .avatar { width: 36px; height: 36px; font-size: 15px; }
.members .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.members .who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.members .who small { color: var(--muted); font-size: 13px; }
.settings .members button {
  flex: none;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  border-radius: calc(var(--radius) / 2);
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--line);
}
.settings .members button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.members label { display: flex; align-items: center; gap: 10px; flex: 1; cursor: pointer; }
.members input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.members li.link { cursor: pointer; }
.settings button.danger { display: block; width: 100%; margin-top: 22px; background: #c62f24; color: #fff; }
.settings button:disabled { opacity: .45; }
.left-note {
  margin: 0;
  padding: 12px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

/* ---------- Вигляд повідомлень */
.look-preview {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background-color: var(--bg);
  background-image: var(--bg-image);
  background-size: var(--bg-size, auto);
  overflow: hidden;
  flex: none;
}
.swatch-label { margin: 14px 0 6px; color: var(--muted); font-size: 14px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.settings .swatches .swatch {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  font-size: 10px;
  font-weight: 600;
  color: var(--text);
}
.settings .swatches .swatch.theme { width: auto; padding: 0 10px; border-radius: 16px; background: var(--surface); }
.settings .swatches .swatch[aria-pressed="true"] { outline: 3px solid var(--accent); outline-offset: 2px; }
#lookReset { margin-top: 16px; }
.settings label.field select { width: 100%; }

/* ---------- Мій профіль */
.profile { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.profile .row { width: 100%; margin-top: 2px; }
.profile .hint, .profile .error { margin: 0; text-align: center; }

/* ---------- Версія внизу налаштувань */
.settings p.version { margin-top: 18px; text-align: center; }

/* ---------- Іконки, вкладки, пошук, чипи, «＋» (будова як у звичних месенджерах) */
.i {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.icon.back { padding: 0; }
.attach { color: var(--muted); display: grid; place-items: center; }
.attach .i { width: 23px; height: 23px; }

.bar.big { min-height: 64px; padding: 16px 18px 6px; padding-top: max(16px, env(safe-area-inset-top)); }
.bar.big h1 { font-size: 26px; font-weight: 700; }
.list-tools { flex: none; padding: 6px 14px 4px; }
.search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 46px;
  padding: 0 16px;
  border-radius: 23px;
  background: var(--field, color-mix(in srgb, var(--text) 7%, var(--surface)));
  color: var(--muted);
}
.search .i { width: 20px; height: 20px; }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--text); font-size: 16px; }
.search input::-webkit-search-cancel-button { filter: grayscale(1); }
.chips { display: flex; gap: 8px; padding: 12px 0 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.chips button i { font-style: normal; margin-left: 6px; opacity: .85; }
.chips button[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--text);
}
.contacts time.new { color: var(--accent); font-weight: 700; }
.contacts .empty { justify-content: center; color: var(--muted); background: transparent; border: 0; cursor: default; }
.scroll { flex: 1; overflow-y: auto; }
.section {
  margin: 22px 16px 4px;
  font: 600 13px/1.2 var(--font);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.hint.pad { margin: 0 16px 8px; }

.fab {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 2;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: var(--accent-image, var(--accent));
  color: var(--accent-text);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
}
.tab-view .fab { bottom: calc(86px + env(safe-area-inset-bottom)); }
.contacts { padding-bottom: 84px; }

.tabs {
  flex: none;
  display: flex;
  padding: 8px 4px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--nav, var(--surface));
  border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}
.tabs .pill { width: 60px; height: 32px; border-radius: 16px; display: grid; place-items: center; }
.tabs button[aria-current="page"] { color: var(--text); }
.tabs button[aria-current="page"] .pill {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
}
.tabs .badge { position: absolute; top: -3px; left: calc(50% + 8px); min-width: 19px; height: 19px; font-size: 11px; }

/* ---------- «Ви»: фото профілю й пункти налаштувань */
.settings button.profile-photo {
  position: relative;
  padding: 0;
  border-radius: 50%;
  background: none;
  margin-top: 6px;
}
.profile .avatar.big { width: 120px; height: 120px; font-size: 50px; }
.profile-photo .plus {
  position: absolute;
  right: 0;
  bottom: 4px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-image, var(--accent));
  color: var(--accent-text);
  border: 3px solid var(--bg);
  font-size: 20px;
  font-weight: 700;
}
.profile .info-name { font-size: 26px; }
.settings button.link {
  padding: 2px 8px;
  background: none;
  color: var(--muted);
  font-weight: 500;
  text-decoration: underline;
}
.menu { margin: 18px -16px 0; }
.settings button.menu-item {
  display: flex;
  align-items: center;
  gap: 22px;
  width: 100%;
  padding: 14px 24px;
  border-radius: 0;
  background: none;
  color: var(--text);
  text-align: left;
  font-weight: 400;
}
.settings button.menu-item:active { background: color-mix(in srgb, var(--text) 6%, transparent); }
.menu-item .i { color: var(--muted); }
.menu-item b { display: block; font-size: 17px; font-weight: 500; }
.menu-item small { display: block; color: var(--muted); font-size: 14px; margin-top: 1px; }
.page > :first-child { margin-top: 12px; }
.info-head .primary { margin-top: 4px; padding: 10px 22px; }

/* ---------- «Нічна латунь» */
[data-theme="brass"] .bar:not(.big) { border-bottom: 1px solid var(--line); }
[data-theme="brass"] .bar h1,
[data-theme="brass"] .info-name { font-family: var(--title-font); color: var(--bar-text); }
[data-theme="brass"] .bar h1.brand { letter-spacing: .3em; color: #e2c07f; }
[data-theme="brass"] .contacts li { background: transparent; border-bottom: 0; padding: 10px 16px; }
[data-theme="brass"] .contacts li:active { background: color-mix(in srgb, var(--text) 5%, transparent); }
[data-theme="brass"] .contacts .avatar { width: 52px; height: 52px; font-size: 21px; }
[data-theme="brass"] .contact-top b { font-size: 16.5px; font-weight: 600; }
[data-theme="brass"] .avatar {
  background: hsl(var(--hue, 200) 22% 24%);
  color: hsl(var(--hue, 200) 55% 80%);
  box-shadow: inset 0 0 0 1.5px rgba(212, 173, 98, .6);
  font-family: var(--title-font);
  font-weight: 600;
}
[data-theme="brass"] .avatar.photo { box-shadow: 0 0 0 1.5px rgba(212, 173, 98, .6); }
[data-theme="brass"] .avatar.group { border-radius: 32%; box-shadow: inset 0 0 0 1.5px rgba(212, 173, 98, .6); }
[data-theme="brass"] .avatar.online::after { border-color: var(--bg); }
[data-theme="brass"] .badge { background: var(--accent-image); color: var(--accent-text); }
[data-theme="brass"] .day {
  background: transparent;
  border: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: 11px;
}
[data-theme="brass"] .msg .author { color: hsl(var(--hue, 200) 60% 72%); }
[data-theme="brass"] .msg.mine .meta .time { opacity: .75; }
[data-theme="brass"] .composer { background: var(--nav); }
[data-theme="brass"] .composer textarea { background: var(--field); border-color: transparent; border-radius: 22px; }
[data-theme="brass"] .send { border-radius: 50%; }
[data-theme="brass"] .settings h2 { font-family: var(--font); font-size: 13px; letter-spacing: .1em; }
[data-theme="brass"] .settings button.secondary { border-color: var(--line); }
[data-theme="brass"] .settings label.field input,
[data-theme="brass"] .settings label.field select,
[data-theme="brass"] .settings .row select { background: var(--field); border-color: var(--line); }
[data-theme="brass"] .primary,
[data-theme="brass"] #logoutButton { text-transform: uppercase; letter-spacing: .12em; font-size: 14px; }

/* Вхід: монета з блискавкою, назва з розрядкою, картка. */
[data-theme="brass"] .login-card { background: var(--surface); border-color: var(--line); }
[data-theme="brass"] .login h1 { letter-spacing: .35em; padding-left: .35em; color: #e2c07f; }
[data-theme="brass"] .login label { text-transform: uppercase; letter-spacing: .14em; font-size: 12px; }
[data-theme="brass"] .login input { background: var(--field); border-color: var(--line); }
[data-theme="brass"] .primary { box-shadow: 0 6px 18px rgba(212, 173, 98, .18); }
[data-theme="brass"] .login .scan { border-color: var(--line); }

/* ---------- Журнал з'єднання («Обліковий запис») */
.conn-log {
  margin: 8px 0 0;
  padding: 10px 12px;
  max-height: 340px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field, var(--surface));
  color: var(--muted);
  font: 12px/1.5 "Roboto Mono", Consolas, monospace;
  white-space: pre-wrap;
}
