/* Ownkin — "Your character. Your pace."
   Warm ivory and ink with one restrained cobalt accent; apricot is a fill behind ink, never text or an outline.
   Tokens and measured contrast: docs/design-ownkin-redesign.md. Every control is 44 px or larger to hit. */

:root {
  /* brand palette */
  --ivory: #f7f3ea;
  --ink-hex: #191c26;
  --cobalt: #3559e8;
  --apricot: #f4b59d;          /* fill only: ink on apricot 9.67:1; apricot on ivory is 1.59:1 */
  --apricot-soft: #f8dccb;     /* ink on it 13.0:1 */

  /* roles (light) */
  --bg: #f3eee3;               /* sheets */
  --chat-bg: var(--ivory);     /* the chat itself */
  --card: #fffdf8;
  --bar: rgba(247, 243, 234, .88);
  --label: var(--ink-hex);     /* 15.35:1 on ivory */
  --secondary: #62616a;        /* 5.52:1 on ivory, 6.01 on card */
  --tertiary: rgba(25, 28, 38, .28); /* decoration only: grabbers, chevrons */
  --placeholder: #6e6c74;
  --separator: rgba(25, 28, 38, .12);
  --field-line: #8e8c93;       /* input outlines: 3.27:1 on card */
  --fill: rgba(25, 28, 38, .06);
  --fill-strong: rgba(25, 28, 38, .12);
  --tint: var(--cobalt);       /* 5.06:1 on ivory */
  --on-tint: #ffffff;          /* 5.61:1 on cobalt */
  --me: var(--ink-hex);        /* your bubbles: ink, ivory text */
  --me-ink: var(--ivory);
  --him: var(--card);          /* the character's bubbles: paper with a hairline */
  --him-ink: var(--ink-hex);
  --him-line: rgba(25, 28, 38, .10);
  --red: #b4261e;              /* 5.86:1 */
  --green: #1e7a45;
  --orange: #8a5a00;
  --yellow-bg: var(--apricot-soft);
  --yellow-ink: var(--ink-hex);
  --scrim: rgba(25, 28, 38, .42);
  --shadow-1: 0 1px 2px rgba(25, 28, 38, .06), 0 4px 14px rgba(25, 28, 38, .06);
  --shadow-2: 0 2px 6px rgba(25, 28, 38, .08), 0 18px 48px rgba(25, 28, 38, .16);
  --meta: #62616a;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Arabic", "Geeza Pro", "Noto Sans Arabic",
          "Segoe UI", system-ui, Roboto, sans-serif;
  /* serif: brand and editorial headings only, never chat, status, form copy or controls */
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px; --space-6: 24px; --space-8: 32px;
  --radius-bubble: 20px; --radius-card: 18px; --radius-control: 14px; --radius-button: 999px; --radius-sheet: 24px;
  --dur-fast: .15s; --dur-base: .25s; --dur-slow: .35s;
  --ease-out: cubic-bezier(.2, .8, .2, 1); --ease-spring: cubic-bezier(.2, .9, .25, 1.05);
  --focus: 0 0 0 3px color-mix(in srgb, var(--tint) 60%, transparent);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  /* night: deliberate, not inverted. Cobalt is only 3.03:1 on ink, so interactive blue is lighter here. */
  :root {
    --bg: #0e1016;
    --chat-bg: #12141b;
    --card: #1b1e28;
    --bar: rgba(18, 20, 27, .86);
    --label: #f3eee4;            /* 15.91:1 */
    --secondary: #a7abb8;        /* 8.02:1 */
    --tertiary: rgba(243, 238, 228, .26);
    --placeholder: #8e94a3;
    --separator: rgba(243, 238, 228, .12);
    --field-line: #6b6f80;       /* 3.33:1 on card */
    --fill: rgba(243, 238, 228, .07);
    --fill-strong: rgba(243, 238, 228, .14);
    --tint: #8ea6ff;             /* 7.93:1 */
    --on-tint: var(--ink-hex);   /* 7.32:1 */
    --me: #ede6d8;
    --me-ink: var(--ink-hex);    /* 13.69:1 */
    --him: #232838;
    --him-ink: #f3eee4;          /* 12.68:1 */
    --him-line: rgba(243, 238, 228, .06);
    --red: #ff8a80;
    --green: #6fd69b;
    --orange: #f2c46b;
    --yellow-bg: var(--apricot);
    --yellow-ink: var(--ink-hex);
    --scrim: rgba(0, 0, 0, .6);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-2: 0 2px 6px rgba(0, 0, 0, .4), 0 18px 48px rgba(0, 0, 0, .5);
    --meta: #a7abb8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
html { background: var(--chat-bg); }
body {
  background: var(--chat-bg);
  color: var(--label);
  font: 17px/1.29 var(--font);
  letter-spacing: -.2px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--tint) 70%, transparent); outline-offset: 2px; border-radius: 12px; }
[hidden] { display: none !important; }
.muted { color: var(--secondary); font-size: 15px; line-height: 1.38; }
code { font-family: var(--mono); font-size: .88em; }
::placeholder { color: var(--placeholder); opacity: 1; }

/* the Ownkin open-loop mark (inline SVG, currentColor) */
.mark { display: block; width: 28px; height: 28px; color: var(--tint); flex: none; }
.mark path { fill: none; stroke: currentColor; stroke-width: 10.5; stroke-linecap: round; }

/* Flex column, not grid rows: a hidden banner used to shift the rows, so the composer
   stretched over an empty chat. */
.app {
  display: flex; flex-direction: column;
  height: var(--app-h, 100dvh);
  max-width: 760px;
  margin: 0 auto;
}
.thread { flex: 1; min-height: 0; }
@media (min-width: 800px) {
  /* desktop: the conversation sits on a paper column with quiet edges */
  body { background: var(--bg); }
  .app { background: var(--chat-bg); border-left: 1px solid var(--separator); border-right: 1px solid var(--separator); }
}

