/* ═══════════════════════════════════════════════════════════════
   ArticulAI — iOS / ChatGPT-inspired UI
   Light & dark themes, phone-first, safe-area aware.
   ═══════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-elevated: #ffffff;
  --sidebar: #f9f9f9;
  --surface: #f4f4f4;
  --surface-2: #ececec;
  --surface-3: #e3e3e3;
  --text: #0d0d0d;
  --text-secondary: #5d5d5d;
  --muted: #8f8f8f;
  --border: #e8e8e8;
  --border-strong: #d7d7d7;
  --user-bubble: #f4f4f4;
  --code-bg: #f6f6f6;
  --accent: #0d0d0d;
  --accent-text: #ffffff;
  --danger: #d93036;
  --ok: #0f9d6e;
  --link: #0b57d0;
  --hover: rgba(0, 0, 0, .05);
  --overlay: rgba(0, 0, 0, .4);
  --shadow: 0 4px 24px rgba(0, 0, 0, .08);
  --shadow-lg: 0 18px 60px rgba(0, 0, 0, .18);
  --radius: 16px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --bg-elevated: #212121;
  --sidebar: #171717;
  --surface: #212121;
  --surface-2: #2f2f2f;
  --surface-3: #3a3a3a;
  --text: #ececec;
  --text-secondary: #b4b4b4;
  --muted: #8e8e8e;
  --border: #2a2a2a;
  --border-strong: #3f3f3f;
  --user-bubble: #303030;
  --code-bg: #0d0d0d;
  --accent: #ffffff;
  --accent-text: #0d0d0d;
  --danger: #ff6b6b;
  --ok: #37d39b;
  --link: #8ab4f8;
  --hover: rgba(255, 255, 255, .08);
  --overlay: rgba(0, 0, 0, .6);
  --shadow: 0 4px 24px rgba(0, 0, 0, .5);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, .65);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .2s ease, color .2s ease;
}

.hidden { display: none !important; }
a { color: var(--link); }
::selection { background: var(--surface-3); }
button, input, textarea { font: inherit; }

svg { display: block; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { transform: scale(.95); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 18px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .06s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.985); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn.primary:hover { opacity: .88; background: var(--accent); }
.btn.big { width: 100%; min-height: 48px; font-size: 16px; }

input, textarea {
  width: 100%;
  padding: 13px 15px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 14px;
  outline: none;
  transition: border-color .15s, background .15s;
}
input:focus, textarea:focus { border-color: var(--border-strong); background: var(--bg-elevated); }
input::placeholder, textarea::placeholder { color: var(--muted); }

.hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.error { margin-top: 14px; color: var(--danger); font-size: 14px; }

/* ────────────────────────────── Login ───────────────────────────── */
#login-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
  animation: rise .35s ease both;
}

.login-logo {
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
}
.login-logo svg { width: 30px; height: 30px; }

.login-card h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -.02em;
}
.login-sub { margin: 0 0 26px; color: var(--text-secondary); font-size: 15px; }

.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  margin-bottom: 20px;
  background: var(--surface);
  border-radius: 12px;
}
.segmented .tab {
  flex: 1;
  padding: 9px 10px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.segmented .tab.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .16);
}

.tab-body { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.tab-body .hint { text-align: center; padding: 0 6px; }

/* ───────────────────────────── Layout ───────────────────────────── */
/* --app-h is the height of the visible area, measured from the visual viewport
   in app.js. iOS keeps the layout viewport untouched when the keyboard opens,
   so the document scrolls and the whole site slides up; with the document
   pinned below and only the app view shortened, nothing moves — the composer
   alone rises above the keyboard. */
#app-view {
  display: flex;
  height: 100%;
  height: var(--app-h, 100%);
  overflow: hidden;
  background: var(--bg);
}

/* An open chat is not a scrolling document: fixing the body is what stops
   iOS Safari from scrolling (and panning) the page on every field focus. */
html.app-open,
html.app-open body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
html.app-open body {
  position: fixed;
  inset: 0;
  width: 100%;
}

#sidebar {
  width: 268px;
  flex: 0 0 268px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 10px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}

.side-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px 6px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -.01em;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
}
.brand-mark svg { width: 18px; height: 18px; }
#sidebar-close { display: none; }

.side-new {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}
.side-new svg { width: 19px; height: 19px; color: var(--text-secondary); }
.side-new:hover { background: var(--hover); }

