/* ==========================================================================
   Calico design system
   Instrument Sans for the interface and prose, Victor Mono for the
   "machine layer" (numbers, model ids, state) and, in its cursive italic,
   for roleplay *actions*: the stage directions of every story.
   ========================================================================== */

/* ---------- Fonts (self-hosted, OFL) ---------- */
@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans-latin.woff2") format("woff2");
  font-weight: 400 700; font-stretch: 75% 100%; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans-latin-ext.woff2") format("woff2");
  font-weight: 400 700; font-stretch: 75% 100%; font-style: normal; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans-latin-italic.woff2") format("woff2");
  font-weight: 400 700; font-stretch: 75% 100%; font-style: italic; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans-latin-ext-italic.woff2") format("woff2");
  font-weight: 400 700; font-stretch: 75% 100%; font-style: italic; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Victor Mono";
  src: url("../fonts/victor-mono-latin.woff2") format("woff2");
  font-weight: 100 700; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Victor Mono";
  src: url("../fonts/victor-mono-latin-ext.woff2") format("woff2");
  font-weight: 100 700; font-style: normal; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Victor Mono";
  src: url("../fonts/victor-mono-latin-italic.woff2") format("woff2");
  font-weight: 100 700; font-style: italic; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Victor Mono";
  src: url("../fonts/victor-mono-latin-ext-italic.woff2") format("woff2");
  font-weight: 100 700; font-style: italic; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- Tokens ---------- */
