:root {
  color-scheme: dark;
  --bg: #212121;
  --side: #171717;
  --panel: #2f2f2f;
  --line: rgba(255, 255, 255, 0.1);
  --user: #303030;
  --user2: #303030;
  --on-user: #ececec;
  --text: #ececec;
  --muted: #b4b4b4;
  --accent: #ececec;
  --on-accent: #0d0d0d;
  --deep: #ececec;
  --green: #10a37f;
  --red: #ef4444;
  --warn: #2f2f2f;
  --grad-a: var(--accent);
  --grad-b: var(--accent);
  --glow: none;
  --ghost-line: rgba(255, 255, 255, 0.18);
  --card-shadow: none;
  --code-bg: #171717;
  --scrim: rgba(0, 0, 0, 0.6);
  --err-bg: #3a1d1d;
  --err-text: #fecaca;
  --err-line: #7f2d2d;
  --font: "Inter", "Segoe UI", -apple-system, system-ui, sans-serif;
  --heading-font: var(--font);
  --pill: 999px;
  --bubble: 20px;
  --heavy: 600;
  --top-a: var(--bg);
  --top-b: var(--bg);
  --pattern: linear-gradient(transparent, transparent);
  --app-h: 100dvh;
  --card: rgba(128, 128, 128, 0.07);
  --on-green: #ffffff;
  --del-bg: rgba(239, 68, 68, 0.14);
  --ins-bg: rgba(16, 163, 127, 0.22);
}
:root[data-scheme="light"]:not([data-persona="chan"]):not([data-persona="san"]) {
  color-scheme: light;
  --bg: #ffffff;
  --side: #f9f9f9;
  --panel: #ffffff;
  --line: rgba(0, 0, 0, 0.1);
  --user: #f4f4f4;
  --user2: #f4f4f4;
  --on-user: #0d0d0d;
  --text: #0d0d0d;
  --muted: #5d5d5d;
  --accent: #0d0d0d;
  --on-accent: #ffffff;
  --deep: #0d0d0d;
  --red: #dc2626;
  --warn: #f4f4f4;
  --ghost-line: rgba(0, 0, 0, 0.15);
  --code-bg: #f4f4f4;
  --scrim: rgba(0, 0, 0, 0.35);
  --err-bg: #fef2f2;
  --err-text: #991b1b;
  --err-line: #fecaca;
}
:root[data-persona="chan"] {
  --bg: #fff5fa;
  --side: #ffe9f3;
  --panel: #ffffff;
  --line: #f6c9de;
  --user: #ff74a8;
  --user2: #ff9bc0;
  --text: #4b2a3d;
  --muted: #8f6178;
  --accent: #ff5f9e;
  --deep: #d63a6e;
  --green: #14a37f;
  --red: #e0345f;
  --warn: #fff1de;
  --grad-a: #ff6fa5;
  --grad-b: #ff9bc0;
  --glow: 0 6px 14px rgba(255, 95, 158, 0.32);
  --ghost-line: #f3b9d3;
  --card-shadow: 0 3px 10px rgba(255, 95, 158, 0.1);
  --code-bg: rgba(75, 42, 61, 0.08);
  --scrim: rgba(40, 10, 30, 0.45);
  --err-bg: #ffe3ea;
  --err-text: #a3153d;
  --err-line: #f6a8bc;
  --font: "Nunito", "Quicksand", "Trebuchet MS", -apple-system, "Segoe UI", system-ui, sans-serif;
  --pill: 999px;
  --bubble: 20px;
  --heavy: 800;
  --top-a: var(--panel);
  --top-b: var(--side);
  --on-accent: #fff;
  --on-user: #fff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root[data-persona="chan"] {
    color-scheme: dark;
    --bg: #1b1220;
    --side: #26172c;
    --panel: #2a1a31;
    --line: #4a2c55;
    --text: #fbe9f2;
    --muted: #c7a0b7;
    --deep: #ff8fb9;
    --warn: #3a2a1f;
    --err-bg: #45202c;
    --err-text: #ffc4d2;
    --err-line: #7a3347;
  }
}