/* ---------- chat header: the character first ---------- */
.bar {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: var(--space-2);
  padding: calc(env(safe-area-inset-top) + 6px) max(8px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
  min-height: 64px;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(160%) blur(20px); backdrop-filter: saturate(160%) blur(20px);
  border-bottom: 1px solid var(--separator);
}
.who { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--space-3); }
.bar-side { display: flex; align-items: center; flex: none; }
.actions { gap: 2px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center; overflow: hidden;
  background: var(--apricot); color: var(--ink-hex);        /* initial: ink on apricot 9.67:1 */
  font-weight: 600; font-size: 18px; letter-spacing: 0;
}
.bar .avatar { box-shadow: 0 0 0 2px var(--chat-bg), 0 0 0 3.5px var(--apricot); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.who-text { min-width: 0; display: grid; gap: 1px; }
.name {
  font-size: 17px; line-height: 22px; font-weight: 600; letter-spacing: -.3px; color: var(--label);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; min-width: 0; min-height: 18px;
  font-size: 13px; line-height: 18px; color: var(--secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color .2s;
}
/* busy: the label may shorten, the "simulated schedule" tag never disappears (it wraps under it) */
.status-label { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.status.typing { color: var(--tint); }
/* "simulated schedule": a labelled tag, so the made-up week is never mistaken for a live state */
.status .sim {
  flex: 0 1 auto; max-width: 100%; white-space: normal; font-size: 12px; line-height: 16px; padding: 1px 7px; border-radius: 999px;
  background: var(--apricot-soft); color: var(--ink-hex); font-weight: 500;
}
.icon {
  width: 44px; height: 44px; border: 0; border-radius: 50%; flex: none;
  background: transparent; display: grid; place-items: center; transition: background var(--dur-fast);
}
.icon svg { width: 22px; height: 22px; fill: var(--label); }
.bar .icon#call svg { fill: var(--tint); }
.icon:disabled svg { fill: var(--tertiary); }
.icon:not(:disabled):hover { background: var(--fill); }
.icon:not(:disabled):active { background: var(--fill-strong); }

.mock-banner {
  margin: 10px 16px 0; padding: 10px 14px; border-radius: var(--radius-control);
  background: var(--yellow-bg); color: var(--yellow-ink); font-size: 13px; line-height: 18px;
}
/* the AI notice: always on screen, so nobody mistakes the companion for a person */
.ai-notice {
  align-self: center; margin: 8px 16px 0; padding: 0; text-align: center;
  font-size: 12px; line-height: 16px; color: var(--meta);
}
.stamp.notice {
  max-width: 300px; text-align: center; padding: 6px 12px; border-radius: 999px;
  background: var(--fill); color: var(--secondary);
}

/* ---------- conversation ---------- */
.thread {
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 10px max(16px, env(safe-area-inset-right)) 14px max(16px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 3px;
  scroll-behavior: smooth;
}
.stamp {
  align-self: center; margin: 16px 0 8px; font-size: 12px; line-height: 16px;
  color: var(--meta); letter-spacing: .02em;
}
.stamp b { font-weight: 600; }
.msg {
  max-width: min(78%, 540px); padding: 9px 14px 10px; border-radius: var(--radius-bubble);
  font-size: 17px; line-height: 23px; white-space: pre-wrap; overflow-wrap: anywhere;
  unicode-bidi: isolate; text-align: start; /* direction comes from dir= (majority script), not the first letter */
  animation: pop .22s var(--ease-out);
}
/* Arabic needs more leading than Latin at 17 pt (marks above and below the line), and no tracking:
   negative letter-spacing pulls joined letters apart. */
.msg.rtl { line-height: 26px; letter-spacing: 0; }
.field textarea[dir=rtl] { letter-spacing: 0; }
.msg.user { align-self: flex-end; background: var(--me); color: var(--me-ink); }
.msg.assistant { align-self: flex-start; background: var(--him); color: var(--him-ink); box-shadow: inset 0 0 0 1px var(--him-line), var(--shadow-1); }
.msg.user + .msg.assistant, .msg.assistant + .msg.user { margin-top: 10px; }
/* grouped bubbles: tighten the joining corners (logical, so RTL layouts mirror) */
.msg.user:has(+ .msg.user) { border-end-end-radius: 6px; }
.msg.user + .msg.user { border-start-end-radius: 6px; }
.msg.assistant:has(+ .msg.assistant), .msg.assistant:has(+ .typing) { border-end-start-radius: 6px; }
.msg.assistant + .msg.assistant, .msg.assistant + .typing { border-start-start-radius: 6px; }
.msg.error {
  align-self: center; max-width: 340px; background: color-mix(in srgb, var(--red) 10%, transparent); box-shadow: none;
  color: var(--red); font-size: 15px; line-height: 20px; text-align: center; border-radius: var(--radius-control);
}
.msg.caption { font-size: 15px; line-height: 20px; opacity: .9; }

/* empty chat: whose chat this is, that it's an AI, and that the pace is yours */
.empty {
  margin: auto; padding: var(--space-8) var(--space-6);
  display: grid; justify-items: center; gap: var(--space-2); text-align: center; max-width: 360px;
  animation: fade var(--dur-slow) var(--ease-out);
}
.empty .avatar.big {
  width: 96px; height: 96px; font-size: 40px; margin-bottom: var(--space-3);
  box-shadow: 0 0 0 6px var(--chat-bg), 0 0 0 9px var(--apricot);
}
.empty-name {
  margin: 0; font-family: var(--serif); font-size: 30px; line-height: 36px; font-weight: 600; letter-spacing: -.4px;
  max-width: 100%; overflow-wrap: anywhere;
}
.empty-note { margin: var(--space-2) 0 0; max-width: 300px; font-size: 15px; line-height: 21px; color: var(--secondary); }
.empty-brand {
  display: flex; align-items: center; gap: 8px; margin-top: var(--space-6);
  font-size: 13px; line-height: 18px; color: var(--secondary);
}
.empty-brand .mark { width: 18px; height: 18px; }

.kb-open .composer { padding-bottom: 8px; }

/* receipts and small meta text */
.receipt {
  align-self: flex-end; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 4px 8px;
  margin: 4px 2px 6px; font-size: 12px; line-height: 16px; color: var(--meta); font-weight: 500; text-align: end;
}
/* Reply now / Try again: an obvious, optional pill; the hit area is 44 px tall */
.receipt-act {
  position: relative; display: inline-flex; align-items: center; min-height: 32px; padding: 0 14px;
  border: 1px solid color-mix(in srgb, var(--tint) 45%, transparent); border-radius: 999px;
  background: var(--card); color: var(--tint); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.receipt-act::after { content: ""; position: absolute; inset: -6px -2px; }
.receipt-act:hover { background: color-mix(in srgb, var(--tint) 8%, var(--card)); }
.cell-input.inline.time { width: auto; min-width: 104px; font-variant-numeric: tabular-nums; -webkit-appearance: none; appearance: none; }
.group-footer.lead { margin: 4px 4px 18px; font-size: 15px; line-height: 21px; }

/* not delivered */
.msg.user.failed { opacity: .55; }
.retry {
  align-self: flex-end; margin: 2px 2px 6px; padding: 0 2px; border: 0; background: none; text-align: end;
  color: var(--red); font-size: 13px; line-height: 18px; min-height: 44px; font-weight: 500;
}

/* the character's photo didn't come: quiet line under the bubbles */
.photo-note {
  align-self: flex-start; margin: 2px 4px 6px; padding: 0; border: 0; background: none; text-align: start;
  color: var(--meta); font: inherit; font-size: 13px; line-height: 18px; min-height: 44px;
}
button.photo-note { color: var(--tint); font-weight: 500; }

.typing {
  align-self: flex-start; background: var(--him); border-radius: var(--radius-bubble);
  box-shadow: inset 0 0 0 1px var(--him-line), var(--shadow-1);
  padding: 14px 16px; display: flex; gap: 5px;
}
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--secondary); animation: blink 1.4s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }

/* flagged ("felt like a bot") */
.msg.assistant[data-id] { cursor: pointer; }
.msg.assistant.bot { box-shadow: inset 0 0 0 2px var(--red); }
.msg.assistant.bot::after { content: "felt like a bot"; display: block; font-size: 12px; line-height: 16px; color: var(--red); margin-top: 4px; }
.flag-menu {
  align-self: flex-start; margin: 4px 0 8px; min-height: 44px; padding: 0 16px;
  border: 0; border-radius: 999px; background: var(--card); color: var(--red); font-size: 15px; font-weight: 500;
  box-shadow: var(--shadow-2);
  animation: pop .15s ease-out;
}

/* ---------- composer ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 8px max(12px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 8px) max(12px, env(safe-area-inset-left));
  transition: padding var(--dur-fast) var(--ease-out);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(160%) blur(20px); backdrop-filter: saturate(160%) blur(20px);
  border-top: 1px solid var(--separator);
}
.composer .icon { width: 44px; height: 44px; flex: none; margin-bottom: 2px; }
.composer .icon svg { fill: var(--secondary); }
/* "/" in the composer: the commands, right above the field */
.cmd-hint { padding: 0 12px 6px; background: var(--bar); }
.cmd-hint .cmd {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 0 16px;
  border: 1px solid var(--separator); border-radius: var(--radius-control); background: var(--card); color: var(--label);
  font: inherit; font-size: 15px; text-align: start; box-shadow: var(--shadow-1); animation: fade var(--dur-fast) ease-out;
}
.cmd-hint .cmd svg { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--tint); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.cmd-hint .cmd span { color: var(--secondary); }
.field {
  flex: 1; min-width: 0; display: flex; align-items: flex-end;
  border: 1px solid var(--field-line); border-radius: 24px; background: var(--card);
  padding: 1px 1px 1px 16px; min-height: 48px;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
[dir=rtl] .field, .field:has(textarea[dir=rtl]) { padding: 1px 16px 1px 1px; }
.field:focus-within { border-color: var(--tint); box-shadow: var(--focus); }
.field textarea {
  flex: 1; min-width: 0; border: 0; background: transparent; resize: none; outline: none;
  font-size: 17px; line-height: 22px; padding: 12px 0; max-height: 140px; color: var(--label);
}
.field textarea:focus-visible { outline: none; }
/* send: a 44 px target with a 36 px cobalt disc */
.send {
  width: 44px; height: 44px; border: 0; border-radius: 50%; flex: none; margin: 0;
  background: radial-gradient(circle, var(--tint) 17.5px, transparent 18px);
  display: grid; place-items: center; transition: transform .15s, opacity .15s;
}
.send svg { width: 20px; height: 20px; fill: var(--on-tint); }
.send:focus-visible { outline-offset: -2px; border-radius: 50%; }
/* empty field: no send button; text while a reply is on its way: dimmed, not gone */
.field:has(textarea:placeholder-shown) .send:disabled { opacity: 0; transform: scale(.6); pointer-events: none; }
.send:disabled { opacity: .4; }
.recording { flex: 1; display: flex; align-items: center; gap: 8px; padding: 12px 0; font-variant-numeric: tabular-nums; min-width: 0; }
.recording .muted { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: blink 1s infinite; flex: none; }
.icon.rec { background: color-mix(in srgb, var(--red) 15%, transparent); }
.icon.rec svg { fill: var(--red); }
#voice { touch-action: none; user-select: none; -webkit-user-select: none; }

/* voice notes */
.voice-msg { display: flex; align-items: center; gap: 10px; min-width: min(220px, 60vw); }
.vplay { width: 36px; height: 36px; border-radius: 50%; border: 0; flex: none; display: grid; place-items: center; background: rgba(127,127,127,.2); color: inherit; }
.vplay svg { width: 16px; height: 16px; fill: currentColor; }
.vplay.playing svg { opacity: .5; }
.vbar {
  --p: 0%; flex: 1; height: 4px; border-radius: 2px; background: rgba(127,127,127,.35);
  background-image: linear-gradient(currentColor, currentColor); background-size: var(--p) 100%; background-repeat: no-repeat;
}
.vlen { font-size: 13px; opacity: .8; font-variant-numeric: tabular-nums; }

/* ---------- action sheet ---------- */
.as-scrim {
  position: fixed; inset: 0; z-index: 40; background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 10px calc(10px + env(safe-area-inset-bottom));
  animation: fade var(--dur-base) var(--ease-out);
}
@media (min-width: 800px) { .as-scrim { align-items: center; } }
.action-sheet { width: 100%; max-width: 420px; display: grid; gap: 8px; animation: up var(--dur-slow) var(--ease-out); }
.as-scrim.out { opacity: 0; transition: opacity var(--dur-base) var(--ease-out); }
.as-scrim.out .action-sheet { transform: translateY(110%); transition: transform var(--dur-base) var(--ease-out); }
.as-group, .as-cancel { border-radius: var(--radius-card); overflow: hidden; background: var(--card); box-shadow: var(--shadow-2); }
.as-msg { margin: 0; padding: 16px 18px; font-size: 15px; line-height: 21px; color: var(--secondary); text-align: center; }
.as-btn {
  display: block; width: 100%; min-height: 56px; border: 0; background: none;
  font: inherit; font-size: 17px; line-height: 22px; font-weight: 600; color: var(--tint);
}
.as-go { color: var(--red); border-top: 1px solid var(--separator); }
.as-cancel.as-btn { color: var(--label); }
.as-btn:active { background: var(--fill); }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 10; animation: fade .25s ease-out; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-width: 680px; margin: 0 auto; height: calc(100dvh - env(safe-area-inset-top) - 24px); max-height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  box-shadow: var(--shadow-2);
  animation: up .35s cubic-bezier(.2, .9, .25, 1);
}
@media (min-width: 800px) {
  .sheet { bottom: 24px; height: calc(100dvh - 72px); border-radius: var(--radius-sheet); }
}
.picker-sheet { z-index: 12; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--tertiary); margin: 8px auto 0; flex: none; }
.sheet-head {
  display: flex; align-items: center; gap: var(--space-2);
  min-height: 60px; padding: 4px max(8px, env(safe-area-inset-right)) 4px max(20px, env(safe-area-inset-left)); flex: none;
}
/* sheet titles are editorial: serif, left */
.sheet-head h2 {
  flex: 1; min-width: 0; margin: 0; font-family: var(--serif); font-size: 24px; line-height: 30px; font-weight: 600;
  letter-spacing: -.3px; text-align: start; overflow-wrap: anywhere;
}
.sheet-head .text-btn { flex: none; }
.text-btn {
  border: 0; background: none; color: var(--tint); font-size: 17px; font-weight: 600; min-height: 44px; min-width: 44px;
  padding: 0 12px; border-radius: 999px;
}
.text-btn:not(:disabled):hover { background: var(--fill); }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 28px) max(16px, env(safe-area-inset-left)); }
.sheet-body > .muted:only-child, #outfitBody:not(:has(*)) { padding: 24px 4px; color: var(--secondary); }