:root {
  --font-sans: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Victor Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Light: lilac milk, aubergine ink, marmalade */
  --bg: #F4F3F8;
  --bg-sunk: #EAE8F1;
  --surface: #FFFFFF;
  --surface-2: #F8F7FB;
  --ink: #1E1A26;
  --ink-2: #565068;
  --ink-3: #847E94;
  --line: #E3E0EB;
  --line-2: #D0CCDB;
  --accent: #EE7A2B;
  --accent-ink: #1E1A26;
  --accent-text: #B0500A;
  --accent-soft: #FCEADC;
  --danger: #C2373A;
  --danger-soft: #FAE6E6;
  --ok: #2B8455;
  --ok-soft: #E1F3E8;
  --warn: #9A6200;
  --warn-soft: #FAF0D8;
  --scrim: rgba(22, 19, 28, .42);
  --shadow-1: 0 1px 2px rgba(30, 26, 38, .06), 0 1px 1px rgba(30, 26, 38, .04);
  --shadow-2: 0 18px 40px -18px rgba(30, 26, 38, .32), 0 2px 8px rgba(30, 26, 38, .06);

  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 999px;
  --av-radius: 30%;

  --fs-0: .8125rem;
  --fs-1: .875rem;
  --fs-2: 1rem;
  --fs-3: 1.1875rem;
  --fs-4: 1.4375rem;
  --fs-5: 1.75rem;
  --fs-6: 2.25rem;
  --fs-7: clamp(2.6rem, 6.2vw, 4.4rem);

  --sidebar-w: 252px;
  --panel-w: 344px;
  --tabbar-h: 62px;
  --pad-x: clamp(16px, 4vw, 48px);
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #16131C;
  --bg-sunk: #100E15;
  --surface: #1F1B27;
  --surface-2: #26222F;
  --ink: #EEEAF4;
  --ink-2: #B4ADC3;
  --ink-3: #847D95;
  --line: #2D2837;
  --line-2: #3D3749;
  --accent: #F28A42;
  --accent-ink: #1A1206;
  --accent-text: #F7A86E;
  --accent-soft: #3A2417;
  --danger: #F2716C;
  --danger-soft: #3A1C20;
  --ok: #5DC690;
  --ok-soft: #16302A;
  --warn: #EAB84E;
  --warn-soft: #33280F;
  --scrim: rgba(6, 5, 9, .62);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 20px 44px -18px rgba(0, 0, 0, .7), 0 2px 8px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #16131C;
    --bg-sunk: #100E15;
    --surface: #1F1B27;
    --surface-2: #26222F;
    --ink: #EEEAF4;
    --ink-2: #B4ADC3;
    --ink-3: #847D95;
    --line: #2D2837;
    --line-2: #3D3749;
    --accent: #F28A42;
    --accent-ink: #1A1206;
    --accent-text: #F7A86E;
    --accent-soft: #3A2417;
    --danger: #F2716C;
    --danger-soft: #3A1C20;
    --ok: #5DC690;
    --ok-soft: #16302A;
    --warn: #EAB84E;
    --warn-soft: #33280F;
    --scrim: rgba(6, 5, 9, .62);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-2: 0 20px 44px -18px rgba(0, 0, 0, .7), 0 2px 8px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

html[data-text="s"] { font-size: 93.75%; }
html[data-text="l"] { font-size: 112.5%; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--fs-2);
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
p a, .hint a, .small a, .lede a, li a { color: var(--accent-text); }
h1, h2, h3, h4 { margin: 0; font-weight: 640; font-stretch: 86%; letter-spacing: -.018em; line-height: 1.15; text-wrap: balance; }
h1 { font-size: var(--fs-6); }
h2 { font-size: var(--fs-4); }
h3, .h3 { font-size: var(--fs-3); }
.h2 { font-size: var(--fs-4); }
.h4, h4 { font-size: var(--fs-2); font-stretch: 92%; }
p { margin: 0 0 .8em; }
p:last-child { margin-bottom: 0; }
code, pre, kbd { font-family: var(--font-mono); font-size: .9em; }
code { background: var(--bg-sunk); padding: .1em .35em; border-radius: var(--r-xs); }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.muted { color: var(--ink-3); }
.small { font-size: var(--fs-0); }
.center { text-align: center; }
.measure { max-width: 66ch; }
.lede { font-size: var(--fs-3); color: var(--ink-2); line-height: 1.5; max-width: 60ch; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row-tight { gap: 6px; flex-wrap: nowrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.skip { position: absolute; left: -9999px; top: 8px; z-index: 300; background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: var(--r-pill); }
.skip:focus { left: 12px; }
.danger { color: var(--danger) !important; }
.link, .link-quiet { background: none; border: 0; padding: 0; font: inherit; color: var(--accent-text); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link-quiet { display: inline-flex; gap: 6px; align-items: center; color: var(--ink-2); text-decoration: none; }
.link-quiet:hover { color: var(--ink); }
.link-quiet .icon { width: 16px; height: 16px; }
.link-more { font-size: var(--fs-1); color: var(--ink-2); text-decoration: none; font-weight: 500; }
.link-more:hover { color: var(--ink); }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 22px;
  padding: 18px 12px 14px; border-right: 1px solid var(--line);
  scrollbar-width: thin;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px; text-decoration: none; font-weight: 650; font-stretch: 80%; font-size: 1.375rem; letter-spacing: -.02em; }
.brand img { width: 30px; height: 30px; }
.nav { display: grid; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px;
  border-radius: var(--r-sm); color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: .9375rem;
}
.nav-link:hover { background: var(--bg-sunk); color: var(--ink); }
.nav-link.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.nav-link.is-active .icon { color: var(--accent); }
.side-section { display: grid; gap: 4px; min-height: 0; }
.side-label { padding: 0 12px 4px; font-size: var(--fs-0); color: var(--ink-3); font-weight: 500; }
.side-chats { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.side-chat { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: var(--r-sm); text-decoration: none; color: var(--ink-2); font-size: var(--fs-1); }
.side-chat:hover { background: var(--bg-sunk); color: var(--ink); }
.side-chat.is-active { background: var(--bg-sunk); color: var(--ink); }
.side-chat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-chat-mood { font-size: .95em; }
.side-foot { margin-top: auto; display: grid; gap: 6px; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px 4px 0 8px; border-top: 1px solid var(--line); margin-top: 6px; }
.me-text { flex: 1; min-width: 0; display: grid; line-height: 1.25; }
.me-text strong { font-size: var(--fs-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text .mono { font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; }
.main { min-width: 0; }
.bare { min-height: 100dvh; display: grid; place-items: start center; padding: clamp(24px, 6vh, 72px) 16px 48px; }

.tabbar {
  display: none; position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 0 6px env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
  align-items: stretch; justify-content: space-around;
}
.tabbar a { flex: 1; display: grid; place-items: center; align-content: center; gap: 2px; text-decoration: none; color: var(--ink-3); font-size: 11px; font-weight: 500; }
.tabbar a .icon { width: 22px; height: 22px; }
.tabbar a.is-active { color: var(--ink); }
.tabbar a.is-active .icon { color: var(--accent); }
.tabbar .tab-create { flex: 0 0 auto; }
.tabbar .tab-create .icon { width: 46px; height: 46px; padding: 11px; border-radius: 16px; background: var(--ink); color: var(--bg); stroke-width: 2.2; }
.tabbar .tab-create.is-active .icon { color: var(--bg); background: var(--accent-text); }

/* ---------- Pages ---------- */
.page { padding: 32px var(--pad-x) 56px; max-width: 1200px; }
.page-narrow { max-width: 440px; margin: 0 auto; padding-top: clamp(32px, 8vh, 88px); }
.page-form { max-width: 920px; }
.page-settings { max-width: 1040px; }
.page-doc { max-width: 980px; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-head .back { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-3); text-decoration: none; font-size: var(--fs-1); margin-bottom: 6px; }
.page-head .back .icon { width: 16px; height: 16px; }
.section { margin-top: 40px; }
.section:first-child { margin-top: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.flashes { padding: 16px var(--pad-x) 0; max-width: 1200px; display: grid; gap: 8px; }
body.is-chat .toasts { top: 70px; bottom: auto; }
body.is-chat .flashes { position: fixed; z-index: 80; top: 70px; left: 50%; transform: translateX(-50%); width: min(560px, calc(100vw - 24px)); padding: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--r-pill);
  border: 1px solid transparent; background: none; color: var(--ink);
  font: 600 var(--fs-1)/1 var(--font-sans); letter-spacing: -.005em;
  cursor: pointer; text-decoration: none; white-space: nowrap; user-select: none;
  transition: background-color .15s, border-color .15s, color .15s, transform .08s;
}
.btn:active { transform: translateY(1px); }
.btn .icon { width: 18px; height: 18px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover { background: color-mix(in srgb, var(--ink) 84%, var(--accent)); }
.btn-ghost { border-color: var(--line-2); }
.btn-ghost:hover { background: var(--surface); border-color: var(--ink-3); }
.btn-ghost.is-on { border-color: color-mix(in srgb, #E0607E 60%, transparent); color: #D2486A; }
.btn-ghost.is-on .icon { fill: currentColor; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 86%, #000); }
.btn-sm { height: 32px; padding: 0 12px; font-size: var(--fs-0); gap: 6px; }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-lg { height: 48px; padding: 0 22px; font-size: .9375rem; }
.btn-block { width: 100%; }
.btn-icon {
  display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0; flex: none;
  border: 0; border-radius: 50%; background: none; color: var(--ink-2); cursor: pointer;
  transition: background-color .15s, color .15s;
}
.btn-icon:hover { background: var(--bg-sunk); color: var(--ink); }
.btn-icon .icon { width: 20px; height: 20px; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 18px; }
.field { display: grid; gap: 6px; min-width: 0; border: 0; padding: 0; margin: 0; }
.label { font-weight: 600; font-size: var(--fs-1); color: var(--ink); }
legend.label { margin-bottom: 6px; }
.optional { font-weight: 400; color: var(--ink-3); margin-left: 4px; }
.hint { font-size: var(--fs-0); color: var(--ink-3); line-height: 1.45; display: block; }
.error { font-size: var(--fs-0); color: var(--danger); font-weight: 500; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]),
select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px;
  font: inherit; font-size: .9375rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  transition: border-color .15s, box-shadow .15s; appearance: none;
}
textarea { line-height: 1.5; resize: vertical; min-height: 84px; }
select {
  padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23847E94' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input:disabled { color: var(--ink-3); background: var(--bg-sunk); }
input::placeholder, textarea::placeholder { color: var(--ink-3); opacity: .85; }
.mono-input { font-family: var(--font-mono) !important; font-size: .875rem !important; letter-spacing: -.01em; }
.input-sm { min-height: 34px !important; padding: 6px 10px !important; font-size: var(--fs-0) !important; }
.has-error input, .has-error textarea, .has-error select { border-color: var(--danger) !important; }
.form-foot { display: flex; justify-content: flex-end; gap: 10px; padding-top: 4px; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: var(--fs-1); }
.check input { margin: 3px 0 0; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.check > span { display: grid; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; margin: 0; cursor: pointer; }
input[type="file"] { font: inherit; font-size: var(--fs-1); }
.range-scale { display: flex; justify-content: space-between; font-size: var(--fs-0); color: var(--ink-3); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch-row > span { display: grid; gap: 2px; font-size: .9375rem; }
.switch {
  appearance: none; -webkit-appearance: none; position: relative; flex: none; margin: 0;
  width: 44px; height: 26px; border-radius: var(--r-pill); background: var(--line-2); cursor: pointer;
  transition: background-color .2s var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s var(--ease);
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }
.select-inline { display: inline-flex; align-items: center; gap: 6px; height: 48px; padding: 0 4px 0 14px; border: 1px solid var(--line-2); border-radius: var(--r-pill); color: var(--ink-2); }
.select-inline select { border: 0; min-height: 0; padding: 0 30px 0 0; background-color: transparent; box-shadow: none !important; font-weight: 500; }
.copy-field { display: flex; gap: 8px; }
.copy-field input { flex: 1; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }

/* ---------- Panels, callouts, flashes ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px; min-width: 0; }
.panel + .panel { margin-top: 20px; }
.panel > h2, .panel > h3, .panel > .h3, .panel > .h4 { margin-bottom: 8px; }
fieldset.panel { margin: 0; }
fieldset.panel legend { float: left; width: 100%; margin-bottom: 14px; }
fieldset.panel legend + * { clear: both; }
.callout { display: flex; gap: 14px; align-items: center; padding: 16px 18px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); margin-bottom: 24px; }
.callout > .icon { width: 24px; height: 24px; color: var(--accent); }
.callout > div { flex: 1; min-width: 0; }
.callout p { margin: 2px 0 0; color: var(--ink-2); font-size: var(--fs-1); }
.callout-accent { background: var(--accent-soft); border-color: transparent; }
.flash { display: flex; align-items: flex-start; gap: 10px; padding: 11px 12px 11px 14px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); font-size: var(--fs-1); box-shadow: var(--shadow-1); }
.flash > span { flex: 1; padding-top: 1px; }
.flash .icon { width: 18px; height: 18px; margin-top: 1px; }
.flash-success { background: var(--ok-soft); border-color: transparent; }
.flash-success > .icon { color: var(--ok); }
.flash-error { background: var(--danger-soft); border-color: transparent; }
.flash-error > .icon { color: var(--danger); }
.flash-info > .icon { color: var(--accent); }
.flash .flash-close { width: 26px; height: 26px; margin: -3px -4px -3px 0; }
.flash .flash-close .icon { width: 16px; height: 16px; margin: 0; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--r-pill); background: var(--bg-sunk); color: var(--ink-2); font-size: 12px; font-weight: 500; vertical-align: middle; }
.badge .icon { width: 13px; height: 13px; }
.mood-pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: var(--r-pill); background: var(--bg-sunk); color: var(--ink-2); font-size: 12px; font-weight: 500; white-space: nowrap; line-height: 1.6; }
.tier { font-family: var(--font-mono); font-size: 11px; padding: 1px 7px; border-radius: var(--r-pill); background: var(--bg-sunk); color: var(--ink-2); white-space: nowrap; }

/* ---------- Chips, tabs, segmented ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 13px;
  border-radius: var(--r-pill); border: 1px solid var(--line-2); background: transparent;
  color: var(--ink-2); font: 500 var(--fs-1)/1 var(--font-sans); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--ink-3); color: var(--ink); }
.chip.is-on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip-sm { height: 22px; padding: 0 8px; font-size: 11.5px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: -4px 0 28px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; margin-bottom: -5px; border-bottom: 2px solid transparent; color: var(--ink-3); text-decoration: none; font-weight: 500; font-size: .9375rem; white-space: nowrap; }
.tabs a .icon { width: 18px; height: 18px; }
.tabs a:hover { color: var(--ink); }
.tabs a.is-active { color: var(--ink); border-bottom-color: var(--accent); }
.seg { display: inline-flex; padding: 3px; border-radius: var(--r-pill); background: var(--bg-sunk); }
.seg a { padding: 6px 14px; border-radius: var(--r-pill); font-size: var(--fs-1); font-weight: 500; color: var(--ink-2); text-decoration: none; white-space: nowrap; }
.seg a.is-on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* ---------- Avatars & tiles ---------- */
.av { border-radius: var(--av-radius); object-fit: cover; background: var(--bg-sunk); flex: none; }
.av-round { border-radius: 50%; }
.av-xs { width: 24px; height: 24px; }
.av-sm { width: 36px; height: 36px; }
.av-md { width: 46px; height: 46px; }
.av-lg { width: 72px; height: 72px; }
.av-xl { width: 112px; height: 112px; }
.av-hero { width: 176px; height: 176px; box-shadow: var(--shadow-2); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); gap: 28px 20px; }
.tile { display: grid; gap: 12px; align-content: start; text-decoration: none; color: inherit; min-width: 0; }
.tile-av { width: 100%; height: auto; aspect-ratio: 1; transition: transform .25s var(--ease), box-shadow .25s var(--ease); }
@media (hover: hover) {
  .tile:hover .tile-av { transform: translateY(-3px) rotate(-1deg); box-shadow: var(--shadow-2); }
}
.tile-body { display: grid; gap: 4px; min-width: 0; }
.tile-name { font-weight: 640; font-stretch: 88%; font-size: 1.0625rem; letter-spacing: -.01em; line-height: 1.2; display: flex; align-items: center; gap: 6px; }
.tile-vis .icon { width: 14px; height: 14px; color: var(--ink-3); }
.tile-tag { color: var(--ink-2); font-size: var(--fs-1); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-meta { display: flex; align-items: center; gap: 12px; color: var(--ink-3); font-family: var(--font-mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.tile-meta > span { display: inline-flex; align-items: center; gap: 4px; }
.tile-meta .icon { width: 13px; height: 13px; }
.tile-by { margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tile-av-new { display: grid; place-items: center; border: 1.5px dashed var(--line-2); border-radius: var(--av-radius); color: var(--ink-3); aspect-ratio: 1; }
.tile-new:hover .tile-av-new { border-color: var(--accent); color: var(--accent); }
.tile-av-new .icon { width: 34px; height: 34px; }

/* ---------- Chat lists ---------- */
.chat-list { list-style: none; margin: 0; padding: 0; display: grid; }
.chat-row { display: flex; gap: 14px; align-items: center; padding: 12px 10px; margin: 0 -10px; border-radius: var(--r-md); text-decoration: none; color: inherit; }
.chat-row:hover { background: var(--surface); }
.chat-row-body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.chat-row-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-row-top strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row-top time { margin-left: auto; color: var(--ink-3); font-size: 12px; flex: none; }
.chat-row-last { color: var(--ink-2); font-size: var(--fs-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row-last .you { color: var(--ink-3); }
.chat-list-full .chat-row { border-bottom: 1px solid var(--line); border-radius: 0; margin: 0; padding: 14px 4px; }
.chat-list-full .chat-row:hover { background: none; }
.chat-list-full .chat-row:hover strong { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Empty & error states ---------- */
.empty { display: grid; justify-items: center; text-align: center; gap: 12px; padding: 56px 16px; }
.empty .av-xl { margin-bottom: 8px; transform: rotate(-4deg); }
.empty p { color: var(--ink-2); max-width: 42ch; }
.error-page { text-align: left; }
.error-mark { font-family: var(--font-mono); font-size: 3.5rem; font-weight: 300; font-style: italic; color: var(--accent-text); line-height: 1; margin-bottom: 14px; }
.error-mark .icon { width: 40px; height: 40px; color: var(--accent); }
.error-detail { margin-top: 24px; padding: 14px; background: var(--bg-sunk); border-radius: var(--r-md); overflow: auto; font-size: 12px; white-space: pre-wrap; }

/* ---------- Landing ---------- */
.hero {
  display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(0, .92fr); gap: clamp(28px, 5vw, 72px); align-items: center;
  padding: clamp(40px, 9vh, 104px) var(--pad-x) 32px; max-width: 1200px; isolation: isolate;
}
.display { font-size: var(--fs-7); font-stretch: 75%; font-weight: 650; line-height: .96; letter-spacing: -.032em; margin: 0 0 22px; max-width: 12ch; }
.hero .lede { margin-bottom: 28px; }
.hero-note { margin-top: 18px; font-size: var(--fs-1); color: var(--ink-3); max-width: 46ch; }
.hero-demo { position: relative; margin: 0; padding: 22px; border-radius: 26px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2); display: grid; gap: 14px; }
/* Calico patches peeking out from behind the card (the stacking context is .hero). */
.hero-demo::before {
  content: ""; position: absolute; z-index: -1; inset: -48px -40px auto auto; width: 46%; aspect-ratio: 1;
  background: url("../img/patches.svg") center / contain no-repeat; opacity: .9; transform: rotate(8deg);
}
.demo-msg { display: grid; grid-template-columns: 46px 1fr; gap: 12px; }
.demo-name { font-weight: 600; font-size: var(--fs-1); display: flex; gap: 8px; align-items: center; margin-bottom: 2px; }
.demo-user { display: flex; justify-content: flex-end; }
.demo-user .prose { background: var(--bg-sunk); padding: 9px 14px; border-radius: 18px 18px 6px 18px; max-width: 85%; }
.demo-feel { display: grid; gap: 9px; padding: 14px 14px 12px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); }
.demo-feel .meter-bar i { animation: meter-fill 1.5s .35s both var(--ease); }
.demo-feel .delta { animation: delta-in .5s 1.55s both var(--ease); }
.demo-memory { display: flex; gap: 8px; align-items: center; font-size: var(--fs-0); color: var(--ink-2); padding-top: 4px; animation: delta-in .5s 1.9s both var(--ease); }
.demo-memory .icon { width: 16px; height: 16px; color: var(--accent); }
@keyframes meter-fill { from { width: 0; } }
@keyframes delta-in { from { opacity: 0; transform: translateY(4px) scale(.96); } }
.steps { list-style: none; counter-reset: step; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 24px; padding: 0; margin: 20px 0 0; }
.steps li { counter-increment: step; display: grid; gap: 4px; align-content: start; padding-top: 14px; border-top: 1px solid var(--line-2); }
.steps li::before { content: counter(step); font-family: var(--font-mono); font-style: italic; font-size: 1.5rem; color: var(--accent-text); line-height: 1; margin-bottom: 6px; }
.steps span { color: var(--ink-2); font-size: var(--fs-1); }
.steps-compact { grid-template-columns: 1fr; gap: 14px; margin-bottom: 22px; }
.mcp-callout { display: flex; flex-wrap: wrap; gap: 20px 32px; align-items: center; justify-content: space-between; }
.mcp-callout > div { max-width: 62ch; }
.mcp-callout p { color: var(--ink-2); margin-top: 8px; }

/* ---------- Explore ---------- */
.search { position: relative; display: flex; align-items: center; width: min(420px, 100%); }
.search .icon { position: absolute; left: 14px; width: 18px; height: 18px; color: var(--ink-3); pointer-events: none; }
.search input { padding-left: 42px !important; border-radius: var(--r-pill) !important; min-height: 44px !important; }
.search-sm { width: min(260px, 100%); }
.search-sm input { min-height: 36px !important; }
.filters { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px 24px; margin-bottom: 28px; }
.filters .chips { flex: 1; min-width: 0; }
.pager { display: flex; justify-content: center; gap: 10px; margin-top: 40px; }

/* ---------- Character profile ---------- */
.profile-head { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 32px; align-items: end; margin-bottom: 40px; }
.profile-id { display: grid; gap: 10px; }
.display-sm { font-size: clamp(2.2rem, 4.5vw, 3.2rem); font-stretch: 76%; font-weight: 650; letter-spacing: -.03em; line-height: 1; }
.profile-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; color: var(--ink-2); font-size: var(--fs-1); }
.profile-meta > span { display: inline-flex; align-items: center; gap: 6px; }
.profile-meta .icon { width: 16px; height: 16px; color: var(--ink-3); }
.profile-actions { margin-top: 8px; }
.start-chat { display: flex; flex-wrap: wrap; gap: 10px; }
.profile-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 48px; align-items: start; }
.profile-main .section h2 { margin-bottom: 12px; }
.profile-side { display: grid; gap: 20px; position: sticky; top: 24px; }
.scenario { color: var(--ink-2); font-size: var(--fs-1); padding-left: 14px; border-left: 2px solid var(--line-2); max-width: 64ch; }
.greeting-preview { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 14px; padding: 18px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); max-width: 70ch; }
.feel-list { list-style: none; margin: 14px 0; padding: 0; display: grid; gap: 8px; }
.feel-list li { display: grid; grid-template-columns: 10px 1fr auto 28px; align-items: center; gap: 10px; font-size: var(--fs-1); }
.feel-list .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--c); transform: rotate(12deg); }
.feel-name { font-weight: 500; }
.feel-kind { color: var(--ink-3); font-size: 12px; }
.feel-start { text-align: right; color: var(--ink-2); font-size: 13px; }

/* ---------- Prose (messages, greetings) ---------- */
.prose { overflow-wrap: anywhere; }
.prose p { margin: 0 0 .75em; }
.prose p:last-child { margin-bottom: 0; }
.prose em.act, em.act {
  font-family: var(--font-mono); font-style: italic; font-weight: 400; font-size: .93em;
  letter-spacing: -.012em; color: var(--ink-2);
}
.prose strong { font-weight: 650; }
.prose code { font-size: .85em; }
.prose .ooc { color: var(--ink-3); font-size: .92em; }

/* ---------- Character editor ---------- */
.starters { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-bottom: 36px; }
.starter { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.starter > summary { display: flex; gap: 14px; align-items: center; padding: 14px 18px; }
.starter > summary > .icon { width: 22px; height: 22px; color: var(--accent); }
.starter > summary > span { display: grid; font-size: var(--fs-1); }
.starter[open] > summary { border-bottom: 1px solid var(--line); }
.starter-body { display: grid; gap: 12px; padding: 16px 18px 18px; }
.char-form { gap: 0; }
.form-section { border: 0; padding: 0; margin: 0 0 44px; display: grid; gap: 20px; min-width: 0; }
.form-section > legend, .form-section > summary { padding: 0; margin-bottom: 4px; width: 100%; }
.form-section > legend span, .form-section > summary span { font-size: var(--fs-4); font-weight: 640; font-stretch: 84%; letter-spacing: -.018em; }
.form-section > summary { display: flex; align-items: center; gap: 8px; }
.form-section > summary::after { content: ""; width: 9px; height: 9px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg) translateY(-3px); margin-left: 6px; transition: transform .2s; }
.form-section[open] > summary::after { transform: rotate(-135deg) translateY(-1px); }
details.form-section[open] { gap: 20px; }
details.form-section > *:not(summary) { margin-top: 18px; }
.section-hint { color: var(--ink-2); font-size: var(--fs-1); max-width: 72ch; margin: -6px 0 0; }
.identity { display: grid; grid-template-columns: 176px minmax(0, 1fr); gap: 28px; align-items: start; }
.identity-sm { grid-template-columns: 112px minmax(0, 1fr); gap: 20px; }
.identity-fields { display: grid; gap: 16px; }
.avatar-edit { display: grid; gap: 10px; justify-items: start; }
.avatar-edit .av-xl { width: 176px; height: 176px; }
.identity-sm .avatar-edit .av-lg { width: 96px; height: 96px; }
.avatar-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.radio-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.radio-card { position: relative; display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 10px; padding: 12px 14px; border: 1px solid var(--line-2); border-radius: var(--r-md); cursor: pointer; background: var(--surface); }
.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card .icon { grid-row: span 2; width: 20px; height: 20px; color: var(--ink-3); }
.radio-card strong { font-size: var(--fs-1); }
.radio-card span { font-size: 12px; color: var(--ink-3); }
.radio-card:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.radio-card:has(input:checked) .icon { color: var(--accent); }
.radio-card:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.alts { display: grid; gap: 10px; }
.alt { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; align-items: start; }
.presets { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.stats-head, .stat-row { display: grid; grid-template-columns: 34px minmax(110px, 1fr) 72px 150px minmax(140px, 1.6fr) 38px; gap: 8px; align-items: center; }
.stats-head { font-size: 12px; color: var(--ink-3); padding: 0 2px; margin-bottom: -12px; }
.stats-editor { display: grid; gap: 8px; }
.stat-row { padding: 6px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--c); }
.stat-row input, .stat-row select { min-height: 36px !important; padding: 6px 10px !important; font-size: var(--fs-1) !important; }
.stat-row select { padding-right: 28px !important; background-position: right 8px center; }
.stat-color { display: grid; place-items: center; }
.stat-color input { width: 28px; height: 28px; padding: 0; border: 0; border-radius: 8px; background: none; cursor: pointer; }
.stat-color input::-webkit-color-swatch-wrapper { padding: 0; }
.stat-color input::-webkit-color-swatch { border: 0; border-radius: 8px; }
.stat-color input::-moz-color-swatch { border: 0; border-radius: 8px; }
.stat-start input { font-family: var(--font-mono); text-align: center; }
.mood-input { display: grid; grid-template-columns: 64px 1fr; gap: 8px; }
.emoji-input { text-align: center; font-size: 1.2rem !important; }
.save-bar {
  position: sticky; bottom: 0; z-index: 20; display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 0; margin-top: 8px; border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.danger-zone { margin-top: 48px; border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line)); border-radius: var(--r-lg); padding: 16px 20px; }
.danger-zone > summary { color: var(--danger); font-weight: 600; }
.danger-zone[open] > summary { margin-bottom: 14px; }
.danger-zone .form { gap: 14px; }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 20px; align-items: start; }
.settings-grid .panel + .panel { margin-top: 0; }
.advanced > summary { color: var(--ink-2); font-weight: 600; font-size: var(--fs-1); padding: 8px 0; display: flex; align-items: center; gap: 8px; }
.advanced > summary::after { content: ""; width: 7px; height: 7px; border-right: 1.75px solid currentColor; border-bottom: 1.75px solid currentColor; transform: rotate(45deg) translateY(-2px); transition: transform .2s; }
.advanced[open] > summary::after { transform: rotate(-135deg); }
.advanced[open] > summary { margin-bottom: 12px; }
.advanced .form, .advanced > .field + .field { margin-top: 0; }
.or-panel { display: grid; gap: 18px; }
.or-head { display: flex; gap: 16px; align-items: flex-start; }
.or-head > img, .or-head > .or-icon { width: 40px; height: 40px; flex: none; }
.or-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 0; }
.or-stats div { padding: 12px 14px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); }
.or-stats dt { font-size: 12px; color: var(--ink-3); }
.or-stats dd { margin: 2px 0 0; font-size: 1.25rem; }
.manual-key > summary { font-size: var(--fs-1); color: var(--ink-2); font-weight: 500; }
.manual-key[open] > summary { margin-bottom: 12px; }
.manual-key .row input { flex: 1; min-width: 220px; }
.model-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 10px; margin: 16px 0; }
.model-cards-sm { grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); }
.model-card { position: relative; display: grid; gap: 4px; align-content: start; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); cursor: pointer; transition: border-color .15s; }
.model-card:hover { border-color: var(--line-2); }
.model-card input { position: absolute; opacity: 0; pointer-events: none; }
.model-card:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }
.model-card:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.model-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.model-top strong { font-size: .9375rem; }
.model-name { font-size: var(--fs-1); color: var(--ink); font-weight: 500; }
.model-id { font-size: 12px; color: var(--ink-2); overflow-wrap: anywhere; }
.model-why { font-size: 12.5px; color: var(--ink-2); line-height: 1.45; }
.model-price { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--ink-3); margin-top: 4px; }
.model-browse { position: relative; max-width: 520px; }
.model-results { list-style: none; margin: 6px 0 0; padding: 6px; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow-2); position: absolute; left: 0; right: 0; z-index: 30; }
.model-results button { width: 100%; display: grid; gap: 2px; text-align: left; padding: 8px 10px; border: 0; border-radius: var(--r-sm); background: none; color: inherit; font: inherit; cursor: pointer; }
.model-results button:hover, .model-results button[aria-selected="true"] { background: var(--bg-sunk); }
.model-results .mono { font-size: 12px; color: var(--ink-3); }
.model-results .r-name { font-size: var(--fs-1); font-weight: 500; display: flex; justify-content: space-between; gap: 10px; }
.model-results .r-price { display: inline-flex; gap: 10px; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); font-weight: 400; white-space: nowrap; }
.model-results .model-none { padding: 8px 10px; font-size: var(--fs-0); color: var(--ink-3); }
.saved-note { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: inline-flex; gap: 6px; align-items: center; padding: 8px 14px; border-radius: var(--r-pill); background: var(--ink); color: var(--bg); font-size: var(--fs-1); z-index: 90; }
.saved-note .icon { width: 16px; height: 16px; }
.persona-list { display: grid; gap: 10px; margin: 20px 0; }
.persona.panel { padding: 0; }
.persona > summary { display: grid; gap: 2px; padding: 14px 18px; }
.persona-name { display: flex; align-items: center; gap: 10px; }
.persona-name .icon { color: var(--ink-3); width: 18px; height: 18px; }
.persona-desc { font-size: var(--fs-1); padding-left: 28px; }
.persona[open] > summary { border-bottom: 1px solid var(--line); }
.persona > form { padding: 16px 18px; }
.persona > form + form { padding-top: 0; }
.grant-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; }
.grant { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 14px 0; border-top: 1px solid var(--line); }
.grant:first-child { border-top: 0; }
.grant-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--bg-sunk); color: var(--ink-2); overflow: hidden; }
.grant-icon img { width: 100%; height: 100%; object-fit: cover; }
.grant-body { display: grid; gap: 4px; min-width: 0; }
.grant-scopes { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------- Docs ---------- */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 16px; margin: 20px 0 12px; }
.doc-grid .panel + .panel { margin-top: 0; }
.doc-grid h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.doc-grid h2 .icon { color: var(--accent); }
.page-doc > h2 { margin: 40px 0 14px; }
.code { margin: 10px 0; padding: 12px 14px; border-radius: var(--r-md); background: var(--bg-sunk); overflow-x: auto; font-size: 13px; line-height: 1.5; }
.code code { background: none; padding: 0; white-space: pre; }
.prompts { display: grid; gap: 10px; padding: 0; list-style: none; max-width: 72ch; }
.prompts li { padding: 12px 16px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 var(--r-md) var(--r-md) 0; font-style: italic; color: var(--ink-2); }
.scopes, .tools { display: grid; gap: 0; margin: 0; max-width: 820px; }
.scopes > div, .tools > div { display: grid; grid-template-columns: minmax(170px, 220px) 1fr; gap: 16px; padding: 12px 0; border-top: 1px solid var(--line); }
.scopes dt, .tools dt { font-size: 13.5px; color: var(--ink); }
.scopes dd, .tools dd { margin: 0; color: var(--ink-2); font-size: var(--fs-1); }
.pick-table { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.pick { padding: 16px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface); display: grid; gap: 6px; align-content: start; }
.pick-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pick p { color: var(--ink-2); font-size: var(--fs-1); margin: 0; }
.pick-helper { background: var(--surface-2); }
.tips { display: grid; gap: 10px; padding-left: 20px; color: var(--ink-2); }