:root[data-persona="san"] {
  --bg: #070b1a;
  --side: #090e22;
  --panel: #0c1330;
  --line: #1d2a55;
  --user: #1f3a99;
  --user2: #4a2fb0;
  --text: #e3e9ff;
  --muted: #8a97c4;
  --accent: #d6336c;
  --deep: #e3e9ff;
  --green: #4fd8b0;
  --on-green: #04241b;
  --ins-bg: rgba(79, 216, 176, 0.2);
  --red: #ff5a7a;
  --warn: #2a0f1d;
  --grad-a: #d6336c;
  --grad-b: #7a1a5e;
  --glow: 0 5px 14px rgba(214, 51, 108, 0.3);
  --ghost-line: #263466;
  --card-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  --code-bg: rgba(0, 0, 0, 0.3);
  --scrim: rgba(2, 4, 12, 0.8);
  --err-bg: #3b1426;
  --err-text: #ffb3c4;
  --err-line: #5a2440;
  --font: "Segoe UI", system-ui, sans-serif;
  --heading-font: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --pill: 12px;
  --bubble: 16px;
  --heavy: 700;
  --top-a: #101a3d;
  --top-b: #0a1030;
  --on-accent: #fff;
  --on-user: #fff;
  color-scheme: dark;
  --pattern:
    radial-gradient(circle at 20px 20px, rgba(170, 182, 230, 0.22) 1px, transparent 1.6px) 0 0 / 74px 74px,
    radial-gradient(circle at 56px 46px, rgba(214, 51, 108, 0.24) 1px, transparent 1.6px) 0 0 / 74px 74px,
    radial-gradient(900px 450px at 100% 0%, rgba(74, 47, 176, 0.28), transparent 60%),
    radial-gradient(700px 450px at 0% 100%, rgba(214, 51, 108, 0.16), transparent 60%);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--pattern), var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  overscroll-behavior: none;
  touch-action: manipulation; /* no double-tap zoom delay */
  -webkit-text-size-adjust: 100%;
}
.app { height: var(--app-h); display: flex; flex-direction: column; overflow: hidden; }

/* ----- full-page screens ----- */
.screen {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}
.screen h1 { margin: 0; font-size: 1.8rem; color: var(--deep); font-family: var(--heading-font); }
:root[data-persona="san"] .screen h1 { font-weight: 500; letter-spacing: 0.05em; }
.screen p { margin: 0; max-width: 24em; }
.muted { color: var(--muted); }
.big { width: 120px; height: 120px; }
:root:not([data-persona="chan"]) .big { width: 88px; height: 88px; }
.wobble { animation: wobble 2.4s ease-in-out infinite; }
@keyframes wobble { 50% { transform: rotate(4deg) translateY(-3px); } }
#setupForm { display: flex; flex-direction: column; gap: 12px; width: min(100%, 22em); margin-top: 6px; }
input[type="text"] {
  font: inherit; font-size: 16px; /* 16px stops iOS from zooming in on focus */
  min-height: 52px; padding: 0 18px; border-radius: var(--pill); border: 1px solid var(--line); background: var(--panel); color: var(--text); text-align: center; outline: none;
}
input[type="text"]:focus { border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 28px;
  border-radius: var(--pill); border: 1px solid transparent; font: inherit; font-weight: var(--heavy); cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--grad-a), var(--grad-b)); color: var(--on-accent); box-shadow: var(--glow); }
.btn.ghost { background: var(--panel); color: var(--deep); border-color: var(--ghost-line); }
.btn.small { min-height: 40px; padding: 0 16px; font-size: 0.9rem; }