/* inset grouped list */
.group-title {
  font-size: 12px; line-height: 16px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600;
  color: var(--secondary); margin: 24px 4px 8px;
}
.group-title:first-child { margin-top: 8px; }
.group { background: var(--card); border-radius: var(--radius-card); overflow: hidden; box-shadow: inset 0 0 0 1px var(--separator); }
.setting { position: relative; padding: 13px 16px 14px; }
.setting + .setting::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--separator);
}
.setting > label { display: block; font-size: 17px; line-height: 22px; font-weight: 500; }
.setting .hint { font-size: 13px; line-height: 18px; color: var(--secondary); margin: 2px 0 10px; }
.fixed .hint { margin-bottom: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input, .row select, .row .picker {
  flex: 1 1 140px; min-width: 0; min-height: 44px; font-size: 17px; color: var(--label);
  background: var(--card); border: 1px solid var(--field-line); border-radius: var(--radius-control); padding: 0 14px;
}
.row input:focus, .row select:focus { outline: none; border-color: var(--tint); box-shadow: var(--focus); }
.row select { appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--secondary) 50%), linear-gradient(135deg, var(--secondary) 50%, transparent 50%);
  background-position: calc(100% - 19px) 52%, calc(100% - 14px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
  padding-right: 34px; }
.row button {
  min-height: 44px; border: 0; border-radius: 999px; padding: 0 20px; font-size: 17px; font-weight: 600;
  background: var(--tint); color: var(--on-tint);
}
.row button:disabled { background: var(--fill-strong); color: var(--secondary); }
.row button.ghost { background: transparent; color: var(--tint); font-weight: 600; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tint) 45%, transparent); }
.row .picker {
  text-align: start; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--secondary) 50%), linear-gradient(135deg, var(--secondary) 50%, transparent 50%);
  background-position: calc(100% - 19px) 52%, calc(100% - 14px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
}
button.link, .row button.link {
  flex: 0 1 auto; background: none; border: 0; color: var(--tint); font-size: 17px; font-weight: 500;
  padding: 0 2px; min-height: 44px; border-radius: 0; box-shadow: none;
}
.row button.link + button.link { margin-left: 18px; }
button.link.danger, .row button.link.danger { color: var(--red); }
.row button.ghost.danger { color: var(--red); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--red) 45%, transparent); }
#charText, #charSaved { display: grid; gap: 12px; }
#charText[hidden], #charSaved[hidden] { display: none; }