/* ---------- Admin ---------- */
.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 0 0 24px; }
.stat-strip > div { padding: 14px 16px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); }
.stat-strip dt { font-size: 12.5px; color: var(--ink-3); }
.stat-strip dd { margin: 4px 0 0; font-size: 1.6rem; font-weight: 300; }
.table-wrap { overflow-x: auto; margin: 8px -6px 0; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-1); }
.table th { text-align: left; font-weight: 500; color: var(--ink-3); font-size: 12.5px; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table .num { text-align: right; }
.table select { min-height: 32px !important; padding: 4px 28px 4px 8px !important; font-size: 13px !important; width: auto !important; background-position: right 8px center; }

/* ---------- Consent & installer ---------- */
.consent { width: 100%; display: grid; place-items: center; }
.consent-card { width: min(480px, 100%); display: grid; gap: 18px; padding: 32px 28px; border-radius: 26px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2); }
.consent-logos { display: flex; align-items: center; gap: 0; }
.consent-app, .consent-site { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--bg-sunk); overflow: hidden; color: var(--ink-2); }
.consent-app img { width: 100%; height: 100%; object-fit: cover; }
.consent-app .icon { width: 26px; height: 26px; }
.consent-link { width: 40px; height: 2px; background: repeating-linear-gradient(90deg, var(--line-2) 0 5px, transparent 5px 9px); }
.consent h1 { font-weight: 500; font-stretch: 92%; line-height: 1.25; }
.consent h1 strong { font-weight: 680; }
.consent-who { display: flex; align-items: center; gap: 8px; font-size: var(--fs-1); color: var(--ink-2); margin: 0; }
.consent-origin { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md); font-size: var(--fs-1); margin: 0; }
.consent-origin .icon { width: 18px; height: 18px; margin-top: 1px; }
.consent-origin.ok { background: var(--ok-soft); }
.consent-origin.ok .icon { color: var(--ok); }
.consent-origin.warn { background: var(--warn-soft); }
.consent-origin.warn .icon { color: var(--warn); }
.consent-scopes { border: 0; padding: 0; margin: 0; display: grid; gap: 12px; }
.consent-scopes legend { font-weight: 600; margin-bottom: 10px; }
.consent-scopes .check > span { gap: 2px; }
.consent-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.install { width: min(780px, 100%); display: grid; gap: 20px; }
.install .panel + .panel { margin-top: 0; }
.install .form { gap: 20px; }
.install-head { display: flex; gap: 18px; align-items: center; }
.checks { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; font-size: var(--fs-1); }
.checks li { display: flex; gap: 10px; align-items: flex-start; }
.checks li > span { display: grid; }
.checks .icon { width: 18px; height: 18px; margin-top: 2px; }
.checks .ok .icon { color: var(--ok); }
.checks .bad .icon { color: var(--danger); }
.checks .warn .icon { color: var(--warn); }
.config-dump { min-height: 320px; font-size: 12.5px !important; }