.balance-pill {
  margin: 2px 4px 4px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.side-label {
  padding: 8px 12px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

#chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 0 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text);
  font-size: 14.5px;
  cursor: pointer;
  transition: background .12s;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--surface); }
.chat-item .row-icon {
  display: flex;
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  color: var(--muted);
}
.chat-item .row-icon svg { width: 16px; height: 16px; }
.chat-item .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-item .row-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .12s;
}
.chat-item:hover .row-actions,
.chat-item.active .row-actions { opacity: 1; }
.chat-item .row-btn {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.chat-item .row-btn:hover { background: var(--surface-2); color: var(--text); }
.chat-item .row-btn svg { width: 15px; height: 15px; }
.chat-item.archived .name { color: var(--text-secondary); }
.chat-item .row-hint {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 5px;
  line-height: 1.5;
}
.restore-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .38);
  backdrop-filter: blur(3px);
  animation: fade .15s ease-out;
}
.restore-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 26px 32px;
  border-radius: 18px;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .22);
}
.restore-box p { margin: 0; font-size: 15px; }
.restore-box .spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  border-top-color: var(--text);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (hover: none) {
  .chat-item .row-actions { opacity: 1; }
}

.side-bottom {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 2px 0;
  border-top: 1px solid var(--border);
}
.side-link {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.side-link svg { width: 18px; height: 18px; color: var(--text-secondary); flex-shrink: 0; }
.side-link:hover { background: var(--surface-2); }
.side-link.hidden { display: none; }
.profile-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
.profile-actions .btn { text-decoration: none; }
.profile-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}
.profile-pill:hover { background: var(--hover); }
.profile-pill .avatar {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-secondary);
}
.profile-pill .avatar svg { width: 16px; height: 16px; }
.profile-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ──────────────────────────── Main / topbar ─────────────────────── */
#main {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

#topbar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  height: calc(54px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  background: var(--bg);
}

#model-chip { grid-column: 2; justify-self: center; }

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.01em;
  cursor: pointer;
}
.model-chip:hover { background: var(--hover); }
.model-chip svg { width: 15px; height: 15px; color: var(--muted); }
.model-name {
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-right {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}
.balance-text {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#top-new-chat { display: none; }

/* ───────────────────────────── Messages ─────────────────────────── */
.messages {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  padding: 14px 16px 26px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.messages > * {
  width: 100%;
  max-width: 768px;
  margin-left: auto;
  margin-right: auto;
  flex-shrink: 0;
}

.msg { animation: rise .2s ease both; }

.msg.user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.msg.user .bubble {
  max-width: min(82%, 620px);
  padding: 10px 16px;
  border-radius: 22px;
  background: var(--user-bubble);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg img.attached {
  max-width: min(72%, 320px);
  border-radius: 16px;
  display: block;
}

.msg.assistant {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.msg-avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
}
.msg-avatar svg { width: 17px; height: 17px; }
.msg-main { flex: 1; min-width: 0; }
.msg-body {
  font-size: 16px;
  line-height: 1.62;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg-body a { text-decoration: underline; text-underline-offset: 2px; }
.msg-body b, .msg-body strong { font-weight: 650; }
.msg-body code {
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--surface);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em;
  white-space: pre-wrap;
}
.msg-body pre {
  margin: 10px 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--code-bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
}
.msg-body pre code { padding: 0; background: none; font-size: inherit; white-space: pre; }
.msg-body blockquote {
  margin: 8px 0;
  padding-left: 12px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-secondary);
}
.msg img.gen {
  display: block;
  max-width: min(100%, 420px);
  margin-top: 10px;
  border-radius: 16px;
}
.msg .meta { margin-top: 6px; color: var(--muted); font-size: 12.5px; }

.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.msg.assistant:hover .msg-actions,
.msg-actions:focus-within { opacity: 1; }
.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
}
.action-btn:hover { background: var(--hover); color: var(--text); }
.action-btn svg { width: 14px; height: 14px; }

.msg-body.streaming .cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  border-radius: 1px;
  background: var(--text);
  vertical-align: -2px;
  animation: blink 1.05s steps(1) infinite;
}

.dots { display: inline-flex; gap: 4px; padding: 7px 0; }
.dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: .16s; }
.dots i:nth-child(3) { animation-delay: .32s; }