/* ---------- settings cells ---------- */
.group-wrap { margin-bottom: var(--space-2); }
.group-wrap > .group-title:first-child { margin-top: 28px; }
.profile-card + .group-wrap > .group-title:first-child { margin-top: 8px; }
.group-footer { font-size: 13px; line-height: 18px; color: var(--secondary); margin: 8px 4px 0; }
.cell {
  position: relative; display: block; width: 100%; text-align: start; border: 0; background: var(--card);
  padding: 12px 16px; min-height: 52px; color: var(--label);
}
.group > * { position: relative; }
.group > * + *::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; z-index: 1; border-top: 1px solid var(--separator);
}
.cell-main { display: flex; align-items: center; gap: var(--space-3); min-height: 28px; }
.cell-label { flex: 1; min-width: 0; font-size: 17px; line-height: 22px; overflow-wrap: anywhere; }
.cell-ctl { display: flex; align-items: center; gap: var(--space-2); min-width: 0; max-width: 62%; color: var(--secondary); font-size: 17px; }
.cell-value { color: var(--secondary); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.cell-hint { font-size: 13px; line-height: 18px; color: var(--secondary); margin-top: 3px; }
.cell-hint:empty { display: none; }
.cell .note { margin-top: 6px; }
.cell.fixed .cell-ctl { font-size: 15px; }
.cell:focus-visible { outline-offset: -3px; border-radius: 0; }
/* Settings > Costs */
.cost-hero { display: grid; gap: 2px; margin: 8px 0 0; padding: 18px; border-radius: var(--radius-card); background: var(--card); box-shadow: inset 0 0 0 1px var(--separator); }
.cost-label { font-size: 12px; font-weight: 600; color: var(--secondary); text-transform: uppercase; letter-spacing: .06em; }
.cost-big { font-size: 36px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.cost-sub { font-size: 15px; color: var(--secondary); font-variant-numeric: tabular-nums; min-height: 20px; }
.cost-chart { display: flex; align-items: flex-end; gap: 3px; height: 96px; margin-top: 14px; }
.cost-bar {
  flex: 1; min-width: 0; height: var(--h); padding: 0; border: 0; border-radius: 3px 3px 1px 1px;
  background: color-mix(in srgb, var(--tint) 40%, transparent); transition: background var(--dur-fast);
}
.cost-bar.today, .cost-bar.picked { background: var(--tint); }
.cost-chart:has(.picked) .cost-bar.today:not(.picked) { background: color-mix(in srgb, var(--tint) 40%, transparent); }
.cost-axis { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--secondary); }
.cell.nav { cursor: pointer; }
.cell.nav:hover, .profile-card:hover { background: color-mix(in srgb, var(--label) 3%, var(--card)); }
.cell.nav:active, .profile-card:active { background: var(--fill); }
.cell.nav.action .cell-label { color: var(--tint); font-weight: 500; }
.cell.nav.danger .cell-label { color: var(--red); }
.chev { width: 8px; height: 14px; flex: none; fill: none; stroke: var(--secondary); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; transition: transform var(--dur-base) var(--ease-out); }
[dir=rtl] .chev { transform: scaleX(-1); }
.cell.disclosure.open .chev { transform: rotate(90deg); }
.note.ok { color: var(--green); }

/* value menus: the native select sits on the right like a pop-up button */
select.menu, button.menu {
  appearance: none; -webkit-appearance: none; min-width: 0; max-width: 100%; border: 0; background: none;
  color: var(--secondary); font-size: 16px; text-align: right; text-align-last: right; padding: 0 20px 0 0; min-height: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 16'%3E%3Cpath d='M2 6l3-3 3 3M2 10l3 3 3-3' fill='none' stroke='%2385838b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right center; background-size: 10px 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
button.menu.model {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 14'%3E%3Cpath d='M1.5 1.5 6.5 7l-5 5.5' fill='none' stroke='%2385838b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: 8px 14px; padding-right: 22px;
}
.mini-play { width: 44px; height: 44px; flex: none; border: 0; border-radius: 50%; background: var(--fill); display: grid; place-items: center; }
.mini-play svg { width: 14px; height: 14px; fill: var(--tint); }

/* switches: Safari 17.4+ draws the native switch for <input switch> (tinted cobalt); others get this copy */
input.switch { accent-color: var(--tint); width: 51px; height: 31px; margin: 6px 0; flex: none; }
.no-native-switch input.switch {
  appearance: none; -webkit-appearance: none; position: relative; border-radius: 16px; background: var(--fill-strong);
  box-shadow: inset 0 0 0 1px var(--field-line);
  transition: background var(--dur-base) var(--ease-out); cursor: pointer;
}
.no-native-switch input.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 3px 1px rgba(0,0,0,.06); transition: transform var(--dur-base) var(--ease-spring);
}
.no-native-switch input.switch:checked { background: var(--tint); box-shadow: none; }
.no-native-switch input.switch:checked::after { transform: translateX(20px); }
.no-native-switch input.switch:disabled { opacity: .45; cursor: default; }

/* top of Settings: the character, as a cover card */
.profile-card {
  display: flex; align-items: center; gap: var(--space-4); width: 100%; margin: 4px 0 22px; padding: 18px;
  border: 0; border-radius: var(--radius-card); background: var(--card); color: var(--label); text-align: start;
  box-shadow: inset 0 0 0 1px var(--separator);
}
.profile-card .avatar { width: 68px; height: 68px; font-size: 28px; box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--apricot); }
.profile-text { flex: 1; min-width: 0; }
.profile-name { font-family: var(--serif); font-size: 26px; line-height: 32px; font-weight: 600; letter-spacing: -.3px; overflow-wrap: anywhere; }
.profile-sub { font-size: 15px; line-height: 20px; color: var(--secondary); }
.advanced[hidden] { display: none; }
.subcells > * { position: relative; }
.subcells > * + *::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--separator);
}
.cell-input { width: 100%; min-height: 28px; border: 0; background: none; outline: none; font-size: 17px; color: var(--label); padding: 0; }
.cell-input:focus-visible { outline: none; }
.cell:has(.cell-input:focus-visible) { box-shadow: inset 0 0 0 2px var(--tint); }
.cell-input.inline { width: 50%; text-align: right; color: var(--secondary); }
.cell.pick { cursor: pointer; }
.cell.pick .cell-main::after { content: ""; width: 22px; flex: none; }
.cell.pick.on { background: color-mix(in srgb, var(--tint) 7%, var(--card)); }
.cell.pick.on .cell-main::after { content: "✓"; color: var(--tint); font-weight: 700; text-align: right; }
.row .play { width: 44px; flex: none; padding: 0; background: var(--fill); color: var(--tint); }
.row .play svg { fill: var(--tint); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: 12px; line-height: 16px; padding: 3px 10px; border-radius: 999px; background: var(--fill); color: var(--secondary); }
.chip.ok { color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); }
.chip.warn { color: var(--yellow-ink); background: var(--yellow-bg); }
.note { font-size: 13px; line-height: 18px; margin-top: 8px; color: var(--secondary); }
.note:empty { display: none; }
.note.bad { color: var(--red); }
.note.warn { color: var(--yellow-ink); background: var(--yellow-bg); padding: 10px 12px; border-radius: var(--radius-control); }
.group > .note { margin: 0; padding: 10px 16px; }
.group > .note:empty { display: none; }

/* model picker */
.picker-search { padding: 0 16px 12px; flex: none; }
.picker-search input {
  width: 100%; min-height: 44px; font-size: 17px; color: var(--label); background: var(--card);
  border: 1px solid var(--field-line); border-radius: var(--radius-control); padding: 0 14px; outline: none;
}
.picker-search input:focus { border-color: var(--tint); box-shadow: var(--focus); }
.pick-group { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--secondary); margin: 20px 4px 8px; }
.pick { display: block; width: 100%; text-align: start; border: 0; background: var(--card); padding: 12px 16px; min-height: 52px; color: var(--label); }
.pick:first-of-type { border-radius: var(--radius-control) var(--radius-control) 0 0; }
.pick + .pick { border-top: 1px solid var(--separator); }
.pick:active:not(:disabled) { background: var(--fill); }
.pick.current { background: color-mix(in srgb, var(--tint) 7%, var(--card)); }
.pick.current .pick-name::after { content: " ✓"; color: var(--tint); }
.pick:disabled { opacity: .45; cursor: not-allowed; }
.pick-name { display: block; font-size: 17px; line-height: 22px; }
.pick-sub { display: block; font-size: 13px; line-height: 18px; color: var(--secondary); margin-top: 1px; overflow-wrap: anywhere; }