/* ---------- Menus, dialogs, toasts ---------- */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 230px; padding: 6px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2); display: grid; gap: 1px; }
.menu form { margin: 0; }
.menu a, .menu button { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 0; border-radius: var(--r-sm); background: none; color: var(--ink); font: 500 var(--fs-1)/1.3 var(--font-sans); text-align: left; text-decoration: none; cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--bg-sunk); }
.menu .icon { width: 18px; height: 18px; color: var(--ink-3); }
.menu .danger .icon { color: var(--danger); }
.dialog { padding: 0; border: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--ink); width: min(520px, calc(100vw - 24px)); max-height: min(86dvh, 720px); box-shadow: var(--shadow-2); }
.dialog::backdrop { background: var(--scrim); }
.dialog[open] { animation: dialog-in .22s var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.dialog-inner { display: grid; gap: 18px; padding: 20px 22px 22px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -4px -8px 0 0; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; }
.toasts { position: fixed; z-index: 200; left: 50%; bottom: 22px; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; width: min(520px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: var(--r-pill); background: var(--ink); color: var(--bg); font-size: var(--fs-1); box-shadow: var(--shadow-2); animation: toast-in .25s var(--ease); max-width: 100%; }
.toast.is-error { background: var(--danger); color: #fff; }
.toast .icon { width: 16px; height: 16px; }
.toast button { background: none; border: 0; color: inherit; font: inherit; font-weight: 650; cursor: pointer; text-decoration: underline; padding: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ==========================================================================
   Chat
   ========================================================================== */
body.is-chat { overflow: hidden; }
body.is-chat .main { height: 100dvh; overflow: hidden; }
.chat {
  display: grid; height: 100dvh;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "head head" "main panel";
}
.chat.panel-hidden { grid-template-columns: minmax(0, 1fr) 0; }
.chat.panel-hidden .chat-panel { visibility: hidden; }
.chat-head {
  grid-area: head; display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 10px 14px 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg); z-index: 5;
}
.chat-back { display: none; }
.chat-who { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; text-decoration: none; color: inherit; }
.chat-who .av { width: 38px; height: 38px; }
.chat-who-text { display: grid; min-width: 0; line-height: 1.25; }
.chat-who-text strong { font-weight: 640; font-stretch: 88%; font-size: 1.0625rem; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-mood { font-size: 12.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: opacity .3s; }
.chat-mood.is-changing { opacity: .2; }
.chat-head-actions { display: flex; align-items: center; gap: 2px; }
.chat-model { width: auto; max-width: 220px; height: 32px; padding: 0 12px; border-radius: var(--r-pill); border: 1px solid var(--line); font-size: 12px; color: var(--ink-2); overflow: hidden; }
.chat-model span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.mood-strip { display: none; }

.chat-main { grid-area: main; display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; }
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: auto; }
.chat-log { max-width: 47rem; margin: 0 auto; padding: 20px 22px 18px; display: flex; flex-direction: column; }
.log-top { display: flex; justify-content: center; min-height: 8px; padding-bottom: 8px; }
.log-intro { display: grid; justify-items: center; text-align: center; gap: 8px; padding: 18px 0 26px; color: var(--ink-3); font-size: var(--fs-1); }
.log-intro .av { width: 72px; height: 72px; }
.log-intro strong { color: var(--ink); font-size: 1.125rem; font-stretch: 88%; }

.msg { position: relative; display: grid; grid-template-columns: 36px minmax(0, 1fr); column-gap: 14px; padding: 12px 0 6px; }
.msg-av { width: 36px; height: 36px; grid-row: 1 / span 3; }
.msg-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; margin-bottom: 2px; }
.msg-name { font-weight: 640; font-stretch: 90%; font-size: .9375rem; }
.msg-time { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); }
.msg-edited { font-size: 11.5px; color: var(--ink-3); font-style: italic; }
.msg-text { font-size: 1rem; line-height: 1.62; }
.msg.user { grid-template-columns: minmax(0, 1fr); justify-items: end; padding: 14px 0 6px; }
.msg.user .msg-av, .msg.user .msg-head { display: none; }
.msg.user .msg-text { background: var(--surface); border: 1px solid var(--line); padding: 10px 15px; border-radius: 20px 20px 6px 20px; max-width: min(85%, 36rem); }
.msg.user .msg-tools { justify-content: flex-end; }
.msg.is-pending .msg-text { opacity: .7; }
.msg.is-error .msg-text { border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); }
.msg-tools { grid-column: 2; display: flex; align-items: center; gap: 2px; min-height: 30px; margin: 2px 0 0 -8px; opacity: 0; transition: opacity .15s; }
.msg.user .msg-tools { grid-column: 1; margin: 2px -6px 0 0; }
.msg:hover .msg-tools, .msg:focus-within .msg-tools, .msg.show-tools .msg-tools, .msg.is-last .msg-tools { opacity: 1; }
.msg-tools .btn-icon { width: 30px; height: 30px; color: var(--ink-3); }
.msg-tools .btn-icon:hover { color: var(--ink); }
.msg-tools .icon { width: 17px; height: 17px; }
.swipe { display: inline-flex; align-items: center; gap: 0; margin-right: 4px; font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); }
.swipe .btn-icon { width: 28px; }
.msg-deltas { grid-column: 2; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.delta-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px 0 7px;
  border-radius: var(--r-pill); font-size: 11.5px; font-weight: 500; color: var(--ink-2);
  background: color-mix(in srgb, var(--c) 13%, transparent); animation: delta-in .4s var(--ease) both;
}
.delta-chip::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: var(--c); transform: rotate(12deg); }
.delta-chip b { font-family: var(--font-mono); font-weight: 600; color: var(--ink); }
.delta-chip:nth-child(2) { animation-delay: .06s; }
.delta-chip:nth-child(3) { animation-delay: .12s; }
.delta-chip:nth-child(4) { animation-delay: .18s; }
.thinking { display: inline-flex; gap: 4px; padding: 10px 0 4px; }
.thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: bob 1.1s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 70%, 100% { transform: translateY(0); opacity: .45; } 35% { transform: translateY(-4px); opacity: 1; } }
.msg.is-streaming .msg-text > :last-child::after {
  content: ""; display: inline-block; width: .5em; height: 1.05em; margin-left: 2px; vertical-align: -.15em;
  background: var(--accent); border-radius: 2px; animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }
.msg-edit { display: grid; gap: 8px; width: 100%; }
.msg.user .msg-edit { max-width: min(100%, 36rem); }
.msg-edit textarea { min-height: 100px; }
.msg-edit .row { justify-content: flex-end; }
.msg-error { grid-column: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 8px; padding: 10px 12px; border-radius: var(--r-md); background: var(--danger-soft); font-size: var(--fs-1); }
.msg-error .icon { width: 18px; height: 18px; color: var(--danger); }
.msg-error span { flex: 1; min-width: 200px; }
.day-break { align-self: center; margin: 14px 0 4px; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); }
.summary-break { display: flex; align-items: center; gap: 10px; margin: 18px 0 6px; color: var(--ink-3); font-size: 12px; }
.summary-break::before, .summary-break::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.summary-break .icon { width: 15px; height: 15px; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; width: calc(100% - 32px); max-width: 46rem; margin: 0 auto 16px;
  padding: 6px 6px 6px 18px; border-radius: 24px; background: var(--surface);
  border: 1px solid var(--line-2); box-shadow: var(--shadow-1); transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 70%, var(--line-2)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent), var(--shadow-1); }
.composer textarea {
  flex: 1; min-height: 40px !important; max-height: 40dvh; padding: 9px 0 !important; border: 0 !important; box-shadow: none !important;
  background: none !important; resize: none; font-size: 1rem !important; line-height: 1.45;
}
.send {
  flex: none; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); cursor: pointer; transition: transform .1s, opacity .15s, background-color .15s;
}
.send .icon { width: 20px; height: 20px; stroke-width: 2.2; }
.send:disabled { opacity: .35; cursor: default; }
.send:not(:disabled):active { transform: scale(.94); }
.send.stop { background: var(--ink); color: var(--bg); }
.send.stop .icon { fill: currentColor; stroke: none; }
.composer-blocked { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 14px; width: calc(100% - 32px); max-width: 46rem; margin: 0 auto 16px; padding: 12px 16px; border-radius: var(--r-lg); background: var(--accent-soft); font-size: var(--fs-1); }
.composer-blocked .icon { color: var(--accent); }

