/*
 * 小镇 · Salon 与酒馆
 * One stylesheet, no build step. Salon reads as daylight on paper; the tavern
 * switches the same tokens to candlelight. Every colour comes from a token so
 * light/dark and both venues stay consistent.
 */
@layer reset, tokens, base, layout, components, modules, responsive;

/* ───────────────────────── reset ───────────────────────── */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body, h1, h2, h3, h4, p, figure, blockquote, fieldset { margin: 0; }
  button, input, textarea, select { font: inherit; color: inherit; }
  button, a, input, textarea, select, summary, label { -webkit-tap-highlight-color: transparent; }
  button { cursor: pointer; background: transparent; border: 0; padding: 0; }
  button:disabled { cursor: not-allowed; opacity: .5; }
  button[aria-busy="true"] { cursor: progress; }
  a { color: inherit; text-decoration: none; }
  [hidden] { display: none !important; }
  img, svg, video { display: block; }
  textarea { resize: none; }
  summary { cursor: pointer; }
  fieldset { border: 0; padding: 0; }
}

/* ───────────────────────── tokens ───────────────────────── */
@layer tokens {
  :root {
    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
      "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC", sans-serif;
    --font-reading: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
      "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC", sans-serif;
    --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Songti SC", STSong,
      "Noto Serif SC", "Source Han Serif SC", SimSun, serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;

    --r-xs: 6px; --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-full: 999px;
    --ease: cubic-bezier(.2, .8, .2, 1);
    --sidebar-w: 284px;
    --header-h: 64px;
    --column: 760px;
    --stage-w: clamp(260px, 25vw, 340px);
    --gutter: 24px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* Salon · daylight */
    --bg: #f6f4ef;
    --chrome: #f6f4ef;
    --sidebar: #efebe3;
    --surface: #fffefb;
    --surface-2: #f2efe8;
    --surface-3: #e8e4da;
    --hover: rgb(40 50 42 / .055);
    --ink: #222a24;
    --ink-2: #48514a;
    --muted: #767d76;
    --faint: #a1a69f;
    --border: #e6e2d8;
    --border-strong: #d6d1c5;
    --accent: #3d6a52;
    --accent-hover: #335b46;
    --accent-ink: #ffffff;
    --accent-soft: #e4ece4;
    --accent-line: #b8ccbc;
    --danger: #b04e3b;
    --danger-soft: #f8e8e3;
    --danger-line: #e6c1b7;
    --gold: #a8844f;
    --chat-bg: var(--bg);
    --bubble: #ffffff;
    --bubble-border: #e9e5dc;
    --bubble-own: #dde9de;
    --bubble-own-ink: #1d281f;
    --chat-muted: #687068;
    --code-bg: #f4f2ec;
    --scrim: rgb(22 30 25 / .4);
    --shadow-sm: 0 1px 2px rgb(30 40 33 / .06);
    --shadow-md: 0 1px 2px rgb(30 40 33 / .05), 0 8px 24px -10px rgb(30 40 33 / .18);
    --shadow-lg: 0 2px 6px rgb(30 40 33 / .06), 0 28px 64px -20px rgb(30 40 33 / .34);
    --focus: 0 0 0 3px rgb(61 106 82 / .2);
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23898f88' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    color-scheme: light;
  }
  /* Tavern · candlelight */
  :root[data-venue="tavern"] {
    --bg: #f5efe5;
    --chrome: #f5efe5;
    --sidebar: #ece4d5;
    --surface: #fffcf6;
    --surface-2: #f1e9dc;
    --surface-3: #e6dccb;
    --hover: rgb(70 48 25 / .06);
    --border: #e6dccb;
    --border-strong: #d7c9b1;
    --accent: #8a5a2c;
    --accent-hover: #764b22;
    --accent-soft: #f2e5d1;
    --accent-line: #dcc29b;
    --bubble-border: #ebe1d1;
    --bubble-own: #f0e0c6;
    --bubble-own-ink: #2c2115;
    --code-bg: #f4ede1;
    --focus: 0 0 0 3px rgb(138 90 44 / .2);
  }
  :root[data-theme="dark"] {
    --bg: #111412;
    --chrome: #111412;
    --sidebar: #0d100e;
    --surface: #191d1a;
    --surface-2: #202521;
    --surface-3: #2a302b;
    --hover: rgb(230 240 232 / .05);
    --ink: #e5e9e3;
    --ink-2: #c0c7be;
    --muted: #8e968d;
    --faint: #626a62;
    --border: #252b26;
    --border-strong: #343b35;
    --accent: #8dc09f;
    --accent-hover: #a3cfb3;
    --accent-ink: #0d1911;
    --accent-soft: #1d2c22;
    --accent-line: #33503f;
    --danger: #ec9b86;
    --danger-soft: #36221d;
    --danger-line: #5c352c;
    --gold: #d6aa6c;
    --bubble: #1a1f1b;
    --bubble-border: #262c27;
    --bubble-own: #22392a;
    --bubble-own-ink: #e1eee4;
    --chat-muted: #97a096;
    --code-bg: #151916;
    --scrim: rgb(0 0 0 / .58);
    --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-md: 0 1px 2px rgb(0 0 0 / .3), 0 10px 28px -10px rgb(0 0 0 / .65);
    --shadow-lg: 0 2px 6px rgb(0 0 0 / .4), 0 30px 70px -20px rgb(0 0 0 / .8);
    --focus: 0 0 0 3px rgb(141 192 159 / .24);
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23858d84' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    color-scheme: dark;
  }
  :root[data-theme="dark"][data-venue="tavern"] {
    --bg: #14100c;
    --chrome: #14100c;
    --sidebar: #0f0c09;
    --surface: #1c1713;
    --surface-2: #241e18;
    --surface-3: #2f271f;
    --hover: rgb(255 230 200 / .05);
    --border: #2b231c;
    --border-strong: #3b3127;
    --accent: #e0ac6c;
    --accent-hover: #ecbf88;
    --accent-ink: #1c1105;
    --accent-soft: #32261a;
    --accent-line: #5a4329;
    --bubble: #1d1814;
    --bubble-border: #2c241d;
    --bubble-own: #392a1a;
    --bubble-own-ink: #f4e7d3;
    --code-bg: #17120e;
    --focus: 0 0 0 3px rgb(224 172 108 / .24);
  }
}

/* ───────────────────────── base ───────────────────────── */
@layer base {
  body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color .35s var(--ease), color .35s var(--ease);
  }
  ::selection { background: color-mix(in srgb, var(--accent) 24%, transparent); }
  h1, h2, h3, h4 { font-weight: 650; letter-spacing: -.01em; line-height: 1.3; }
  h2 { font-size: 22px; }
  h3 { font-size: 15px; }
  small { color: var(--muted); }
  .icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
  .i {
    width: 18px; height: 18px; flex: none;
    fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
  }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .muted, .subtle { color: var(--muted); }
  .error { color: var(--danger); font-size: 13px; }
  .error:empty { display: none; }
  .eyebrow { font-size: 10.5px; letter-spacing: .18em; color: var(--muted); font-weight: 600; text-transform: uppercase; }
  .wide { width: 100%; }
  .sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  .danger-text { color: var(--danger) !important; }

  /* Controls */
  label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); }
  input, select, textarea {
    max-width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--surface);
    padding: 9px 12px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink);
    transition: border-color .15s, box-shadow .15s, background-color .15s;
  }
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select { width: 100%; min-height: 42px; }
  input:hover:not(:focus):not([type="checkbox"]):not([type="radio"]), select:hover:not(:focus), textarea:hover:not(:focus) {
    border-color: color-mix(in srgb, var(--border-strong) 60%, var(--ink-2));
  }
  input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
  input[readonly] { background: var(--surface-2); color: var(--muted); }
  input::placeholder, textarea::placeholder { color: var(--faint); opacity: 1; }
  select {
    appearance: none;
    background-image: var(--select-arrow);
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 34px;
    cursor: pointer;
  }
  input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--accent); cursor: pointer; }
  input[type="number"] { font-variant-numeric: tabular-nums; }
  progress { accent-color: var(--accent); }
  details > summary { list-style: none; display: flex; align-items: center; gap: 8px; }
  details > summary::-webkit-details-marker { display: none; }
  details > summary::before {
    content: ""; flex: none; width: 6px; height: 6px; margin: 0 2px;
    border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg); transition: transform .2s;
  }
  details[open] > summary::before { transform: rotate(45deg) translate(-2px, -1px); }

  /* Buttons */
  .primary {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 40px; padding: 9px 18px;
    border-radius: 11px;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 600; font-size: 14px; white-space: nowrap;
    box-shadow: var(--shadow-sm), inset 0 1px 0 rgb(255 255 255 / .12);
    transition: background-color .15s, transform .1s;
  }
  .primary:hover:not(:disabled) { background: var(--accent-hover); }
  .primary:active:not(:disabled) { transform: scale(.98); }
  .secondary {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 40px; padding: 8px 16px;
    border: 1px solid var(--border-strong); border-radius: 11px;
    background: var(--surface);
    color: var(--ink);
    font-size: 14px; font-weight: 500; white-space: nowrap;
    transition: background-color .15s, border-color .15s, color .15s;
  }
  .secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--accent-line); color: var(--accent); }
  a.secondary { text-decoration: none; }
  .text-button {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 4px; border-radius: 7px;
    font-size: 13px; color: var(--muted);
    transition: color .15s, background-color .15s;
  }
  .text-button:hover:not(:disabled) { color: var(--accent); }
  .icon-button {
    display: inline-grid; place-items: center; flex: none;
    width: 36px; height: 36px; border-radius: 10px;
    color: var(--ink-2);
    transition: background-color .15s, color .15s;
  }
  .icon-button:hover { background: var(--hover); color: var(--ink); }
  .icon-button .i { width: 20px; height: 20px; }
  .danger-button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 40px; padding: 8px 16px;
    border: 1px solid var(--danger-line); border-radius: 11px;
    background: var(--danger-soft); color: var(--danger);
    font-size: 14px; font-weight: 600;
  }
  .danger-button:hover:not(:disabled) { filter: brightness(.97); }
  .primary.danger-button { background: var(--danger); color: #fff; border-color: transparent; }

  .avatar {
    width: 32px; height: 32px; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: var(--accent-soft); color: var(--accent);
    font-size: 15px; line-height: 1; overflow: hidden;
  }
  .avatar > img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
  .owner-avatar { background: var(--surface-3); color: var(--ink-2); font-size: 12px; font-weight: 600; }

  .stop-button {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-height: 34px; padding: 6px 13px 6px 11px;
    border: 1px solid var(--danger-line); border-radius: var(--r-full);
    color: var(--danger);
    font-size: 12.5px; font-weight: 550; white-space: nowrap;
    transition: background-color .15s;
  }
  .stop-button:hover { background: var(--danger-soft); }
  .stop-square { width: 8px; height: 8px; border-radius: 2px; background: currentColor; flex: none; }
}