/* "what he sees" (timing only) */
.dbg-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.dbg-block { margin: 16px 0; }
.dbg-block h3 { font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--secondary); margin: 0 4px 8px; }
.dbg-block pre {
  margin: 0; padding: 14px 16px; border-radius: var(--radius-control); background: var(--card);
  white-space: pre-wrap; overflow-wrap: anywhere; unicode-bidi: plaintext;
  font: 13px/1.5 var(--mono); letter-spacing: 0;
}
.turn { font-size: 15px; line-height: 20px; padding: 10px 16px; background: var(--card); unicode-bidi: plaintext; }
.turn:first-of-type { border-radius: var(--radius-control) var(--radius-control) 0 0; }
.turn:last-child { border-radius: 0 0 var(--radius-control) var(--radius-control); }
.turn + .turn { border-top: 1px solid var(--separator); }
.turn b { color: var(--secondary); font-weight: 600; margin-right: 6px; }

/* memories: each one is a readable card row, with Forget as the tap */
.mem-group .cell.nav { padding: 14px 16px; }
.mem-group .cell-main { flex-direction: column; align-items: stretch; gap: 4px; }
.mem-group .cell-label { color: var(--label) !important; font-weight: 400 !important; unicode-bidi: plaintext; }
.mem-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; line-height: 18px; color: var(--secondary); }
.mem-forget { color: var(--red); font-weight: 600; }
.mem {
  display: flex; gap: 12px; align-items: center; padding: 12px 16px; min-height: 52px;
  background: var(--card); border-bottom: 1px solid var(--separator);
}
.mem:first-of-type { border-top-left-radius: var(--radius-control); border-top-right-radius: var(--radius-control); }
.mem:last-of-type { border-bottom-left-radius: var(--radius-control); border-bottom-right-radius: var(--radius-control); border-bottom: 0; }
.mem-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.mem-kind { font-size: 12px; line-height: 16px; letter-spacing: .04em; text-transform: uppercase; color: var(--secondary); }
.mem-content { font-size: 17px; line-height: 22px; overflow-wrap: anywhere; unicode-bidi: plaintext; }
.mem-date { font-size: 13px; color: var(--secondary); }
.mem-del {
  width: 44px; height: 44px; flex: none; border-radius: 50%; border: 0;
  background: var(--fill); color: var(--secondary); font-size: 18px; line-height: 1;
}
.mem-del:hover { color: var(--red); }
.mem-del.use { width: auto; height: 44px; padding: 0 16px; border-radius: 22px; font-size: 15px; font-weight: 600; color: var(--tint); }
.mem .vplay { color: var(--tint); background: var(--fill); }
.pick-mem { cursor: pointer; }
.pick-mem input { width: 22px; height: 22px; flex: none; accent-color: var(--tint); }
#importBody > .muted { margin: 4px 4px 12px; }
#importText, .charform input:not([type=file]):not([type=checkbox]), .charform select, .charform textarea {
  width: 100%; font-size: 17px; line-height: 22px; color: var(--label); background: var(--card);
  border: 1px solid var(--field-line); border-radius: var(--radius-control); padding: 12px 14px; resize: vertical; outline: none;
}
#importText:focus, .charform input:focus, .charform select:focus, .charform textarea:focus { border-color: var(--tint); box-shadow: var(--focus); }
#importBody .row { margin: 10px 0 14px; }
#importFile { flex: 1; min-width: 0; font-size: 15px; color: var(--secondary); background: transparent; padding: 0; border: 0; }
#importStep > p { margin: 10px 4px; }
.inline-btn {
  display: inline-flex; align-items: center; min-height: 44px; margin: 8px 0 0; border: 0; border-radius: 999px;
  padding: 0 18px; background: var(--tint); color: var(--on-tint); font-size: 15px; font-weight: 600;
}

/* character sheet: a cover card, then the parts grouped like a profile */
.charform { display: grid; gap: 6px; padding-top: 4px; }
.charform > label { display: grid; gap: 6px; font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--secondary); margin-top: 14px; }
.charform > label > * { text-transform: none; letter-spacing: normal; font-weight: 400; }
.char-top {
  display: flex; gap: 16px; align-items: center; background: var(--card); border-radius: var(--radius-card); padding: 18px;
  box-shadow: inset 0 0 0 1px var(--separator);
}
.char-top .grow { flex: 1; min-width: 0; display: grid; gap: 10px; }
.char-top label { display: grid; gap: 4px; font-size: 13px; color: var(--secondary); }
.char-top input, .char-top select { min-height: 44px; padding: 0 12px !important; }
.char-top .avatar.big { width: 84px; height: 84px; box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--apricot); }
#charAvatar { flex: none; } /* the face comes from the character's look; nothing is uploaded */
.charform .row { margin-top: 16px; }
.charform .row button { flex: 1; }
.char-group {
  font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--secondary); margin: 20px 4px 0; padding-top: 16px; border-top: 1px solid var(--separator);
}
.char-group:first-child { margin-top: 4px; padding-top: 0; border-top: 0; }
.char-more { display: grid; gap: 10px; }
.char-more > summary, details > summary {
  color: var(--tint); font-size: 17px; line-height: 22px; font-weight: 500; padding: 11px 0; min-height: 44px; cursor: pointer;
  list-style-position: inside;
}
.char-more[open] > summary { margin-bottom: 2px; }
.char-more .row { margin-top: 4px; }
.look-box .note:empty, .char-more .note:empty { display: none; }
.fresh-row {
  display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: var(--radius-card); padding: 12px 16px; margin-top: 14px;
  box-shadow: inset 0 0 0 1px var(--separator);
}
.fresh-row label { flex: 1; display: grid; gap: 2px; font-size: 17px; line-height: 22px; color: var(--label); }
.fresh-row label span { font-size: 13px; line-height: 18px; color: var(--secondary); }
/* Try: a throwaway chat inside the character sheet */
.try-box { display: grid; gap: 8px; padding: 14px; border-radius: var(--radius-card); background: var(--chat-bg); box-shadow: inset 0 0 0 1px var(--separator); }
.try-box[hidden] { display: none; }
.try-log { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; }
.try-log:empty { display: none; }
.try-bubble { max-width: 80%; padding: 8px 13px; border-radius: var(--radius-bubble); font-size: 17px; line-height: 22px; white-space: pre-wrap; overflow-wrap: anywhere; }
.try-bubble.me { align-self: flex-end; background: var(--me); color: var(--me-ink); }
.try-bubble.him { align-self: flex-start; background: var(--him); color: var(--him-ink); box-shadow: inset 0 0 0 1px var(--him-line); }
.try-bubble.rtl { line-height: 25px; }
.try-box .row { margin-top: 0; }
.try-box .row input { flex: 1; min-width: 0; }
.try-box .row button { flex: none; }

/* A/B comparison */
table.ab { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 15px; background: var(--card); border-radius: var(--radius-control); overflow: hidden; margin: 4px 0 12px; }
table.ab th, table.ab td { padding: 11px 12px; text-align: right; font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--separator); }
table.ab tr:last-child td { border-bottom: 0; }
table.ab th { font-size: 13px; font-weight: 600; color: var(--secondary); }
table.ab th:first-child, table.ab td:first-child { text-align: left; color: var(--secondary); }