/* ───────────────────────────── Empty state ──────────────────────── */
.empty {
  margin: auto;
  padding: 8vh 0 4vh;
  text-align: center;
  animation: rise .35s ease both;
}
.empty-logo {
  width: 52px;
  height: 52px;
  margin: 0 auto 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
}
.empty-logo svg { width: 27px; height: 27px; }
.empty h1 {
  margin: 0 0 26px;
  font-size: 27px;
  font-weight: 650;
  letter-spacing: -.03em;
}
.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-width: 540px;
  margin: 0 auto;
}
.suggestion {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.suggestion:hover { background: var(--surface); border-color: var(--border-strong); }

/* ───────────────────────────── Composer ─────────────────────────── */
#composer {
  flex: 0 0 auto;
  padding: 6px max(12px, calc((100% - 768px) / 2)) calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 78%, transparent);
}

.composer-shell {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 7px 7px 7px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 26px;
  background: var(--surface);
  box-shadow: 0 2px 12px rgba(0, 0, 0, .06);
  transition: border-color .15s, background .15s;
}
.composer-shell:focus-within { border-color: var(--muted); }

.composer-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background .15s, color .15s, transform .06s;
}
.composer-btn:hover { background: var(--surface-2); color: var(--text); }
.composer-btn:active { transform: scale(.92); }
.composer-btn svg { width: 21px; height: 21px; }

#msg-input {
  flex: 1;
  min-width: 0;
  max-height: 200px;
  padding: 8px 4px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  resize: none;
  outline: none;
}
#msg-input:focus { background: transparent; border: none; }

.send-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  transition: background .15s, color .15s, transform .06s;
}
.send-btn svg { width: 18px; height: 18px; }
.send-btn:active { transform: scale(.92); }
.send-btn:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: default;
}

.composer-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  text-align: center;
}

#photo-preview {
  position: relative;
  display: inline-block;
  margin: 0 0 8px 4px;
}
#photo-preview img {
  max-height: 84px;
  border-radius: 14px;
  border: 1px solid var(--border);
  display: block;
}
#photo-preview .icon-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 26px;
  height: 26px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
#photo-preview .icon-btn svg { width: 14px; height: 14px; }

/* ───────────────────────────── Modals ───────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade .16s ease both;
}
.modal-box {
  width: 100%;
  max-width: 460px;
  max-height: min(86vh, 760px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 22px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: rise .22s ease both;
}
.modal-box.wide { max-width: 620px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.01em;
}
.modal-close {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-close svg { width: 15px; height: 15px; }
.modal-body {
  padding: 4px 18px 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.fam-btn, .mode-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  margin-bottom: 6px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: transparent;
  color: var(--text);
  font-size: 15.5px;
  text-align: left;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.fam-btn:hover, .mode-btn:hover { background: var(--surface); border-color: var(--border-strong); }
.fam-btn::after, .mode-btn::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  flex: 0 0 7px;
}
.back-btn { margin-top: 6px; }

/* Profile */
.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.profile-row:last-of-type { border-bottom: none; }
.profile-row .k { color: var(--text-secondary); }
.profile-row .v { font-variant-numeric: tabular-nums; }
.profile-row code {
  padding: 3px 7px;
  border-radius: 7px;
  background: var(--surface);
  font-size: 13.5px;
}
.modal-body h3 {
  margin: 20px 0 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}