.picker { display: inline-flex; border: 1px solid var(--ghost-line); border-radius: var(--pill); overflow: hidden; background: var(--panel); }
.picker button { font: inherit; font-size: 0.85rem; font-weight: 700; min-height: 38px; padding: 0 14px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.picker button.on { background: var(--accent); color: var(--on-accent); }
.picker.wide { display: flex; width: 100%; }
.picker.wide button { flex: 1; min-height: 44px; }

/* ----- chat ----- */
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.top {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: linear-gradient(180deg, var(--top-a), var(--top-b)); border-bottom: 1px solid var(--line);
}
:root[data-persona="san"] .top { box-shadow: 0 1px 0 rgba(214, 51, 108, 0.55); }
.top img { width: 40px; height: 40px; flex: none; }
:root:not([data-persona="chan"]) .top img { border-radius: 10px; }
.top img.talking { animation: nod 0.7s ease-in-out infinite; }
@keyframes nod { 50% { transform: translateY(-2px) scale(1.05); } }
.who { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.who b { color: var(--deep); font-size: 1.05rem; font-family: var(--heading-font); }
.who small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg { margin-left: auto; display: inline-flex; border: 1px solid var(--ghost-line); border-radius: var(--pill); overflow: hidden; background: var(--panel); flex: none; }
.seg button { font: inherit; font-size: 0.85rem; font-weight: 700; min-height: 40px; padding: 0 12px; border: 0; background: transparent; color: var(--deep); cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--on-accent); }
.seg button:disabled { opacity: 0.45; cursor: not-allowed; }
@media (max-width: 560px) {
  .top { flex-wrap: wrap; row-gap: 8px; }
  .top .seg { order: 10; flex: 1 1 100%; margin-left: 0; }
  .top .seg button { flex: 1; padding: 0 6px; }
}
.icon { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--ghost-line); background: var(--panel); color: var(--deep); font-size: 1.3rem; line-height: 1; cursor: pointer; }
:root:not([data-persona="chan"]) .icon { border-radius: var(--pill); }

.banner { flex: none; padding: 8px 16px; font-size: 0.9rem; text-align: center; }
.banner.warn { background: var(--warn); color: var(--text); border-bottom: 1px solid var(--line); }