/* ---------- lock / passkey ---------- */
/* covers the whole app (sheets, action sheets, the call screen) until Face ID, and in the app switcher */
.lock {
  position: fixed; inset: 0; z-index: 50; background: var(--chat-bg); overflow-y: auto;
  display: grid; place-items: center; padding: calc(env(safe-area-inset-top) + 24px) 24px calc(env(safe-area-inset-bottom) + 24px);
}
.lock-card { width: 100%; max-width: 360px; text-align: center; display: grid; gap: 12px; justify-items: center; }
.lock-mark { width: 76px; height: 76px; color: var(--tint); }
.lock-card h1 { margin: 10px 0 0; font-family: var(--serif); font-size: 40px; line-height: 46px; font-weight: 600; letter-spacing: -.5px; }
.lock-tagline { font-size: 17px; line-height: 22px; color: var(--label); margin-top: -2px !important; }
.lock-card p { margin: 0; }
.avatar.big { width: 84px; height: 84px; font-size: 36px; }
.app-icon { width: 84px; height: 84px; border-radius: 19px; }
.lock button.link { font-size: 15px; min-height: 44px; }
#setupBox, #unlockBox, #recoverBox, #encryptBox, #savedKeyBox { display: grid; gap: 12px; width: 100%; margin-top: 16px; }
#setupCode, #recoveryInput, #recoveryCheck {
  font-size: 22px; letter-spacing: .12em; text-align: center; color: var(--label);
  background: var(--card); border: 1px solid var(--field-line); border-radius: var(--radius-control); min-height: 54px; font-variant-numeric: tabular-nums;
}
#setupCode:focus, #recoveryInput:focus, #recoveryCheck:focus { outline: none; border-color: var(--tint); box-shadow: var(--focus); }
#recoveryInput, #recoveryCheck { font-size: 17px; letter-spacing: .04em; }
.recovery-key {
  font: 600 17px/1.5 var(--mono); letter-spacing: .04em; word-break: break-all;
  background: var(--card); border-radius: var(--radius-control); padding: 14px; user-select: all; -webkit-user-select: all;
  box-shadow: inset 0 0 0 1px var(--separator);
}
.primary {
  width: 100%; min-height: 52px; border: 0; border-radius: 999px; background: var(--tint); color: var(--on-tint);
  font-size: 17px; font-weight: 600;
}
.primary:active { opacity: .85; }
.primary:disabled { background: var(--fill-strong); color: var(--secondary); }

/* ---------- call ---------- */
.call {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 64px) 24px calc(env(safe-area-inset-bottom) + 36px);
  background: #0d0f14;
  color: #f3eee4; text-align: center; letter-spacing: -.3px;
}
.call-top { display: grid; justify-items: center; gap: 6px; }
.call-timer:empty { display: none; }
.call .avatar.big { width: 128px; height: 128px; font-size: 52px; background: var(--apricot); color: var(--ink-hex); }