.tx-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 0; font-size: 13.5px; }
.tx-item {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
}
.tx-item .cost { float: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.tx-item .muted { color: var(--muted); font-size: 12px; margin-top: 2px; }
.password-form { display: flex; flex-direction: column; gap: 9px; margin-top: 10px; }

/* profile: name + unique handle */
.profile-edit { display: flex; flex-direction: column; gap: 10px; margin: 2px 0 14px; }
.profile-field { display: flex; flex-direction: column; gap: 5px; }
.profile-field > span { font-size: 12.5px; color: var(--text-secondary); }
.profile-field input { padding: 11px 13px; font-size: 15px; }
.handle-input { display: flex; align-items: center; gap: 2px; }
.handle-input > span {
  padding-left: 13px;
  color: var(--muted);
  font-size: 15px;
}
.handle-input input { padding-left: 4px; }
.handle-status { min-height: 16px; font-size: 12.5px; color: var(--muted); }
.handle-status.ok { color: var(--ok); }
.handle-status.bad { color: var(--danger); }

/* friends (beta) */
.friends-add { display: flex; gap: 8px; margin: 4px 0 8px; }
.friends-add input { flex: 1; min-width: 0; }
.friends-add .btn { flex: 0 0 auto; white-space: nowrap; }
.friends-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.friend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 12px;
  background: var(--surface);
}
.friend-ava {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 650;
  text-transform: uppercase;
}
.friend-main { flex: 1; min-width: 0; }
.friend-name { font-size: 14.5px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend-handle { font-size: 12.5px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend-row .icon-btn { flex: 0 0 auto; }
@media (max-width: 420px) {
  .friends-add { flex-direction: column; }
  .friends-add .btn { width: 100%; }
}

/* ───────────────────────────── Dialog (iOS alert) ───────────────── */
.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: fade .16s ease both;
}
.dialog {
  width: 100%;
  max-width: 320px;
  padding: 20px 18px 14px;
  border-radius: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: pop .2s cubic-bezier(.32, .72, 0, 1) both;
}
.dialog h3 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.01em;
}
.dialog p {
  margin: 0 0 12px;
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.45;
}
.dialog input { margin-bottom: 12px; text-align: center; }
.dialog-actions { display: flex; gap: 8px; }
.dialog-actions .btn { flex: 1; min-width: 0; }
.dialog-choices { display: grid; gap: 8px; margin: 4px 0 12px; }
.dialog-choices .btn { width: 100%; }

/* ───────────────────────────── Toast ────────────────────────────── */
#toast {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast-item {
  max-width: 100%;
  padding: 11px 16px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  line-height: 1.35;
  box-shadow: var(--shadow-lg);
  animation: drop .25s ease both;
}

/* ───────────────────────────── Keyframes ────────────────────────── */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ───────────────────────────── Mobile ───────────────────────────── */
.mobile-only { display: none; }

@media (max-width: 900px) {
  #sidebar {
    position: fixed;
    z-index: 60;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(84vw, 320px);
    transform: translateX(-102%);
    transition: transform .26s cubic-bezier(.32, .72, 0, 1);
    box-shadow: var(--shadow-lg);
    border-right: none;
  }
  #sidebar.open { transform: none; }
  #sidebar-close { display: inline-flex; }

  #sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 55;
    background: var(--overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s;
  }
  #sidebar-overlay.open { opacity: 1; pointer-events: auto; }

  .mobile-only { display: inline-flex; }
  #top-new-chat { display: inline-flex; }
  #top-balance { display: none; }
  #topbar { height: calc(50px + env(safe-area-inset-top)); padding-left: 6px; padding-right: 6px; }
  .messages { padding: 8px 14px 20px; gap: 18px; }
  .msg.user .bubble { max-width: 86%; }
  .msg-avatar { width: 26px; height: 26px; flex-basis: 26px; }
  .msg-avatar svg { width: 15px; height: 15px; }
  .msg.assistant { gap: 10px; }
  .msg-body { font-size: 16px; }
  .empty { padding: 5vh 0 2vh; }
  .empty h1 { font-size: 24px; margin-bottom: 22px; }
  .suggestions { grid-template-columns: 1fr; gap: 7px; }
  .suggestion { padding: 11px 14px; }
  .composer-hint { display: none; }
  #composer { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }

  .modal { padding: 0; align-items: flex-end; }
  .modal-box {
    max-width: none;
    max-height: 88dvh;
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
    animation: sheet-up .28s cubic-bezier(.32, .72, 0, 1) both;
  }
  .msg-actions { opacity: 1; }
}

@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ───────────────────────────── Admin ────────────────────────────── */
#admin-login {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
}
#admin-login .login-card .btn { margin-top: 8px; }

.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: calc(18px + env(safe-area-inset-top)) 22px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.admin-head h1 { margin: 0 0 2px; font-size: 22px; font-weight: 650; letter-spacing: -.02em; }
.admin-head .hint { font-size: 13px; }
.admin-head > div:last-child { display: flex; align-items: center; gap: 8px; }

.admin-tabs {
  display: flex;
  gap: 3px;
  margin: 16px 22px 0;
  padding: 3px;
  width: fit-content;
  background: var(--surface);
  border-radius: 11px;
}
.admin-tabs .tab {
  padding: 7px 16px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.admin-tabs .tab.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .14);
}