.log {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px max(14px, env(safe-area-inset-right)) 14px max(14px, env(safe-area-inset-left));
}
.log > :first-child { margin-top: auto; }
.msg { max-width: 86%; padding: 10px 15px; border-radius: var(--bubble); white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
.msg.ai { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 7px; }
:root[data-persona="san"] .msg.ai, :root[data-persona="san"] .msg.me { box-shadow: var(--card-shadow); }
.msg.me { align-self: flex-end; background: linear-gradient(135deg, var(--user), var(--user2)); color: var(--on-user); border-bottom-right-radius: 7px; }
.msg.err { align-self: center; background: var(--err-bg); color: var(--err-text); border: 1px solid var(--err-line); font-size: 0.92rem; text-align: center; }
.msg.info { align-self: center; background: transparent; color: var(--muted); font-size: 0.88rem; text-align: center; }
.msg pre { margin: 8px 0 0; padding: 10px 12px; background: var(--code-bg); border-radius: 12px; overflow-x: auto; font: 0.85rem/1.4 ui-monospace, Menlo, Consolas, monospace; white-space: pre; }
.msg.me pre { background: rgba(255, 255, 255, 0.2); }
.msg.rich { white-space: normal; line-height: 1.55; }
.msg.rich > :first-child { margin-top: 0; }
.msg.rich > :last-child { margin-bottom: 0; }
.msg.rich p { margin: 0 0 0.7em; }
.msg.rich h3, .msg.rich h4, .msg.rich h5, .msg.rich h6 { margin: 1em 0 0.4em; font-size: 1rem; font-weight: var(--heavy); line-height: 1.35; }
.msg.rich h3 { font-size: 1.08rem; }
.msg.rich ul, .msg.rich ol { margin: 0 0 0.7em; padding-left: 1.4em; }
.msg.rich li { margin: 0.25em 0; }
.msg.rich li > ul, .msg.rich li > ol { margin: 0.25em 0 0; }
.msg.rich li::marker { color: var(--muted); }
.msg.rich blockquote { margin: 0 0 0.7em; padding: 2px 0 2px 12px; border-left: 3px solid var(--ghost-line); color: var(--muted); }
.msg.rich hr { margin: 0.9em 0; border: 0; border-top: 1px solid var(--line); }
.msg.rich code { padding: 1px 5px; border-radius: 6px; background: var(--code-bg); font: 0.86em ui-monospace, Menlo, Consolas, monospace; }
.msg.rich pre { margin: 0 0 0.7em; }
.msg.rich pre code { padding: 0; background: none; font-size: inherit; }
.msg.rich .table-wrap { width: fit-content; max-width: 100%; margin: 0 0 0.8em; overflow-x: auto; border: 1px solid var(--ghost-line); border-radius: 12px; }
.msg.rich table { border-collapse: collapse; font-size: 0.92rem; }
.msg.rich th, .msg.rich td { padding: 9px 14px; border: 0; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.msg.rich th + th, .msg.rich td + td { border-left: 1px solid var(--line); }
.msg.rich tbody tr:last-child td { border-bottom: 0; }
.msg.rich th { font-weight: var(--heavy); background: var(--card); white-space: nowrap; }
.msg.rich td:first-child { font-weight: var(--heavy); }
.msg.rich .lead { margin: 0 0 0.45em; font-size: 1.14rem; line-height: 1.4; font-weight: var(--heavy); }
.msg.rich .lead strong { font-weight: inherit; }
.msg.rich .code { margin: 0 0 0.8em; overflow: hidden; border: 1px solid var(--ghost-line); border-radius: 12px; background: var(--code-bg); }
.msg.rich .code-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 6px 5px 14px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 0.8rem; font-weight: var(--heavy); }
.msg.rich .code pre { margin: 0; padding: 11px 14px; border-radius: 0; background: transparent; }
.msg.rich .code .line { display: block; min-height: 1.4em; }
.msg.rich .code .numbered { counter-reset: ln; }
.msg.rich .code .numbered .line::before { counter-increment: ln; content: counter(ln); display: inline-block; min-width: 2ch; margin-right: 16px; color: var(--muted); opacity: 0.55; text-align: right; user-select: none; -webkit-user-select: none; }
.msg .code-copy, .msg .act { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font: inherit; cursor: pointer; }
.msg .code-copy { padding: 4px 9px; }
.msg .code-copy:hover, .msg .act:hover { background: var(--card); color: var(--text); }
.msg .copied, .msg .copied:hover { color: var(--green); }
.msg [class^="icon-"] { display: inline-grid; place-items: center; }
.msg.rich ol.steps { display: grid; gap: 8px; margin: 0 0 0.8em; padding: 0; list-style: none; }
.msg.rich ol.steps > li { display: grid; grid-template-columns: auto 1fr auto; align-items: start; column-gap: 12px; margin: 0; padding: 10px 12px; border: 1px solid var(--ghost-line); border-radius: 12px; background: var(--card); }
.msg.rich ol.steps > li > * { grid-column: 2; }
.msg.rich ol.steps > li > .step-n { grid-column: 1; grid-row: 1; display: inline-grid; place-items: center; min-width: 1.9em; height: 1.9em; padding: 0 6px; border-radius: 8px; background: var(--code-bg); color: var(--text); font-size: 0.86rem; font-weight: var(--heavy); line-height: 1; }
.msg.rich ol.steps > li > .item-body { grid-row: 1; padding-top: 0.1em; }
.msg.rich ol.steps > li > .tick { grid-column: 3; grid-row: 1; display: grid; place-items: center; width: 22px; height: 22px; margin-top: 0.15em; padding: 0; border: 1.5px solid var(--ghost-line); border-radius: 6px; background: transparent; color: transparent; cursor: pointer; }
.msg.rich ol.steps > li > .tick:hover { border-color: var(--green); }
.msg.rich ol.steps > li.done > .tick { border-color: var(--green); background: var(--green); color: var(--on-green); }
.msg.rich ol.steps > li.done > .item-body { color: var(--muted); }
.msg.rich ol.steps > li > ul, .msg.rich ol.steps > li > ol { margin: 0.35em 0 0; }
.msg.rich p.ask { margin-bottom: 0.6em; font-size: 1.05rem; font-weight: var(--heavy); }
.msg.rich .choices { display: grid; gap: 8px; width: 360px; max-width: 100%; margin: 0 0 0.6em; }
.msg .choice { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 11px 14px; border: 1px solid var(--ghost-line); border-radius: 12px; background: var(--card); color: var(--text); font: inherit; text-align: left; cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
.msg .choice:hover:not(:disabled) { border-color: var(--accent); transform: translateX(2px); }
.msg .choice .icon-chevron { flex: none; color: var(--muted); }
.msg .choices.used .choice { cursor: default; opacity: 0.5; }
.msg .choices.used .choice.chosen { opacity: 1; border-color: var(--accent); }
.msg.rich .rewrite { margin: 0 0 0.8em; }
.msg.rich .rewrite-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.msg.rich .rewrite-col { overflow: hidden; border: 1px solid var(--ghost-line); border-radius: 12px; background: var(--card); }
.msg.rich .rewrite-label { padding: 7px 14px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 0.72rem; font-weight: var(--heavy); letter-spacing: 0.08em; text-transform: uppercase; }
.msg.rich .rewrite-text { padding: 10px 14px; white-space: pre-wrap; }
.msg.rich .rewrite del { border-radius: 4px; background: var(--del-bg); color: var(--red); text-decoration: line-through; }
.msg.rich .rewrite ins { padding: 0 1px; border-radius: 4px; background: var(--ins-bg); color: inherit; text-decoration: none; }
.msg.rich .rewrite-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.msg .rw-btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 15px; border: 1px solid var(--ghost-line); border-radius: 10px; background: transparent; color: var(--text); font: inherit; font-weight: var(--heavy); cursor: pointer; }
.msg .rw-btn:hover { border-color: var(--accent); }
.msg .rw-btn.main { border-color: var(--green); background: var(--green); color: var(--on-green); }
.msg .rw-btn.main.copied { color: var(--on-green); filter: brightness(1.1); }
.msg-actions { display: flex; gap: 2px; margin-top: 8px; }
.msg .act { justify-content: center; width: 30px; height: 30px; padding: 0; }
@media (max-width: 640px) { .msg.rich .rewrite-cols { grid-template-columns: 1fr; } }
.msg .cite { display: inline-block; min-width: 1.5em; margin: 0 1px; padding: 0 5px; border-radius: 999px; background: var(--code-bg); color: var(--muted); font-size: 0.72em; line-height: 1.55; text-align: center; text-decoration: none; vertical-align: 0.18em; }
.msg .cite-group { white-space: nowrap; }
.msg .cite:hover, .msg .src:hover { color: var(--text); border-color: var(--ghost-line); }
.msg .sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; white-space: normal; }
.msg .sources-label { width: 100%; color: var(--muted); font-size: 0.78rem; font-weight: var(--heavy); }
.msg .src { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; padding: 4px 11px 4px 4px; border: 1px solid var(--line); border-radius: var(--pill); color: var(--muted); font-size: 0.8rem; text-decoration: none; }
.msg .src .n { flex: none; display: inline-grid; place-items: center; min-width: 1.5em; height: 1.5em; padding: 0 4px; border-radius: 999px; background: var(--code-bg); font-size: 0.72rem; }
.msg .src .h { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dots { display: inline-flex; gap: 5px; padding: 4px 2px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); opacity: 0.4; animation: dot 1.1s infinite; }
.dots i:nth-child(2) { animation-delay: 0.18s; }
.dots i:nth-child(3) { animation-delay: 0.36s; }
@keyframes dot { 40% { opacity: 1; transform: translateY(-3px); } }
.msg.streaming::after { content: "▍"; margin-left: 1px; opacity: 0.6; animation: dot 1.1s infinite; }