/* presence: the character's voice drives the glow (--him, 0..1), yours a thin ring (--me) */
.call-orb { position: relative; width: 128px; height: 128px; margin-bottom: 24px; --him: 0; --me: 0; }
.call-orb .avatar.big { position: relative; z-index: 1; }
.call-orb .ring { position: absolute; inset: 0; border-radius: 50%; pointer-events: none; }
.ring.him {
  background: radial-gradient(closest-side, rgba(244,181,157,.42), rgba(244,181,157,.1) 70%, transparent);
  transform: scale(calc(1.08 + var(--him) * .75)); opacity: calc(.15 + var(--him) * 1.4);
  transition: transform 90ms linear, opacity 90ms linear;
}
.ring.me { box-shadow: 0 0 0 2px rgba(142,166,255,.7); transform: scale(calc(1.03 + var(--me) * .18)); opacity: calc(var(--me) * 2.2); transition: transform 90ms linear, opacity 90ms linear; }
.call-orb.speaking .ring.him { animation: breathe 1.8s ease-in-out infinite; }
.call-orb.thinking .ring.him { animation: think 1.1s ease-in-out infinite; }
.call-orb.initializing .ring.him { animation: think 1.6s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { scale: 1; } 50% { scale: 1.06; } }
@keyframes think { 0%, 100% { opacity: .12; } 50% { opacity: .4; } }
.call-net {
  margin-top: 10px; font-size: 13px; line-height: 18px; padding: 4px 12px; border-radius: 999px;
  background: var(--apricot); color: var(--ink-hex); font-weight: 500;
}
.call-name { font-family: var(--serif); font-size: 36px; line-height: 42px; font-weight: 600; overflow-wrap: anywhere; }
.call-status { font-size: 17px; color: #a7abb8; }
.call-timer { font-size: 15px; color: #a7abb8; font-variant-numeric: tabular-nums; }
.call-latency { margin-top: 8px; font-size: 13px; padding: 4px 12px; border-radius: 999px; background: rgba(243,238,228,.1); }
.call-mode, .call-error {
  max-width: 340px; margin-top: 12px; font-size: 15px; line-height: 21px; padding: 12px 16px; border-radius: var(--radius-control);
  background: rgba(243,238,228,.08);
}
.call-error { background: rgba(255,138,128,.16); color: #ffd2cd; }
.call-notice { margin-top: 10px; font-size: 13px; line-height: 18px; color: #a7abb8; }
.call-actions { display: flex; justify-content: center; gap: 56px; }
.round-wrap { display: grid; justify-items: center; gap: 8px; font-size: 13px; color: #d9d4ca; }
.round {
  width: 72px; height: 72px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: rgba(243,238,228,.16);
}
.round svg { width: 30px; height: 30px; fill: #fff; }
.round.off { background: #f3eee4; }
.round.off svg { fill: var(--ink-hex); }
.round.hang { background: #d9362b; }
.round.go { background: #1e9a55; }
.call:not(.ended) #callBackWrap, .call.ended #muteWrap { display: none; }
.call-orb.muted .ring.me { opacity: 0; }
.round:active { filter: brightness(.85); }
.call :focus-visible { outline-color: #8ea6ff; }

/* rating after a call */
.rate {
  display: grid; gap: 12px; justify-items: center; margin-top: 18px; width: 100%; max-width: 340px; padding: 18px;
  border-radius: var(--radius-card); background: rgba(243,238,228,.08);
}
.rate-engine { font-size: 17px; line-height: 22px; font-weight: 600; }
.stars { display: flex; gap: 4px; }
.stars button { width: 44px; height: 44px; font-size: 32px; line-height: 1; border: 0; background: none; color: rgba(255,255,255,.25); }
.stars button.on { color: var(--apricot); }
#rateNote {
  width: 100%; font-size: 17px; border-radius: var(--radius-control); border: 0; min-height: 44px; padding: 0 12px;
  background: rgba(243,238,228,.12); color: #fff;
}
#rateNote::placeholder { color: #a7abb8; }
.rate-actions { display: flex; gap: 12px; width: 100%; }
.rate-actions button { flex: 1; min-height: 44px; border: 0; border-radius: 999px; font-size: 17px; font-weight: 600; }
#rateSend { background: #f3eee4; color: var(--ink-hex); }
#rateSend:disabled { opacity: .4; }
#rateSkip { background: rgba(243,238,228,.14); color: #fff; }

/* ---------- accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (prefers-contrast: more) {
  :root { --separator: rgba(25, 28, 38, .4); --secondary: #45444c; --him-line: rgba(25, 28, 38, .4); }
}
@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root { --separator: rgba(243, 238, 228, .4); --secondary: #c9ccd6; --him-line: rgba(243, 238, 228, .4); }
}
@media (forced-colors: active) {
  .msg, .typing, .group, .field, .receipt-act { border: 1px solid CanvasText; }
  .send { background: ButtonText; }
}

/* disappearing messages */
.msg.vanishing {
  opacity: 0; height: 0 !important; padding-top: 0; padding-bottom: 0; margin-top: 0 !important; margin-bottom: 0;
  overflow: hidden; filter: blur(2px);
  transition: opacity .5s ease-out, filter .5s ease-out, height .35s .45s var(--ease-out), padding .35s .45s var(--ease-out), margin .35s .45s var(--ease-out);
}
@media (prefers-reduced-motion: reduce) { .msg.vanishing { transition: none; } }

/* the character's look */
.look-box { display: grid; gap: 10px; margin: 6px 0 14px; padding: 16px; border-radius: var(--radius-card); background: var(--card); box-shadow: inset 0 0 0 1px var(--separator); }
#charSaved > .look-box { margin: 0; }
.preset-list { display: grid; gap: 8px; }
.preset-row { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; padding: 10px 0; }
.preset-row + .preset-row { border-top: 1px solid var(--separator); }
.charform .preset-row.row button { flex: none; padding: 0 18px; }
.preset-row .grow { flex: 1; min-width: 0; }
.preset-name { font-weight: 600; }
.preset-blurb { color: var(--secondary); font-size: 13px; line-height: 18px; }
.look-title { font-family: var(--serif); font-size: 20px; line-height: 26px; font-weight: 600; }
.look-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.look-grid:empty { display: none; }
.look-pick { padding: 0; border: 0; border-radius: var(--radius-control); overflow: hidden; background: none; }
.look-pick img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; }
.msg.photo { flex-shrink: 0; padding: 0; background: none; overflow: hidden; box-shadow: var(--shadow-1); }
.msg.photo img { display: block; max-width: 240px; width: 100%; border-radius: var(--radius-bubble); }
#charText > label, .char-more > label { display: grid; gap: 6px; font-size: 13px; line-height: 18px; font-weight: 500; color: var(--secondary); }

/* ---------- day and week ---------- */
/* an overview of the made-up week: every day says Work or Off in words, never by colour alone */
.week-strip { display: grid; grid-template-columns: repeat(7, minmax(44px, 1fr)); gap: 6px; margin: 0 0 8px; }
/* under 376 px seven 44 px days don't fit: wrap to four a row instead of shrinking targets or text */
@media (max-width: 375px) { .week-strip { grid-template-columns: repeat(4, minmax(44px, 1fr)); } }
.week-day {
  display: grid; justify-items: center; align-content: center; gap: 2px; min-width: 44px; min-height: 68px; padding: 8px 2px;
  border: 0; border-radius: var(--radius-control); background: var(--card); color: var(--label);
  box-shadow: inset 0 0 0 1px var(--separator); font: inherit; cursor: pointer;
}
.week-day b { font-size: 13px; line-height: 16px; font-weight: 600; }
.week-day span { font-size: 12px; line-height: 16px; color: var(--secondary); white-space: nowrap; }
.week-day span + span { font-variant-numeric: tabular-nums; min-height: 16px; }
.week-day.work { background: var(--apricot-soft); color: var(--ink-hex); box-shadow: none; }
.week-day.work span { color: var(--ink-hex); }
.week-day.today { box-shadow: inset 0 0 0 2px var(--tint); }

/* ---------- wardrobe ---------- */
.outfit-card {
  margin: 0 0 14px; padding: 16px; border-radius: var(--radius-card); background: var(--card);
  box-shadow: inset 0 0 0 1px var(--separator); display: grid; gap: 8px;
}
.outfit-card.wearing { box-shadow: inset 0 0 0 2px var(--tint); }
.outfit-card h3 {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0;
  font-family: var(--serif); font-size: 20px; line-height: 26px; font-weight: 600;
}
.outfit-card .wearing-tag {
  font-family: var(--font); font-size: 12px; line-height: 16px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: var(--apricot-soft); color: var(--ink-hex);
}
.outfit-card img {
  display: block; width: min(100%, 300px); max-height: 360px; object-fit: contain; margin: 4px auto;
  border-radius: var(--radius-control); background: var(--fill);
}
.outfit-card > p { margin: 0; }
.outfit-when { font-size: 15px; line-height: 20px; color: var(--secondary); }
.outfit-form { display: grid; gap: 14px; padding: 8px 0 12px; }
.outfit-form label { display: grid; gap: 6px; font-size: 13px; line-height: 18px; font-weight: 500; color: var(--secondary); }
.outfit-form textarea, .outfit-form input:not([type=checkbox]) {
  width: 100%; max-width: 100%; box-sizing: border-box; font: inherit; font-size: 17px; color: var(--label);
  min-height: 44px; padding: 10px 14px; background: var(--card); border: 1px solid var(--field-line); border-radius: var(--radius-control);
}
.outfit-form textarea:focus, .outfit-form input:not([type=checkbox]):focus { outline: none; border-color: var(--tint); box-shadow: var(--focus); }
.outfit-days, .outfit-times, .outfit-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.outfit-days { margin: 0; padding: 0; border: 0; min-width: 0; }
.outfit-days legend { padding: 0; margin-bottom: 8px; font-size: 13px; line-height: 18px; font-weight: 500; color: var(--secondary); }
/* day toggles: a pill with a visible check, so on/off is never colour alone */
.outfit-days label {
  position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 46px; min-width: 64px; padding: 0 12px;
  border-radius: 999px; background: var(--card); box-shadow: inset 0 0 0 1px var(--field-line);
  font-size: 15px; font-weight: 500; color: var(--label); cursor: pointer;
}
.outfit-days input {
  appearance: none; -webkit-appearance: none; margin: 0; width: 18px; height: 18px; flex: none; border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--field-line); background: transparent; cursor: pointer;
}
.outfit-days input:checked {
  box-shadow: none; background: var(--tint) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 10'%3E%3Cpath d='M1 5l3.5 3.5L11 1.5' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 10px no-repeat;
}
.outfit-days label:has(input:checked) { box-shadow: inset 0 0 0 2px var(--tint); }
.outfit-days label:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--tint) 70%, transparent); outline-offset: 2px; }
.outfit-days input:focus-visible { outline: none; }
.outfit-times label { flex: 1 1 120px; }
.outfit-actions button, .outfit-form button[type=submit] {
  min-height: 44px; padding: 0 18px; border: 0; border-radius: 999px; font-size: 15px; font-weight: 600; cursor: pointer;
  background: transparent; color: var(--tint); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tint) 45%, transparent);
}
.outfit-actions button:first-child, .outfit-form button[type=submit] { background: var(--tint); color: var(--on-tint); box-shadow: none; }
.outfit-actions button.danger { color: var(--red); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--red) 45%, transparent); background: transparent; }
.outfit-actions button:disabled, .outfit-form button:disabled { opacity: .5; cursor: progress; }
.outfit-form button[type=submit] { justify-self: start; }
#outfitBody > details { margin: 4px 0 14px; padding: 4px 16px 8px; border-radius: var(--radius-card); background: var(--card); box-shadow: inset 0 0 0 1px var(--separator); }
.outfit-card details { border-top: 1px solid var(--separator); }
.outfit-empty { margin: 4px 0 16px; padding: 20px; text-align: center; border-radius: var(--radius-card); background: var(--card); box-shadow: inset 0 0 0 1px var(--separator); color: var(--secondary); font-size: 15px; line-height: 21px; }