.admin-section { padding: 16px 22px 32px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input { max-width: 360px; }
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
}
table { width: 100%; min-width: 780px; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 11px 13px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
th:hover { color: var(--text); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface); }
td.actions button {
  margin-right: 4px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
  cursor: pointer;
}
td.actions button:hover { border-color: var(--border-strong); background: var(--surface); }
td.actions button.danger:hover { border-color: var(--danger); color: var(--danger); }

.badge { padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; }
.badge.guest { background: #6b7280; }
.badge.basic { background: #2563eb; }
.badge.pro { background: #7c3aed; }
.badge.admin { background: #d97706; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

.tab-count {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.tab-count:empty { display: none; }
.rstat {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.rstat.new { background: rgba(217, 119, 6, .18); color: #d97706; }
.rstat.read { background: rgba(37, 99, 235, .16); color: #3b82f6; }
.rstat.done { background: rgba(22, 163, 74, .16); color: #16a34a; }
/* install help */
.install-step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0 0 10px;
  line-height: 1.45;
  color: var(--text);
}
.install-num {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(42, 165, 255, .16);
  color: #2AA5FF;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
}
.install-addr {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 14px 0 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft, rgba(127, 127, 127, .06));
}
.install-addr code {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  line-height: 1.35;
  word-break: normal;
  overflow-wrap: break-word;
}
.install-addr .btn { flex: none; }
.install-open { display: block; text-align: center; text-decoration: none; }

.report-text { max-width: 460px; white-space: pre-wrap; word-break: break-word; }

@media (max-width: 720px) {
  .admin-head { padding: calc(14px + env(safe-area-inset-top)) 14px 12px; }
  .admin-tabs { margin: 12px 14px 0; }
  .admin-section { padding: 12px 14px 28px; }
  .toolbar input { max-width: none; }
}

/* ═══════════════════════════════════════════════════════════════
   ArticulAI — brand, fonts, receipts, progress
   ═══════════════════════════════════════════════════════════════ */

/* Comic Sans look: Comic Neue covers Latin, Neucha covers Cyrillic. */
@font-face {
  font-family: "Comic Neue";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/comicneue-latin-400.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Comic Neue";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/comicneue-latin-700.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Neucha";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/neucha-cyrillic-400.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Neucha";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/neucha-latin-400.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --font-default: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-comic: "Comic Neue", "Neucha", "Comic Sans MS", "Comic Sans", cursive;
  --brand-red: #e11d1d;
}

html[data-font="comic"] body { font-family: var(--font-comic); }
html[data-font="serif"] body { font-family: Georgia, "Times New Roman", serif; }
html[data-font="mono"] body {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
}

/* White circle, red "A" — everywhere the old cross logo used to be. */
.brand-mark,
.login-logo,
.empty-logo,
.msg-avatar {
  background: transparent;
  color: var(--brand-red);
}
.brand-mark svg { width: 30px; height: 30px; }
.login-logo svg { width: 58px; height: 58px; }
.empty-logo svg { width: 52px; height: 52px; }
.msg-avatar svg { width: 30px; height: 30px; }
.brand-mark svg circle,
.login-logo svg circle,
.empty-logo svg circle,
.msg-avatar svg circle {
  stroke: rgba(0, 0, 0, .1);
  stroke-width: .7px;
}
[data-theme="dark"] .brand-mark svg circle,
[data-theme="dark"] .login-logo svg circle,
[data-theme="dark"] .empty-logo svg circle,
[data-theme="dark"] .msg-avatar svg circle {
  stroke: rgba(255, 255, 255, .18);
}

/* «ArticulAI» smoothly glowing red while the model is working. */
.thinking-brand {
  display: inline-block;
  padding: 4px 0;
  font-family: var(--font-comic);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--brand-red);
  animation: brand-glow 1.9s ease-in-out infinite;
}
@keyframes brand-glow {
  0%, 100% { opacity: .45; text-shadow: 0 0 6px rgba(225, 29, 29, .18); }
  45% { opacity: 1; text-shadow: 0 0 14px rgba(225, 29, 29, .45); }
}
@media (prefers-reduced-motion: reduce) {
  .thinking-brand { animation: none; opacity: .85; }
}

/* Picture / video progress: like ChatGPT's %. */
.gen-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  max-width: 320px;
}
.gen-bar {
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}
.gen-bar i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #ff5a5a, var(--brand-red));
  transition: width .45s ease;
}
.gen-pct {
  min-width: 38px;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.msg video.gen {
  display: block;
  width: min(100%, 420px);
  margin-top: 10px;
  border-radius: 16px;
  background: #000;
}

/* «цена · время · модель» under every reply. */
.msg-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.msg-meta:empty { display: none; }
.msg-meta i { opacity: .55; font-style: normal; }
.msg-meta .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Preferences sheet. */
.settings-block { padding: 4px 0 16px; }
.settings-block + .settings-block { border-top: 1px solid var(--border); padding-top: 16px; }
.settings-name { font-size: 15px; font-weight: 600; }
.settings-sub { margin-top: 3px; color: var(--muted); font-size: 13px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }

.font-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.font-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, background .15s;
}
.font-opt:hover { background: var(--surface); }
.font-opt.active { border-color: var(--brand-red); box-shadow: inset 0 0 0 1px var(--brand-red); }
.font-sample { font-size: 20px; font-weight: 700; line-height: 1; }
.font-name { font-size: 13.5px; color: var(--text-secondary); }

.switch { position: relative; display: inline-block; width: 46px; height: 27px; flex: 0 0 46px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 99px;
  background: var(--surface-3);
  transition: background .18s;
  cursor: pointer;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .18s;
}
.switch input:checked + .switch-track { background: var(--brand-red); }
.switch input:checked + .switch-track::after { transform: translateX(19px); }

/* No copy button until the answer is finished. */
.msg .msg-body.streaming ~ .msg-actions { display: none; }

/* ══════════════════════════ Арти (бета) ═══════════════════════════
   Exactly three capsules: two eyes + one mouth. No head, no body, no
   nose, no brows, no outline — just filled pills on the plain page
   background. Hands are a separate, hidden-by-default component.

   All sizes below are the 1920×1080 spec divided by 10, so 1u = 10px
   on a 1080-tall screen and the whole figure scales with the viewport.
   ─────────────────────────────────────────────────────────────── */
.beta-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  vertical-align: 1px;
}

.arti-entry { position: relative; }
.arti-mini {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  width: 19px;
  height: 19px;
  justify-content: center;
  flex: 0 0 19px;
}
.arti-mini i {
  display: block;
  width: 6px;
  height: 2px;
  border-radius: 999px;
  background: #2AA5FF;
}
.arti-mini b {
  position: absolute;
  left: 50%;
  bottom: 3px;
  width: 4px;
  height: 2px;
  margin-left: 1px;
  border-radius: 999px;
  background: #2AA5FF;
}

#arti-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2vmin;
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
  background: var(--bg);
  overflow: hidden;
}
#arti-view.hidden { display: none; }

.arti-stage {
  --u: calc(100vmin / 108);
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4vmin;
}

/* ── the figure: three capsules ── */
.arti-figure {
  --eye-w: calc(31 * var(--u));
  /* Calm face: eyes open, exactly 2:1 (310×155 at 1920), blinking now and then.
     Derived from the width so the proportion holds on any screen. */
  --eye-h: calc(var(--eye-w) / 2);
  --eye-gap: calc(15 * var(--u));
  --mouth-w: calc(10 * var(--u));       /* shorter mouth, sits right under the eyes */
  --mouth-h: calc(2.4 * var(--u));
  --arti-color: #2AA5FF;
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  color: var(--arti-color);
  transition: color 1.2s ease-in-out;
}

.arti-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(2.2 * var(--u));
  transform-origin: center;
  animation: arti-breathe 6.5s ease-in-out infinite;
}
@keyframes arti-breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.015); }
}