.queuebar {
  flex: none; display: flex; align-items: center; gap: 12px; margin: 0 max(12px, env(safe-area-inset-left)) 8px;
  padding: 10px 12px 10px 16px; border-radius: 18px; background: var(--warn); border: 1px solid var(--line);
}
.qtext { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.qtext b { color: var(--deep); }
.qtext span { color: var(--muted); font-size: 0.85rem; }

.composer {
  flex: none; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: var(--bg); border-top: 1px solid var(--line);
}
:root[data-persona="san"] .composer { background: #0a1030; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; font: inherit; font-size: 16px; /* 16px stops iOS from zooming in on focus */
  line-height: 1.35; max-height: 7.5em; min-height: 48px; padding: 12px 16px; border-radius: 24px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); outline: none; -webkit-appearance: none; appearance: none;
}
:root:not([data-persona="chan"]) .composer textarea { border-radius: 14px; }
:root[data-persona="san"] .composer textarea { background: #070b1a; border-color: #263466; }
.composer textarea:focus { border-color: var(--accent); }
.send {
  flex: none; width: 48px; height: 48px; border-radius: 50%; border: 0; cursor: pointer; font-size: 1.15rem; color: var(--on-accent);
  background: linear-gradient(135deg, var(--grad-a), var(--grad-b)); box-shadow: var(--glow);
}
:root:not([data-persona="chan"]) .send { border-radius: 14px; }
.send:disabled { opacity: 0.45; box-shadow: none; }
.send:active { transform: scale(0.94); }

/* ----- menu sheet ----- */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--scrim); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card {
  width: min(100%, 520px); background: var(--panel); border-radius: 24px 24px 0 0; padding: 18px 18px max(18px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
}
:root[data-persona="san"] .sheet-card { border: 1px solid #263466; box-shadow: 0 0 0 1px rgba(214, 51, 108, 0.18); }
.sheet-card h2 { margin: 0 0 4px; color: var(--deep); text-align: center; font-family: var(--heading-font); }
.row { display: flex; align-items: center; justify-content: center; min-height: 52px; border-radius: 16px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; }
:root:not([data-persona="chan"]) .row { border-radius: var(--pill); }
.row.strong { background: linear-gradient(135deg, var(--grad-a), var(--grad-b)); color: var(--on-accent); border-color: transparent; }
.hint { margin: 0; padding: 4px 8px; text-align: center; color: var(--muted); font-size: 0.9rem; }

/* narrow phones: tighter header */
@media (max-width: 380px) {
  .seg button { padding: 0 6px; font-size: 0.72rem; }
  .who small { display: none; }
}
/* landscape phones: less chrome */
@media (max-height: 460px) and (orientation: landscape) {
  .top img { width: 32px; height: 32px; }
  .composer textarea { min-height: 40px; padding: 8px 14px; }
  .send { width: 40px; height: 40px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

/* accounts, chat list */
.screen.scroll { justify-content: flex-start; overflow-y: auto; padding-top: max(28px, env(safe-area-inset-top)); }
.screen.scroll > * { flex: none; }
.tabs { display: inline-flex; border: 1px solid var(--ghost-line); border-radius: var(--pill); overflow: hidden; background: var(--panel); }
.tabs button { font: inherit; font-weight: var(--heavy); min-height: 44px; padding: 0 26px; border: 0; background: transparent; color: var(--deep); cursor: pointer; }
.tabs button.on { background: var(--accent); color: var(--on-accent); }
#authForm { display: flex; flex-direction: column; gap: 12px; width: min(100%, 24em); text-align: left; }
input[type="password"] { font: inherit; font-size: 16px; min-height: 52px; padding: 0 18px; border-radius: var(--pill); border: 1px solid var(--line); background: var(--panel); color: var(--text); outline: none; text-align: center; }
input[type="password"]:focus { border-color: var(--accent); }
#authForm input[type="text"] { text-align: center; }
.notice { margin: 0; padding: 12px 14px; border-radius: 16px; background: var(--warn); border: 1px solid var(--line); font-size: 0.88rem; line-height: 1.4; }
.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 700; min-height: 44px; align-items: center; }
.check input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.error { margin: 0; color: var(--red); font-weight: 700; text-align: center; }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.pad { padding: 30px 10px; }
.link { background: none; border: 0; color: var(--muted); font: inherit; text-decoration: underline; min-height: 44px; cursor: pointer; }
.list { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 10px; }
.chatrow { display: flex; gap: 8px; align-items: stretch; }
.chatopen { flex: 1; min-width: 0; text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border-radius: var(--bubble); border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; cursor: pointer; box-shadow: var(--card-shadow); }
.chatopen b { color: var(--deep); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chatopen small { color: var(--muted); }
.chatdel { flex: none; min-width: 52px; border-radius: var(--bubble); border: 1px solid var(--line); background: var(--panel); font: inherit; font-size: 1.1rem; cursor: pointer; color: var(--muted); }
.chatdel.sure { background: var(--red); color: #fff; border-color: var(--red); font-size: 0.8rem; font-weight: 800; }
.listfoot { flex: none; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); border-top: 1px solid var(--line); background: var(--bg); }
.listfoot .btn { width: 100%; }
.listfoot .btn:disabled { opacity: 0.45; box-shadow: none; }
/* ----- roleplay stories ----- */
.storyform { display: flex; flex-direction: column; gap: 12px; width: min(100%, 26em); text-align: left; }
.storyform label { display: flex; flex-direction: column; gap: 6px; font-weight: 700; color: var(--deep); }
.storyform input[type="text"] { text-align: left; }
.storyform textarea, .storyform select {
  font: inherit; font-size: 16px; padding: 12px 16px; border-radius: 18px; border: 1px solid var(--line); background: var(--panel); color: var(--text); outline: none; font-weight: 400; resize: vertical;
}
.storyform select { min-height: 52px; border-radius: var(--pill); }
.storyform textarea:focus, .storyform select:focus { border-color: var(--accent); }
.notes-card { max-height: 85vh; }
.notesbody { overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 2px; text-align: left; }
.notesbody h3 { margin: 0 0 4px; font-size: 0.95rem; color: var(--deep); }
.notesbody p { margin: 0 0 6px; font-size: 0.9rem; line-height: 1.4; overflow-wrap: anywhere; }
.keep-item { padding: 10px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.keep-item .keep-text { margin: 0 0 2px; font-weight: 600; color: var(--text); }
.keep-tools { display: flex; gap: 14px; align-items: center; justify-content: flex-end; }
.keep-tools .link { min-height: 36px; }
.keep-add, .keep-paste { display: flex; flex-direction: column; gap: 8px; }
.keep-add { flex-direction: row; }
.keep-input { flex: 1; min-width: 0; min-height: 44px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); font: inherit; resize: vertical; }
.keep-input:focus { outline: none; border-color: var(--accent); }
.chatrow .tag { display: inline-block; margin-right: 6px; padding: 1px 8px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: 0.72rem; font-weight: 800; vertical-align: middle; }

.mark { color: var(--text); }
.big.mark { width: 72px; height: 72px; }
.scheme-toggle {
  position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right));
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--text); cursor: pointer;
}
.scheme-toggle .sun, :root[data-scheme="light"] .scheme-toggle .moon { display: none; }
:root[data-scheme="light"] .scheme-toggle .sun { display: block; }
.scheme-row .to-light, :root[data-scheme="light"] .scheme-row .to-dark { display: inline; }
.scheme-row .to-dark, :root[data-scheme="light"] .scheme-row .to-light { display: none; }
:root[data-persona="chan"] .scheme-row, :root[data-persona="san"] .scheme-row { display: none; }
.screen { position: relative; }
:root[data-persona="am"] .msg.ai { background: transparent; border-color: transparent; padding-left: 2px; padding-right: 2px; max-width: 100%; }
:root[data-persona="am"] .top img { border-radius: 10px; }
:root[data-persona="am"] .chatopen { background: var(--side); }
:root[data-persona="am"] .sheet-card { background: var(--side); border: 1px solid var(--line); }
:root[data-persona="am"] .row:not(.strong) { background: var(--panel); }
.am-mark { display: inline-block; flex: none; background-color: currentColor; -webkit-mask: url("/img/am-mark.png") center / contain no-repeat; mask: url("/img/am-mark.png") center / contain no-repeat; }

.callbtn { display: inline-grid; place-items: center; }
.top .callbtn { margin-left: auto; }
.top .callbtn:not([hidden]) + .seg { margin-left: 0; }
.callsheet {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--bg); color: var(--text); text-align: center; overflow-y: auto;
}
.call-top { position: absolute; top: max(16px, env(safe-area-inset-top)); left: 0; right: 0; }
.call-tag { display: inline-block; padding: 4px 12px; border-radius: var(--pill); border: 1px solid var(--line); color: var(--muted); font-size: 0.8rem; font-weight: 700; }
.call-face { position: relative; display: grid; place-items: center; width: 168px; height: 168px; margin: 8px 0; padding: 0; border: 0; border-radius: 50%; background: transparent; cursor: pointer; --level: 0; }
.call-face img { position: relative; width: 120px; height: 120px; border-radius: 50%; object-fit: cover; }
.call-ring { position: absolute; inset: 14px; border-radius: 50%; background: var(--card); border: 2px solid var(--line); transform: scale(calc(1 + var(--level) * 0.22)); transition: transform 0.08s linear; }
.callsheet[data-state="listening"] .call-ring { border-color: var(--green); }
.callsheet[data-state="hearing"] .call-ring { border-color: var(--green); background: var(--ins-bg); }
.callsheet[data-state="speaking"] .call-ring { border-color: var(--accent); animation: callpulse 1.1s ease-in-out infinite; }
.callsheet[data-state="thinking"] .call-ring { border-style: dashed; animation: callspin 2.4s linear infinite; }
.callsheet[data-state="error"] .call-ring { border-color: var(--red); }
@keyframes callpulse { 50% { transform: scale(1.12); } }
@keyframes callspin { to { transform: rotate(360deg); } }
.call-name { margin: 0; font-size: 1.5rem; color: var(--deep); font-family: var(--heading-font); }
.call-status { margin: 0; min-height: 1.4em; font-weight: 700; color: var(--muted); }
.callsheet[data-state="error"] .call-status { color: var(--err-text); }
.call-caption { margin: 4px 0 0; max-width: 420px; min-height: 2.8em; font-size: 0.95rem; line-height: 1.4; color: var(--text); overflow-wrap: anywhere; }
.call-caption b { color: var(--muted); font-weight: 700; }
.call-note { margin: 4px 0 8px; max-width: 360px; font-size: 0.78rem; color: var(--muted); }
.call-buttons { display: flex; gap: 36px; margin-top: 8px; }
.call-round { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 76px; padding: 0; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 0.82rem; font-weight: 700; cursor: pointer; }
.call-round svg { box-sizing: content-box; padding: 18px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); }
.call-round .slash { display: none; }
.call-round.on svg { background: var(--accent); color: var(--on-accent); }
.call-round.on .slash { display: inline; }
.call-round.end svg { background: var(--red); color: #ffffff; border-color: transparent; }
.callsheet[data-state="error"] #callMute { visibility: hidden; }
@media (prefers-reduced-motion: reduce) { .call-ring { animation: none !important; transition: none; } }