/* ---------- gallery (Settings > Photos): nothing leaves the app ---------- */
.gallery {
  position: fixed; inset: 0; z-index: 13; display: flex; flex-direction: column;
  background: var(--chat-bg); animation: up var(--dur-slow) var(--ease-out);
}
.gallery.closing { transform: translateY(100%); transition: transform var(--dur-base) var(--ease-out); }
/* photos stay inside the app: no long-press "Save to Photos", no dragging them out */
.gallery img, .msg.photo img { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-user-drag: none; }
.gal-head {
  flex: none; padding-top: env(safe-area-inset-top); background: var(--bar);
  -webkit-backdrop-filter: saturate(160%) blur(20px); backdrop-filter: saturate(160%) blur(20px);
  border-bottom: 1px solid var(--separator); position: relative; z-index: 2;
}
.gal-nav { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 52px; padding: 0 8px; }
.gal-nav > :first-child { justify-self: start; }
.gal-nav > :last-child { justify-self: end; }
.gal-title { display: grid; justify-items: center; line-height: 1.15; }
.gal-title h2 { margin: 0; font-family: var(--serif); font-size: 20px; font-weight: 600; letter-spacing: -.2px; }
.gal-title span { font-size: 12px; color: var(--secondary); min-height: 14px; }
.seg {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; margin: 4px 16px 10px; padding: 3px;
  border-radius: 999px; background: var(--fill);
}
.seg button {
  border: 0; border-radius: 999px; background: none; color: var(--label); font: inherit; font-size: 13px; font-weight: 500;
  min-height: 38px; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background var(--dur-fast);
}
.seg button[aria-selected="true"] { background: var(--card); box-shadow: var(--shadow-1); font-weight: 600; }
.gal-scroll {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  touch-action: pan-y; padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
}
.gallery.selecting .gal-scroll { padding-bottom: calc(env(safe-area-inset-bottom) + 64px); }
.gal-note { margin: 12px 16px 4px; font-size: 13px; color: var(--secondary); text-align: center; }
.gal-day {
  position: sticky; top: 0; z-index: 1; margin: 0; padding: 14px 16px 8px; font-size: 17px; font-weight: 600;
  background: linear-gradient(var(--chat-bg) 60%, transparent);
}
.gal-grid { --cols: 3; display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 2px; }
.gallery.dense .gal-grid { --cols: 5; }
@media (min-width: 800px) { .gal-grid { --cols: 5; } .gallery.dense .gal-grid { --cols: 8; } }
.gal-flat { padding-top: 2px; }
.gal-tile {
  position: relative; padding: 0; border: 0; border-radius: 0; background: var(--fill); aspect-ratio: 1;
  overflow: hidden; content-visibility: auto; contain-intrinsic-size: 130px 130px;
}
.gal-tile img { display: block; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity var(--dur-base); }
.gal-tile img.ready { opacity: 1; }
.gal-tile .gal-fav {
  position: absolute; left: 5px; bottom: 5px; width: 15px; height: 15px; display: none;
  fill: #fff; filter: drop-shadow(0 0 2px rgba(0, 0, 0, .55));
}
.gal-tile.fav .gal-fav { display: block; }
.gal-tile .gal-left {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 4px 4px; text-align: center;
  font-size: 11px; font-weight: 600; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .55));
}
.gal-check {
  position: absolute; right: 5px; bottom: 5px; width: 23px; height: 23px; border-radius: 50%;
  border: 1.5px solid #fff; box-shadow: 0 0 3px rgba(0, 0, 0, .45); display: none;
}
.gallery.selecting .gal-check { display: block; }
.gal-tile.picked::after { content: ""; position: absolute; inset: 0; background: rgba(255, 255, 255, .28); }
.gal-tile.picked .gal-check {
  z-index: 1; background: var(--cobalt) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 10'%3E%3Cpath d='M1 5l3.5 3.5L11 1.5' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 12px no-repeat;
}
.gallery.dense .gal-check { width: 18px; height: 18px; right: 3px; bottom: 3px; }
.gal-empty { display: grid; justify-items: center; gap: 6px; padding: 96px 32px 0; text-align: center; }
.gal-empty svg { width: 56px; height: 56px; fill: none; stroke: var(--secondary); stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
.gal-empty h3 { margin: 6px 0 0; font-family: var(--serif); font-size: 24px; font-weight: 600; }
.gal-empty p { margin: 0; font-size: 15px; color: var(--secondary); }
.gal-foot { margin: 16px; text-align: center; font-size: 15px; font-weight: 600; color: var(--label); }
.gal-foot:empty { display: none; }
.gal-bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  min-height: 52px; padding: 0 8px env(safe-area-inset-bottom); background: var(--bar);
  -webkit-backdrop-filter: saturate(160%) blur(20px); backdrop-filter: saturate(160%) blur(20px);
  border-top: 1px solid var(--separator);
}
.gal-bar > :first-child, .gal-bar > #galleryErase { justify-self: start; }
.gal-bar > :last-child, .gal-bar > #galleryRecover { justify-self: end; }
.gal-bar .gal-count { grid-column: 2; font-size: 13px; font-weight: 600; text-align: center; }
.gal-bar #galleryErase { grid-column: 1; grid-row: 1; }
.gal-bar #galleryRecover { grid-column: 3; grid-row: 1; }
.gal-bar #galleryFav { grid-column: 1; grid-row: 1; }
.gal-bar #galleryDelete { grid-column: 3; grid-row: 1; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--tint);
}
.icon-btn svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:disabled { color: var(--tertiary); }
.icon-btn.on .heart { fill: currentColor; }
.text-btn.danger { color: var(--red); }
.text-btn:disabled { color: var(--tertiary); }
.gal-bar .icon-btn.danger { color: var(--tint); }

/* the photo, full screen: swipe between, pinch or double-tap to zoom, swipe down to close, tap for chrome */
.gal-view { position: absolute; inset: 0; z-index: 3; background: #000; color: #fff; overflow: hidden; }
.gal-view.opening { animation: fade var(--dur-base) ease-out; }
.gv-pager { position: absolute; inset: 0; overflow: hidden; touch-action: none; overscroll-behavior: none; }
.gv-track { display: flex; gap: 20px; height: 100%; will-change: transform; }
.gv-track.settle { transition: transform 320ms cubic-bezier(.25, .9, .3, 1); }
.gv-slide { position: relative; flex: 0 0 100%; height: 100%; overflow: hidden; }
.gv-slide img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transform-origin: 0 0;
  will-change: transform;
}
.gv-slide img.settle { transition: transform var(--dur-base) var(--ease-out); }
.gv-top, .gv-bottom {
  position: absolute; left: 0; right: 0; z-index: 2; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 8px; background: rgba(13, 15, 20, .6);
  -webkit-backdrop-filter: saturate(160%) blur(20px); backdrop-filter: saturate(160%) blur(20px);
  transition: opacity var(--dur-base);
}
.gv-top { top: 0; min-height: 52px; padding-top: env(safe-area-inset-top); }
.gv-bottom { bottom: 0; min-height: 52px; padding-bottom: env(safe-area-inset-bottom); }
.gal-view.bare .gv-top, .gal-view.bare .gv-bottom { opacity: 0; pointer-events: none; }
.gv-top .text-btn, .gv-bottom .icon-btn, .gv-bottom .text-btn:not(.danger) { color: #fff; }
.gv-top .text-btn svg { width: 12px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.gv-when { display: grid; justify-items: center; line-height: 1.2; }
.gv-when b { font-size: 15px; font-weight: 600; }
.gv-when span { font-size: 12px; color: rgba(255, 255, 255, .75); }
.gv-bottom > :first-child, .gv-bottom #gvErase { grid-column: 1; grid-row: 1; justify-self: start; }
.gv-bottom #gvDelete, .gv-bottom #gvRecover { grid-column: 3; grid-row: 1; justify-self: end; }
.gv-left { grid-column: 2; font-size: 13px; color: rgba(255, 255, 255, .75); }
#gvFav.on { color: #fff; }
#gvFav.pop svg { animation: favpop .35s var(--ease-spring); }
@keyframes favpop { 40% { transform: scale(1.3); } }
@media (prefers-reduced-motion: reduce) {
  .gallery, .gal-view.opening, #gvFav.pop svg { animation: none; }
  .gallery.closing, .gv-slide img.settle, .gv-track.settle, .gal-tile img { transition: none; }
}

/* narrow phones (320): keep the header and composer whole */
@media (max-width: 359px) {
  .bar { gap: 2px; padding-left: max(10px, env(safe-area-inset-left)); }
  .who { gap: 8px; }
  .status .sim { padding: 1px 5px; }
  .bar .avatar { width: 40px; height: 40px; }
  .composer { gap: 2px; padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .msg { max-width: 86%; }
  .sheet-head h2 { font-size: 22px; }
}