.arti-eyes {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--eye-gap);
}

.arti-capsule {
  display: block;
  border-radius: 999px;
  background: currentColor;
  border: none;
  box-shadow: none;
}

.arti-eye {
  width: var(--eye-w);
  height: var(--eye-h);
  transition: width 500ms ease-in-out, height 500ms ease-in-out,
              clip-path 500ms ease-in-out;
}
.arti-eye:first-child { transition-delay: 80ms; }

.arti-mouth {
  width: var(--mouth-w);
  height: max(var(--mouth-h), 8px);
  transition: width 500ms ease-in-out, height 500ms ease-in-out;
}

/* ── emotions ── */
/* Calm: the base look, declared like every other emotion so one table lists
   all of them. Eyes exactly 2:1, open, blinking now and then. */
.arti-figure[data-emotion="neutral"] {
  --eye-w: calc(31 * var(--u));
  --eye-h: calc(var(--eye-w) / 2);
  --mouth-w: calc(10 * var(--u));
  --mouth-h: calc(2.4 * var(--u));
}
.arti-figure[data-emotion="surprised"] {
  --eye-w: calc(26 * var(--u));
  --eye-h: calc(23 * var(--u));
  --mouth-w: calc(7 * var(--u));
  --mouth-h: calc(2.6 * var(--u));
}
.arti-figure[data-emotion="happy"] {
  /* Half of this height is what the clip reveals, so the arch stays a low ∩. */
  --eye-h: calc(18 * var(--u));
  --mouth-w: calc(13 * var(--u));
  --mouth-h: calc(2.6 * var(--u));
}