/* ───────────────────────── layout ───────────────────────── */
@layer layout {
  .app {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  .sidebar {
    display: flex; flex-direction: column;
    min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    padding: 18px 14px 14px;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
    transition: background-color .35s var(--ease);
  }
  .room {
    display: flex; flex-direction: column;
    min-width: 0; min-height: 0;
    background: var(--chat-bg);
    transition: background-color .35s var(--ease);
  }
  .room-header {
    flex: none;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    min-height: var(--header-h);
    padding: 10px var(--gutter);
    border-bottom: 1px solid var(--border);
  }
  .room-heading { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .room-title { min-width: 0; }
  .title-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .title-row h1 {
    font-size: 17px; font-weight: 650; letter-spacing: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .room-heading p {
    margin-top: 2px; font-size: 12px; color: var(--muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .header-actions { display: flex; align-items: center; gap: 6px; flex: none; }

  .members-bar {
    flex: none;
    display: flex; align-items: center; gap: 8px;
    padding: 9px var(--gutter);
    border-bottom: 1px solid var(--border);
    overflow-x: auto; overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .members-bar::-webkit-scrollbar { display: none; }
  .members-bar > * { flex-shrink: 0; white-space: nowrap; }

  .timeline-wrap { position: relative; display: flex; flex: 1; min-height: 0; min-width: 0; }
  .timeline {
    flex: 1; min-height: 0; min-width: 0;
    display: flex; flex-direction: column;
    overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain;
    scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
  }
  .timeline:focus-visible { outline: none; }
  .messages {
    flex: 1 0 auto;
    display: flex; flex-direction: column;
    width: 100%; max-width: calc(var(--column) + var(--gutter) * 2);
    margin: 0 auto;
    padding: 20px var(--gutter) 16px;
  }
  .composer-area {
    flex: none;
    width: 100%; max-width: calc(var(--column) + var(--gutter) * 2);
    margin: 0 auto;
    padding: 4px var(--gutter) 14px;
  }
  .mobile-only { display: none; }
}

/* ───────────────────────── components ───────────────────────── */
@layer components {
  /* Wordmark */
  .wordmark { display: flex; align-items: center; gap: 10px; line-height: 1; min-width: 0; }
  .wordmark img { border-radius: 9px; }
  .wordmark-name { font-family: var(--font-serif); font-size: 24px; font-weight: 600; letter-spacing: .06em; color: var(--ink); }
  .wordmark-tag { font-size: 11px; color: var(--muted); letter-spacing: .08em; padding-top: 5px; white-space: nowrap; }

  /* Sidebar */
  .sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 6px 18px; flex: none; }
  .venue-switch {
    flex: none;
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
    padding: 4px; margin-bottom: 14px;
    border-radius: 14px;
    background: var(--surface-3);
  }
  .venue-switch button {
    display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 9px; align-items: center;
    padding: 9px 10px; border-radius: 10px;
    text-align: left; color: var(--muted);
    transition: background-color .2s, color .2s, box-shadow .2s;
  }
  .venue-switch button:hover { color: var(--ink-2); }
  .venue-switch .i { grid-row: span 2; width: 20px; height: 20px; }
  .venue-switch strong { font-size: 14px; font-weight: 650; line-height: 1.25; }
  .venue-switch small { font-size: 11px; color: inherit; opacity: .85; white-space: nowrap; line-height: 1.3; }
  .venue-switch button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
  .venue-switch button[aria-pressed="true"] .i { color: var(--accent); }

  .tavern-tools { display: flex; flex-direction: column; gap: 1px; margin-bottom: 10px; flex: none; }
  .tavern-tools:not(:has(> :not([hidden]))) { display: none; }
  .sidebar-action {
    display: flex; align-items: center; gap: 11px;
    width: 100%; min-height: 38px; padding: 8px 10px;
    border-radius: 10px;
    font-size: 13.5px; color: var(--ink-2); text-align: left;
    transition: background-color .15s, color .15s;
  }
  .sidebar-action:hover { background: var(--hover); color: var(--ink); }
  .sidebar-action .i { color: var(--muted); }
  .new-topic {
    flex: none;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; min-height: 42px; margin: 2px 0 18px; padding: 10px 14px;
    border-radius: 12px;
    background: var(--accent); color: var(--accent-ink);
    font-size: 14px; font-weight: 600;
    box-shadow: var(--shadow-sm), inset 0 1px 0 rgb(255 255 255 / .12);
    transition: background-color .15s, transform .1s;
  }
  .new-topic:hover { background: var(--accent-hover); }
  .new-topic:active { transform: scale(.985); }

  #conversation-nav {
    flex: 1 1 auto; min-height: 80px;
    overflow-y: auto; overscroll-behavior: contain;
    margin: 0 -6px; padding: 0 6px;
    scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
  }
  .nav-group { margin-bottom: 16px; }
  .nav-label, .nav-group > summary {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    min-height: 26px; padding: 0 6px 4px 10px;
    font-size: 11.5px; font-weight: 600; letter-spacing: .04em; color: var(--muted);
  }
  .nav-label > span { font-weight: 500; color: var(--faint); font-variant-numeric: tabular-nums; padding-right: 4px; }
  .nav-group > summary { list-style: none; justify-content: flex-start; border-radius: 8px; }
  .nav-group > summary::-webkit-details-marker { display: none; }
  .nav-group > summary::before {
    content: ""; width: 6px; height: 6px; margin: 0 4px 0 1px;
    border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg); transition: transform .2s;
  }
  .nav-group[open] > summary::before { transform: rotate(45deg) translate(-2px, -1px); }
  .nav-group > summary:hover { color: var(--ink-2); }
  .nav-group > summary .nav-count { margin-left: auto; }
  .nav-add { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; color: var(--muted); }
  .nav-add:hover { background: var(--hover); color: var(--accent); }
  .nav-add .i { width: 16px; height: 16px; }
  .nav-row { position: relative; display: flex; align-items: center; min-width: 0; border-radius: 10px; transition: background-color .15s; }
  .nav-row:hover { background: var(--hover); }
  .nav-row.active { background: var(--surface); box-shadow: var(--shadow-sm); }
  .nav-item {
    flex: 1; min-width: 0;
    display: flex; align-items: center; gap: 10px;
    min-height: 38px; padding: 8px 4px 8px 10px;
    border-radius: 10px;
    font-size: 13.5px; color: var(--ink-2); text-align: left;
  }
  .nav-row.active .nav-item { color: var(--ink); font-weight: 600; }
  .nav-item > span:nth-child(2) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-icon { display: grid; place-items: center; flex: none; color: var(--faint); }
  .nav-icon .i { width: 17px; height: 17px; }
  .nav-row.active .nav-icon { color: var(--accent); }
  .nav-count { flex: none; margin-left: auto; font-size: 11.5px; font-weight: 500; color: var(--faint); font-variant-numeric: tabular-nums; }
  .nav-more {
    flex: none; display: grid; place-items: center;
    width: 30px; height: 30px; margin-right: 4px; border-radius: 8px;
    color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: 1px; line-height: 1;
    opacity: 0; transition: opacity .15s, background-color .15s;
  }
  .nav-row:hover .nav-more, .nav-row.active .nav-more, .nav-more:focus-visible { opacity: 1; }
  .nav-more:hover { background: var(--hover); color: var(--ink); }
  .nav-row.nav-private .nav-item { padding-left: 34px; font-size: 13px; }
  .nav-row.nav-private::before {
    content: ""; position: absolute; left: 18px; top: -6px; height: 25px; width: 10px;
    border-left: 1.5px solid var(--border-strong); border-bottom: 1.5px solid var(--border-strong);
    border-bottom-left-radius: 8px; pointer-events: none;
  }
  .nav-parent { display: block; overflow: hidden; text-overflow: ellipsis; color: var(--faint); font-size: 11px; font-weight: 400; }
  .nav-empty { padding: 4px 10px 6px; font-size: 12.5px; color: var(--faint); line-height: 1.6; }
  .nav-new { width: 100%; color: var(--muted); }
  .nav-new:hover { background: var(--hover); color: var(--accent); }
  .nav-new .nav-icon { color: inherit; }
  .archived-conversations { padding-top: 12px; border-top: 1px solid var(--border); }

  .sidebar-bottom { flex: none; margin-top: auto; padding-top: 12px; display: flex; flex-direction: column; gap: 1px; }
  .sidebar-note { font-family: var(--font-serif); font-size: 13px; line-height: 1.9; color: var(--faint); padding: 4px 10px 12px; }
  #sidebar-stop { display: none; }
  .owner-row {
    display: flex; align-items: center; gap: 8px;
    margin-top: 8px; padding: 10px 2px 0 6px;
    border-top: 1px solid var(--border);
    font-size: 13.5px;
  }
  .owner-row > span:nth-child(2) { flex: 1; min-width: 0; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .theme-to-light { display: none; }
  :root[data-theme="dark"] .theme-to-light { display: block; }
  :root[data-theme="dark"] .theme-to-dark { display: none; }

  /* Header */
  .scope-tag {
    flex: none;
    padding: 2px 9px; border-radius: var(--r-full);
    background: var(--accent-soft); color: var(--accent);
    font-size: 11px; font-weight: 600; white-space: nowrap;
  }
  .cost-button {
    min-height: 32px; padding: 5px 11px; border-radius: var(--r-full);
    font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
    transition: background-color .15s, color .15s;
  }
  .cost-button:hover { background: var(--hover); color: var(--ink); }
  .header-tool .i { width: 20px; height: 20px; }

  /* Members & tools strip */
  .group-private-button {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 34px; padding: 6px 13px;
    border: 1px solid var(--border-strong); border-radius: var(--r-full);
    background: var(--surface);
    color: var(--ink-2); font-size: 13px; font-weight: 500;
    transition: border-color .15s, color .15s, background-color .15s;
  }
  .group-private-button .i { width: 16px; height: 16px; }
  .group-private-button:hover:not(:disabled) { border-color: var(--accent-line); color: var(--accent); }
  #group-private-button { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
  #group-private-button.is-back { background: var(--accent); color: var(--accent-ink); }
  .members-divider { display: none; width: 1px; height: 20px; background: var(--border-strong); margin: 0 4px; }
  .members-bar:has(> .group-private-button:not([hidden]), > .tavern-pacing-control:not([hidden])) .members-divider { display: block; }
  .member-chips { display: flex; align-items: center; gap: 6px; }
  .member-chip {
    display: inline-flex; align-items: center; gap: 8px;
    min-height: 34px; padding: 3px 12px 3px 3px;
    border: 1px solid var(--border); border-radius: var(--r-full);
    background: var(--surface);
    font-size: 13px; font-weight: 550; color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
  }
  .member-chip:hover { border-color: var(--accent-line); box-shadow: var(--shadow-sm); }
  .member-chip .avatar { width: 26px; height: 26px; font-size: 14px; }
  .member-chip > span:nth-child(2) { display: flex; flex-direction: column; line-height: 1.25; text-align: left; }
  .member-chip.paused { opacity: .55; }
  .member-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
  .member-chip.paused .member-dot { background: var(--faint); box-shadow: none; }
  .member-status { display: block; font-size: 10.5px; font-weight: 400; color: var(--muted); line-height: 1.3; }
  .no-members { font-size: 13px; color: var(--muted); }
  .add-chair {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 34px; padding: 6px 12px; border-radius: var(--r-full);
    border: 1px dashed var(--accent-line);
    color: var(--accent); font-size: 13px; font-weight: 550;
    transition: background-color .15s;
  }
  .add-chair .i { width: 16px; height: 16px; }
  .add-chair:hover { background: var(--accent-soft); }
  .resident-library { font-size: 13px; }
  .tavern-pacing-control {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12.5px; color: var(--muted); font-weight: 500;
  }
  .tavern-pacing-control select {
    width: auto; min-width: 96px; min-height: 34px;
    padding: 5px 30px 5px 12px; border-radius: var(--r-full);
    font-size: 13px; background-position: right 8px center; background-size: 14px;
  }

  /* Timeline */
  .context-notice {
    flex: none; align-self: center;
    width: fit-content; max-width: min(var(--column), calc(100% - 32px));
    margin: 16px auto 0; padding: 6px 14px;
    border-radius: 14px;
    background: var(--surface-2);
    color: var(--muted); font-size: 12px; line-height: 1.6; text-align: center;
  }
  .day-divider {
    display: flex; align-items: center; justify-content: center; gap: 14px;
    margin: 6px 0 22px;
    color: var(--faint); font-size: 12px; font-weight: 500;
  }
  .day-divider::before, .day-divider::after { content: ""; flex: 0 1 64px; height: 1px; background: var(--border); }

  .message {
    --speaker-ink: #3f6b52; --speaker-bg: #dde9df;
    position: relative;
    display: flex; align-items: flex-start; gap: 12px;
    margin-top: 18px;
    outline: none;
  }
  .day-divider + .message, .messages > .message:first-child { margin-top: 0; }
  .speaker-tone-0 { --speaker-ink: #3f6b52; --speaker-bg: #dce9de; }
  .speaker-tone-1 { --speaker-ink: #3d6a8f; --speaker-bg: #dce8f3; }
  .speaker-tone-2 { --speaker-ink: #8a6036; --speaker-bg: #f1e4d2; }
  .speaker-tone-3 { --speaker-ink: #745595; --speaker-bg: #e9e1f3; }
  .speaker-tone-4 { --speaker-ink: #9a5a4a; --speaker-bg: #f4e0da; }
  .speaker-tone-5 { --speaker-ink: #2f7672; --speaker-bg: #d9eceb; }
  :root[data-theme="dark"] .speaker-tone-0 { --speaker-ink: #a9d4b6; --speaker-bg: #263a2d; }
  :root[data-theme="dark"] .speaker-tone-1 { --speaker-ink: #a9cdeb; --speaker-bg: #22364a; }
  :root[data-theme="dark"] .speaker-tone-2 { --speaker-ink: #e6c49c; --speaker-bg: #3f3222; }
  :root[data-theme="dark"] .speaker-tone-3 { --speaker-ink: #d1bcec; --speaker-bg: #342a47; }
  :root[data-theme="dark"] .speaker-tone-4 { --speaker-ink: #eab9a9; --speaker-bg: #43281f; }
  :root[data-theme="dark"] .speaker-tone-5 { --speaker-ink: #a6dcd6; --speaker-bg: #1f3a38; }
  .message > .avatar {
    width: 36px; height: 36px; border-radius: 12px;
    background: var(--speaker-bg); color: var(--speaker-ink);
    font-size: 17px; font-weight: 600;
  }
  .message-main {
    position: relative;
    min-width: min(250px, 100%); max-width: min(86%, 68ch);
    display: flex; flex-direction: column; align-items: flex-start;
  }
  .message-meta {
    display: flex; align-items: baseline; gap: 8px;
    height: 20px; margin: 0 4px 5px;
    font-size: 13px; line-height: 20px; white-space: nowrap;
  }
  .message-name { font-weight: 650; color: var(--speaker-ink); overflow: hidden; text-overflow: ellipsis; }
  .message-time { font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
  .message-marker { font-size: 11px; font-weight: 600; color: var(--accent); }
  .message-bubble {
    max-width: 100%;
    padding: 11px 16px;
    background: var(--bubble);
    border: 1px solid var(--bubble-border);
    border-radius: 6px 18px 18px 18px;
    box-shadow: var(--shadow-sm);
  }
  .message.owner { flex-direction: row-reverse; }
  .message.owner > .avatar { display: none; }
  .message.owner .message-main { align-items: flex-end; max-width: min(82%, 64ch); }
  .message.owner .message-name { color: var(--muted); font-weight: 550; }
  .message.owner .message-bubble {
    background: var(--bubble-own); color: var(--bubble-own-ink);
    border-color: transparent; border-radius: 18px 6px 18px 18px; box-shadow: none;
  }
  .message.grouped { margin-top: 6px; }
  .message.grouped > .avatar { visibility: hidden; height: 0; }
  .message.grouped .message-meta { display: none; }
  .message.grouped .message-bubble { border-top-left-radius: 18px; }
  .message.owner.grouped .message-bubble { border-top-right-radius: 18px; }
  .message-highlight .message-bubble { box-shadow: 0 0 0 2px var(--accent), var(--shadow-md); transition: box-shadow .3s; }

  .message-body, .draft-card p {
    font-family: var(--font-reading);
    font-size: 16px; line-height: 1.75;
    overflow-wrap: anywhere; tab-size: 2; text-align: start;
  }
  .message-body > :first-child { margin-top: 0; }
  .message-body > :last-child { margin-bottom: 0; }
  .message-body p { margin: 0 0 .75em; }
  .message-body .plain-message { white-space: pre-wrap; }
  .message-body .tavern-narration { color: var(--chat-muted); font-style: normal; font-weight: 400; }
  .message-body :is(h1, h2, h3, h4, h5, h6) { font-family: inherit; font-weight: 650; line-height: 1.5; margin: 1em 0 .5em; letter-spacing: 0; }
  .message-body h1 { font-size: 1.3em; }
  .message-body h2 { font-size: 1.18em; }
  .message-body :is(h3, h4, h5, h6) { font-size: 1.05em; }
  .message-body :is(ul, ol) { margin: .6em 0; padding-inline-start: 1.4em; }
  .message-body li { margin: .25em 0; padding-inline-start: .15em; }
  .message-body li::marker { color: var(--chat-muted); }
  .message-body li > p { margin-bottom: .4em; }
  .message-body blockquote { margin: .8em 0; padding: .1em .95em; border-left: 3px solid var(--accent-line); color: var(--chat-muted); }
  .message-body blockquote > :last-child { margin-bottom: 0; }
  .message-body a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
  .message-body hr { border: 0; border-top: 1px solid var(--bubble-border); margin: 1em 0; }
  .message-body strong { font-weight: 650; }
  .message-body code { font: .86em/1.6 var(--font-mono); background: var(--code-bg); padding: .12em .38em; border-radius: 5px; }
  .message.owner .message-body code { background: rgb(0 0 0 / .06); }
  .code-block { margin: .85em 0; border: 1px solid var(--bubble-border); border-radius: 12px; overflow: hidden; background: var(--code-bg); }
  .code-header {
    display: flex; justify-content: space-between; align-items: center; gap: 16px;
    padding: 4px 6px 4px 14px; border-bottom: 1px solid var(--bubble-border);
    font: 500 12px/1.5 var(--font-sans); color: var(--chat-muted);
  }
  .code-header button { min-height: 30px; padding: 4px 10px; border-radius: 7px; font-size: 12px; }
  .code-header button:hover { color: var(--accent); background: var(--hover); }
  .message-body pre { margin: 0; padding: 12px 14px; overflow: auto; white-space: pre; max-height: 420px; scrollbar-width: thin; font-size: 14px; }
  .message-body pre code { padding: 0; border-radius: 0; background: none; overflow-wrap: normal; }
  .message-table { max-width: 100%; overflow-x: auto; margin: .85em 0; border: 1px solid var(--bubble-border); border-radius: 10px; }
  .message-table table { border-collapse: collapse; min-width: 100%; font-size: .9em; }
  .message-table :is(td, th) { border-bottom: 1px solid var(--bubble-border); padding: 8px 12px; min-width: 88px; text-align: start; }
  .message-table th { background: var(--code-bg); font-weight: 600; }
  .message-table tr:last-child td { border-bottom: 0; }
  .message-body img.preset-illustration { display: block; width: auto; max-width: 100%; max-height: 520px; object-fit: contain; border-radius: 10px; margin: 12px 0; cursor: zoom-in; }
  .preset-image-error { color: var(--muted); font-size: 12px; border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; display: inline-block; }
  .message-notice { margin: 6px 0 0; }

  /* Floating per-message toolbar: appears on hover / keyboard focus, or after a tap on touch screens. */
  .message-actions {
    position: absolute; z-index: 2;
    top: 25px; right: 8px;
    display: flex; gap: 1px; padding: 3px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 11px;
    box-shadow: var(--shadow-md);
    opacity: 0; pointer-events: none;
    transform: translateY(-62%) scale(.96);
    transition: opacity .14s, transform .14s var(--ease);
  }
  .message.owner .message-actions { right: auto; left: 8px; }
  .message.grouped .message-actions { top: 0; }
  .message:hover .message-actions,
  .message:focus-within .message-actions,
  .message.is-active .message-actions {
    opacity: 1; pointer-events: auto; transform: translateY(-62%) scale(1);
  }
  .message-actions button {
    display: grid; place-items: center;
    min-width: 30px; height: 28px; padding: 0 6px; border-radius: 8px;
    color: var(--chat-muted);
  }
  .message-actions button:hover { color: var(--accent); background: var(--hover); }
  .message-actions .i { width: 17px; height: 17px; }

  .message-quote {
    display: block; width: 100%;
    margin: 0 0 10px; padding: 7px 11px;
    border-left: 3px solid var(--accent-line);
    border-radius: 4px 9px 9px 4px;
    background: color-mix(in srgb, var(--code-bg) 80%, transparent);
    color: var(--chat-muted); font-size: 13px; line-height: 1.55;
    overflow-wrap: anywhere; text-align: start;
  }
  .message-quote strong { display: block; color: var(--accent); margin-bottom: 2px; font-size: 12px; }
  .message-quote span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
  button.message-quote { cursor: pointer; transition: border-color .15s; }
  button.message-quote:hover { border-left-color: var(--accent); }
  .shared-label { display: flex; align-items: center; gap: 6px; padding: 0 0 8px; font-size: 12px; color: var(--chat-muted); }
  .shared-label .i { width: 14px; height: 14px; }

  .message-menu {
    position: fixed; z-index: 40;
    min-width: 200px; max-width: calc(100vw - 16px);
    padding: 5px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    animation: pop-in .14s var(--ease);
  }
  .message-menu button {
    display: flex; align-items: center; gap: 11px;
    width: 100%; min-height: 40px; padding: 8px 12px;
    border-radius: 9px;
    font-size: 14px; text-align: left; color: var(--ink);
  }
  .message-menu button .i { color: var(--muted); }
  .message-menu button.danger-text .i { color: currentColor; }
  .message-menu button:hover, .message-menu button:focus-visible { background: var(--hover); outline: none; }

  .latest-button {
    position: absolute; z-index: 5; bottom: 14px; left: 50%;
    transform: translateX(-50%);
    display: flex; align-items: center; gap: 7px;
    min-height: 38px; padding: 7px 16px 7px 13px;
    background: var(--surface); color: var(--accent);
    border: 1px solid var(--border); border-radius: var(--r-full);
    box-shadow: var(--shadow-md);
    font-size: 13px; font-weight: 550; white-space: nowrap;
    animation: rise-in .2s var(--ease);
  }
  .latest-button .i { width: 16px; height: 16px; }

  /* Live drafts */
  .draft-panel {
    flex: none;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 12px;
    width: 100%; max-width: calc(var(--column) + var(--gutter) * 2);
    margin: 0 auto; padding: 0 var(--gutter) 18px;
  }
  .draft-card {
    --speaker-ink: var(--accent);
    min-width: 0; padding: 12px 15px;
    background: var(--bubble);
    border: 1px dashed color-mix(in srgb, var(--speaker-ink) 40%, var(--bubble-border));
    border-radius: 6px 18px 18px 18px;
    animation: card-in .2s var(--ease);
  }
  .draft-card > div { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; color: var(--speaker-ink); }
  .draft-card .muted { color: var(--chat-muted); font-size: 12px; }
  .draft-card p { white-space: pre-wrap; font-size: 15px; max-height: 190px; overflow-y: auto; scrollbar-width: thin; }
  .typing-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--speaker-ink); animation: typing-pulse 1.2s ease-in-out infinite; }

  /* Composer */
  .run-status {
    display: flex; align-items: center; gap: 8px;
    min-height: 26px; padding: 0 6px 6px;
    font-size: 12.5px; color: var(--muted);
  }
  .run-status.running { color: var(--accent); font-weight: 500; }
  .run-status.running::before {
    content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%;
    background: currentColor; animation: typing-pulse 1.2s ease-in-out infinite;
  }
  .run-status.failed { color: var(--danger); }
  .run-status button { flex: none; min-height: 26px; padding: 2px 6px; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }
  .run-summary { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .run-reason { white-space: pre-wrap; overflow-wrap: anywhere; }
  .chat-help {
    display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
    margin: 0 0 8px; padding: 8px 8px 8px 14px;
    border-radius: 14px;
    background: var(--accent-soft); color: var(--ink-2);
    font-size: 13px;
  }
  .chat-help > span { flex: 1; min-width: 160px; overflow-wrap: anywhere; }
  .chat-help button { min-height: 34px; font-size: 13px; }
  .chat-help:not(:has(button)) { background: none; padding: 0 6px; margin-bottom: 6px; color: var(--muted); font-size: 12.5px; }
  .chat-help.error { background: var(--danger-soft); color: var(--danger); }

  .composer {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 22px;
    box-shadow: var(--shadow-md);
    transition: border-color .15s, box-shadow .15s;
  }
  .composer:focus-within { border-color: var(--accent-line); box-shadow: var(--shadow-md), var(--focus); }
  .composer textarea {
    display: block; width: 100%;
    min-height: 54px; max-height: 200px;
    padding: 15px 18px 4px;
    border: 0; border-radius: 22px; background: none; box-shadow: none;
    font-family: var(--font-reading); font-size: 16px; line-height: 1.6;
  }
  .composer textarea:focus { box-shadow: none; }
  .composer-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 8px 10px; }
  .invite-button {
    display: inline-flex; align-items: center; gap: 6px;
    min-width: 0; min-height: 34px; padding: 5px 10px 5px 11px;
    border-radius: var(--r-full);
    background: var(--surface-2); color: var(--ink-2);
    font-size: 13px; font-weight: 500;
    transition: background-color .15s;
  }
  .invite-button:hover { background: var(--surface-3); }
  .invite-button .i { width: 16px; height: 16px; color: var(--muted); }
  .invite-button > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .invite-button .chevron { width: 14px; height: 14px; transition: transform .2s; }
  .invite-button[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }
  .invite-button[aria-expanded="true"] .chevron { transform: rotate(180deg); }
  .send-options { display: flex; align-items: center; gap: 6px; flex: none; }
  .continue-button {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 36px; padding: 6px 13px;
    border: 1px solid var(--border-strong); border-radius: var(--r-full);
    font-size: 13px; font-weight: 500; color: var(--ink-2); white-space: nowrap;
    transition: border-color .15s, color .15s, background-color .15s;
  }
  .continue-button .i { width: 16px; height: 16px; }
  .continue-button:hover:not(:disabled) { border-color: var(--accent-line); color: var(--accent); }
  .send-button { min-height: 38px; padding: 7px 14px 7px 17px; border-radius: var(--r-full); gap: 6px; }
  .send-button .i { width: 17px; height: 17px; stroke-width: 2.1; }
  .composer-footnote {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 8px 8px 0;
    font-size: 11.5px; color: var(--faint);
  }
  .composer-footnote > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #connection-label { display: inline-flex; align-items: center; }
  .connection-dot { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--accent); }
  .connection-dot.offline { background: var(--danger); animation: typing-pulse 1.2s ease-in-out infinite; }

  .reply-preview {
    display: flex; align-items: center; gap: 8px;
    margin: 10px 10px 0; padding: 5px 5px 5px 12px;
    border-left: 3px solid var(--accent);
    border-radius: 6px 12px 12px 6px;
    background: var(--surface-2);
    font-size: 13px; color: var(--ink-2);
  }
  .reply-preview span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .reply-preview button { display: grid; place-items: center; min-width: 30px; min-height: 30px; border-radius: 8px; font-size: 18px; color: var(--muted); }
  .reply-preview button:hover { background: var(--hover); color: var(--ink); }

  .invite-picker {
    position: absolute; z-index: 15;
    bottom: calc(100% + 10px); left: 0;
    width: 320px; max-height: min(480px, 62dvh);
    padding: 14px;
    overflow-y: auto; overscroll-behavior: contain;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    animation: pop-in .16s var(--ease);
    transform-origin: bottom left;
  }
  .invite-picker > label[for="chat-mode"] { display: grid; gap: 6px; margin-bottom: 8px; }
  .invite-picker > p { font-size: 12.5px; color: var(--muted); line-height: 1.6; margin-bottom: 8px; }
  .invite-picker .picker-tools { display: flex; gap: 6px; padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
  .invite-picker .picker-tools .text-button { padding: 4px 10px; border-radius: var(--r-full); background: var(--surface-2); color: var(--ink-2); font-size: 12.5px; }
  .invite-picker .picker-tools .text-button:hover { color: var(--accent); }
  .invite-picker label:has(> input[type="checkbox"]) {
    display: flex; align-items: center; gap: 10px;
    min-height: 42px; padding: 6px 8px; margin: 0 -6px;
    border-radius: 10px;
    font-size: 14px; color: var(--ink); font-weight: 500; cursor: pointer;
  }
  .invite-picker label:has(> input[type="checkbox"]):hover { background: var(--hover); }
  .picker-advanced { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 13px; }
  .picker-advanced summary { padding: 6px 0; color: var(--ink-2); font-weight: 500; }
  .picker-advanced small { display: block; margin-top: 8px; font-size: 12px; line-height: 1.6; color: var(--muted); }
  .continuous-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
  .continuous-actions label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
  .continuous-actions input { width: 60px !important; min-height: 34px !important; padding: 4px 8px; text-align: center; }
  .continuous-actions button { min-height: 34px; padding: 6px 12px; font-size: 13px; }

  .observer-panel {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 14px 14px 14px 18px; margin-bottom: 2px;
    border-radius: 18px;
    background: var(--accent-soft);
  }
  .observer-panel > div { min-width: 0; }
  .observer-panel strong { font-size: 14px; }
  .observer-panel p { margin-top: 2px; font-size: 12.5px; color: var(--ink-2); overflow-wrap: anywhere; }
  .observer-panel button { flex: none; }

  /* Toast */
  .toast {
    position: fixed; z-index: 60;
    bottom: 28px; left: 50%;
    transform: translateX(-50%);
    max-width: min(560px, calc(100vw - 32px));
    padding: 11px 18px;
    border-radius: 14px;
    background: var(--ink); color: var(--bg);
    box-shadow: var(--shadow-lg);
    font-size: 13.5px; line-height: 1.5; overflow-wrap: anywhere;
    animation: toast-in .22s var(--ease);
  }

  /* Empty states */
  .welcome {
    margin: auto; align-self: center;
    width: 100%; max-width: 520px;
    padding: 48px 16px 64px;
    text-align: center;
  }
  .welcome-symbol { width: 150px; height: 88px; margin: 0 auto 22px; color: var(--accent); opacity: .85; }
  .welcome .eyebrow { margin-bottom: 14px; }
  .welcome h2 {
    margin-bottom: 14px;
    font-family: var(--font-serif); font-size: 28px; font-weight: 500;
    line-height: 1.55; letter-spacing: .06em;
  }
  .welcome p { max-width: 380px; margin: 0 auto; font-size: 14px; line-height: 1.85; color: var(--muted); }
  .welcome > button { margin-top: 24px; }
  .empty-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
  .tavern-sign {
    display: grid; place-items: center;
    width: 76px; height: 92px; margin: 0 auto 28px;
    border: 1.5px solid var(--gold); border-radius: 38px 38px 10px 10px;
    color: var(--gold); font-size: 44px; font-family: var(--font-serif);
    background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--gold) 18%, transparent), transparent 70%);
  }
  .tavern-welcome h2 { line-height: 1.55; }
  .tavern-footnote { margin-top: 34px !important; font-size: 12.5px !important; color: var(--faint) !important; }
  .tavern-empty { text-align: center; padding: 36px 12px; color: var(--muted); }
  .tavern-empty > span { display: block; font-size: 34px; color: var(--gold); margin-bottom: 8px; }

  /* Login */
  .login-view {
    min-height: 100vh; min-height: 100dvh;
    display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    background: var(--bg);
  }
  .login-art {
    position: relative; overflow: hidden;
    display: flex; flex-direction: column; justify-content: flex-end;
    padding: 64px;
    color: #f2eee3;
    background:
      radial-gradient(120% 70% at 50% 110%, rgb(233 177 104 / .2), transparent 60%),
      linear-gradient(165deg, #34503f 0%, #22362b 52%, #16221b 100%);
  }
  .login-art-glow {
    position: absolute; left: 50%; top: 34%;
    width: 420px; height: 420px; transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgb(246 200 128 / .28), transparent 62%);
    pointer-events: none;
  }
  .login-art-window {
    position: absolute; left: 50%; top: 34%;
    transform: translate(-50%, -50%);
    display: grid; grid-template-columns: 1fr 1fr; gap: 7px;
    width: 156px; height: 196px; padding: 13px;
    border: 1.5px solid rgb(242 238 227 / .4);
    border-radius: 78px 78px 10px 10px;
  }
  .window-pane { background: linear-gradient(180deg, #f8dc9c, #eaa95c); border-radius: 3px; opacity: .9; animation: window-glow 6s ease-in-out infinite; }
  .window-pane:nth-child(1) { border-top-left-radius: 62px; }
  .window-pane:nth-child(2) { border-top-right-radius: 62px; animation-delay: -2s; }
  .window-pane:nth-child(3) { animation-delay: -4s; }
  .window-pane:nth-child(4) { animation-delay: -1s; }
  .art-line { position: relative; font-family: var(--font-serif); font-size: clamp(30px, 3.2vw, 48px); line-height: 1.25; letter-spacing: -.01em; }
  .art-footer { position: relative; margin-top: 26px; font-size: 11px; letter-spacing: .3em; opacity: .6; }
  .login-panel { display: flex; align-items: center; justify-content: center; padding: 48px 40px; }
  .login-inner { width: 100%; max-width: 360px; }
  .login-inner .wordmark { margin-bottom: 64px; }
  .login-inner .wordmark-name { font-size: 28px; }
  .login-inner h1 { margin: 12px 0 12px; font-family: var(--font-serif); font-size: 40px; font-weight: 500; letter-spacing: .08em; }
  .login-lede { font-size: 14px; line-height: 1.85; max-width: 300px; }
  .login-inner form { margin-top: 34px; }
  .login-inner label { margin-bottom: 8px; }
  .login-inner input { min-height: 50px !important; font-size: 16px; border-radius: 13px; }
  .login-inner .primary { margin-top: 14px; min-height: 50px; justify-content: space-between; padding: 12px 18px; font-size: 15px; border-radius: 13px; }
  #login-error { margin-top: 12px; }
  .login-note { margin-top: 40px; font-size: 12px; color: var(--faint); }

  /* Dialog */
  dialog {
    width: min(640px, calc(100vw - 32px));
    max-height: min(88dvh, 920px);
    padding: 0;
    overflow: auto; overscroll-behavior: contain;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow-lg);
    scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
  }
  dialog[open] { animation: dialog-in .22s var(--ease); }
  dialog::backdrop { background: var(--scrim); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fade-in .2s ease; }
  .modal-head {
    position: sticky; top: 0; z-index: 3;
    display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
    padding: 20px 20px 14px 26px;
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
  }
  .modal-titles { min-width: 0; padding-top: 2px; }
  .modal-head .eyebrow { margin-bottom: 5px; }
  .modal-head h2 { font-size: 20px; overflow-wrap: anywhere; }
  .modal-head-actions { display: flex; align-items: center; gap: 6px; flex: none; }
  .modal-head-actions .stop-button { min-height: 32px; padding: 5px 11px 5px 10px; font-size: 12px; }
  #modal-body { padding: 20px 26px 26px; font-size: 14px; line-height: 1.6; }
  #modal-body > h3, #modal-body form > h3 { margin: 24px 0 10px; }

  /* Forms */
  .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .field { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
  .field.full { grid-column: 1 / -1; }
  .field small { font-size: 12px; line-height: 1.6; }
  .field textarea { width: 100%; resize: vertical; line-height: 1.7; }
  #modal-body form > .field { margin-bottom: 16px; }
  .check-row { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; font-weight: 400; color: var(--ink); line-height: 1.5; cursor: pointer; padding: 4px 0; }
  .check-row input { margin-top: 1px; }
  .form-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; margin-top: 24px; }
  .form-actions .error { margin-right: auto; }
  .form-section { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border); }
  .form-section > summary { margin-bottom: 14px; font-size: 13.5px; font-weight: 550; color: var(--ink-2); }
  .form-section > summary:hover { color: var(--accent); }
  .form-help {
    margin: 14px 0 18px; padding: 11px 14px;
    border-radius: 12px;
    background: var(--surface-2); color: var(--ink-2);
    font-size: 13px; line-height: 1.75;
  }
  .setup-intro { margin: 0 0 16px; color: var(--muted); line-height: 1.6; }
  .tabs {
    display: flex; gap: 4px;
    margin-bottom: 22px; padding: 4px;
    border-radius: 13px; background: var(--surface-2);
    overflow-x: auto; scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button {
    flex: 1 0 auto; min-height: 34px; padding: 6px 14px;
    border-radius: 9px;
    font-size: 13px; font-weight: 550; color: var(--muted); white-space: nowrap;
    transition: background-color .15s, color .15s;
  }
  .tabs button:hover { color: var(--ink); }
  .tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

  .catalog-actions, .provider-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
  .catalog-actions small { flex: 1; min-width: 0; }
  .provider-actions { flex: 0 0 auto !important; justify-content: flex-end; max-width: 200px; }
  .provider-actions small { flex-basis: 100%; text-align: right; }
  .billing-switch { margin-bottom: 16px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
  .setting-list { display: flex; flex-direction: column; }
  .setting-item { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
  .setting-item > div { flex: 1; min-width: 0; }
  .setting-item strong { font-size: 14px; }
  .setting-item p { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
  .stat-line { display: flex; justify-content: space-between; align-items: center; gap: 15px; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
  .stat-line strong { font-variant-numeric: tabular-nums; font-size: 15px; }
  .bill-note { margin: 14px 0; font-size: 12.5px; line-height: 1.75; color: var(--muted); }
  .call-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
  .call-row small { display: block; margin-top: 2px; font-size: 12px; }
  .diagnostic {
    max-height: 53dvh; overflow: auto;
    padding: 14px 16px; border-radius: 12px;
    background: var(--code-bg); border: 1px solid var(--border);
    font: 12px/1.6 var(--font-mono); white-space: pre-wrap; word-break: break-all;
  }
  .empty-small { padding: 18px 0; color: var(--muted); font-size: 13.5px; }
  .tool-list { display: flex; flex-direction: column; gap: 8px; }
  .tool-list button {
    display: flex; align-items: center; gap: 12px;
    min-height: 48px; padding: 10px 16px;
    border: 1px solid var(--border); border-radius: 14px;
    background: var(--surface);
    font-size: 14px; text-align: left;
    transition: background-color .15s, border-color .15s;
  }
  .tool-list button .i { color: var(--muted); }
  .tool-list button.danger-text .i { color: currentColor; }
  .tool-list button:hover { background: var(--surface-2); border-color: var(--border-strong); }
  .lifecycle-tools { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
  .delete-summary { line-height: 1.8; overflow-wrap: anywhere; }
  .delete-message-preview { margin: 16px 0; padding: 12px 16px; border-left: 3px solid var(--border-strong); border-radius: 4px 12px 12px 4px; background: var(--surface-2); overflow-wrap: anywhere; }
  .delete-message-preview p { white-space: pre-wrap; margin: 8px 0 0; }
  .archive-panel > div, .archive-panel p { min-width: 0; overflow-wrap: anywhere; }
  .pin-row { padding: 13px 0; border-bottom: 1px solid var(--border); font-size: 14px; overflow-wrap: anywhere; white-space: pre-wrap; }
  .pin-row small { display: block; margin-bottom: 4px; font-weight: 600; }
  .private-member-list { display: grid; gap: 8px; margin-block: 16px; }
  .private-member {
    display: flex; align-items: center; gap: 12px;
    width: 100%; min-width: 0; padding: 12px 14px;
    border: 1px solid var(--border); border-radius: 14px;
    text-align: left; transition: background-color .15s, border-color .15s;
  }
  .private-member:hover { background: var(--surface-2); border-color: var(--accent-line); }
  .private-member .avatar, .private-member-action { flex: none; }
  .private-member-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 550; }
  .private-member-name small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
  .private-member-action { color: var(--accent); font-size: 13px; font-weight: 550; }
  .context-meter { display: grid; gap: 8px; margin: 16px 0; }
  .context-meter progress { width: 100%; height: 10px; }
  .context-meter small { line-height: 1.6; }
}

/* ───────────────────────── feature modules ───────────────────────── */
@layer modules {
  /* Quick model picker */
  .quick-form .field input, .quick-form .field select { min-height: 42px; }
  .quick-form .field small, .quick-accounting small { font-size: 12px; line-height: 1.6; }
  .quick-provider { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 14px; }
  .quick-provider .field { flex: 1; }
  .quick-provider > button { min-height: 42px; white-space: nowrap; }
  .quick-form .catalog-actions { margin: 8px 0; }
  .quick-model-list { max-height: min(260px, 30dvh); min-height: 96px; overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--border); border-radius: 14px; }
  .model-option { display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 10px 14px; cursor: pointer; transition: background-color .12s; }
  .model-option + .model-option { border-top: 1px solid var(--border); }
  .model-option:hover { background: var(--hover); }
  .model-option:has(input:checked) { background: var(--accent-soft); }
  .model-option:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }
  .model-option span { min-width: 0; }
  .model-option strong { display: block; font-weight: 550; font-size: 14px; overflow-wrap: anywhere; color: var(--ink); }
  .model-option small { display: block; margin-top: 2px; font-size: 12px; font-weight: 400; color: var(--muted); }
  .quick-selected { display: flex; flex-wrap: wrap; gap: 6px; max-height: 90px; overflow: auto; margin-top: 10px; }
  .quick-selected:empty { display: none; }
  .quick-selected button { padding: 6px 10px; border-radius: var(--r-full); background: var(--accent-soft); color: var(--accent); font-size: 12.5px; max-width: 100%; overflow-wrap: anywhere; text-align: left; }
  .quick-manual { margin-top: 12px; color: var(--muted); font-size: 13px; }
  .quick-manual summary { padding: 6px 0; }
  .manual-entry { display: flex; gap: 8px; margin-top: 8px; }
  .manual-entry input { flex: 1; min-width: 0; width: auto; }
  .manual-entry button { flex-shrink: 0; }
  .quick-form .form-section { margin-top: 14px; padding-top: 10px; }
  .quick-accounting { display: grid; grid-template-columns: auto 1fr; align-items: start; gap: 12px; grid-column: 1 / -1; }
  .quick-accounting .check-row { white-space: nowrap; }
  .quick-submit {
    position: sticky; bottom: -26px; z-index: 2;
    display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px;
    margin: 16px -26px -26px; padding: 14px 26px calc(14px + var(--safe-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .quick-submit > small { color: var(--muted); font-size: 12px; line-height: 1.5; }
  .quick-submit > button { min-height: 44px; }
  .quick-submit .form-error { grid-column: 1 / -1; margin: 0; }
  .quick-form .form-error:empty { display: none; }

  /* Residents */
  .resident-list { display: grid; gap: 10px; margin: 16px 0; }
  .resident-card {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 14px 16px;
    border: 1px solid var(--border); border-radius: 16px;
    background: var(--surface);
  }
  .resident-card > div { min-width: 0; }
  .resident-card strong { font-size: 15px; }
  .resident-card p { margin: 4px 0; font-size: 13px; }
  .resident-card .form-actions { margin: 0; flex-shrink: 0; }
  .resident-card p, .resident-card small { overflow-wrap: anywhere; }
  .resident-profile { margin: 20px 0; display: grid; gap: 12px; }
  .resident-profile textarea { width: 100%; resize: vertical; min-height: 100px; }
  #memory-recall-form { margin-top: 24px; }
  #memory-results { max-height: 260px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

  /* Tavern library & scene editor */
  .library-actions { display: flex; gap: 10px; margin: 18px 0; flex-wrap: wrap; align-items: center; }
  .import-label { display: inline-flex; cursor: pointer; }
  .import-label:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
  .cast-list { display: grid; gap: 10px; margin: 14px 0 24px; }
  .cast-row {
    display: grid; grid-template-columns: minmax(100px, 1fr) minmax(140px, 1.2fr); align-items: center; gap: 16px;
    padding: 12px 14px; border: 1px solid var(--border); border-radius: 14px;
  }
  .cast-row:has(input[type="checkbox"]:checked) { border-color: var(--accent-line); background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
  .cast-row .field { margin: 0; }
  .cast-row .check-row { overflow-wrap: anywhere; font-weight: 550; }
  .lore-entry { min-width: 0; border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; margin: 16px 0; }
  .lore-entry legend { padding: 0 8px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
  .lore-entry .field { margin-top: 12px; }
  .lore-flags { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
  .book-choices { margin: 12px 0; display: grid; gap: 2px; }
  #scene-form h3 { margin-top: 26px; font-size: 15px; }
  #scene-form > .eyebrow { margin-bottom: 14px; }
  #scene-form > .field, #card-form .field, #persona-form .field { margin-bottom: 14px; }
  #card-form details > summary { margin: 18px 0; color: var(--ink-2); font-weight: 550; }

  .tavern-pacing-control:has(select:disabled) { opacity: .6; }

  /* Personas */
  .persona-list { display: grid; gap: 14px; }
  .persona-tile { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 18px; padding: 18px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); }
  .persona-avatar { display: block; width: 100%; aspect-ratio: 1; border-radius: 50%; object-fit: cover; }
  .persona-placeholder { display: grid; place-items: center; background: var(--surface-3); color: var(--gold); font: 28px var(--font-serif); }
  .persona-tile-body { min-width: 0; }
  .persona-title { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
  .persona-title h3 { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
  .persona-default { padding: 2px 9px; border-radius: var(--r-full); background: var(--accent-soft); color: var(--accent); font-size: 11.5px; font-weight: 600; }
  .persona-description { margin: 8px 0 12px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; font-size: 13.5px; line-height: 1.65; }
  .persona-tile .form-actions { justify-content: flex-start; margin: 0; }
  .persona-identity { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 24px; margin: 20px 0; }
  .persona-identity > aside { display: flex; flex-direction: column; align-items: center; gap: 10px; }
  #persona-avatar-preview { width: 100%; }
  .persona-identity > aside small { color: var(--muted); font-size: 11.5px; line-height: 1.6; text-align: center; }
  .persona-upload { font-size: 13px; }
  .scene-persona { margin: 24px 0; padding: 20px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface-2); }
  .scene-persona h3 { margin: 0; }
  .persona-save-preset { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
  #persona-save-status { color: var(--muted); font-size: 13px; }

  /* Story stage: a quiet side panel on desktop, a short strip on small screens. */
  .timeline-wrap.has-scene-background::before {
    content: ""; position: absolute; inset: 0;
    background: var(--scene-image) center / cover no-repeat;
    opacity: .14; pointer-events: none;
  }
  .timeline-wrap.has-scene-background > .timeline { position: relative; }
  .tavern-stage {
    position: relative;
    width: var(--stage-w); flex: none; min-height: 0;
    display: flex; flex-direction: column;
    border-left: 1px solid var(--border);
    background: var(--surface);
  }
  .stage-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px 10px 16px; flex: none; border-bottom: 1px solid var(--border); }
  .stage-heading .eyebrow { letter-spacing: .12em; }
  .stage-heading .text-button { font-size: 12.5px; padding: 5px 8px; }
  .stage-content { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  .stage-picture { flex: 1; min-height: 0; width: 100%; padding: 0; background: var(--surface-2); display: flex; align-items: center; justify-content: center; overflow: hidden; cursor: zoom-in; }
  .stage-picture > img { width: 100%; height: 100%; object-fit: contain; }
  .stage-picture:disabled { cursor: default; opacity: 1; }
  .stage-empty { padding: 24px; text-align: center; color: var(--muted); font-family: var(--font-serif); }
  .stage-empty > span { display: block; margin-bottom: 12px; font-size: 40px; color: var(--gold); }
  .stage-empty > p { font-size: 16px; line-height: 1.9; }
  .stage-details { flex: none; padding: 14px 16px; display: grid; gap: 8px; }
  .stage-details > select { width: 100%; min-width: 0; font-size: 13px; }
  .stage-scene-state { font-size: 13px; line-height: 1.7; }
  .stage-scene-state summary { color: var(--muted); font-weight: 550; }
  .stage-scene-state p { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 200px; overflow: auto; }
  .stage-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .stage-actions button {
    justify-content: center;
    min-height: 34px; padding: 6px 8px;
    border-radius: 10px; background: var(--surface-2);
    font-size: 12.5px; color: var(--ink-2);
  }
  .stage-actions button:hover:not(:disabled) { background: var(--surface-3); color: var(--accent); }
  .stage-actions button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
  .stage-details > .form-help { margin: 0; }
  .art-status { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }
  .art-status.working { color: var(--accent); }
  .art-status > small { width: 100%; font-size: 12px; line-height: 1.6; }
  .tavern-stage.is-collapsed { width: 52px; }
  .tavern-stage.is-collapsed .stage-heading { padding: 10px 4px; justify-content: center; border-bottom: 0; }
  .tavern-stage.is-collapsed .stage-heading > span, .tavern-stage.is-collapsed .stage-content { display: none; }
  .tavern-stage.is-collapsed .stage-heading .text-button { writing-mode: vertical-rl; padding: 10px 6px; letter-spacing: .2em; }

  /* Artwork, gallery, references */
  .artwork-viewer { display: flex; justify-content: center; background: var(--surface-2); border-radius: 14px; overflow: hidden; }
  .artwork-viewer > img { display: block; max-width: 100%; max-height: 72dvh; object-fit: contain; }
  .draw-reference-preview { display: block; max-width: 100%; max-height: 220px; object-fit: contain; border-radius: 12px; margin: 8px 0 16px; }
  .draw-reference-preview[hidden] { display: none; }
  .character-reference-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin: 12px 0; }
  .character-reference-choice { display: grid; grid-template-columns: 20px 1fr; align-items: center; gap: 6px; min-width: 0; cursor: pointer; padding: 8px; border: 1px solid var(--border); border-radius: 12px; }
  .character-reference-choice:has(input:checked) { border-color: var(--accent-line); background: var(--accent-soft); }
  .character-reference-choice input { width: 18px; height: 18px; margin: 0; }
  .character-reference-choice img { width: 100%; height: 100px; object-fit: contain; border-radius: 8px; }
  .character-reference-choice span { grid-column: 1 / -1; text-align: center; overflow-wrap: anywhere; font-size: 13px; }
  dialog:has(.artwork-viewer, .artwork-grid, #draw-scene-form) { width: min(1000px, calc(100vw - 32px)); }
  .artwork-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 18px; }
  .artwork-grid > .tavern-empty { grid-column: 1 / -1; }
  .artwork-tile { min-width: 0; border: 1px solid var(--border); border-radius: 16px; overflow: hidden; padding-bottom: 12px; background: var(--surface); }
  .artwork-thumb { display: block; width: 100%; padding: 0; background: var(--surface-2); cursor: zoom-in; }
  .artwork-thumb > img { width: 100%; aspect-ratio: 3 / 2; object-fit: contain; }
  .artwork-tile > p { margin: 10px 14px; font-size: 13px; overflow-wrap: anywhere; }
  .artwork-tile > p > small { display: block; font-size: 12px; margin-top: 3px; }
  .artwork-tile .form-actions { margin: 10px 14px 0; justify-content: flex-start; gap: 8px; }
  .artwork-tile .form-actions button { font-size: 12.5px; }
  .artwork-pending { aspect-ratio: 3 / 2; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-size: 13px; }
  .art-prompt { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: 13px; line-height: 1.8; padding: 16px; max-height: 55dvh; overflow: auto; background: var(--surface-2); border-radius: 12px; margin-bottom: 16px; }
  .image-profile-list .resource-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 16px 0; border-bottom: 1px solid var(--border); }
  .image-profile-list .resource-row > div { min-width: 0; overflow-wrap: anywhere; }
  .image-profile-list .resource-row p { font-size: 13px; margin: 4px 0; }
  .image-profile-list .resource-row small { font-size: 12px; }

  /* Character pool */
  dialog:has(#character-pool) { width: min(1080px, calc(100vw - 32px)); }
  .pool-intro { color: var(--muted); margin: -4px 0 22px; line-height: 1.7; }
  .pool-workspace { display: grid; grid-template-columns: minmax(270px, .85fr) minmax(0, 1.25fr); gap: 30px; }
  .pool-compose { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
  .pool-compose textarea { min-height: 160px; resize: vertical; }
  .pool-compose > .form-help { margin: -6px 0 0; }
  .pool-workspace .form-help { background: transparent; padding: 0; margin: 8px 0; line-height: 1.6; }
  .pool-section-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
  .pool-section-heading h3 { margin: 0; font-size: 16px; }
  .pool-section-heading h3 span { font-size: 12.5px; font-weight: 400; margin-left: 5px; color: var(--muted); }
  .pool-profile { display: flex; align-items: end; gap: 10px; }
  .pool-profile .field { flex: 1; min-width: 0; }
  .pool-profile .text-button { flex-shrink: 0; margin-bottom: 8px; }
  .pool-generate { justify-content: center; min-height: 44px; }
  .pool-library { border-left: 1px solid var(--border); padding-left: 28px; min-width: 0; }
  .pool-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 12px; }
  .pool-tile { border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: var(--surface); }
  .pool-tile.is-reference { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
  .pool-picture { display: block; border: 0; padding: 0; width: 100%; background: transparent; cursor: zoom-in; }
  .pool-picture img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--surface-2); }
  .pool-tile-body { display: flex; flex-direction: column; gap: 7px; padding: 12px; }
  .pool-tile-body strong, .pool-tile-body small { overflow-wrap: anywhere; }
  .pool-tile-body .check-row { margin: 3px 0 0; }
  .pool-placeholder { min-height: 140px; display: grid; place-content: center; text-align: center; padding: 16px; color: var(--muted); background: var(--surface-2); }
  .pool-placeholder span, .pool-empty > span { font-size: 32px; color: var(--gold); }
  .pool-placeholder small { overflow-wrap: anywhere; line-height: 1.5; }
  .pool-empty { grid-column: 1 / -1; text-align: center; padding: 56px 16px; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: 16px; }
  .pool-empty h3 { font-size: 15px; font-weight: 550; color: var(--ink-2); }
  .pool-empty p { line-height: 1.7; }
  #pool-selected { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
  .pool-reference-chip { display: flex; align-items: center; gap: 7px; max-width: 100%; padding: 4px 10px 4px 4px; border: 1px solid var(--border); border-radius: 10px; background: transparent; color: var(--ink); cursor: pointer; }
  .pool-reference-chip img { width: 32px; height: 36px; object-fit: cover; border-radius: 6px; }
  .pool-reference-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #pool-qwen summary { color: var(--muted); margin-bottom: 12px; }
  #pool-qwen .field { margin-top: 12px; }
  .pool-prompt-record { white-space: pre-wrap; line-height: 1.7; overflow-wrap: anywhere; }
  #pool-rename { display: flex; align-items: end; gap: 10px; margin: 18px 0; }
  #pool-rename .field { flex: 1; }

  /* Character cards */
  dialog:has(.character-grid, .persona-list, #card-form, #persona-form, #scene-form) { width: min(960px, calc(100vw - 32px)); }
  .card-library-filter { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
  .card-library-filter input { flex: 1; min-width: 0; }
  .card-library-filter > span { flex: none; color: var(--muted); font-size: 13px; }
  .character-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
  .character-grid > .tavern-empty { grid-column: 1 / -1; }
  .character-tile { min-width: 0; overflow: hidden; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); transition: box-shadow .2s, transform .2s; }
  .character-tile:hover { box-shadow: var(--shadow-md); }
  .character-cover-button { border: 0; padding: 0; background: transparent; display: block; width: 100%; overflow: hidden; }
  .card-portrait { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; transition: transform .25s var(--ease); }
  .character-cover-button:hover .card-portrait { transform: scale(1.03); }
  .portrait-placeholder {
    display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 10px;
    background: linear-gradient(150deg, var(--surface-2), var(--surface-3));
    color: var(--gold);
  }
  .portrait-placeholder > span { font-size: 50px; font-family: var(--font-serif); }
  .portrait-placeholder small { font-size: 11px; letter-spacing: .1em; color: var(--muted); }
  .character-tile-body { padding: 14px 16px 16px; display: flex; flex-direction: column; flex: 1; gap: 8px; }
  .card-byline { font-size: 11.5px; color: var(--muted); letter-spacing: .02em; margin: 0; }
  .character-tile h3 { font-size: 16px; line-height: 1.45; margin: 0; overflow-wrap: anywhere; }
  .card-description { font-size: 13px; color: var(--muted); line-height: 1.7; margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .card-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: auto; }
  .card-tags span { padding: 2px 8px; border-radius: var(--r-full); background: var(--surface-2); font-size: 11.5px; color: var(--muted); max-width: 100%; overflow-wrap: anywhere; }
  .card-start { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; margin-top: 6px; }
  .card-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .card-tools > * { font-size: 12.5px; color: var(--muted); padding: 6px 0; text-decoration: none; }
  .card-tools > a:hover { color: var(--accent); text-decoration: underline; }
  .card-identity { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 26px; align-items: start; }
  .card-identity > aside { text-align: center; }
  .card-editor-portrait { display: block; width: 100%; max-height: 310px; aspect-ratio: 3 / 4; object-fit: contain; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; }
  .card-editor-portrait.portrait-placeholder { display: flex; }
  .cover-upload { width: 100%; margin: 10px 0 0; text-align: center; }
  #card-remove-cover { font-size: 13px; margin-top: 6px; }
  .card-identity aside .form-help { font-size: 12px; margin-top: 10px; }
  .card-openings-editor { margin: 22px 0; padding-top: 22px; border-top: 1px solid var(--border); }
  .section-heading { display: flex; justify-content: space-between; align-items: end; gap: 10px; margin-bottom: 10px; }
  .section-heading h3 { font-size: 17px; margin: 5px 0; }
  .section-heading > span { font-size: 12.5px; color: var(--muted); white-space: nowrap; padding-bottom: 5px; }
  .greeting-editor { padding: 14px; border: 1px solid var(--border); border-radius: 14px; margin: 14px 0; background: var(--surface-2); }
  .greeting-editor textarea { width: 100%; resize: vertical; min-height: 110px; line-height: 1.8; }
  .greeting-editor-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
  .greeting-editor-head > strong { font-size: 13px; flex: none; }
  .greeting-editor-head > div { display: flex; flex-wrap: wrap; gap: 3px; justify-content: flex-end; }
  .greeting-editor-head button { font-size: 12.5px; padding: 5px 8px; min-width: 30px; }
  .card-group-greetings, .card-extra { padding: 6px 0; }
  .greeting-preview { border: 1px solid var(--border); border-radius: 16px; padding: 18px; margin: 22px 0 8px; background: var(--surface-2); }
  .greeting-preview-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
  .greeting-preview-head > strong { font-size: 13px; }
  .greeting-navigation { display: flex; align-items: center; gap: 8px; min-width: 0; }
  .greeting-navigation select { min-width: 0; flex: 1; max-width: 240px; font-size: 13px; }
  .greeting-navigation button { min-width: 36px; min-height: 36px; padding: 2px 10px; font-size: 20px; flex: none; }
  .greeting-preview .message-body { max-height: 300px; overflow-y: auto; font-size: 14px; }
  .card-save-actions { position: sticky; bottom: -26px; z-index: 1; margin: 0 -26px -26px; padding: 16px 26px calc(16px + var(--safe-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
  .import-notices { padding: 12px 16px; margin-bottom: 20px; background: color-mix(in srgb, var(--gold) 10%, transparent); border-left: 3px solid var(--gold); border-radius: 6px; font-size: 13px; line-height: 1.7; }
  .import-notices p { margin: 4px 0; }
  .cast-character-preview { grid-column: 1 / -1; display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: 18px; }
  .cast-character-preview:empty { display: none; }
  .cast-portrait { width: 100px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 10px; align-self: start; }
  .cast-portrait.portrait-placeholder > span { font-size: 30px; }
  .cast-portrait.portrait-placeholder > small { display: none; }
  .cast-opening { min-width: 0; }
  .cast-opening > strong { display: block; font-size: 15px; margin: 3px 0 10px; }
  .cast-opening > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
  .cast-greeting-text { font-size: 13px; max-height: 220px; overflow: auto; margin-top: 12px; }
  .opening-controls { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 10px; margin-top: 12px; border-top: 1px solid var(--bubble-border); color: var(--chat-muted); font-size: 12px; }
  .opening-controls .greeting-navigation { font-variant-numeric: tabular-nums; }

  /* Video & storyboards */
  .video-list { display: grid; gap: 12px; }
  .video-tile { padding: 16px; border: 1px solid var(--border); border-radius: 16px; min-width: 0; background: var(--surface); }
  .video-tile-heading { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; justify-content: space-between; }
  .video-tile .form-actions { flex-wrap: wrap; }
  .video-viewer video { display: block; width: 100%; max-height: 65vh; border-radius: 14px; background: #0d1012; }
  #video-form textarea { width: 100%; resize: vertical; }
  .video-plan-overview { padding: 16px; border-radius: 16px; background: var(--surface-2); margin: 16px 0; }
  .video-plan-overview h3, .video-shot h4 { margin: 0 0 8px; }
  .video-shot { padding: 16px; border: 1px solid var(--border); border-radius: 16px; margin: 12px 0; min-width: 0; }
  .video-shot details { margin: 10px 0; }
  .video-shot .field { margin-top: 12px; }
  .video-shot textarea, .video-plan-overview textarea { display: block; width: 100%; }
  .video-shot .form-actions { flex-wrap: wrap; }
  .video-shot p, .video-plan-overview p { overflow-wrap: anywhere; }
  .video-shot [data-shot-time] { font-size: 13px; color: var(--muted); white-space: nowrap; }
  .storyboard-inline { margin: 10px 0 0; padding: 12px; width: 100%; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); }
  .storyboard-thumbs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .storyboard-thumbs button { min-width: 0; padding: 4px; border: 0; border-radius: 10px; background: var(--surface-2); }
  .storyboard-thumbs img { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 7px; }
  .storyboard-thumbs span { display: block; padding: 20px 0; }
  .storyboard-thumbs small { display: block; overflow-wrap: anywhere; }
  #storyboard-editor fieldset { min-width: 0; border: 0; padding: 0; margin: 0; }
  #storyboard-editor label, #storyboard-create label { display: block; margin: 12px 0; }
  #storyboard-editor input:not([type=checkbox]), #storyboard-editor textarea, #storyboard-editor select,
  #storyboard-create textarea, #storyboard-create select { width: 100%; }
  .storyboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 16px 0; }
  .storyboard-shot { min-width: 0; padding: 12px; border: 1px solid var(--border); border-radius: 16px; }
  .storyboard-shot img { width: 100%; border-radius: 10px; }
  .storyboard-shot h3 { margin-top: 0; }
  .storyboard-characters label { font-size: 13px; }
}

/* ───────────────────────── motion ───────────────────────── */
@keyframes typing-pulse { 50% { opacity: .3; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.96) translateY(4px); } }
@keyframes rise-in { from { opacity: 0; transform: translate(-50%, 6px); } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(.985); } }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
@keyframes window-glow { 50% { opacity: .72; } }
@keyframes card-in { from { opacity: 0; transform: translateY(6px); } }

/* ───────────────────────── responsive ───────────────────────── */
@layer responsive {
  @media (max-width: 1180px) {
    :root { --sidebar-w: 260px; }
  }
  @media (max-height: 820px) and (min-width: 761px) {
    .sidebar-note { display: none; }
  }

  @media (min-width: 1101px) {
    .room:has(.tavern-stage:not([hidden])) { --stage-offset: var(--stage-w); }
    .room:has(.tavern-stage.is-collapsed:not([hidden])) { --stage-offset: 52px; }
    .room:has(.tavern-stage:not([hidden])) .composer-area {
      max-width: calc(var(--column) + var(--gutter) * 2 + var(--stage-offset));
      padding-right: calc(var(--gutter) + var(--stage-offset));
    }
  }

  /* Tablets: the story stage moves above the transcript. */
  @media (max-width: 1100px) {
    .timeline-wrap:has(.tavern-stage:not([hidden])) { flex-direction: column; }
    .tavern-stage { order: -1; width: 100%; height: 172px; border-left: 0; border-bottom: 1px solid var(--border); }
    .stage-heading { padding: 4px 8px 4px 16px; }
    .stage-content { flex-direction: row; }
    .stage-picture { flex: 0 0 40%; width: 40%; }
    .stage-details { flex: 1; min-width: 0; padding: 10px 14px; overflow-y: auto; align-content: start; }
    .stage-actions { grid-template-columns: repeat(4, minmax(0, auto)); justify-content: start; }
    .stage-empty { padding: 10px; display: flex; align-items: center; gap: 12px; }
    .stage-empty > span { font-size: 26px; margin: 0; }
    .stage-empty > p { font-size: 13px; }
    .stage-details > .form-help { display: none; }
    .tavern-stage.is-collapsed { width: 100%; height: auto; }
    .tavern-stage.is-collapsed .stage-heading { padding: 2px 8px 2px 16px; justify-content: space-between; }
    .tavern-stage.is-collapsed .stage-heading > span { display: inline; }
    .tavern-stage.is-collapsed .stage-heading .text-button { writing-mode: horizontal-tb; letter-spacing: 0; padding: 5px 8px; }
  }

  /* Phones, including landscape phones */
  @media (max-width: 760px), (max-height: 500px) and (pointer: coarse) {
    :root { --gutter: 14px; --header-h: 56px; }
    body { font-size: 15px; }
    .app { display: block; }
    .room { height: 100vh; height: 100dvh; }
    .mobile-only { display: inline-grid; }

    .sidebar {
      position: fixed; inset: 0 auto 0 0; z-index: 30;
      width: min(86vw, 330px);
      padding: calc(14px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
      transform: translateX(-102%);
      transition: transform .3s var(--ease), box-shadow .3s;
      border-right: 0;
    }
    .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
    .sidebar-shade {
      position: fixed; inset: 0; z-index: 29;
      background: var(--scrim);
      backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
      animation: fade-in .25s ease;
    }
    .sidebar-heading { padding-bottom: 14px; }
    #sidebar-stop { display: flex; margin: 8px 0 2px; min-height: 40px; }
    .sidebar-note { display: none; }
    .nav-more { opacity: 1; }
    .nav-item, .sidebar-action { min-height: 44px; }

    .room-header {
      min-height: calc(var(--header-h) + var(--safe-top));
      padding: var(--safe-top) 8px 0 4px;
      gap: 6px;
    }
    .room-heading { gap: 2px; }
    .title-row { gap: 7px; }
    .title-row h1 { font-size: 16px; }
    .scope-tag { font-size: 10.5px; padding: 1px 7px; }
    .room-heading p { font-size: 11.5px; margin-top: 0; }
    .cost-button { display: none; }
    .header-actions { gap: 2px; }
    .room-header .stop-button { width: 36px; height: 36px; min-height: 0; padding: 0; border-radius: 50%; }
    .room-header .stop-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

    .members-bar { padding: 8px var(--gutter); gap: 6px; }
    .member-chip { min-height: 34px; font-size: 13px; }
    .resident-library { display: none; }
    .members-divider { margin: 0 2px; }

    .context-notice { margin-top: 12px; font-size: 11.5px; padding: 5px 12px; }
    .messages { padding: 14px var(--gutter) 10px; }
    .message { gap: 9px; margin-top: 16px; }
    .message > .avatar { width: 32px; height: 32px; border-radius: 11px; font-size: 15px; }
    .message-main { max-width: calc(100% - 41px); }
    .message.owner .message-main { max-width: 88%; }
    .message-bubble { padding: 10px 14px; }
    .message-actions { top: 25px; }
    .message-actions button { min-width: 38px; height: 34px; }
    .message:hover:not(.is-active) .message-actions,
    .message:focus-within:not(.is-active) .message-actions { opacity: 0; pointer-events: none; }
    .draft-panel { grid-template-columns: 1fr; padding: 0 var(--gutter) 14px; }
    .latest-button { bottom: 10px; }
    .welcome { padding: 36px 8px 48px; }
    .welcome h2 { font-size: 24px; letter-spacing: .04em; }
    .welcome p { font-size: 14px; }

    .composer-area { padding: 4px 10px calc(8px + var(--safe-bottom)); }
    .run-status { padding: 0 8px 6px; min-height: 22px; font-size: 12px; }
    .run-status:not(.running):not(.failed):not(:has(button)) { display: none; }
    .chat-help { font-size: 12.5px; }
    .composer { border-radius: 24px; }
    .composer textarea { min-height: 48px; max-height: 34dvh; padding: 13px 16px 2px; }
    .composer-tools { padding: 4px 6px 6px 8px; }
    .invite-button { max-width: 52vw; }
    .continue-button { width: 38px; height: 38px; min-height: 0; padding: 0; justify-content: center; border-radius: 50%; }
    .continue-button > span { display: none; }
    .continue-button .i { width: 18px; height: 18px; }
    .send-button { width: 40px; height: 40px; min-height: 0; padding: 0; border-radius: 50%; }
    .send-label { display: none; }
    .send-button .i { width: 19px; height: 19px; }
    .composer-footnote { display: none; }
    .composer-footnote:has(.offline) { display: flex; justify-content: center; padding-top: 6px; }
    .composer-footnote:has(.offline) > :not(#connection-label) { display: none; }
    .observer-panel { padding: 12px 12px 12px 16px; gap: 10px; }

    /* Popovers become bottom sheets. */
    .invite-picker {
      position: fixed; z-index: 45;
      inset: auto 0 0 0; width: auto;
      max-height: 78dvh;
      padding: 26px 18px calc(18px + var(--safe-bottom));
      border-radius: 24px 24px 0 0; border-bottom: 0;
      box-shadow: 0 0 0 100vmax var(--scrim), var(--shadow-lg);
      animation: sheet-in .28s var(--ease);
    }
    .invite-picker::before, .message-menu::before {
      content: ""; position: absolute; top: 9px; left: 50%;
      width: 38px; height: 4px; margin-left: -19px;
      border-radius: 4px; background: var(--border-strong);
    }
    .message-menu {
      inset: auto 8px calc(8px + var(--safe-bottom)) 8px !important;
      width: auto; max-width: none;
      padding: 22px 8px 8px;
      border-radius: 22px;
      box-shadow: 0 0 0 100vmax var(--scrim), var(--shadow-lg);
      animation: sheet-in .26s var(--ease);
    }
    .message-menu button { min-height: 50px; font-size: 15.5px; padding: 10px 14px; }
    .toast { top: calc(12px + var(--safe-top)); bottom: auto; animation-name: toast-down; }

    dialog {
      width: 100%; max-width: 100%;
      max-height: calc(100dvh - 24px - var(--safe-top));
      margin: 0; inset: auto 0 0 0;
      border-radius: 24px 24px 0 0; border-bottom: 0;
    }
    dialog[open] { animation: sheet-in .3s var(--ease); }
    .modal-head { padding: 22px 12px 12px 18px; }
    .modal-head::before {
      content: ""; position: absolute; top: 8px; left: 50%;
      width: 38px; height: 4px; margin-left: -19px;
      border-radius: 4px; background: var(--border-strong);
    }
    .modal-head h2 { font-size: 18px; }
    .modal-head-actions .stop-button { width: 34px; height: 34px; min-height: 0; padding: 0; border-radius: 50%; }
    .modal-head-actions .stop-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    #modal-body { padding: 16px 18px calc(22px + var(--safe-bottom)); }
    .quick-submit { bottom: calc(-22px - var(--safe-bottom)); margin: 16px -18px calc(-22px - var(--safe-bottom)); padding: 12px 18px calc(12px + var(--safe-bottom)); grid-template-columns: 1fr; gap: 8px; }
    .quick-submit > button { width: 100%; }
    .quick-accounting { grid-template-columns: 1fr; gap: 6px; }
    .card-save-actions { bottom: calc(-22px - var(--safe-bottom)); margin: 0 -18px calc(-22px - var(--safe-bottom)); padding: 14px 18px calc(14px + var(--safe-bottom)); }
    .form-actions { margin-top: 20px; }
    .tool-list button { min-height: 52px; }

    .login-view { display: flex; flex-direction: column; }
    .login-art { min-height: 34dvh; padding: calc(24px + var(--safe-top)) 24px 24px; }
    .login-art-window { top: 38%; width: 96px; height: 122px; padding: 8px; gap: 5px; }
    .login-art-glow { top: 38%; width: 260px; height: 260px; }
    .art-line { font-size: 22px; }
    .art-footer { margin-top: 10px; font-size: 10px; }
    .login-panel { flex: 1; align-items: flex-start; padding: 32px 24px calc(32px + var(--safe-bottom)); }
    .login-inner .wordmark { margin-bottom: 28px; }
    .login-inner h1 { font-size: 32px; }
    .login-note { margin-top: 28px; }

    .tavern-stage { height: 152px; }
    .stage-heading { padding: 0 4px 0 14px; }
    .stage-heading .text-button { min-height: 32px; }
    .stage-picture { flex-basis: 36%; width: 36%; }
    .stage-details { padding: 8px 10px; gap: 6px; }
    .stage-details > select { min-height: 34px; padding-block: 4px; font-size: 13px; }
    .stage-details > .form-help, .stage-scene-state { display: none; }
    .stage-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
    .stage-actions button { min-height: 30px; padding: 4px 6px; font-size: 12px; }

    .character-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .character-tile-body { padding: 12px; }
    .card-identity { grid-template-columns: 140px minmax(0, 1fr); gap: 18px; }
    .greeting-editor-head { align-items: start; }
    .greeting-preview { padding: 12px; }
    .pool-workspace { grid-template-columns: 1fr; gap: 24px; }
    .pool-library { border-left: 0; border-top: 1px solid var(--border); padding: 22px 0 0; }
    .pool-grid { gap: 10px; }
    .pool-tile-body { padding: 10px; }
    .cast-row { grid-template-columns: 1fr; gap: 8px; }
    .lore-flags { gap: 8px 14px; }
  }

  @media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; gap: 14px; }
    .field.full { grid-column: auto; }
    .resident-card { align-items: stretch; flex-direction: column; gap: 10px; }
    .resident-card .form-actions { justify-content: flex-end; }
    .persona-identity { grid-template-columns: 1fr; gap: 20px; }
    .persona-identity > aside { display: grid; grid-template-columns: 72px minmax(0, 1fr); column-gap: 16px; justify-items: start; }
    #persona-avatar-preview { grid-row: 1 / 4; width: 72px; }
    .persona-identity > aside small { text-align: left; }
    .persona-tile { grid-template-columns: 52px minmax(0, 1fr); padding: 14px; gap: 12px; }
    .scene-persona { padding: 16px; }
    .setting-item { flex-wrap: wrap; }
    .provider-actions { max-width: none; flex-basis: 100%; justify-content: flex-start; }
    .provider-actions small { text-align: left; }
    .storyboard-grid { grid-template-columns: 1fr; }
    .storyboard-thumbs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }

  @media (max-width: 520px) {
    .artwork-grid { grid-template-columns: 1fr; }
    .image-profile-list .resource-row { align-items: start; flex-direction: column; gap: 4px; }
    .image-profile-list .form-actions { margin-top: 6px; }
  }

  @media (max-width: 480px) {
    .character-grid { grid-template-columns: 1fr; }
    .card-portrait { aspect-ratio: 4 / 3; object-position: center 25%; }
    .card-identity { grid-template-columns: 1fr; }
    .card-identity > aside { width: 150px; justify-self: center; }
    .card-library-filter { gap: 8px; }
    .cast-character-preview { grid-template-columns: 66px minmax(0, 1fr); gap: 12px; }
    .cast-portrait { width: 66px; }
    .greeting-navigation { gap: 4px; }
    .greeting-navigation button { min-height: 40px; min-width: 38px; }
    .greeting-editor { padding: 10px; }
    .greeting-editor-head > div { gap: 0; }
    .greeting-editor-head button { min-height: 36px; padding: 5px; }
  }

  @media (max-width: 370px) {
    .scope-tag { display: none; }
    .invite-button { max-width: 44vw; }
  }

  /* Short windows (landscape phones, split screens) */
  @media (max-height: 560px) {
    .room-header { min-height: 48px; }
    .room-heading p { display: none; }
    .members-bar { padding-block: 5px; }
    .composer-area { padding-block: 2px 6px; }
    .composer textarea { min-height: 42px; max-height: 72px; padding-block: 9px 2px; }
    .composer-tools { padding-block: 2px 4px; }
    .composer-footnote { display: none; }
    .run-status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .reply-preview { margin-top: 6px; padding-block: 2px; }
    .tavern-stage:not(.is-collapsed) { height: 118px; }
  }

  @media (hover: none), (pointer: coarse) {
    .send-shortcut { display: none; }
    .nav-more { opacity: 1; }
    .message:hover:not(.is-active) .message-actions,
    .message:focus-within:not(.is-active) .message-actions { opacity: 0; pointer-events: none; }
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: .01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: .01ms !important;
      scroll-behavior: auto !important;
    }
  }
}
@keyframes toast-down { from { opacity: 0; transform: translate(-50%, -8px); } }

.compute-nodes { display: grid; gap: 12px; margin: 16px 0; }
.compute-node { border: 1px solid var(--border, #ddd); border-radius: 12px; padding: 16px; overflow-wrap: anywhere; }
.compute-badge { font-size: .8rem; color: var(--muted, #777); }
.compute-badge.online { color: #34855c; }
@media (max-width: 600px) { .compute-node { padding: 12px; } .compute-node .video-tile-heading { flex-wrap: wrap; } }