/* Side panel: feelings, memories, story */
.chat-panel { grid-area: panel; min-height: 0; overflow-y: auto; border-left: 1px solid var(--line); background: var(--bg); display: flex; flex-direction: column; }
.panel-grab { display: none; }
.panel-tabs { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 2px; padding: 10px 10px 0; background: var(--bg); border-bottom: 1px solid var(--line); }
.panel-tabs [role="tab"] { display: inline-flex; align-items: center; gap: 6px; padding: 9px 10px 11px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--ink-3); font: 500 var(--fs-1)/1 var(--font-sans); cursor: pointer; white-space: nowrap; }
.panel-tabs [role="tab"] .icon { width: 16px; height: 16px; }
.panel-tabs [role="tab"].is-on { color: var(--ink); border-bottom-color: var(--accent); }
.panel-tabs .count { font-size: 11px; padding: 0 5px; border-radius: var(--r-pill); background: var(--bg-sunk); color: var(--ink-2); }
.panel-close { margin-left: auto; display: none; }
.panel-body { padding: 18px 18px 28px; }
.panel-body section { display: grid; gap: 16px; }
.pane-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pane-note { font-size: 12.5px; color: var(--ink-3); line-height: 1.5; margin: 0; }
.pane-note:empty { display: none; }
.mood-card { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px; align-items: center; padding: 16px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); }
.mood-emoji { grid-row: span 2; font-size: 2.1rem; line-height: 1; width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px; background: var(--bg-sunk); }
.mood-label { font-weight: 640; font-stretch: 88%; font-size: 1.125rem; letter-spacing: -.01em; }
.mood-thought { grid-column: 1 / -1; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line-2); font-family: var(--font-mono); font-style: italic; font-size: 13.5px; color: var(--ink-2); line-height: 1.5; }
.mood-thought::before { content: "thinking: "; color: var(--ink-3); }
.mood-sub { font-size: 12.5px; color: var(--ink-3); }
.meters { display: grid; gap: 12px; }
.meter { display: grid; grid-template-columns: minmax(84px, 7rem) minmax(0, 1fr) 2.2rem; grid-template-rows: auto; align-items: center; gap: 4px 12px; position: relative; }
.meter-label { font-size: var(--fs-1); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter-bar { height: 8px; border-radius: var(--r-pill); background: color-mix(in srgb, var(--c) 15%, var(--bg-sunk)); overflow: hidden; position: relative; }
.meter-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: var(--v); border-radius: inherit; background: var(--c); transition: width 1s var(--ease); }
.meter-bar .start-tick { position: absolute; top: -2px; bottom: -2px; width: 2px; left: var(--s); background: var(--ink-3); opacity: .35; border-radius: 1px; }
.meter-val { font-family: var(--font-mono); font-size: 13px; text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
/* A change sits on the end of its bar for a few seconds, ringed so it reads over the track. */
.meter .delta { position: absolute; right: calc(2.2rem + 18px); top: 50%; translate: 0 -50%; box-shadow: 0 0 0 2px var(--bg); }
.demo-feel .meter .delta { box-shadow: 0 0 0 2px var(--surface-2); }
.delta { font-family: var(--font-mono); font-size: 11px; line-height: 1; padding: 3px 6px; border-radius: var(--r-pill); }
.delta.up { color: var(--ok); background: var(--ok-soft); }
.delta.down { color: var(--danger); background: var(--danger-soft); }
.meter-desc { grid-column: 1 / -1; font-size: 12px; color: var(--ink-3); margin-top: -2px; display: none; }
.meters.is-editing .meter-desc { display: block; }
.meter input[type="range"] { grid-column: 2; height: 22px; accent-color: var(--c); }
.meters.is-editing .meter-bar { display: none; }
.meters.is-busy { opacity: .75; }
.meter.has-delta .meter-val { color: var(--ink); font-weight: 600; }
.mem-add { display: flex; gap: 6px; }
.mem-add input { min-height: 38px !important; font-size: var(--fs-1) !important; }
.mem-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.mem { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 6px; padding: 10px 8px 8px 12px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); font-size: var(--fs-1); line-height: 1.45; }
.mem.is-pinned { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.mem-text { overflow-wrap: anywhere; }
.mem-meta { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--ink-3); }
.mem-cat { font-family: var(--font-mono); }
.mem-imp { font-family: var(--font-mono); }
.mem-tools { display: flex; gap: 0; align-self: start; margin: -4px -2px 0 0; }
.mem-tools .btn-icon { width: 28px; height: 28px; }
.mem-tools .icon { width: 15px; height: 15px; }
.mem-tools .is-on { color: var(--accent); }
.mem textarea { grid-column: 1 / -1; min-height: 70px; font-size: var(--fs-1) !important; }
.mem-empty { color: var(--ink-3); font-size: var(--fs-1); padding: 8px 0; }
.story { font-size: .9375rem; line-height: 1.62; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.story.is-empty { color: var(--ink-3); font-size: var(--fs-1); white-space: normal; }
.story-meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); }
.story textarea { min-height: 260px; font-size: var(--fs-1) !important; }
.chapters { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 10px; }
.chapters li { display: grid; grid-template-columns: 22px 1fr; gap: 2px 8px; font-size: 13px; color: var(--ink-2); }
.chapters li::before { content: attr(data-n); font-family: var(--font-mono); font-style: italic; color: var(--accent-text); grid-row: span 2; }
.chapters strong { color: var(--ink); font-weight: 600; }
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 55; animation: fade-in .2s both; }
@keyframes fade-in { from { opacity: 0; } }