/* Sly / doubtful: the eyes flatten into strips, the mouth stays calm. */
.arti-figure[data-emotion="squint"] {
  --eye-h: calc(4.5 * var(--u));
  --mouth-w: calc(11 * var(--u));
  --mouth-h: calc(2.2 * var(--u));
}

/* Sad: half-closed eyes and a small mouth sitting a little lower. */
.arti-figure[data-emotion="sad"] {
  --eye-h: calc(9 * var(--u));
  --mouth-w: calc(5.5 * var(--u));
  --mouth-h: calc(2 * var(--u));
}
.arti-figure[data-emotion="sad"] .arti-mouth { transform: translateY(calc(1.2 * var(--u))); }
.arti-figure[data-emotion="sad"] .arti-body { animation-duration: 7.5s; }

/* Asleep: closed lines, slow breathing. */
.arti-figure[data-emotion="sleep"] {
  --eye-h: max(calc(0.9 * var(--u)), 4px);
  --mouth-w: calc(5 * var(--u));
  --mouth-h: calc(0.9 * var(--u));
}
.arti-figure[data-emotion="sleep"] .arti-body { animation-duration: 9.5s; }

/* Just woke up: eyes wide open, a little startled. */
.arti-figure[data-emotion="wake"] {
  --eye-h: calc(19 * var(--u));
  --mouth-w: calc(4.6 * var(--u));
  --mouth-h: calc(2.8 * var(--u));
}
.arti-figure[data-emotion="wake"] .arti-eye { transition-duration: 220ms; }

/* Thinking: narrowed eyes, small mouth; one eye pulses as if pondering. */
.arti-figure[data-emotion="think"] {
  --eye-h: calc(7 * var(--u));
  --mouth-w: calc(4 * var(--u));
  --mouth-h: calc(2 * var(--u));
}
.arti-figure[data-emotion="think"] .arti-eye:first-child {
  animation: arti-think 2.2s ease-in-out infinite;
}
@keyframes arti-think {
  0%, 100% { transform: scaleY(1); }
  50%      { transform: scaleY(1.55); }
}
/* A filled dome: the capsule itself keeps border-radius 999px, the
   clip only reveals its upper half, which reads as the ∩ eye. */
.arti-figure[data-emotion="happy"] .arti-eye {
  clip-path: ellipse(50% 100% at 50% 100%);
}
.arti-figure[data-emotion="blink"] { --eye-h: max(calc(0.4 * var(--u)), 3px); }
.arti-figure[data-emotion="blink"] .arti-eye { transition-duration: 420ms; }

/* Speaking: the mouth is re-measured by JS (90 → 140 px), while the eyes keep
   whatever expression Arti chose — the face talks without losing its mood. */
.arti-figure.talking .arti-mouth {
  --mouth-h: calc(2.8 * var(--u));
  transition-duration: 160ms;
}
.arti-figure.listening { --mouth-w: calc(6 * var(--u)); --mouth-h: max(calc(3.2 * var(--u)), 12px); }

/* ── hands: separate, tiny squares, hidden by default ── */
.arti-hand {
  position: absolute;
  top: calc(var(--eye-h) / 2 - 4 * var(--u));
  width: calc(8 * var(--u));
  height: calc(8 * var(--u));
  border-radius: 20%;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
}
/* Percent of the figure, not of --u: on a narrow phone a fixed u-offset
   pushed the waving hands off the screen edge. */
.arti-hand.left  { left: -15%; }
.arti-hand.right { right: -15%; }
.arti-figure { position: relative; }
.arti-body { position: relative; }
.arti-hand.wave { animation: arti-wave 1.6s ease-in-out 1; }
.arti-hand.wave.right { animation-delay: .1s; }
@keyframes arti-wave {
  0%   { opacity: 0; transform: translateY(0) rotate(0); }
  12%  { opacity: 1; transform: translateY(-6px) rotate(-6deg); }
  30%  { transform: translateY(-2px) rotate(6deg); }
  50%  { transform: translateY(-6px) rotate(-6deg); }
  70%  { transform: translateY(-2px) rotate(6deg); }
  88%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(0); }
}

/* ── the answer under Arti: slow upward drift when it gets long ── */
.arti-text {
  width: min(720px, 92vw);
  max-height: 34vh;
  overflow-y: auto;
  text-align: center;
  color: var(--text);
  font-size: clamp(15px, 1.9vmin, 21px);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  scrollbar-width: none;
  opacity: 0;
  transition: opacity .3s ease;
  mask-image: linear-gradient(to bottom, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
}
.arti-text::-webkit-scrollbar { display: none; }
.arti-text.show { opacity: 1; }
.arti-text .cursor {
  display: inline-block;
  width: .5em;
  height: 1em;
  margin-left: 2px;
  vertical-align: -2px;
  border-radius: 999px;
  background: currentColor;
  opacity: .5;
}

/* ── controls ── */
.arti-controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.arti-side-btn {
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .18s, color .18s, border-color .18s;
}
.arti-side-btn:hover { background: var(--hover); }
.arti-side-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.arti-mic {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #2AA5FF;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(42, 165, 255, .32);
  transition: transform .15s ease, background .2s ease, box-shadow .2s;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.arti-mic svg { width: 26px; height: 26px; }
.arti-mic:hover { background: #1b93ea; }
.arti-mic:active { transform: scale(.94); }
/* Always-on listening: a slow ring instead of the red push-to-talk pulse. */
.arti-mic.loop {
  animation: arti-ear 2.6s ease-out infinite;
}
@keyframes arti-ear {
  0%   { box-shadow: 0 6px 22px rgba(42,165,255,.32), 0 0 0 0 rgba(42,165,255,.38); }
  70%  { box-shadow: 0 6px 22px rgba(42,165,255,.32), 0 0 0 13px rgba(42,165,255,0); }
  100% { box-shadow: 0 6px 22px rgba(42,165,255,.32), 0 0 0 0 rgba(42,165,255,0); }
}
.arti-mic.listening {
  background: #e11d1d;
  box-shadow: 0 0 0 0 rgba(225, 29, 29, .5);
  animation: arti-pulse 1.6s ease-out infinite;
}
@keyframes arti-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(225, 29, 29, .45); }
  100% { box-shadow: 0 0 0 18px rgba(225, 29, 29, 0); }
}
.arti-hint {
  flex: 0 0 auto;
  margin: 0;
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* Voice-only input for browsers without speech recognition. */
.arti-typing {
  display: none;
  width: min(560px, 92vw);
  gap: 8px;
}
.arti-typing.show { display: flex; }
.arti-typing input {
  flex: 1;
  padding: 11px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}
.arti-typing button {
  padding: 0 18px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 720px) {
  .arti-stage { gap: 5vmin; }
  .arti-text { max-height: 30vh; }
  .arti-mic { width: 58px; height: 58px; }
  .arti-controls { gap: 10px; }
  .arti-side-btn { padding: 8px 13px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .arti-body { animation: none; }
  .arti-capsule { transition-duration: 1ms; }
  /* Always-on listening: a slow ring instead of the red push-to-talk pulse. */
.arti-mic.loop {
  animation: arti-ear 2.6s ease-out infinite;
}
@keyframes arti-ear {
  0%   { box-shadow: 0 6px 22px rgba(42,165,255,.32), 0 0 0 0 rgba(42,165,255,.38); }
  70%  { box-shadow: 0 6px 22px rgba(42,165,255,.32), 0 0 0 13px rgba(42,165,255,0); }
  100% { box-shadow: 0 6px 22px rgba(42,165,255,.32), 0 0 0 0 rgba(42,165,255,0); }
}
.arti-mic.listening { animation: none; }
}