/* Bits created by the scripts */
.msg > .msg-head, .msg > .msg-text, .msg > .msg-edit { grid-column: 2; }
.msg.user > .msg-text, .msg.user > .msg-edit { grid-column: 1; }
.msg-model { display: block; flex: 0 1 auto; min-width: 0; margin-left: 6px; font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.msg-model > span + span { margin-left: 8px; }
.mem-chip { border: 0; cursor: pointer; font-family: var(--font-sans); }
.mem-chip::before { display: none; }
.mem-chip .icon { width: 13px; height: 13px; color: var(--accent-text); }
.mem-chip:hover { color: var(--ink); }
.chat-log > .msg-error { margin-left: 50px; }
.msg-error.is-soft { background: var(--surface); border: 1px solid var(--line); }
.msg-error.is-soft > .icon { color: var(--ink-3); }
.log-intro span { color: var(--ink-3); }
.counter { justify-self: end; font-size: 11.5px; color: var(--ink-3); margin-top: -2px; }
.counter.is-near { color: var(--warn); }
.confirm-text { margin: 0; font-size: 1.0625rem; line-height: 1.5; text-wrap: pretty; }
.mood-edit { display: grid; gap: 4px; }
.mood-card .emoji-input { width: 52px; height: 52px; min-height: 0 !important; padding: 0 !important; text-align: center; font-size: 1.6rem !important; border-radius: 16px !important; }
.ms-text > span { margin-left: 12px; }
.ms-text .mono { color: var(--ink); }
.mem-edit-row, .story .row { grid-column: 1 / -1; justify-content: flex-end; margin-top: 6px; }
.story textarea { white-space: pre-wrap; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1180px) {
  .chat { grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "main"; }
  .chat-panel {
    position: fixed; z-index: 60; top: 0; right: 0; bottom: 0; width: min(380px, 92vw);
    border-left: 1px solid var(--line); box-shadow: var(--shadow-2);
    transform: translateX(105%); transition: transform .3s var(--ease); visibility: hidden;
  }
  .chat.panel-open .chat-panel { transform: none; visibility: visible; }
  .chat.panel-hidden .chat-panel { visibility: hidden; }
  .panel-close { display: inline-grid; }
}
@media (max-width: 980px) {
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-demo { max-width: 520px; }
  .profile-grid { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  .profile-side { position: static; }
}
@media (max-width: 860px) {
  :root { --pad-x: 18px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .tabbar { display: flex; }
  .main { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .flashes { padding-top: 12px; }
  .page { padding-top: 22px; }
  h1 { font-size: var(--fs-5); }
  .page-head { margin-bottom: 18px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(146px, 1fr)); gap: 22px 14px; }
  .tile-name { font-size: 1rem; }
  .profile-head { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .av-hero { width: 132px; height: 132px; }
  .identity { grid-template-columns: minmax(0, 1fr); }
  .avatar-edit { grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: 16px; }
  .avatar-edit .av-xl { width: 104px; height: 104px; grid-row: span 3; }
  .identity-sm .avatar-edit { grid-template-columns: auto minmax(0, 1fr); }
  .radio-cards { grid-template-columns: minmax(0, 1fr); }
  .stats-head { display: none; }
  .stat-row { grid-template-columns: 34px 112px minmax(0, 1fr) 64px 38px; grid-template-areas: "color label label start remove" "kind kind desc desc desc"; }
  .stat-row .stat-color { grid-area: color; }
  .stat-row .stat-label { grid-area: label; }
  .stat-row .stat-start { grid-area: start; }
  .stat-row .stat-remove { grid-area: remove; }
  .stat-row select { grid-area: kind; }
  .stat-row .stat-desc { grid-area: desc; }
  .save-bar { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .scopes > div, .tools > div { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .grant { grid-template-columns: 40px minmax(0, 1fr); }
  .grant > form { grid-column: 2; }
  .toasts { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); }
  .saved-note { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); }
  .dialog { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 22px 22px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .dialog[open] { animation: sheet-in .28s var(--ease); }

  /* Chat on phones: full screen, no tab bar, panel becomes a bottom sheet */
  body.is-chat .tabbar { display: none; }
  body.is-chat .main { padding-bottom: 0; }
  body.is-chat .toasts { bottom: 96px; }
  .chat { grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "head" "strip" "main"; }
  .chat-head { padding: 8px 8px 8px 4px; gap: 4px; padding-top: max(8px, env(safe-area-inset-top)); }
  .chat-back { display: inline-grid; }
  .chat-who { gap: 10px; }
  .chat-who .av { width: 34px; height: 34px; }
  .chat-model { display: none; }
  .mood-strip {
    grid-area: strip; display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 16px; border: 0;
    border-bottom: 1px solid var(--line); background: var(--bg); color: var(--ink-2); font: inherit; font-size: 12px; cursor: pointer; text-align: left;
  }
  .ms-bars { display: flex; align-items: flex-end; gap: 3px; height: 18px; flex: none; }
  .ms-bars i { width: 5px; border-radius: 2px; background: var(--c); min-height: 2px; transition: height .8s var(--ease); }
  .ms-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ms-text b { color: var(--ink); font-weight: 600; }
  .ms-hint { color: var(--ink-3); flex: none; display: inline-flex; align-items: center; }
  .ms-hint .icon { width: 16px; height: 16px; }
  .chat-log { padding: 14px 14px 12px; }
  .chat-log > .msg-error { margin-left: 43px; }
  .msg { column-gap: 11px; }
  .msg-av { width: 32px; height: 32px; }
  .msg { grid-template-columns: 32px minmax(0, 1fr); }
  .msg.user { grid-template-columns: minmax(0, 1fr); }
  .msg.user .msg-text { max-width: 88%; }
  .msg-tools { opacity: 1; display: none; }
  .msg.is-last .msg-tools, .msg.show-tools .msg-tools { display: flex; }
  .composer { width: calc(100% - 20px); margin-bottom: max(10px, env(safe-area-inset-bottom)); padding-left: 16px; }
  .composer-blocked { margin-bottom: max(10px, env(safe-area-inset-bottom)); }
  .chat-panel {
    top: auto; left: 0; right: 0; width: 100%; max-height: 84dvh; border-left: 0;
    border-radius: 22px 22px 0 0; transform: translateY(105%); padding-bottom: env(safe-area-inset-bottom);
  }
  .panel-grab { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 8px auto 0; flex: none; }
  .panel-tabs { padding-top: 4px; }
  .panel-tabs [role="tab"] { padding: 9px 8px 11px; }
}
@media (max-width: 520px) {
  .display { font-size: clamp(2.3rem, 11.5vw, 3rem); }
  .hero { padding-top: 32px; }
  .hero-demo { padding: 16px; border-radius: 22px; }
  .hero-demo::before { width: 40%; inset: -30px -8px auto auto; }
  .filters { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
  .filters .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 calc(var(--pad-x) * -1); padding: 0 var(--pad-x); scrollbar-width: none; }
  .filters .chips::-webkit-scrollbar { display: none; }
  .seg { align-self: flex-start; }
  .consent-card { padding: 24px 20px; }
  .consent-actions { grid-template-columns: minmax(0, 1fr); }
  .consent-actions .btn-primary { order: -1; }
  .panel { padding: 18px; }
  .meter { grid-template-columns: minmax(78px, 6rem) minmax(0, 1fr) 2rem; }
}
@keyframes sheet-in { from { transform: translateY(40px); opacity: .4; } }
@media (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]),
  select, textarea, .mono-input { font-size: 16px !important; }
  .msg-tools .btn-icon { width: 36px; height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; transition-delay: 0s !important; scroll-behavior: auto !important; }
}
@media print {
  .sidebar, .tabbar, .composer, .chat-panel, .msg-tools, .chat-head-actions { display: none !important; }
  .shell, .chat { display: block; height: auto; }
  body.is-chat, body.is-chat .main { overflow: visible; height: auto; }
}
