/*
 * Bundled Courier Prime (OFL, https://quoteunquoteapps.com/courierprime/).
 * Final Draft, WriterDuet, Highland, and Fade In all ship Courier Prime as
 * the screenplay face. We bundle it so the editor's page wrapping and
 * pagination match those tools exactly — falling back to a system Courier
 * is what was causing the editor view to diverge from the exported PDF.
 */
@font-face {
  font-family: 'Courier Prime';
  src: url('../assets/fonts/courier-prime/Courier%20Prime.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: 'Courier Prime';
  src: url('../assets/fonts/courier-prime/Courier%20Prime%20Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: 'Courier Prime';
  src: url('../assets/fonts/courier-prime/Courier%20Prime%20Italic.ttf') format('truetype');
  font-weight: 400;
  font-style: italic;
  font-display: block;
}
@font-face {
  font-family: 'Courier Prime';
  src: url('../assets/fonts/courier-prime/Courier%20Prime%20Bold%20Italic.ttf')
    format('truetype');
  font-weight: 700;
  font-style: italic;
  font-display: block;
}

/*
 * Bundled Inter 4 (OFL, https://github.com/rsms/inter) for the UI chrome
 * only — never the page, which stays Courier Prime. Bundled rather than
 * left to the system stack so Mac and Windows writers get the same face and
 * widths: --font-ui named 'Inter' before it shipped here, so only writers
 * who had installed Inter themselves got it. The opsz files carry both the
 * weight and optical-size axes, so headings draw from Inter Display
 * (font-optical-sizing: auto). Split into the latin / latin-ext subsets
 * (unicode ranges from Fontsource) so accented names stay in Inter.
 */
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/inter/inter-latin-opsz-normal.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: block;
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/inter/inter-latin-ext-opsz-normal.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: block;
  unicode-range:
    U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/inter/inter-latin-opsz-italic.woff2') format('woff2');
  font-weight: 100 900;
  font-style: italic;
  font-display: block;
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/inter/inter-latin-ext-opsz-italic.woff2') format('woff2');
  font-weight: 100 900;
  font-style: italic;
  font-display: block;
  unicode-range:
    U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}

/*
 * Bundled Figtree (OFL, https://github.com/erikdkennedy/figtree) for the
 * non-printing annotations that live inside the page (sections, synopses,
 * notes, the page-break label, the dual chip) and the element menus over
 * it — --font-page-ui. It was the UI face before Inter, and those blocks are
 * measured by editor pagination (offsetHeight), so moving them to Inter
 * would shift page breaks. Variable weight 300–900, latin / latin-ext.
 */
@font-face {
  font-family: 'Figtree';
  src: url('../assets/fonts/figtree/figtree-latin-wght-normal.woff2') format('woff2');
  font-weight: 300 900;
  font-style: normal;
  font-display: block;
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Figtree';
  src: url('../assets/fonts/figtree/figtree-latin-ext-wght-normal.woff2') format('woff2');
  font-weight: 300 900;
  font-style: normal;
  font-display: block;
  unicode-range:
    U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}
@font-face {
  font-family: 'Figtree';
  src: url('../assets/fonts/figtree/figtree-latin-wght-italic.woff2') format('woff2');
  font-weight: 300 900;
  font-style: italic;
  font-display: block;
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Figtree';
  src: url('../assets/fonts/figtree/figtree-latin-ext-wght-italic.woff2') format('woff2');
  font-weight: 300 900;
  font-style: italic;
  font-display: block;
  unicode-range:
    U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}

/*
 * Theme tokens.
 *
 *   - :root holds the dark palette (the default) and every token that does
 *     not change with the theme: type, radius, motion, density.
 *   - @media (prefers-color-scheme: light) overrides for OS-driven
 *     light mode (applied unless an explicit override is set).
 *   - html[data-theme="light"|"dark"] is the manual override layer.
 *     Selecting "System" in Settings removes data-theme, letting the
 *     media query take effect.
 *
 * Three more attributes on <html> come from Settings → Appearance
 * (js/shared/appearance.js): data-accent, data-density, data-motion. Each
 * only re-points tokens defined here, so no component rule names a theme,
 * an accent or a density.
 *
 * The palette is warm monochrome with three low-saturation status hues
 * (green/orange/red) preserved as functional signals. The chrome sits on
 * the desk colour (--bg-shell) with no dividing lines; the page is the
 * brightest object in the window.
 */
:root,
html[data-theme='dark'] {
  /* Native pieces the page doesn't draw itself (checkboxes, the date and
   * select pop-ups, Windows scrollbars on unstyled scrollers) follow the
   * theme instead of staying light on a dark window. */
  color-scheme: dark;
  --bg-base: #191817; /* the desk the page sits on, and the chrome around it */
  --bg-surface: #1f1e1c; /* panels: chat pane, dialogs, settings */
  --bg-elevated: #282725; /* cards, inputs, menus */
  --bg-hover: #2e2d2a;
  --bg-selected: #35332f; /* active/selected rows (sidebar etc.) */
  --bg-page: #222120; /* the script page */
  --page-text: #d4d4ce; /* script body text — dimmed off-white, easier on the eyes than --text-primary (~11:1) */
  /* Script element tonal hierarchy (screen only). A subtle brightness ladder
   * — scene > character > dialogue > action > transition > parenthetical — so
   * the element types read as distinct without color-coding the body (keeps
   * print fidelity + leaves hue free for revision/collab conventions). Print/
   * PDF export gates these all back to #000 (see body.printing .screenplay-page). */
  --el-scene: #f7f7f2;
  --el-character: #eeeee9;
  --el-dialogue: #d8d8d2;
  --el-action: #c0c0ba;
  --el-transition: #c8c8c2;
  --el-parenthetical: #93938c;
  --border: #353430;
  --border-soft: #2a2927;
  --board-dot: #2a2927;
  --control-border: #77756f; /* WCAG 1.4.11: form-field boundary ≥3:1 (decorative --border stays subtle) */
  --titlebar-btn-border: #45433e; /* the control sits on its own --bg-elevated fill, so the edge is decorative */
  /* Scrollbar thumb: idle must clear 3:1 against --bg-base (the editor desk),
   * NOT the form-field surfaces --control-border was tuned for — the two
   * diverge in light/parchment. Pinned by test/ui/editor-scrollbar.spec.js. */
  --scrollbar-thumb: #77756f;
  --scrollbar-thumb-hover: #9a978e;
  --text-primary: #ecece7;
  --text-secondary: #bdbbb4;
  --text-muted: #9a978e;
  /* Graphite unless the writer picked an accent (Settings → Appearance sets
   * data-accent, which supplies --accent-d / --accent-l). */
  --accent: var(--accent-d, #ecece7);
  --accent-text: #141413;
  --btn-primary-hover: color-mix(in srgb, var(--accent) 90%, #000);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.25), 0 10px 28px rgba(0, 0, 0, 0.36);
  --shadow-3:
    0 0 0 1px rgba(255, 250, 235, 0.07), 0 8px 20px rgba(0, 0, 0, 0.3),
    0 28px 64px rgba(0, 0, 0, 0.5);
  --page-edge: rgba(255, 250, 235, 0.08); /* 1px page-card frame; HC overrides with a solid edge */
  --shadow-page: 0 0 0 1px var(--page-edge), 0 12px 36px rgba(0, 0, 0, 0.32);
  --overlay-scrim: rgba(0, 0, 0, 0.5);

  /* The writer's own chat message: a surface one step above the panel,
   * never a light slab. A light-grey bubble was the largest bright area in
   * the dark window (calm-chrome.spec.js measures it). */
  --user-bubble-bg: #302f2c;
  --user-bubble-border: transparent;
  --user-bubble-text: #ecece7;
  /* The solid tag ("Recommended" on a plan, "Pro" on a locked History
   * row). On a dark surface it is raised, not the accent: the accent there
   * is ivory, and a column of ivory tags in the side panel is the light
   * slab the bubble rule above exists to prevent. Light themes and High
   * Contrast re-point both to the accent pair. */
  --tag-solid-bg: color-mix(in srgb, var(--text-primary) 20%, var(--bg-elevated));
  --tag-solid-text: var(--text-primary);
  /* Long-form reading text (a chat answer): a step softer than
   * --text-primary, which is for titles and the line being acted on. A
   * column of prose at headline brightness is what glares. Set in every
   * theme block. */
  --text-body: #d6d4cd;

  /* The picked segment of a segmented control sitting on --segment-track
   * (the view switch). Dark needs its own value: --bg-elevated is the very
   * shade the 7% track resolves to here, so the picked segment vanished.
   * Every theme block sets this token; view-switch-contrast.spec.js
   * measures the result in all five. */
  --segment-thumb: color-mix(in srgb, var(--text-primary) 20%, var(--bg-base));

  /* Status hues — slate-warm so they sit naturally on the palette. */
  --green: #8fae8f; /* 6.8:1 on --bg-surface — 11px status text needs 4.5 */
  --orange: #b08458;
  --red: #c07070;
  --banner-warn-bg: #8a5a2e; /* darker than --orange so white banner text ≥4.5:1 in dark */
  --banner-ok-bg: #4f6e4f; /* darker than --green so white banner text ≥4.5:1 in dark */

  --act-1: #40403e;
  --act-2: #666663;
  --act-3: #91918d;
  --diff-removed-bg: rgba(176, 132, 88, 0.1);
  --diff-added-bg: rgba(110, 138, 110, 0.14);
}

:root {
  /* The chrome field (top bar, rail, scene list, status bar). The desk
   * colour by default so the window reads as one surface; a theme that
   * needs visible structure sets --shell-divider (High Contrast). */
  --bg-shell: var(--bg-base);
  --shell-divider: transparent;
  /* The one line the chrome does draw: a hairline setting each side pane
   * (scene list, chat) off from the script between them. */
  --pane-divider: var(--border);
  /* Scrollbar fade, for the board's own DOM scrollbars; the native ones are
   * faded by js/shared/scrollbars.js with the same two numbers
   * (scrollbars.test.js fails if they drift). */
  --scrollbar-fade-in: 120ms;
  --scrollbar-fade-out: 450ms;
  accent-color: var(--accent); /* native checkboxes and radios */

  /* Derived from the accent so a picked accent carries through pressed
   * borders, tints, list washes, toggles and focus without per-accent
   * rules. Focus uses the accent at full strength: a mix fails the 3:1
   * non-text contrast floor for the coloured accents. */
  --accent-border: color-mix(in srgb, var(--accent) 50%, var(--bg-surface));
  --accent-bg: color-mix(in srgb, var(--accent) 9%, var(--bg-surface));
  --hover-wash: color-mix(in srgb, var(--accent) 6%, transparent);
  --selected-wash: color-mix(in srgb, var(--accent) 12%, transparent);
  --focus-color: var(--accent);
  --segment-track: color-mix(in srgb, var(--text-primary) 7%, transparent);
  --segment-ring: color-mix(in srgb, var(--text-primary) 9%, transparent);
  --focus-ring: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--focus-color);
  --accent-soft: var(--hover-wash);

  --font-script: 'Courier Prime', 'Courier New', monospace;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  --font-page-ui:
    'Figtree', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* Chrome rhythm scale (theme-invariant; px/unitless, so defined once).
   * --leading-ui is the base chrome line-height — the script page is
   * insulated because .screenplay-page sets its own `line-height: normal`.
   * The two px values match the dominant real chrome row paddings. */
  --leading-ui: 1.45;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;

  /* Chrome type scale (Oct 2026 refresh): every UI font-size is one of these
   * ten steps; the 30 px values they replaced included 9.5 / 10.5 / 11.5 /
   * 12.5 / 13.5 half-steps no one could tell apart. The page never uses
   * them — it sets its own 12pt Courier Prime. */
  --text-2xs: 10px;
  --text-xs: 11px;
  --text-sm: 12px;
  --text-md: 13px;
  --text-lg: 14px;
  --text-xl: 16px;
  --text-2xl: 18px;
  /* The wordmark beside the logo, at lastslate.com's nav size. */
  --text-wordmark: 21px;
  --text-3xl: 22px;
  --text-display: 28px;
  --text-hero: 34px;
  /* The signed-out headline only (lastslate.com's hero, owner's call Nov
     2026), and its size in a short window. A phone-width window uses
     --text-hero. */
  --text-poster: 52px;
  --text-poster-compact: 38px;
  --tracking-caps: 0.06em;

  /* Chrome weights. Regular for what is read (lists, descriptions), medium
   * for what is pressed or picked, strong only for a surface's own title.
   * Inter is variable, so 560 is a real cut: semibold without the shout.
   * Never used inside the page — its annotations are measured by
   * pagination and a weight change moves line wraps. */
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-strong: 560;

  /* One radius scale. xs: chips and marks; sm: small controls; md: buttons,
   * inputs, list rows; lg: cards, menus, popovers; xl: dialogs and the
   * composer; 2xl: the sign-in card (lastslate.com's hero, after
   * claude.ai/login); pill: switches, badges, avatars. */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 7px;
  --radius-lg: 10px;
  --radius-xl: 14px;
  --radius-2xl: 32px;
  --radius-pill: 999px;

  /* Motion. Three durations and two curves; nothing in the chrome times
   * itself with a literal. --ease-out decelerates into place (things that
   * appear, hover and press); --ease-move is for things that travel. */
  --dur-1: 90ms;
  --dur-2: 150ms;
  --dur-3: 220ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-move: cubic-bezier(0.3, 0, 0.1, 1);

  /* Density (Settings → Appearance). Comfortable here; compact re-points
   * the same six tokens further down. The top bar is not in the set: its
   * 44px is the macOS traffic-light row. */
  --bar-h: 44px; /* panel header rows: Scenes, the chat tabs */
  --statusbar-h: 34px;
  --row-pad-y: 7px; /* list rows: scenes, chat sessions */
  --nav-row-h: 32px; /* settings nav rows */
  --card-pad-y: 13px; /* settings rows */
  --menu-pad-y: 6px; /* menu items */

  /* Brand accent (lastslate.com palette). Theme-invariant. Two jobs:
   * (1) brand moments (launch splash); (2) the deliberate "attention"
   * accent for the review-comments feature — comment/finding
   * badges, the toolbar comment count, the active comment card, and the
   * comment-text highlight. NOT a general primary-action color (--accent
   * owns that; solid-pink buttons fail AA white-on-pink at small
   * sizes) and NOT used for severity (semantic --red/--orange/grey).
   * Deliberately NOT overridden in light/data-theme blocks.
   * ≥3:1 against both --bg-base values (WCAG 1.4.11). */
  --brand-pink: #ff2e8b;

  /* The fox (js/shared/mascot.js) is the logo mark with eyes, so it wears
   * the logo's pink, and like the logo it is the same in every theme. */
  --mascot-fur: var(--brand-pink);
  --mascot-eye: #ffffff;
  --mascot-pupil: #1f1f1e;

  /* Writing streak. The week row ramps from soft pink to a fiery red on
   * the newest earned day; the modal opens under a metallic gold band.
   * Fixed values in every theme (they sit on the streak modal's own
   * surfaces, never on body text), so no per-theme overrides. */
  --streak-fire: #ff2a1a;
  --streak-ramp-0: #ff7eb6;
  --streak-ramp-1: #ff64a3;
  --streak-ramp-2: #ff4b8f;
  --streak-ramp-3: #ff4275;
  --streak-ramp-4: #ff4a5a;
  --streak-ramp-5: #ff4a3d;
  --streak-gold: linear-gradient(
    90deg,
    #8f6a1f 0%,
    #d4a84b 22%,
    #f3dc8c 50%,
    #d4a84b 78%,
    #8f6a1f 100%
  );
}

/* Light mode — warm ivory. Two selectors carry the same block: the OS
 * preference when no theme is forced, and the manual override. */
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg-base: #efede6; /* warm desk; the page is the only white object on it */
    --bg-surface: #f7f6f1;
    --bg-elevated: #fffefb;
    --bg-hover: #e8e5dc;
    --bg-selected: #dfdcd1; /* darker than hover so it reads as "picked" */
    --bg-page: #ffffff;
    --page-text: #33332c; /* script body text — faintly warm charcoal, softer than --text-primary (~12:1) */
    /* Script element tonal hierarchy — light mirror of the dark ladder. */
    --el-scene: #14140f;
    --el-character: #1f1f1e;
    --el-dialogue: #2a2a24;
    --el-action: #5a5a52;
    --el-transition: #44443f;
    --el-parenthetical: #6f6f6a;
    --border: #dedbd0;
    --border-soft: #e7e4da;
    --board-dot: #c9c6bb; /* board dot grid — darker than --bg-base; --border-soft is lighter and vanished */
    --control-border: #8b887f;
    --titlebar-btn-border: #dedbd0;
    --scrollbar-thumb: #7d7a72; /* 3:1 vs --bg-base, not the white form fields */
    --scrollbar-thumb-hover: #67645d;
    --text-primary: #1f1f1e; /* deep charcoal — kinder than pure black */
    --text-secondary: #4d4b46;
    --text-muted: #696660;
    --accent: var(--accent-l, #1f1f1e);
    --accent-text: #ffffff;
    --btn-primary-hover: color-mix(in srgb, var(--accent) 88%, #fff);
    --shadow-1: 0 1px 2px rgba(41, 37, 28, 0.06);
    --shadow-2: 0 1px 2px rgba(41, 37, 28, 0.05), 0 8px 24px rgba(41, 37, 28, 0.09);
    --shadow-3:
      0 0 0 1px rgba(41, 37, 28, 0.06), 0 6px 16px rgba(41, 37, 28, 0.06),
      0 24px 56px rgba(41, 37, 28, 0.16);
    --page-edge: rgba(41, 37, 28, 0.08); /* 1px page-card frame; HC overrides with a solid edge */
    --shadow-page:
      0 0 0 1px var(--page-edge), 0 1px 2px rgba(41, 37, 28, 0.04),
      0 10px 30px rgba(41, 37, 28, 0.07);
    --overlay-scrim: rgba(38, 33, 24, 0.3);

    --user-bubble-bg: #e6e3d9;
    --user-bubble-border: transparent;
    --user-bubble-text: #1f1f1e;
    --tag-solid-bg: var(--accent);
    --tag-solid-text: var(--accent-text);
    --text-body: #2e2d29;
    --segment-thumb: var(--bg-elevated);

    --green: #4a7550;
    --orange: #86602f;
    --red: #8a4646;
    --banner-warn-bg: #86602f;
    --banner-ok-bg: #4a7550;

    --act-1: #bfbfba;
    --act-2: #91918d;
    --act-3: #5f5f5c;
    --diff-removed-bg: rgba(138, 100, 56, 0.08);
    --diff-added-bg: rgba(79, 122, 79, 0.1);
  }
}

html[data-theme='light'] {
  color-scheme: light;
  --bg-base: #efede6; /* warm desk; the page is the only white object on it */
  --bg-surface: #f7f6f1;
  --bg-elevated: #fffefb;
  --bg-hover: #e8e5dc;
  --bg-selected: #dfdcd1; /* darker than hover so it reads as "picked" */
  --bg-page: #ffffff;
  --page-text: #33332c; /* script body text — faintly warm charcoal, softer than --text-primary (~12:1) */
  /* Script element tonal hierarchy — light mirror of the dark ladder. */
  --el-scene: #14140f;
  --el-character: #1f1f1e;
  --el-dialogue: #2a2a24;
  --el-action: #5a5a52;
  --el-transition: #44443f;
  --el-parenthetical: #6f6f6a;
  --border: #dedbd0;
  --border-soft: #e7e4da;
  --board-dot: #c9c6bb; /* board dot grid — darker than --bg-base; --border-soft is lighter and vanished */
  --control-border: #8b887f;
  --titlebar-btn-border: #dedbd0;
  --scrollbar-thumb: #7d7a72; /* 3:1 vs --bg-base, not the white form fields */
  --scrollbar-thumb-hover: #67645d;
  --text-primary: #1f1f1e; /* deep charcoal — kinder than pure black */
  --text-secondary: #4d4b46;
  --text-muted: #696660;
  --accent: var(--accent-l, #1f1f1e);
  --accent-text: #ffffff;
  --btn-primary-hover: color-mix(in srgb, var(--accent) 88%, #fff);
  --shadow-1: 0 1px 2px rgba(41, 37, 28, 0.06);
  --shadow-2: 0 1px 2px rgba(41, 37, 28, 0.05), 0 8px 24px rgba(41, 37, 28, 0.09);
  --shadow-3:
    0 0 0 1px rgba(41, 37, 28, 0.06), 0 6px 16px rgba(41, 37, 28, 0.06),
    0 24px 56px rgba(41, 37, 28, 0.16);
  --page-edge: rgba(41, 37, 28, 0.08); /* 1px page-card frame; HC overrides with a solid edge */
  --shadow-page:
    0 0 0 1px var(--page-edge), 0 1px 2px rgba(41, 37, 28, 0.04), 0 10px 30px rgba(41, 37, 28, 0.07);
  --overlay-scrim: rgba(38, 33, 24, 0.3);

  --user-bubble-bg: #e6e3d9;
  --user-bubble-border: transparent;
  --user-bubble-text: #1f1f1e;
  --tag-solid-bg: var(--accent);
  --tag-solid-text: var(--accent-text);
  --text-body: #2e2d29;
  --segment-thumb: var(--bg-elevated);

  --green: #4a7550;
  --orange: #86602f;
  --red: #8a4646;
  --banner-warn-bg: #86602f;
  --banner-ok-bg: #4a7550;

  --act-1: #bfbfba;
  --act-2: #91918d;
  --act-3: #5f5f5c;
  --diff-removed-bg: rgba(138, 100, 56, 0.08);
  --diff-added-bg: rgba(79, 122, 79, 0.1);
}

/* Accents (Settings → Appearance). Graphite is the default and needs no
 * rule. Each accent is a pair: -l for light surfaces (white label ≥ 5.8:1),
 * -d for dark (dark label ≥ 8.9:1). The three complete themes below
 * (High Contrast, Midnight, Parchment) keep their own accent. Brand pink is
 * not offered: it is the logo and the comments accent only. */
/* The swatch for the default, so the picker can draw it like the rest. */
[data-swatch='graphite'] {
  --accent-l: #1f1f1e;
  --accent-d: #ecece7;
}
html[data-accent='ink'],
[data-swatch='ink'] {
  --accent-l: #2f5aa3;
  --accent-d: #9dbaf0;
}
html[data-accent='harbor'],
[data-swatch='harbor'] {
  --accent-l: #236670;
  --accent-d: #8ccbd1;
}
html[data-accent='moss'],
[data-swatch='moss'] {
  --accent-l: #3b6a4c;
  --accent-d: #9cc8a9;
}
html[data-accent='clay'],
[data-swatch='clay'] {
  --accent-l: #a04e2d;
  --accent-d: #e6a688;
}
html[data-accent='plum'],
[data-swatch='plum'] {
  --accent-l: #69499a;
  --accent-d: #c5b0ec;
}

/* Signed out (the sign-in column and title page, and on the web the page
 * below them) the window is Lastslate's, not yet the writer's: it wears
 * graphite whatever accent Settings → Appearance holds (owner, Nov 2026).
 * Clearing the pair lets the theme blocks' own graphite fallback through,
 * and every token computed from --accent on :root is declared again here,
 * or it would keep the value <html> computed. The three complete themes
 * keep their own accent and are left alone (:where keeps this rule weaker
 * than the light-theme ones below). web-surfaces.test.js fails if an
 * accent token is missing from this list. */
html:not(:where([data-theme='high-contrast'], [data-theme='midnight'], [data-theme='parchment']))
  .welcome.is-split {
  --accent-l: initial;
  --accent-d: initial;
  --accent: var(--accent-d, #ecece7);
  --btn-primary-hover: color-mix(in srgb, var(--accent) 90%, #000);
  accent-color: var(--accent);
  --accent-border: color-mix(in srgb, var(--accent) 50%, var(--bg-surface));
  --accent-bg: color-mix(in srgb, var(--accent) 9%, var(--bg-surface));
  --hover-wash: color-mix(in srgb, var(--accent) 6%, transparent);
  --selected-wash: color-mix(in srgb, var(--accent) 12%, transparent);
  --focus-color: var(--accent);
  --focus-ring: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--focus-color);
  --accent-soft: var(--hover-wash);
  --toggle-on: var(--accent);
}
@media (prefers-color-scheme: light) {
  html:not([data-theme]) .welcome.is-split {
    --accent: var(--accent-l, #1f1f1e);
    --btn-primary-hover: color-mix(in srgb, var(--accent) 88%, #fff);
    --tag-solid-bg: var(--accent);
    --tag-solid-text: var(--accent-text);
  }
}
html[data-theme='light'] .welcome.is-split {
  --accent: var(--accent-l, #1f1f1e);
  --btn-primary-hover: color-mix(in srgb, var(--accent) 88%, #fff);
  --tag-solid-bg: var(--accent);
  --tag-solid-text: var(--accent-text);
}
@media (prefers-color-scheme: light) {
  html:not([data-theme]) .welcome.is-split {
    --welcome-card: color-mix(in srgb, var(--bg-base) 40%, #fff);
    --welcome-field: color-mix(in srgb, var(--text-primary) 3%, transparent);
    --welcome-field-line: color-mix(in srgb, var(--text-primary) 10%, transparent);
  }
}
html[data-theme='light'] .welcome.is-split,
html[data-theme='parchment'] .welcome.is-split {
  --welcome-card: color-mix(in srgb, var(--bg-base) 40%, #fff);
  --welcome-field: color-mix(in srgb, var(--text-primary) 3%, transparent);
  --welcome-field-line: color-mix(in srgb, var(--text-primary) 10%, transparent);
}
html[data-theme='high-contrast'] .welcome.is-split {
  --welcome-card-line: var(--border);
  --welcome-field-line: var(--border);
}

html[data-density='compact'] {
  --bar-h: 36px;
  --statusbar-h: 28px;
  --row-pad-y: 4px;
  --nav-row-h: 28px;
  --card-pad-y: 9px;
  --menu-pad-y: 4px;
}

/* Reduce motion on request (Settings → Appearance), for writers whose OS
 * setting is off or out of reach. The OS preference is honoured by the
 * prefers-reduced-motion blocks beside each animation; this is the same
 * outcome by attribute, as one rule. */
html[data-motion='reduced'] *,
html[data-motion='reduced'] *::before,
html[data-motion='reduced'] *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

/* High Contrast — accessibility theme (WCAG AAA target). Pure black surfaces,
 * white text, strong borders. The element ladder leans on LIGHTNESS + weight,
 * not hue, so it stays legible for colorblind / low-vision users. Every text
 * token clears 7:1 on black. Print still gates --el-* to #000 (body.printing). */
html[data-theme='high-contrast'] {
  /* Stated here, not inherited: with the OS set to light, the
     prefers-color-scheme block's :root would otherwise hand this dark theme
     the light values of both. */
  color-scheme: dark;
  --segment-thumb: color-mix(in srgb, var(--text-primary) 26%, var(--bg-base));
  --bg-base: #000000;
  --bg-surface: #0a0a0a;
  --bg-elevated: #1a1a1a;
  --bg-hover: #2a2a2a;
  --bg-selected: #2f2f2f;
  --bg-page: #000000;
  --shell-divider: var(--border); /* HC keeps every panel edge drawn */
  --shadow-1: 0 0 0 1px #8a8a8a;
  --shadow-2: 0 0 0 1px #8a8a8a, 0 10px 28px rgba(0, 0, 0, 0.6);
  --shadow-3: 0 0 0 1px #cfcfcf, 0 28px 64px rgba(0, 0, 0, 0.7);
  --shadow-page: 0 0 0 1px var(--page-edge);
  --overlay-scrim: rgba(0, 0, 0, 0.72);
  --page-edge: #8a8a8a; /* HC: page and desk are both pure black, so the card
                         * needs an explicit edge or it vanishes. Other themes
                         * leave this unset → var() fallback is transparent. */
  --page-text: #ffffff;
  --el-scene: #ffffff;
  --el-character: #ffffff;
  --el-dialogue: #ffffff;
  --el-action: #cfcfcf; /* ~16:1 on black — clearly dimmer than #fff, still AAA */
  --el-transition: #ffffff;
  --el-parenthetical: #a9a9a9; /* dimmest rung, ~10:1 on black */
  --border: #8a8a8a; /* strong boundaries — HC needs visible structure */
  --border-soft: #5a5a5a;
  --board-dot: #5a5a5a;
  --control-border: #cfcfcf; /* form fields high-contrast */
  --titlebar-btn-border: #cfcfcf;
  --scrollbar-thumb: #cfcfcf;
  --scrollbar-thumb-hover: #ffffff;
  --text-primary: #ffffff;
  --text-secondary: #e0e0e0; /* "secondary" stays high-contrast in HC, not muted-grey */
  --text-muted: #c0c0c0; /* even muted clears AAA */
  --accent: #ffffff;
  --accent-text: #000000;
  --accent-bg: #1a1a1a;
  --accent-border: #ffffff;
  --btn-primary-hover: #d6d6d6;
  --user-bubble-bg: #ffffff;
  --user-bubble-border: #ffffff;
  --user-bubble-text: #000000;
  --tag-solid-bg: var(--accent);
  --tag-solid-text: var(--accent-text);
  --text-body: #ffffff; /* High Contrast softens nothing */
  --green: #5fe07a; /* bright status hues, distinct + high-contrast on black */
  --orange: #ffb84d;
  --red: #ff7b7b;
  --banner-warn-bg: #8a5a2e;
  --banner-ok-bg: #4f6e4f;
  --act-1: #5a5a5a;
  --act-2: #909090;
  --act-3: #d0d0d0;
  --diff-removed-bg: rgba(255, 123, 123, 0.22);
  --diff-added-bg: rgba(95, 224, 122, 0.22);
}

/* Midnight — a cooler, deeper dark. Blue-black surfaces; the element ladder
 * stays brightness-based (faint cool cast) so it never collides with revision
 * colors. Print still gates --el-* to #000 (body.printing). */
html[data-theme='midnight'] {
  color-scheme: dark; /* as in High Contrast: never the OS-light fallback */
  --segment-thumb: color-mix(in srgb, var(--text-primary) 20%, var(--bg-base));
  --bg-base: #0e1015;
  --bg-surface: #14171d;
  --bg-elevated: #1b1f27;
  --bg-hover: #252b35;
  --bg-selected: #2a313d;
  --bg-page: #11141a;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.42);
  --shadow-3:
    0 0 0 1px rgba(214, 226, 255, 0.08), 0 8px 20px rgba(0, 0, 0, 0.35),
    0 28px 64px rgba(0, 0, 0, 0.55);
  --page-edge: rgba(214, 226, 255, 0.09);
  --shadow-page: 0 0 0 1px var(--page-edge), 0 12px 36px rgba(0, 0, 0, 0.36);
  --overlay-scrim: rgba(0, 0, 0, 0.55);
  --page-text: #d4dae3;
  --el-scene: #f0f4fa;
  --el-character: #dde4ee;
  --el-dialogue: #cfd6e0;
  --el-action: #aab2bf;
  --el-transition: #c2c8d4;
  --el-parenthetical: #868f9c;
  --border: #333b47;
  --border-soft: #232a34;
  --board-dot: #232a34;
  --control-border: #6b7480;
  --titlebar-btn-border: #6b7480;
  --scrollbar-thumb: #6b7480;
  --scrollbar-thumb-hover: #8e96a3;
  --text-primary: #eef2f8;
  --text-secondary: #b9c0cc;
  --text-muted: #8e96a3;
  --accent: #c9d3e2;
  --accent-text: #11141a;
  --accent-bg: #1b1f27;
  --accent-border: #6b7480;
  --btn-primary-hover: #dde4ee;
  --user-bubble-bg: #252b35;
  --user-bubble-border: transparent;
  --user-bubble-text: #eef2f8;
  /* Restated, not inherited: with the OS in light mode the light block's
   * accent pair would otherwise reach this dark theme. */
  --tag-solid-bg: color-mix(in srgb, var(--text-primary) 20%, var(--bg-elevated));
  --tag-solid-text: var(--text-primary);
  --text-body: #d3d9e3;
  --green: #6e9a86;
  --orange: #b89068;
  --red: #b86b6b;
  --banner-warn-bg: #8a5a2e;
  --banner-ok-bg: #45685a;
  --act-1: #333b47;
  --act-2: #5d6675;
  --act-3: #8e96a3;
  --diff-removed-bg: rgba(184, 107, 107, 0.12);
  --diff-added-bg: rgba(110, 154, 134, 0.14);
}

/* Parchment — a warm, low-blue-light reading theme for night writing. Sepia
 * paper, ink-brown text; element ladder stays brightness-based. */
html[data-theme='parchment'] {
  color-scheme: light;
  --segment-thumb: var(--bg-elevated);
  --bg-base: #e9dcc0;
  --bg-surface: #f3e9d2;
  --bg-elevated: #f7f0de;
  --bg-hover: #ddcfae;
  --bg-selected: #cdbb92;
  --bg-page: #f3e9d2;
  --page-text: #463a26;
  --el-scene: #2b2114;
  --el-character: #3a2c18;
  --el-dialogue: #463a26;
  --el-action: #6b5a3e;
  --el-transition: #5a4a30;
  --el-parenthetical: #7a6646;
  --border: #cdbb92;
  --border-soft: #ddcfae;
  --board-dot: #ddcfae;
  --control-border: #9a8a66;
  --titlebar-btn-border: #cdbb92;
  --scrollbar-thumb: #857550; /* darker than --control-border: 3:1 vs the sepia --bg-base */
  --scrollbar-thumb-hover: #6b5a3e;
  --text-primary: #3a2c18;
  --text-secondary: #6b5a3e;
  --text-muted: #8a7656;
  --accent: #3a2c18;
  --accent-text: #f3e9d2;
  --accent-bg: #ddcfae;
  --accent-border: #b3a173;
  --btn-primary-hover: #2b2114;
  --shadow-1: 0 1px 2px rgba(58, 44, 24, 0.08);
  --shadow-2: 0 1px 2px rgba(58, 44, 24, 0.06), 0 8px 24px rgba(58, 44, 24, 0.12);
  --shadow-3:
    0 0 0 1px rgba(58, 44, 24, 0.08), 0 6px 16px rgba(58, 44, 24, 0.08),
    0 24px 56px rgba(58, 44, 24, 0.2);
  --page-edge: rgba(58, 44, 24, 0.1);
  --shadow-page: 0 0 0 1px var(--page-edge), 0 10px 30px rgba(58, 44, 24, 0.1);
  --overlay-scrim: rgba(58, 44, 24, 0.34);
  --user-bubble-bg: #ddcfae;
  --user-bubble-border: transparent;
  --user-bubble-text: #3a2c18;
  --tag-solid-bg: var(--accent);
  --tag-solid-text: var(--accent-text);
  --text-body: #463a26;
  --green: #4a6a35; /* 5.1:1 on parchment --bg-surface */
  --orange: #9a6e34;
  --red: #9a4a3a;
  --banner-warn-bg: #9a6e34;
  --banner-ok-bg: #5a7a42;
  --act-1: #c0ad84;
  --act-2: #9a8a66;
  --act-3: #6b5a3e;
  --diff-removed-bg: rgba(154, 74, 58, 0.1);
  --diff-added-bg: rgba(90, 122, 66, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  font-family: var(--font-ui);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: var(--text-md);
  line-height: var(--leading-ui);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* One keyboard-focus look for anything that doesn't set its own, so no
   control falls back to the OS ring (orange on a Mac set to an orange
   accent, blue on Windows). Zero-specificity via :where(), so every
   component's own :focus / :focus-visible rule still wins. */
:where(button, a, input, select, textarea, summary, [tabindex], [role='button']):focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

/* WCAG 2.4.1 Bypass Blocks: visible-on-focus skip link so keyboard users
   jump straight to the editor instead of tabbing the whole scene sidebar.
   Off-screen (still focusable) until focused. No transition → no motion. */
.skip-link {
  position: absolute;
  top: 8px;
  left: -9999px;
  z-index: 2000;
  padding: 8px 12px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  -webkit-app-region: no-drag;
}

.skip-link:focus,
.skip-link:focus-visible {
  left: 8px;
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

/* ----------- Welcome ----------- */
.welcome {
  display: flex;
  /* `safe center` centers when content fits, otherwise anchors to the
     top — so a small viewport clips the bottom of the list (recoverable
     via scroll inside the picker), not the logo above the macOS
     traffic-lights. */
  align-items: safe center;
  justify-content: center;
  height: 100vh;
  width: 100vw;
  /* Reserve top breathing room past the macOS traffic-lights, plus a
     matching bottom inset so the centered layout reads as deliberate. */
  padding: 48px 0;
  box-sizing: border-box;
  background: var(--bg-base);
  -webkit-app-region: drag;
}

.welcome-inner {
  max-width: 380px;
  width: 100%;
  text-align: center;
  -webkit-app-region: no-drag;
  /* Natural-sized stack — when content fits, .welcome's
     align-items:center vertically centers us. When the screenplay
     list overflows, the picker body inside handles it via its own
     max-height + overflow. */
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ----------- Signed out: the form and a title page, side by side -----------
 * renderWelcomeState() sets .is-split while the sign-in form or the
 * "Check your email" card is up. The page keeps its place down to the
 * smallest window main allows (1000x600): it narrows with the window, and
 * when the window is shorter than the page `safe center` pins it under the
 * top padding and it runs off the bottom edge. Signed in, there is no page
 * and the picker has the window to itself. */
.welcome.is-split {
  /* lastslate.com's hero (owner's call, Nov 2026): a slim bar across the
     top where the site has its nav, the sign-in column centred in the left
     part of the site's 1200px column, and the title page as tall as the
     window under the bar, rounded, on the column's right edge. */
  --welcome-bar-h: 52px;
  --welcome-edge: max(28px, calc((100% - 1200px) / 2));
  --welcome-bar-x: var(--welcome-edge);
  --welcome-fill: color-mix(in srgb, var(--text-primary) 8%, var(--bg-base));
  --welcome-fill-hover: color-mix(in srgb, var(--text-primary) 13%, var(--bg-base));
  /* The sign-in card: a step off the page, a hair line, a quiet field. */
  --welcome-card: color-mix(in srgb, var(--bg-base) 76%, #000);
  --welcome-card-line: color-mix(in srgb, var(--text-primary) 7%, transparent);
  --welcome-field: color-mix(in srgb, var(--text-primary) 5%, transparent);
  --welcome-field-line: color-mix(in srgb, var(--text-primary) 8%, transparent);
  position: relative;
  justify-content: space-between;
  gap: 32px;
  padding: calc(var(--welcome-bar-h) + 20px) var(--welcome-edge) 28px;
  overflow: hidden;
}
/* The Mac window draws its traffic lights over the bar's left end. */
html[data-platform='darwin']:not([data-client='web']):not([data-fullscreen]) .welcome.is-split {
  --welcome-bar-x: max(92px, var(--welcome-edge));
}
.welcome-topbar {
  display: none;
}
.welcome.is-split .welcome-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--welcome-bar-h);
  padding: 0 var(--welcome-edge) 0 var(--welcome-bar-x);
}
.welcome-brand {
  display: flex;
  align-items: center;
  gap: 4px;
}
/* mark.png's mark fills two thirds of the image: 36px draws a 24px mark,
   level with the wordmark, as on lastslate.com. The negative margin keeps
   the bar its height. */
.welcome-mark {
  width: 36px;
  height: 36px;
  margin: -5px 0;
  display: block;
}
.welcome-wordmark {
  font-size: var(--text-wordmark);
  font-weight: var(--weight-strong);
  letter-spacing: -0.015em;
  color: var(--text-primary);
}
/* The outgoing face of the welcome screen, cloned for the moment it takes
   to fade out over the incoming one (beginWelcomeSwap in app.js). It takes
   no clicks and claims no drag region, so the real controls under it work
   at once. The logo rides above it while it travels between the two
   faces. */
.welcome-ghost {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  -webkit-app-region: no-drag;
}

.welcome-logo.is-travelling {
  position: relative;
  z-index: 2;
}

.welcome.is-split .welcome-inner {
  flex: 1 1 0;
  min-width: 0;
  max-width: none;
  align-items: center;
}
.welcome.is-split .welcome-inner > :not(.welcome-logo) {
  width: min(100%, 440px);
}
.welcome.is-split .welcome-inner > .welcome-title,
.welcome.is-split .welcome-inner > .welcome-subtitle {
  width: min(100%, 520px);
}
.welcome.is-split .welcome-inner > .welcome-title {
  font-size: var(--text-poster);
  line-height: 1.06;
  letter-spacing: -0.03em;
  margin-bottom: var(--space-4);
  text-wrap: balance;
}
.welcome.is-split .welcome-subtitle {
  font-size: var(--text-3xl);
  line-height: 1.35;
  margin-bottom: 36px;
}

/* Signed out on the desktop, the app icon sits centred over the headline
   (owner's call, Nov 2026), with nothing at the top left; it is still the
   one .welcome-logo, so signing in carries it to the middle of the picker.
   The web's bar carries the website's logo instead (.welcome-brand). */
.welcome.is-split .welcome-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-5);
  box-shadow: none;
}
html[data-client='web'] .welcome.is-split .welcome-logo {
  position: absolute;
  visibility: hidden;
}

.welcome-page {
  /* As tall as the window under the bar, and never more than about half
     its width. */
  --page-w: min(calc((100vh - var(--welcome-bar-h, 52px) - 48px) * 8.5 / 11), 48vw);
  display: none;
  flex: none;
  flex-direction: column;
  align-items: center;
  width: var(--page-w);
  aspect-ratio: 8.5 / 11;
  border-radius: var(--radius-xl);
  /* 12pt Courier on a US Letter page (51 characters across), at this
     page's width. */
  font-family: var(--font-script);
  font-size: calc(var(--page-w) / 51);
  line-height: 1;
  padding-top: 21.5em;
  background: var(--bg-page);
  color: var(--page-text);
  box-shadow: var(--shadow-page);
  -webkit-app-region: no-drag;
  user-select: none;
}

.welcome.is-split .welcome-page {
  display: flex;
}

/* A window narrower than main's minimum (it should not happen) keeps the
   form and gives up the page. */
@media (max-width: 940px) {
  .welcome.is-split .welcome-page {
    display: none;
  }
}

.welcome-page-line {
  margin: 0;
  white-space: pre;
}

.welcome-page-title .welcome-page-typed {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.welcome-page-by {
  margin-top: 3.97em;
}

.welcome-page-name {
  margin-top: 1.98em;
}

.welcome-page-rest {
  visibility: hidden;
}

.welcome-page-caret {
  display: inline-block;
  width: 0;
  height: 1.05em;
  margin-right: -1px;
  vertical-align: -0.15em;
  border-left: 1px solid var(--page-text);
  animation: welcome-caret-blink 1.06s steps(1, end) infinite;
}

/* The caret always blinks, parked where the page is typing or deleting
   (owner's call, Nov 2026). Reduced motion shows the finished page with no
   caret at all (js/welcome-page.js removes it). */
@keyframes welcome-caret-blink {
  50% {
    opacity: 0;
  }
}

.welcome-logo {
  width: 96px;
  height: 96px;
  /* Center the icon under the parent's text-align: center — block
     elements ignore text-align, so we center via auto side-margins. */
  display: block;
  margin: 0 auto 24px;
  flex-shrink: 0;
  /* Approximate the macOS dock appearance: a near-black squircle
     surface that visibly frames the M on the welcome screen, so the
     in-app brand matches what the writer sees in their dock instead
     of floating as a bare shape on the page background. */
  border-radius: 22%;
  background: #0a0a0a;
  box-shadow: var(--shadow-2);
}

.welcome-title {
  font-size: var(--text-display);
  font-weight: var(--weight-strong);
  letter-spacing: -0.01em;
  margin-bottom: 6px;
}

/* Signed-in brand pose — the logo/title sit 28px above natural flow
   once the cloud list is the primary surface. Static rule only: the
   travel into this pose is a measured FLIP run by
   revealWelcomeWithSettle() in app.js (the splash is vertically
   centered, so the start position depends on viewport height — a
   fixed keyframe can't express it). */
.welcome-logo.is-lifted,
.welcome-title.is-lifted {
  transform: translateY(-28px);
}

.welcome-subtitle {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  margin-bottom: 28px;
}

/* ----------- Welcome splash indicator -----------
 * Shown only pre-bootstrap (renderWelcomeState gates it). The 250ms
 * appear-delay means a fast boot resolves before the ring ever
 * becomes visible — no flash on quick signed-out launches. */
.welcome-loading {
  display: flex;
  justify-content: center;
  padding: 6px 0 20px;
}

.welcome-loading-spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--brand-pink);
  border-radius: 50%;
  opacity: 0;
  animation:
    welcome-loading-appear 200ms ease-out 250ms forwards,
    welcome-spin 0.8s linear infinite;
}

@keyframes welcome-loading-appear {
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  /* Drop the rotation; keep the delay-gated appearance (a one-frame
     opacity step is not motion) so the anti-flash behavior survives.
     The static pink-arc ring still reads as "working". */
  .welcome-loading-spinner {
    animation: welcome-loading-appear 1ms linear 250ms forwards;
  }
}

/* ----------- Welcome sign-in (signed-out state) -----------
 * One full-width stack: the one-click providers first, then the email
 * link, which is the universal path (Yahoo / Proton / work / any
 * address). */
.welcome-signin {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  text-align: left;
  -webkit-app-region: no-drag;
}

.welcome-signin-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* The sign-in card (lastslate.com's hero, after claude.ai/login): the
   providers, the email link and the legal line, and in their place the
   "signing in" line or "Check your email", so what changes, changes inside
   the card. A hair line and a fill a step off the page; no shadow. */
.welcome-signin-card,
.welcome-signing,
.welcome-magic-sent {
  box-sizing: border-box;
  padding: 28px;
  border-radius: var(--radius-2xl);
  background: var(--welcome-card);
  border: 0.5px solid var(--welcome-card-line);
}

/* Continue with email: full width and as tall as the field above it. */
.welcome-signin-submit {
  height: 44px;
  border-radius: var(--radius-lg);
  font-size: var(--text-lg);
}

.welcome-signin-email {
  min-width: 0;
  height: 44px;
  font-family: var(--font-ui);
  font-size: var(--text-lg);
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--welcome-field);
  box-shadow: inset 0 0 0 1px var(--welcome-field-line);
  color: var(--text-primary);
  outline: none;
  transition: box-shadow var(--dur-2) var(--ease-out);
}

/* Focus and a refused address are a 1px ring inside the field, never a
   thicker edge that moves the text (claude.ai's field). */
.welcome-signin-email:focus {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text-primary) 55%, transparent);
}
.welcome-signin-form.has-error .welcome-signin-email {
  box-shadow: inset 0 0 0 1px var(--danger, #d04444);
}

.welcome-signin-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 6px 0;
  color: var(--text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
}

/* Google, then Apple, one under the other. Their icons and labels start on
   one vertical line (owner, Nov 2026), so the two buttons share columns:
   the icons in one, the labels left-aligned in the next, the pair centred
   by the flexible columns either side. lastslate.com's card does the same
   (.hero-gate-providers). Without subgrid, each button centres its own
   content as before. */
.welcome-providers {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}
@supports (grid-template-columns: subgrid) {
  .welcome-providers {
    display: grid;
    grid-template-columns: 1fr auto auto 1fr;
    column-gap: 10px;
    row-gap: 8px;
  }
  .welcome-providers > button {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: subgrid;
    align-items: center;
  }
  .welcome-providers > button > svg {
    grid-column: 2;
  }
  .welcome-providers > button > span {
    grid-column: 3;
    text-align: start;
  }
}

/* Google, then Apple: one filled style, no outline (lastslate.com's hero,
   owner's call Nov 2026; the black Apple button went with it). */
.welcome-google-btn,
.welcome-apple-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 44px;
  padding: 0 16px;
  background: var(--welcome-fill);
  border: 0;
  border-radius: var(--radius-lg);
  font-family: var(--font-ui);
  font-size: var(--text-lg);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  cursor: pointer;
  -webkit-app-region: no-drag;
  transition: background var(--dur-2) var(--ease-out);
}

.welcome-google-btn:hover,
.welcome-apple-btn:hover {
  background: var(--welcome-fill-hover);
}

.welcome-google-btn:focus-visible,
.welcome-apple-btn:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

.welcome-google-icon {
  flex-shrink: 0;
}

.welcome-apple-icon {
  flex-shrink: 0;
}

.welcome-signin-status {
  min-height: 0;
  margin: 8px 0 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-align: center;
}

.welcome-legal {
  margin: 18px 0 0;
  font-size: var(--text-xs);
  line-height: 1.55;
  color: var(--text-muted);
  text-align: center;
}

.welcome-legal-link {
  padding: 0;
  border: none;
  background: transparent;
  font: inherit;
  color: var(--text-secondary);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  -webkit-app-region: no-drag;
}

.welcome-legal-link:hover {
  color: var(--text-primary);
}

.welcome-legal-link:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

.welcome-signin-status.is-error {
  color: var(--danger, #d04444);
}

/* ----------- Welcome: a sign-in is under way -----------
 * The stack steps aside for a ring and one line. paintWelcomeState() makes
 * the panel as tall as the stack it replaces, so the logo and heading
 * above it do not move when a provider is chosen. */
.welcome-signing {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  -webkit-app-region: no-drag;
  animation: welcome-signing-in var(--dur-2) var(--ease-out);
}

@keyframes welcome-signing-in {
  from {
    opacity: 0;
  }
}

.welcome-signing-spinner {
  width: 22px;
  height: 22px;
  margin-bottom: 16px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: welcome-signing-spin 0.8s linear infinite;
}

@keyframes welcome-signing-spin {
  to {
    rotate: 360deg;
  }
}

@media (prefers-reduced-motion: reduce) {
  /* The still ring with its one dark arc reads as "working". */
  .welcome-signing,
  .welcome-signing-spinner {
    animation: none;
  }
}

.welcome-signing-title {
  margin: 0;
  font-size: var(--text-lg);
  color: var(--text-primary);
}

.welcome-signing-blurb {
  margin: 6px 0 0;
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--text-secondary);
}

.welcome-signing-blurb:empty {
  display: none;
}

.welcome-signing .welcome-link {
  margin-top: 18px;
}

/* ----------- Welcome magic-link sent state -----------
 * The card's own words, as claude.ai/login puts them: where to click, then
 * a way to send again and a way back to the form, inline. */
.welcome-magic-sent {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  text-align: center;
  -webkit-app-region: no-drag;
}
.welcome-magic-lead {
  margin: 0;
  font-size: var(--text-lg);
  line-height: 1.55;
  color: var(--text-primary);
}
.welcome-magic-lead strong {
  display: block;
  font-weight: var(--weight-medium);
  word-break: break-all;
}
.welcome-magic-help {
  margin: 16px 0 0;
  font-size: var(--text-md);
  line-height: 1.75;
  color: var(--text-secondary);
}
.welcome-inline-link {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
  text-underline-offset: 3px;
  cursor: pointer;
  -webkit-app-region: no-drag;
}
.welcome-inline-link:hover {
  text-decoration-color: currentColor;
}
.welcome-inline-link:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
.welcome-inline-link:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.welcome-magic-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--accent, var(--text-primary));
}

.welcome-magic-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-strong);
  margin: 0 0 8px;
}

.welcome-magic-blurb {
  font-size: var(--text-md);
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0 0 18px;
}

.welcome-magic-blurb strong {
  color: var(--text-primary);
  font-weight: var(--weight-strong);
}

.welcome-magic-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.welcome-link {
  background: transparent;
  border: none;
  padding: 4px 2px;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  cursor: pointer;
  -webkit-app-region: no-drag;
}

.welcome-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.welcome-link:disabled {
  color: var(--text-muted);
  cursor: default;
  text-decoration: none;
  opacity: 0.6;
}

/* Companion Mode entry under the sign-in / project list: the same row
   as a project in the Welcome list, so it reads as a place to go. */
.welcome-companion {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: 0 0 18px;
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  -webkit-app-region: no-drag;
  transition:
    background var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out);
}

.welcome-companion:hover {
  background: var(--bg-elevated);
  border-color: var(--accent-border);
}

.welcome-companion:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

.welcome-companion-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
}

.welcome-companion:hover .welcome-companion-icon {
  color: var(--text-primary);
}

.welcome-companion-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.welcome-companion-name {
  font-size: var(--text-md);
  font-weight: 500;
}

.welcome-companion-meta {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.welcome-companion-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
}

/* Inside the signed-in picker the row spans the card column and sits
   between the cards and the search field. */
/* ----------- Welcome cloud project list (signed-in state) ----------- */
.welcome-cloud {
  width: 100%;
  max-width: 440px;
  margin: 0 auto 18px;
  text-align: left;
  -webkit-app-region: no-drag;
  /* Natural height; the picker-body inside owns its own scroll. We
     stay a flex column so children stack predictably. */
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.welcome-cloud-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
}

/* A button since Nov 2026: it opens the account menu under itself. Its
   anchor (.account-anchor-start) carries the negative margin that keeps
   the avatar on the header's left edge while the hover wash gets room. On
   the button itself that margin plus max-width cut 12px off the text. */
.welcome-identity {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  padding: 4px 6px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out);
}
.welcome-identity:hover,
.welcome-identity[aria-expanded='true'] {
  background: var(--hover-wash);
}
.welcome-identity:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}
.welcome-identity-name {
  min-width: 0;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  font-weight: 500;
  line-height: 1.25;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.welcome-cloud-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 56px;
}

.welcome-cloud-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  -webkit-app-region: no-drag;
  transition:
    background var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out);
}

.welcome-cloud-item:hover {
  background: var(--bg-elevated);
  border-color: var(--accent-border);
}

.welcome-cloud-item:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

.welcome-cloud-item.is-busy {
  opacity: 0.6;
  cursor: progress;
}

.welcome-cloud-item-icon {
  flex-shrink: 0;
  color: var(--text-secondary);
}

.welcome-cloud-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.welcome-cloud-item-name {
  font-size: var(--text-md);
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.welcome-cloud-item-meta {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.welcome-cloud-empty {
  padding: 18px 12px;
  font-size: var(--text-md);
  color: var(--text-secondary);
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

.welcome-cloud-loading::after {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: welcome-cloud-pulse 0.9s ease-in-out infinite alternate;
  vertical-align: middle;
}

@keyframes welcome-cloud-pulse {
  from {
    opacity: 0.25;
  }
  to {
    opacity: 1;
  }
}

.welcome-cloud-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 12px;
  font-size: var(--text-md);
  color: var(--text-secondary);
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.welcome-cloud-retry {
  align-self: center;
}

/* Locked-list state: while a restore is in flight, the whole list
 * stops accepting clicks so a fast user can't fire two save sheets
 * (the OS file dialog) on top of each other. */
.welcome-cloud-list.is-locked .welcome-cloud-item:not(.is-busy) {
  pointer-events: none;
  opacity: 0.5;
}

.welcome-cloud-status {
  min-height: 16px;
  margin: 10px 4px 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.welcome-cloud-status.is-error {
  color: var(--danger, #d04444);
}

.welcome-picker-mount {
  width: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Welcome list is a flex column that sizes to its CONTENT, capped by a
   max-height. A small library stays compact and vertically centred (no empty
   reserve pushing the logo up); a large one stops growing at the cap and the
   folder tree scrolls inside it, so the logo/title aren't pushed off-screen.
   The Recent rows + section labels stay pinned; only `.project-picker-tree`
   scrolls. During search the body is additionally frozen to its pre-search
   height in JS so filtering never bounces the logo. The reserve covers
   logo/title/eyebrow/action row/search + .welcome padding. */
.welcome-picker-mount .project-picker-body {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  max-height: min(420px, calc(100vh - 432px));
}
/* The Companion Mode row above the list takes its height out of the cap
   so the library still scrolls inside instead of pushing off-screen. */
.welcome-picker-mount.has-companion .project-picker-body {
  max-height: min(420px, calc(100vh - 508px));
}
.welcome-picker-mount .project-picker-body > * {
  flex: 0 0 auto;
}
.welcome-picker-mount .project-picker-body > .project-picker-tree {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.link {
  color: var(--accent);
  text-decoration: underline; /* WCAG 1.4.1: inline links distinguished by more than color */
}

/* ----------- Project picker (Welcome inline + titlebar dropdown + ⌘O)
 *
 * One component, three surfaces. Owns its own search field, the
 * Recent/All section split, keyboard navigation between rows, and
 * loading/error/empty states. The dropdown surface wraps it in
 * .project-switcher-overlay; the Welcome surface mounts it directly
 * into #welcome-picker-mount. */
.project-picker {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  -webkit-app-region: no-drag;
}

.project-picker-search {
  position: relative;
  padding: 0 0 10px;
}

.project-picker-input {
  width: 100%;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  padding: 9px 12px 9px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  transition:
    border-color var(--dur-2) var(--ease-out),
    box-shadow var(--dur-2) var(--ease-out);
}

.project-picker-input:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-soft, rgba(80, 130, 255, 0.12));
}

.project-picker-search-icon {
  position: absolute;
  left: 11px;
  top: 9px;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.project-picker-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0 -2px;
  padding: 0 2px;
}

.project-picker-section {
  margin-bottom: 4px;
}

.project-picker-section:last-child {
  margin-bottom: 0;
}

.project-picker-section-label {
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-muted);
  padding: 6px 8px 2px;
}

.project-picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 4px 10px;
  background: transparent;
  border: 0;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  -webkit-app-region: no-drag;
  transition: background var(--dur-1) var(--ease-out);
}

.project-picker-item:hover,
.project-picker-item.is-active {
  background: var(--hover-wash);
}

.project-picker-item.is-current {
  background: var(--selected-wash);
}

/* The open script: a check, not a dot. */
.project-picker-item.is-current::after {
  content: '✓';
  margin-left: auto;
  color: var(--text-primary);
  font-size: var(--text-lg);
  font-weight: var(--weight-strong);
  line-height: 1;
}

.project-picker-item.is-busy {
  opacity: 0.55;
  cursor: progress;
}

/* Every script wears the same quiet page: cloud is the default, so it
   is not marked (owner, Nov 2026). */
.project-picker-item-icon {
  color: var(--text-muted);
}

/* Per-project list inside Settings → Cloud sync. Each row uses the
   shared .setting-row chrome so the spacing + colors match the rest
   of the tab; the toggle is the existing .settings-toggle. */
.setting-section {
  margin-top: 18px;
}

.setting-section-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.cloud-projects-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cloud-project-row {
  /* Slightly tighter than the default setting-row for compact lists. */
  padding: 8px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
}

.project-picker-item:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}

.project-picker-item-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}

.project-picker-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.project-picker-item-name {
  font-size: var(--text-md);
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Flex child of the title line — without this it refuses to shrink
   * and the ellipsis (and the Shared pill beside it) never engage. */
  min-width: 0;
}

.project-picker-item-meta {
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Local rows carry a file path: trim it from the LEFT so the file name
 * survives (VS Code's recent list does the same). */
.project-picker-item--local .project-picker-item-meta {
  direction: rtl;
  text-align: left;
}

/* Title line: name + optional Shared pill side by side. The name
 * ellipsizes; the pill never shrinks and never detaches from it. */
.project-picker-item-titleline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* Pill on shared-with-me projects — permanent provenance marker
 * (never-opened ones are additionally pinned to the top). Hugs the
 * name inside the title line. Text-secondary on bg-elevated meets
 * 4.5:1 in both themes. */

/* ── Welcome action cards (Cursor-style, above the list) ──────────── */
.project-picker-actions-top {
  /* Single horizontal row, equal-width — one column per action regardless of
     count (no wrapping to a second row). */
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 10px;
  margin: 2px 0 20px;
}
.project-picker-action-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 14px 13px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition:
    border-color var(--dur-2) var(--ease-out),
    background var(--dur-2) var(--ease-out);
}
.project-picker-action-card:hover {
  border-color: var(--accent-border);
  background: var(--bg-hover);
}
.project-picker-action-card:focus-visible {
  outline: none;
  border-color: var(--accent-border);
  box-shadow: 0 0 0 2px var(--selected-wash);
}
.project-picker-action-card-icon {
  display: inline-flex;
  align-items: center;
  color: var(--text-secondary);
  line-height: 1;
}
.project-picker-action-card-icon svg {
  width: 26px;
  height: 26px;
}
.project-picker-action-card-label {
  font-size: var(--text-lg);
  font-weight: 500;
}
@media (prefers-reduced-motion: reduce) {
  .project-picker-action-card {
    transition: none;
  }
}

/* ── Cloud folder "Library" tree ──────────────────────────────────── */
.project-picker-tree {
  display: flex;
  flex-direction: column;
}

/* Depth indentation for nested folders + projects (clamped ~6 levels so deep
   trees don't march off-screen; aria-level stays accurate regardless). */
.project-picker-item.is-nested,
.project-picker-folder {
  padding-left: calc(8px + min(var(--depth, 0), 6) * 16px);
}

.project-picker-folder {
  width: 100%;
  text-align: left;
  cursor: pointer;
  background: transparent;
  border: none;
}

.project-picker-folder-twisty {
  flex-shrink: 0;
  width: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: transform var(--dur-2) var(--ease-out);
}
.project-picker-folder-twisty.is-expanded {
  transform: rotate(90deg);
}
@media (prefers-reduced-motion: reduce) {
  .project-picker-folder-twisty {
    transition: none;
  }
}

.project-picker-folder-count {
  flex-shrink: 0;
  min-width: 16px;
  margin-left: auto;
  text-align: right;
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* No-match state when type-to-filtering the Library. */
.project-picker-tree-empty {
  padding: 18px 8px;
  font-size: var(--text-md);
  color: var(--text-muted);
  text-align: center;
}

/* Drag-and-drop: file a script into a folder by dragging it. */
.project-picker-item[draggable='true'] {
  cursor: grab;
}
.project-picker-item.is-dragging {
  opacity: 0.45;
}
.project-picker-folder.is-drop-target {
  background: var(--selected-wash);
  outline: 1.5px dashed var(--accent-border);
  outline-offset: -2px;
}

/* "Inherited" reads quieter than the "Shared" provenance pill. */

.project-picker-row-kebab {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin-left: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-xl);
  line-height: 1;
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease-out);
}
.project-picker-item:hover .project-picker-row-kebab,
.project-picker-item.is-active .project-picker-row-kebab,
.project-picker-row-kebab:focus-visible {
  opacity: 1;
}
.project-picker-row-kebab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Body-portaled action menu (kebab / move target). */
.library-action-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10050; /* above the welcome layers + drag region; below modals' own logic */
  background: transparent;
  /* CRITICAL: the welcome screen is `-webkit-app-region: drag`, so without this
     the OS swallows clicks here as window-drags and the menu never dismisses. */
  -webkit-app-region: no-drag;
}
.library-action-menu {
  position: fixed;
  z-index: 10051;
  -webkit-app-region: no-drag;
  min-width: 200px;
  max-width: 280px;
  padding: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  display: flex;
  flex-direction: column;
}
.library-action-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: var(--text-md);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.library-action-item:hover:not([disabled]),
.library-action-item:focus-visible {
  background: var(--hover-wash);
  outline: none;
}
.library-action-item.is-danger {
  color: var(--danger, #d04444);
}
.library-action-item[disabled] {
  color: var(--text-muted);
  cursor: default;
  opacity: 0.6;
}
.library-action-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border);
}

/* Prompt / download / share modal bits (atop the settings-modal chrome). */
.library-prompt-input {
  width: 100%;
  box-sizing: border-box;
  margin: 6px 0 4px;
  padding: 10px 12px;
  font-size: var(--text-lg);
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-md);
  outline: none;
}
.library-prompt-input:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 2px var(--selected-wash);
}

/* Library modals reuse the settings shell but need their own vertical rhythm:
   the settings panel relies on tall content above the action row, so .settings-
   actions has no top margin — in a short prompt that leaves the buttons hugging
   the field. Give the action row real breathing room here. */
.library-modal .settings-actions {
  margin-top: 22px;
}
.library-modal .settings-explainer {
  margin-bottom: 14px;
}

.library-dl-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 4px;
}
.library-dl-radio,
.library-dl-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-lg);
  color: var(--text-primary);
  cursor: pointer;
}
.library-dl-check {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.library-dl-bar {
  height: 8px;
  margin: 10px 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.library-dl-bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width var(--dur-3) var(--ease-out);
}
@media (prefers-reduced-motion: reduce) {
  .library-dl-bar-fill,
  .project-picker-row-kebab {
    transition: none;
  }
}

.library-share-scope {
  padding: 9px 11px;
  background: var(--selected-wash);
  border-radius: var(--radius-md);
}
/* Folder-scope banner in the shared Share modal (#share-scope-note). */
.share-scope-note {
  margin: 0 0 18px;
  padding: 10px 12px;
  background: var(--selected-wash);
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--text-secondary);
}
/* The banner becomes the modal-body's first child, which would knock the
   Collaborators section out of :first-child and draw a divider/top-padding
   hugging the banner text. Keep that section flush in BOTH scopes (the banner
   is display:none in script scope, so this also restores the script modal). */
.share-scope-note + .share-section {
  border-top: none;
  padding-top: 0;
}
.library-share-invite {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}
.library-share-invite .library-prompt-input {
  margin: 0;
}
.library-share-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
}
.library-share-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--border-soft);
}
.library-share-who {
  flex: 1;
  min-width: 0;
  font-size: var(--text-md);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.library-share-remove {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.library-share-remove:hover {
  color: var(--text-primary);
  border-color: var(--accent-border);
}
.library-share-empty,
.library-share-loading {
  padding: 10px 4px;
  font-size: var(--text-md);
  color: var(--text-muted);
}

.project-picker-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 4px 0;
  margin-top: 6px;
  border-top: 1px solid var(--border);
}

.project-picker-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-app-region: no-drag;
}

.project-picker-action:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.project-picker-action:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

.project-picker-empty,
.project-picker-loading,
.project-picker-error {
  padding: 14px 12px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-align: center;
}

.project-picker-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 12px;
}

.welcome-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border, rgba(255, 255, 255, 0.12));
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: welcome-spin 0.8s linear infinite;
  flex: 0 0 auto;
}

@keyframes welcome-spin {
  to {
    transform: rotate(360deg);
  }
}

.project-picker-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* Subtle inline activity strip — used when the cached project list
   stays rendered while loadWelcomeCloudProjects refreshes in the
   background. Visual weight is lower than .project-picker-loading
   so it reads as "something's happening" without competing with
   the actual rows. */
.project-picker-refreshing {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.project-picker-no-matches {
  padding: 14px 12px;
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
}

/* Titlebar trigger: the script title becomes a button. The chevron
 * sits to the right and rotates 180° when the dropdown is open so the
 * affordance is visible without re-reading the label. */
button.titlebar-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-app-region: no-drag;
  transition:
    background var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out);
  max-width: 60vw;
}

button.titlebar-title:hover {
  background: var(--bg-elevated);
  border-color: var(--border);
}

button.titlebar-title:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}

button.titlebar-title[aria-expanded='true'] {
  background: var(--bg-elevated);
  border-color: var(--border);
}

button.titlebar-title #script-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* A slate glyph marks the title as "the project" (a Linear workspace
 * tile, not a dropdown caret); hover / open state carries the
 * affordance. */
.titlebar-project-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}

button.titlebar-title:hover .titlebar-project-icon,
button.titlebar-title[aria-expanded='true'] .titlebar-project-icon {
  color: var(--text-primary);
}

/* Dropdown overlay anchored under the titlebar. Click-outside the card
 * dismisses (handled in JS). z-index keeps it above the editor body
 * but the titlebar still sits visually above its top edge thanks to
 * top: 38px (matching the titlebar height). */
.project-switcher-overlay {
  position: fixed;
  inset: 44px 0 0 0;
  z-index: 70;
  pointer-events: auto;
  background: transparent;
}

/* Popover hung off the title button (openProjectSwitcher sets `left`
 * from the trigger's rect): search row, list, footer strip — a
 * Linear / Notion workspace switcher, not a centred modal. */
.project-switcher-card {
  position: absolute;
  top: 6px;
  width: 380px;
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  background: var(--bg-elevated);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-3);
  -webkit-app-region: no-drag;
  animation: popover-in var(--dur-2) var(--ease-out);
}

.project-switcher-card .project-picker-search {
  position: relative;
  padding: 0;
  border-bottom: 1px solid var(--border-soft);
}
.project-switcher-card .project-picker-search::after {
  content: 'Esc';
  position: absolute;
  right: 12px;
  top: 13px;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  background: var(--bg-hover);
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: 16px;
  pointer-events: none;
}
.project-switcher-card .project-picker-input {
  height: 44px;
  padding: 0 48px 0 38px;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.project-switcher-card .project-picker-input:focus {
  border-color: transparent;
  box-shadow: none;
}
.project-switcher-card .project-picker-search-icon {
  left: 14px;
  top: 14px;
}
.project-switcher-card .project-picker-body {
  max-height: 372px;
  margin: 0;
  padding: 6px;
}
.project-switcher-card .project-picker-item-icon svg {
  width: 16px;
  height: 16px;
}
.project-switcher-card .project-picker-footer {
  margin: 0;
  padding: 8px 8px 8px 10px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-soft);
}

/* ----------- Buttons ----------- */
.btn {
  font-family: var(--font-ui);
  font-size: var(--text-md);
  font-weight: 500;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    background var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out),
    transform var(--dur-1) var(--ease-out);
  -webkit-app-region: no-drag;
  /* <button> defaults to color: ButtonText; reset so the variant
     classes (.btn-primary, .btn-secondary, .btn-danger) can win
     reliably and any unstyled .btn at least inherits theme color. */
  color: inherit;
}

.btn-small {
  font-size: var(--text-sm);
  padding: 7px 12px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--btn-primary-hover);
  border-color: var(--btn-primary-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

/* A red that reads as "this deletes something" on a dark window as well
   as a light one (owner, Nov 2026: the brick red was too dull). White on
   it is 4.8:1; the console (infra/studio) and CLAUDE.md name the same
   value. */
.btn-danger {
  background: #dc2626;
  color: #fff;
  border-color: #dc2626;
}

.btn-danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

/* Pressed: a 2% dip, the feedback a physical key gives. Reduced motion
   drops the transform and keeps the colour change. */
.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ----------- Editor layout ----------- */
.editor-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* The one top bar: identity on the left, the Script|Board|Split switch
 * dead-centre (a grid column, so it never shifts when a side cluster
 * changes width), actions on the right. 44px is the mac traffic-light
 * row; the old 57px editor toolbar is gone — its controls moved to the
 * status bar (element type, scene) and the icon rail (Title Page). */
.titlebar {
  -webkit-app-region: drag;
  height: 44px;
  display: grid;
  /* minmax(0, …): a bare 1fr cannot shrink below its content, so at the
     minimum window width the title and draft name pushed out of their
     column and sat on top of the Script | Board | Split switch. The side
     columns now give way and their text truncates instead. */
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  column-gap: 8px;
  padding: 0 12px 0 10px;
  background: var(--bg-shell);
  border-bottom: 1px solid var(--shell-divider);
  flex-shrink: 0;
  user-select: none;
}

/* The cluster itself stays part of the bar's drag region; only its
   controls opt out. As a whole it is a 1fr grid column — marked no-drag,
   it took the left third of the bar out of the drag region, so that
   stretch could neither move the window nor take the double-click that
   zooms it (the OS handles both, and only on a drag region). */
.titlebar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.titlebar-left > :not(.titlebar-mark) {
  -webkit-app-region: no-drag;
}
/* When the column runs out, the draft name gives way first (three times as
   fast as the title), then the title; the traffic-light gutter, the mark
   and collaborators' avatars never shrink. Both names end in an ellipsis
   and stay on one line. */
.titlebar-left > .titlebar-traffic,
.titlebar-left > .tb-logo-btn,
.titlebar-left > .menu-bar,
.titlebar-left > .presence-anchor {
  flex-shrink: 0;
}
.titlebar-left > button.titlebar-title {
  flex: 0 1 auto;
  min-width: 56px;
}
.titlebar-left > .branch-wrap {
  flex: 0 3 auto;
  min-width: 30px;
}
.branch-wrap > .branch-badge {
  max-width: 100%;
}
.branch-badge-label {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The gutter the native traffic lights sit in (hiddenInset draws them; the
   placeholder dots are never shown). 60px here plus the bar's 10px padding
   clears the lights, which end 58px from the window edge. It used to be
   122px wide — 70px of padding plus the hidden dots — which left a dead
   stretch beside the lights and squeezed the title at narrow widths. */
.titlebar-traffic {
  flex: 0 0 60px;
  width: 60px;
  overflow: hidden;
  -webkit-app-region: no-drag;
  visibility: hidden;
}
/* Only macOS draws window controls inside this bar. Windows and Linux
   keep the native frame above it, and a full-screen Mac window has no
   traffic lights, so there the reserved gutter is dead space. */
html:not([data-platform='darwin']) .titlebar-traffic,
html[data-fullscreen] .titlebar-traffic {
  display: none;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.dot-close {
  background: #ff5f57;
}
.dot-min {
  background: #ffbd2e;
}
.dot-max {
  background: #28c840;
}

.titlebar-title {
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}

.titlebar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  justify-self: end;
  gap: 6px;
  min-width: 0;
  -webkit-app-region: no-drag;
}

.titlebar-center {
  justify-self: center;
  -webkit-app-region: no-drag;
}

/* Borderless 32px icon buttons in the title bar: the one-click tools (Title
 * Page, Versions, Settings), review comments and the two panel toggles.
 * They lived in a 52px icon rail down the left edge until Nov 2026; the
 * owner moved them here to give that column back to the script.
 * `is-active` = the panel is open — same contract
 * updatePanelToggleButtons() had with .titlebar-btn.icon-btn, and the
 * pane-half glyph fills when open (VS Code's layout-toggle convention). */
.tb-icon {
  position: relative;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out),
    transform var(--dur-1) var(--ease-out);
}
.tb-icon:hover {
  background: var(--hover-wash);
  color: var(--text-primary);
}
.tb-icon:active {
  transform: scale(0.94);
}
/* An open panel's toggle: the lighter wash. With both panels open — the
   usual state — two full selections sat lit in the corner all day. */
.tb-icon.is-active {
  background: var(--hover-wash);
  color: var(--text-primary);
}
/* A little air between the tools and the two panel toggles. */
.tb-icon.tb-icon-group-start {
  margin-left: 6px;
}
.tb-icon .panel-fill {
  fill: transparent;
  transition: fill var(--dur-2) var(--ease-out);
}
.tb-icon.is-active .panel-fill {
  fill: currentColor;
}
.tb-icon:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}
.tb-icon.hidden {
  display: none;
}
.tb-icon .toolbar-comment-count {
  position: absolute;
  top: 2px;
  right: 2px;
  margin: 0;
}

.branch-wrap {
  position: relative;
  -webkit-app-region: no-drag;
}

.branch-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  color: var(--text-secondary); /* 12px clears 4.5:1 on --bg-surface in both themes */
  font-size: var(--text-sm);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out);
}

.branch-badge:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.branch-badge[aria-expanded='true'] {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.branch-badge[disabled],
.branch-badge:disabled {
  opacity: 0.5;
  cursor: default;
}

/* A draft glyph, not a caret — same affordance model as
   .titlebar-project-icon (hover / open state carries it). */
.branch-badge-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}
.branch-badge:hover .branch-badge-icon,
.branch-badge[aria-expanded='true'] .branch-badge-icon {
  color: var(--text-primary);
}

/* Loading state — used while switchToCloudDraft is waiting on the
   network. The icon is hidden and a small spinner takes its place
   so the writer sees that the switch is in flight (and that the
   slowness isn't the editor freezing). Reuses .welcome-spinner's
   animation to stay design-system consistent. */
.branch-badge.is-loading {
  cursor: progress;
}
.branch-badge.is-loading .branch-badge-icon {
  display: none;
}
.branch-badge-spinner {
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--border, rgba(255, 255, 255, 0.18));
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: welcome-spin 0.8s linear infinite;
  flex: 0 0 auto;
}

.branch-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 240px;
  max-width: 320px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  z-index: 200;
  padding: 4px;
}

.branch-dropdown.hidden {
  display: none;
}

.branch-dropdown-section-label {
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-secondary);
  padding: 6px 10px 4px;
}

.branch-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  color: var(--text-primary);
  font-size: var(--text-sm);
  user-select: none;
}

.branch-dropdown-item:hover {
  background: var(--bg-hover);
}

.branch-dropdown-check {
  width: 12px;
  display: inline-flex;
  justify-content: center;
  color: var(--accent);
  font-size: var(--text-xs);
}

.branch-dropdown-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.branch-dropdown-item.is-current .branch-dropdown-name {
  font-weight: var(--weight-strong);
}

.branch-dropdown-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  opacity: 0.7;
}

.branch-dropdown-action {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 3px;
  font-size: var(--text-xs);
  line-height: 1;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.branch-dropdown-action svg {
  display: block;
}

.branch-dropdown-action:hover {
  background: var(--bg);
  color: var(--text-primary);
}

.branch-dropdown-action[disabled],
.branch-dropdown-action:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.branch-dropdown-separator {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.branch-dropdown-item.new-draft {
  color: var(--accent);
  font-weight: 500;
}

.branch-dropdown-item.new-draft .branch-dropdown-check {
  color: var(--accent);
}

.new-draft-modal {
  width: 460px;
  max-width: 92vw;
}

.new-draft-modal input[type='text'] {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: var(--text-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  outline: none;
  transition:
    border-color var(--dur-2) var(--ease-out),
    box-shadow var(--dur-2) var(--ease-out);
  margin-bottom: 16px;
  box-sizing: border-box;
}

.new-draft-modal input[type='text']:focus {
  border-color: var(--accent-border);
}

.new-draft-modal .settings-explainer {
  margin-bottom: 20px;
}

.new-draft-modal .settings-actions {
  margin-top: 4px;
}

/* ---- Compare Drafts modal ---- */

.compare-modal {
  width: 620px;
  max-width: 92vw;
}

.compare-pickers {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 16px;
}

.compare-picker {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Same spec as the modal text inputs — there is no other <select> in the
 * app yet, so this is the canonical select styling. Native chevrons
 * ignore padding, so we draw our own (mid-gray #888 reads on both
 * themes; CSS vars can't reach into url()). */
.compare-picker select {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 9px 32px 9px 12px;
  font-size: var(--text-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  outline: none;
  transition: border-color var(--dur-2) var(--ease-out);
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="%23888888" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>');
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.compare-picker select:focus {
  border-color: var(--accent-border);
}

.compare-arrow {
  color: var(--text-secondary);
  padding-bottom: 10px;
  flex: none;
}

/* The shared .settings-status is green + right-aligned; the compare
   status reads as a sentence and sits above the action buttons, so
   left-align, soften, and give it breathing room (same precedent as
   .contact-status). */
.compare-modal .settings-status {
  text-align: left;
  color: var(--text-secondary);
  margin: 0 0 14px;
}

.compare-results {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  max-height: 320px;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin-bottom: 16px;
}

.compare-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-md);
}

.compare-row:last-child {
  border-bottom: none;
}

/* Status chips are labeled, never color-only (same rule as beat colors). */
.compare-chip {
  flex: none;
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  letter-spacing: 0.02em;
  border-radius: var(--radius-xs);
  padding: 1px 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.compare-chip--added {
  color: var(--accent);
  border-color: var(--accent-border);
}

.compare-row-heading {
  color: var(--text-primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compare-row-heading.is-cut {
  text-decoration: line-through;
  color: var(--text-secondary);
}

.compare-row-detail {
  flex: none;
  margin-left: auto;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.compare-summary {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  align-self: center;
}

.pdf-password-modal {
  width: 420px;
  max-width: 92vw;
}

.pdf-password-modal input[type='password'],
.pdf-password-modal input[type='text'] {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: var(--text-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  outline: none;
  transition: border-color var(--dur-2) var(--ease-out);
  margin-bottom: 10px;
  box-sizing: border-box;
}

.pdf-password-modal input[type='password']:focus,
.pdf-password-modal input[type='text']:focus {
  border-color: var(--accent-border);
}

.pdf-password-show {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  margin-bottom: 10px;
}

.pdf-password-show input[type='checkbox'] {
  margin: 0;
}

/* Always reserve the error slot's vertical space so populating the
 * message doesn't push the actions row down. */
.pdf-password-error {
  min-height: 18px;
  margin-bottom: 8px;
}

.export-security-modal {
  width: 460px;
  max-width: 92vw;
}

.export-security-modal .settings-explainer {
  margin-bottom: 14px;
}

.export-security-row {
  margin-bottom: 16px;
}

/* Name check at export: a calm, non-blocking line — Save stays the default. */
.export-name-check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  padding: 8px 8px 8px 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  color: var(--text-primary);
}

.export-name-check svg {
  flex: none;
  color: var(--text-secondary);
}

.export-name-check-text {
  flex: 1;
  min-width: 0;
}

.export-name-check-text span {
  display: block;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.export-security-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-md);
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}

.export-security-toggle input[type='checkbox'] {
  margin: 0;
}

.export-security-fields {
  margin: 12px 0 16px;
  padding-left: 26px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.export-security-fields input[type='password'] {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 10px;
  font-size: var(--text-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  outline: none;
  transition: border-color var(--dur-2) var(--ease-out);
  box-sizing: border-box;
}

.export-security-fields input[type='password']:focus {
  border-color: var(--accent-border);
}

.export-security-helper {
  font-size: var(--text-sm);
  margin: 14px 0 8px;
  opacity: 0.85;
}

/* Reserve the error slot so populating it doesn't push the actions
 * row. min-height + margin already set inline on the element. */

.settings-status.is-error {
  color: #c0392b;
}

.titlebar-btn {
  background: var(--bg-elevated);
  /* Per-theme boundary: dark needs the ≥3:1 control border (WCAG
   * 1.4.11) — the decorative --border is invisible on the dark
   * titlebar; light keeps today's subtle look. */
  border: 1px solid var(--titlebar-btn-border);
  color: var(--text-primary);
  padding: 4px 10px;
  font-size: var(--text-xs);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    background var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out),
    transform var(--dur-1) var(--ease-out);
}

.titlebar-btn:hover {
  background: var(--bg-hover);
}
.titlebar-btn:active {
  transform: scale(0.97);
}

.titlebar-btn.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  color: var(--text-secondary);
}

.titlebar-btn.icon-btn:hover {
  color: var(--text-primary);
}

/* Panel-toggle buttons (Scenes / right pane): "active" means the panel
 * is currently visible. The glyph's pane-half FILLS when open and
 * empties when closed (VS Code's layout-toggle convention) — the
 * previous bg-elevated→bg-hover delta was ~1.1:1, indistinguishable in
 * both themes. The button also takes the app's pressed treatment
 * (accent bg + border, same as #btn-toggle-timeline[aria-pressed]). */
.titlebar-btn.icon-btn .panel-fill {
  fill: transparent;
  transition: fill var(--dur-2) var(--ease-out);
}
.titlebar-btn.icon-btn.is-active .panel-fill {
  fill: currentColor;
}
.titlebar-btn.icon-btn.is-active {
  color: var(--text-primary);
  background: var(--accent-bg);
  border-color: var(--accent-border);
}

.titlebar-btn:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}

.editor-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Center trio wrapper (board + divider + editor). A plain flex row by
 * default — Split's stacked orientation flips it to a column. min-*: 0
 * on both axes so the children scroll instead of overflowing. */
.center-split {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  /* Anchors .cloud-open-wait, which covers the script and the board. */
  position: relative;
}

/* A cloud script that has no copy on this computer yet. The cover sits on
   the desk colour with no card: it is the absence of a page, not a dialog.
   No animation — it can lift mid-keystroke-distance from the page it hides. */
.cloud-open-wait {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-shell);
}
.cloud-open-wait.hidden {
  display: none;
}
.cloud-open-wait-inner {
  max-width: 420px;
  text-align: center;
}
.cloud-open-wait-title {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-xl);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}
.cloud-open-wait-body {
  margin: 10px 0 0;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.55;
  color: var(--text-body);
}
.cloud-open-wait-body:empty {
  display: none;
}
.cloud-open-wait-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}
.cloud-open-wait-actions.hidden,
.cloud-open-wait-actions .btn.hidden {
  display: none;
}
/* The quiet first phase: the page is covered at once, the words wait a
   beat so a normal open never flashes them. */
.cloud-open-wait.is-quiet .cloud-open-wait-inner {
  visibility: hidden;
}
.editor-body.board-split-stacked .center-split {
  flex-direction: column;
}
/* Stacked split floors: the script keeps the same working minimum as
 * the board (240px — BOARD_PANE_MIN_HEIGHT in app.js). The board pane
 * YIELDS below its dragged inline height (flex-shrink) when the window
 * gets short, instead of holding it and crushing the script; both
 * floors always fit inside the 600px window minimum. */
.editor-body.board-split-stacked .board-pane {
  flex-shrink: 1;
  min-height: 240px;
}
.editor-body.board-split-stacked .editor-center {
  min-height: 240px;
}

/* ----------- Sidebar ----------- */
.sidebar {
  width: 236px;
  background: var(--bg-shell);
  border-right: 1px solid var(--pane-divider);
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar.collapsed {
  display: none;
}

/* ----------- Resize handles (sidebar / AI pane) -----------
 * Thin invisible grippers between the sidebar and the editor, and
 * between the editor and the AI pane. Hover and active states reveal
 * a hairline so the writer can see what they're grabbing. The cursor
 * is the standard col-resize affordance. */
.resize-handle {
  flex-shrink: 0;
  width: 4px;
  cursor: col-resize;
  background: transparent;
  transition: background var(--dur-2) var(--ease-out);
  position: relative;
  z-index: 5;
  user-select: none;
}

.resize-handle:hover,
.resize-handle.resizing {
  background: var(--accent-border);
}

body.is-resizing {
  cursor: col-resize;
  user-select: none;
}

body.is-resizing.resizing-y {
  cursor: row-resize;
}

body.is-resizing * {
  pointer-events: none;
}

/* When a pane is collapsed, hide its handle so it doesn't sit
 * orphaned at the page edge. */
.sidebar.collapsed + .resize-handle {
  display: none;
}
#resize-handle-ai:has(+ .ai-pane.collapsed) {
  display: none;
}

.sidebar-header {
  height: var(--bar-h);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}

.scene-list {
  padding-bottom: 24px;
}

.act-header {
  padding: calc(var(--row-pad-y) + 5px) 16px calc(var(--row-pad-y) - 1px);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: var(--tracking-caps);
}

.scene-item {
  /* Inset pill (same idiom as chat session rows): 8px side margin + 8px
     padding keeps the scene number aligned with the ACT header's 16px. */
  padding: var(--row-pad-y) 8px;
  margin: 1px 8px;
  border-radius: var(--radius-md);
  /* 12px: in capitals every letter stands at cap height, so 13px here read
     a size larger than the 13px mixed-case text beside it. */
  font-size: var(--text-sm);
  /* Regular at rest, medium when picked. A column of all-caps headings in
     medium read as a wall of bold; regular in --text-secondary still clears
     7:1 on the desk, and the active row carries the emphasis. */
  font-weight: var(--weight-regular);
  /* Resting rows sit between secondary and muted so the current scene is
     the one bright line in the column (8:1 on the dark desk, 6:1 on the
     light one — still body-text legible). */
  color: color-mix(in srgb, var(--text-secondary) 60%, var(--text-muted));
  cursor: pointer;
  display: flex;
  /* First baselines, not centres: a name may run to three lines, and its
     number and badges belong beside the first. */
  align-items: baseline;
  gap: 10px;
  transition: background var(--dur-2) var(--ease-out);
  user-select: none;
}

.scene-item:hover {
  background: var(--hover-wash);
  color: var(--text-secondary);
}

.scene-item.active {
  background: var(--selected-wash);
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}

.scene-number {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-xs);
  min-width: 16px;
}

/* WCAG 1.4.3: on the active row's --bg-selected fill, muted numbers drop
   to ~3.2:1 (light). Match the active row's primary text instead. */
.scene-item.active .scene-number {
  color: var(--text-primary);
}

/* The whole name, wrapped — a writer finds a scene by the END of its
   heading as often as the start ("…KITCHEN - NIGHT" vs "…KITCHEN - DAY"),
   and one clipped line showed about twelve characters. Most headings take
   one or two lines; the longest in the reference script (85 characters)
   takes five. The six-line cap is only a net under a runaway heading — a
   paragraph mistyped as one — whose tooltip still has all of it. */
.scene-name {
  flex: 1;
  min-width: 0;
  line-height: 1.3;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
  overflow: hidden;
}

/* ----------- Editor center ----------- */
.editor-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
  /* min-height matters inside the stacked split: without it the column
   * flex item grows to fit content and .editor-scroll stops scrolling. */
  min-height: 0;
  background: var(--bg-base);
}

.editor-scene-indicator {
  font-size: var(--text-sm);
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---------- Element type dropdown (Final Draft-style) ---------- */
.element-menu {
  position: relative;
  flex-shrink: 0;
}
/* No box at rest, like every other small control on the bar: a boxed
   button read as a system dropdown dropped into the chrome. The button,
   not the label, holds the stable width (the bar must not reflow as the
   label goes from "Shot" to "Parenthetical"), so the caret can sit beside
   the word instead of at the far end of an empty field. */
.element-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  min-width: 112px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-2) var(--ease-out);
}
.element-menu-btn:hover,
.element-menu-btn[aria-expanded='true'] {
  background: var(--hover-wash);
}
.element-menu-btn:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}
/* Caret in a non-element block (outline / page break): the label reads
 * "—", dim it so it doesn't look like a real element. */
.element-menu-btn.is-neutral .element-menu-label {
  color: var(--text-secondary);
}
.element-menu-label {
  text-align: left;
}
.element-menu-caret {
  flex-shrink: 0;
  color: var(--text-secondary);
  transition: transform var(--dur-2) var(--ease-out);
}
.element-menu-btn[aria-expanded='true'] .element-menu-caret {
  transform: rotate(180deg);
}
@media (prefers-reduced-motion: reduce) {
  .element-menu-btn,
  .element-menu-caret {
    transition: none;
  }
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid transparent; /* the fill is its edge */
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--dur-2) var(--ease-out);
}

.toolbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Primary action in the toolbar (Share for Review — the #1 conversion
   lever). Mirrors the design-system .btn-primary so it reads as THE
   action in the cluster, not just another neutral button. */
.toolbar-btn--primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
.toolbar-btn--primary:hover {
  background: var(--btn-primary-hover);
  color: var(--accent-text);
  border-color: var(--btn-primary-hover);
}

.toolbar-btn.is-active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--accent-border);
}

/* Owner-gated controls (e.g. Share for a non-owner collaborator): present but
   inert, and not reactive to hover. */
.toolbar-btn:disabled,
.toolbar-btn.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.toolbar-btn:disabled:hover,
.toolbar-btn.is-disabled:hover {
  background: transparent;
  color: var(--text-secondary);
}

.toolbar-btn svg {
  flex-shrink: 0;
}

/* Pinned home for above-editor banners. Sits in the .editor-center flex
   column above .editor-scroll; zero-height when empty, holds its banner's
   height when filled (never squeezed by flex). */
.editor-banner-slot {
  flex-shrink: 0;
}

.editor-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  /* Side gutters give way before the page does. The page is a fixed 816px
     (8.5in) and the vertical scrollbar takes 14px, so a pane narrower than
     816 + 14 + 80 used to keep both 40px gutters and push the page's right
     edge off screen behind a permanent horizontal scrollbar — the case at
     the default window size with both side panels open. Now the gutters
     shrink first and the sideways scrollbar appears only when the page
     itself can't fit. Scroller padding never reaches pagination: the page
     container is a fixed-width block and breaks are measured inside it. */
  padding: 30px clamp(4px, calc((100% - 830px) / 2), 40px) 200px;
  background: var(--bg-base);
}

.page-container {
  --zoom: 1;
  /* Layout is ALWAYS logical 100% (--in fixed at 96px); display zoom is a pure
     visual transform applied here, so content, page-break pushes, and the
     gradient page cards scale as ONE unit. Pagination + page count are computed
     on the un-scaled DOM, so they're identical at every zoom and match the
     export (which always renders at 100%). */
  --in: 96px;
  position: relative;
  width: calc(8.5 * var(--in));
  margin: 0 auto;
  transform: scale(var(--zoom, 1));
  transform-origin: top center;
  /* Page-card edge. box-shadow (not border) so it never alters the content
     box → pagination/page count stay identical. Themes that don't define
     --page-edge fall back to transparent; dark and light draw an 8% hairline
     (the dark card used to vanish into the desk) and High Contrast sets it
     visible because the page and desk are both pure black. */
  box-shadow: var(--shadow-page);
}

.page-numbers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.page-num {
  position: absolute;
  font-family: var(--font-script);
  font-size: 12pt; /* logical; scaled by the .page-container transform */
  color: var(--text-secondary);
  user-select: none;
}

.page-num.page-num-hidden {
  display: none;
}

.screenplay-page {
  --zoom: 1;
  --in: 96px; /* logical; display zoom is the .page-container transform */
  position: relative;
  z-index: 1;
  min-height: calc(11 * var(--in));
  /* Industry standard US Letter margins: 1" top, 1" right, 1" bottom, 1.5" left */
  padding: calc(1 * var(--in)) calc(1 * var(--in)) calc(1 * var(--in)) calc(1.5 * var(--in));
  /*
   * Page background: one repeating-linear-gradient with HARD color
   * stops (no partial alpha). Each cycle is 11.25" tall — 11" of
   * page area painted in --bg-page, then 0.25" of gap painted in
   * --bg-base (matching the editor scroll backdrop). 1px hairlines
   * at the bottom edge of each page and the top edge of the next
   * give the boundary definition without fading.
   */
  background-color: var(--bg-page);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--bg-page) 0,
    var(--bg-page) calc(11 * var(--in) - 1px),
    rgba(0, 0, 0, 0.5) calc(11 * var(--in) - 1px),
    rgba(0, 0, 0, 0.5) calc(11 * var(--in)),
    var(--bg-base) calc(11 * var(--in)),
    var(--bg-base) calc(11.25 * var(--in) - 1px),
    rgba(255, 255, 255, 0.12) calc(11.25 * var(--in) - 1px),
    rgba(255, 255, 255, 0.12) calc(11.25 * var(--in))
  );
  border: none;
  border-radius: 0;
  box-shadow: none;
  font-family: var(--font-script);
  /* 12pt Courier at 6 lines per inch (54 lines in the 9" content area),
     the industry standard. Pinned, never `normal`: Chromium's `normal`
     reads Courier Prime's hhea metrics on macOS (16px) but its usWin
     metrics on Windows (21px), so the same script ran ~30% longer on
     Windows, in the editor and the PDF. Do NOT use line-height: 1
     (forces glyphs to touch). */
  font-size: 12pt; /* logical; display zoom is the .page-container transform */
  line-height: 12pt;
  color: var(--page-text);
  outline: none;
  caret-color: var(--accent);
}

/*
 * Soft page-break spacer (ProseMirror widget decoration). Splits a straddling
 * body paragraph: a block-level empty box in the inline flow ends the line
 * before it and pushes the rest onto the next page card. Its height is set
 * inline (logical px, so the .page-container transform scales it with the
 * content). Inert — the painted page gap shows through and the caret skips it.
 * Print hides it: the export stamps the editor's page starts as forced
 * breaks (#199), so the spacer must not add a gap on top of them.
 */
.page-break-spacer {
  display: block;
  width: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/*
 * Screen-only rasterization. Scoped to @media screen so it NEVER
 * participates in PDF/print: printToPDF emulates print media, and the
 * body.printing rules own the export look (#000 on #fff). The global
 * "html, body { -webkit-font-smoothing: antialiased }" thins Courier's
 * strokes, which reads as "sharp"; "auto" lets the engine render them
 * fuller/softer. Purely a rasterization hint — no advance-width or line
 * metric change, so pagination is untouched.
 */
@media screen {
  .screenplay-page {
    -webkit-font-smoothing: auto;
  }
}

/*
 * The editing surface intentionally has NO focus ring. A ring around the
 * full-page contenteditable is visually noisy while writing, and the blinking
 * text caret (caret-color: var(--accent)) is an accepted focus indicator for a
 * text field under WCAG 2.4.7. Other interactive controls keep their rings.
 */

/*
 * Keyboard focus rings for interactive controls that were missing one
 * (WCAG 2.4.7). Same token + pattern as the ~20 existing :focus-visible
 * rules. Inset offset so rings inside scroll containers (scene list,
 * timeline) aren't clipped. Visual only — no layout impact.
 */
.find-btn:focus-visible,
.ai-tab:focus-visible,
.scene-item:focus-visible,
.timeline-segment:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}
/* A whole pane (the script scroller, the board canvas) takes the softer
   mixed ring: at full accent strength a focused pane wears a heavy frame
   the size of the window, and the caret or the selected card inside it is
   the real focus cue. */
.editor-scroll:focus-visible {
  outline: 2px solid var(--accent-border);
  outline-offset: -2px;
}

/* The chat input is a text field like the editor: the caret (plus the
   composer's own outline) is the focus cue, so it gets no inner ring. */
.chat-input:focus-visible {
  outline: none;
}

/*
 * WCAG 1.4.11: real form-field boundaries need ≥3:1. The global --border
 * token is tuned for decorative dividers (exempt), so text fields use the
 * stronger --control-border. Tag selectors here (+ :not for native widgets)
 * outrank the .class rules that set the subtle border, overriding only the
 * border color. Decorative card/dropdown borders are untouched.
 */
input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='color']):not(
    [type='file']
  ),
textarea,
select {
  border-color: var(--control-border);
}

/*
 * Indents below are extra padding INSIDE .screenplay-page, whose content
 * box already starts at 1.5" from the page left edge. So "padding-left"
 * here = (target distance from page edge) - 1.5".
 *
 * Canonical spec (US screenplay; matches docs/REQUIREMENTS.md table):
 *
 *   Element            | Left  | Right edge | Space before
 *   -------------------|-------|------------|--------------
 *   Scene Heading      | 1.5"  | 7.5"       | 24pt (2 lines)
 *   Action             | 1.5"  | 7.5"       | 12pt (1 line)
 *   Character          | 3.5"  | 7.25"      | 12pt
 *   Parenthetical      | 3.0"  | 5.5"       | 0
 *   Dialogue           | 2.5"  | 6.0"       | 0
 *   Transition         | 5.5"  | 7.1"       | 12pt, right-aligned
 */

.screenplay-page > div {
  /* Default: 1 line of vertical breathing room between major blocks. */
  margin: 1em 0 0;
}

.screenplay-page > div:first-child {
  margin-top: 0;
}

.scene-heading {
  font-weight: bold;
  text-transform: uppercase;
  /* Brightest in the tonal ladder so sluglines read as section dividers. */
  color: var(--el-scene);
  /* Scene heading gets 2 lines of breathing room above (24pt). */
  margin-top: 2em;
}

.action {
  /* A notch dimmer than dialogue — the cue that separates description from
     speech (indent alone wasn't enough, especially in dark mode). */
  color: var(--el-action);
}

.character {
  text-transform: uppercase;
  /* Brighter than body so each speech block reads as an anchored unit. */
  color: var(--el-character);
  /* 3.5" from page edge = 2.0" inside the 1.5" left margin.
     7.25" right edge   = 0.25" right padding inside the 7.5" content edge. */
  padding-left: calc(2 * var(--in));
  padding-right: calc(0.25 * var(--in));
}

.dialogue {
  /* Full reading brightness — the body text you spend the most time on. */
  color: var(--el-dialogue);
  /* 2.5" left = 1.0" inside the margin. 6.0" right = 1.5" right pad. */
  padding-left: calc(1 * var(--in));
  padding-right: calc(1.5 * var(--in));
}

.parenthetical {
  /* 3.0" left = 1.5" inside the margin. 5.5" right = 2.0" right pad. */
  padding-left: calc(1.5 * var(--in));
  padding-right: calc(2 * var(--in));
  font-style: italic;
  /* Dimmest in the ladder — an aside, not a line you scan to. */
  color: var(--el-parenthetical);
}

.transition {
  /* 5.5"–7.1": 4.0" left pad, 0.4" right pad, right-aligned within the box. */
  padding-left: calc(4 * var(--in));
  padding-right: calc(0.4 * var(--in));
  text-align: right;
  text-transform: uppercase;
  /* A structural label — kept crisp, distinct from body prose. */
  color: var(--el-transition);
}

.more-marker {
  /* (MORE) sits at the character-cue indent of 3.5" from page edge. */
  padding-left: calc(2 * var(--in));
  text-transform: uppercase;
}
/* The markers sit inside the dialogue block's 1"/1.5" padding, so a long
 * "NAME (CONT'D)" wrapped to two lines where pagination reserves one (#199).
 * Cancel the padding (the character cue's measure) and never wrap. */
.more-marker,
.contd-cue {
  margin-left: calc(-1 * var(--in));
  margin-right: calc(-1.5 * var(--in));
  white-space: nowrap;
}

/* Dialogue break spacer (a page-break-spacer that also carries the
 * (MORE)/(CONT'D) markers). The flex column pins (MORE) to the top — the
 * bottom of the current page, right under the last dialogue line — and the
 * repeated cue to the bottom — the top of the next page, right above the
 * continuation. The painted page gap shows through the space between. The
 * print stylesheet collapses the gap and turns the cue into a forced break. */
.dialogue-break {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
/* The repeated cue is a character cue: same 3.5" indent + caps. */
.contd-cue {
  padding-left: calc(2 * var(--in));
  text-transform: uppercase;
}

.character + .parenthetical,
.character + .dialogue,
.parenthetical + .dialogue,
.dialogue + .parenthetical,
.dialogue + .dialogue {
  margin-top: 0;
}

/* Dual dialogue: two speakers side by side. One .dual-dialogue block
 * (measured as a single block by the pagination engine) holds two
 * .dual-column flex children. Applies on screen AND in print, so the
 * editor and the exported PDF both show two columns. Inside a column the
 * cue re-centers over its own half-width column and dialogue takes a
 * small column-local indent (the full-width 1"–2" indents would overflow
 * a half-width column). */
.dual-dialogue {
  display: flex;
  gap: 0.25in;
}
.dual-column {
  flex: 1 1 50%;
  min-width: 0;
}
.dual-column .character {
  padding-left: 0;
  padding-right: 0;
  text-align: center;
}
.dual-column .dialogue,
.dual-column .parenthetical {
  padding-left: 0.2in;
  padding-right: 0.2in;
}

/* Centered text (Fountain `> text <`). Spans the full action width and
 * centers — title cards, "THE END", song titles. Printed (no nonPrinting). */
.centered {
  text-align: center;
}

/* Lyric lines (Fountain `~`). A PRINTING element — italic and centered so it
 * reads as sung verse, visually distinct from spoken dialogue. */
.lyric {
  font-style: italic;
  text-align: center;
}

/* Manual page break (Fountain `===`). In the editor it is a labeled dashed
 * rule so the writer sees exactly where the forced break lands; in print it
 * collapses to a real page break (body.printing rule near the other print
 * overrides). */
.page-break-manual {
  height: 0;
  margin: 18px 0;
  border-top: 1px dashed var(--border);
  position: relative;
}
.page-break-manual::after {
  content: 'PAGE BREAK';
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 8px;
  background: var(--bg-elevated);
  font-family: var(--font-page-ui);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}
.ProseMirror-selectednode.page-break-manual {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

/* Inline note (Fountain `[[ … ]]` embedded mid-line). Non-printing (the
 * `nonprinting` class hides it in the export, like the block-level note);
 * shown in the editor as a small UI-font chip so the writer sees it inline
 * without mistaking it for script prose. */
.note-inline {
  font-family: var(--font-page-ui);
  font-size: 0.82em;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 0 4px;
}

/* Outline & annotation blocks (Fountain `#`, `=`, `[[ ]]`). Non-printing:
 * the writer sees them, the exported PDF never does (hidden under
 * body.printing below). Rendered in the UI font and accent tints so they
 * read as metadata, never mistaken for script content (which stays
 * Courier black). They flow normally — see schema.js's nonPrinting note for
 * why not zero-height overlays. */
.section,
.synopsis,
.note {
  font-family: var(--font-page-ui);
  margin: 12px 0 4px;
}
.section {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent);
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}
/* Deeper `##`/`###` sections step in and lighten. */
.section[data-level='2'] {
  margin-left: 18px;
  opacity: 0.85;
}
.section[data-level='3'] {
  margin-left: 36px;
  opacity: 0.72;
}
.synopsis {
  font-size: 13px;
  font-style: italic;
  color: var(--text-secondary);
  padding-left: 10px;
  border-left: 3px solid var(--border);
}
.note {
  font-size: 12.5px;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  display: inline-block;
}

/* Whole-block selection (PM NodeSelection) — e.g. Backspace at the start of
 * a block selects the non-printing block above it instead of merging into
 * it; this makes that selection visible so a second Backspace's delete isn't
 * a surprise. */
.ProseMirror-selectednode {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Dual-dialogue authoring chip (dual-chip-plugin.js). A caret-anchored
 * toggle on the second speaker's cue: "⇄ Dual" pairs it with the speaker
 * above, "⇄ Unsplit" splits a pair back. `has-dual-chip` only flips the
 * cue to position:relative (no box-size change → pagination measurements
 * stay exact); the chip is absolutely positioned out of flow. Print CSS
 * hides it so it never reaches the PDF. */
.has-dual-chip {
  position: relative;
}
.dual-chip {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-page-ui);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  padding: 4px 8px;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  opacity: 0.7;
  transition:
    opacity 0.15s,
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}
.dual-chip:hover {
  opacity: 1;
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}
/* Glyph + label are CSS content, not text nodes, so the chip never leaks
 * into the cue block's textContent (see dual-chip-plugin.js). */
.dual-chip::before {
  content: '⇄';
  font-size: 12px;
}
.dual-chip[data-kind='pair']::after {
  content: 'Dual';
}
.dual-chip[data-kind='unpair']::after {
  content: 'Unsplit';
}

/* Gap cursor (prosemirror-gapcursor): a blinking caret in spots no
 * textblock occupies — e.g. after an isolating dual_dialogue that's the
 * last block. Restyled from the package default: upstream draws a wide
 * horizontal rule, which in a screenplay reads as an em-dash or a scene
 * divider — content, not a cursor. We render a slim VERTICAL caret in the
 * text colour instead, so it's unmistakably "type here." Typing at the gap
 * inserts an action block. */
.ProseMirror-gapcursor {
  display: none;
  pointer-events: none;
  position: absolute;
}
.ProseMirror-gapcursor::after {
  content: '';
  display: block;
  position: absolute;
  top: 0;
  height: 1em;
  width: 0;
  /* 1px to match the native text caret's weight — 2px reads as a bolder
   * cursor than the one the writer sees everywhere else. */
  border-left: 1px solid var(--text-primary);
  animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
}
.ProseMirror-focused .ProseMirror-gapcursor {
  display: block;
}
@keyframes ProseMirror-cursor-blink {
  to {
    visibility: hidden;
  }
}
@media (prefers-reduced-motion: reduce) {
  .ProseMirror-gapcursor::after {
    animation: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .dual-chip {
    transition: none;
  }
}

/* ----------- Shadow placeholders for empty paragraphs -----------
 * Greyed hint text overlaid on an empty paragraph (e.g. "CHARACTER
 * NAME", "(parenthetical)", or an auto-guessed character name). The
 * placeholder plugin scopes the attr to the caret's empty block, so
 * the hint follows the caret and vanishes on type.
 *
 * The ghost is OUT-OF-FLOW on purpose: it's absolutely positioned over
 * the blank line the block already has (ProseMirror's trailing <br>
 * supplies the line height, exactly as it does without a ghost). The
 * block must measure pixel-identical with and without its ghost, on
 * screen and in print — pagination depends on it.
 *
 * The host paragraph supplies font-family (Courier Prime, inherited from
 * .screenplay-page), font-size (12pt × zoom), padding-left (the per-
 * element indent / "tab stop"), text-transform (uppercase on caps-mode
 * elements), font-weight (bold scene-heading), font-style (italic
 * parenthetical), and text-align (right-aligned transition). Absolute
 * offsets anchor to the host's PADDING box, so `padding: inherit` +
 * border-box re-creates the host's content box and the hint lands at
 * the same column as the real text will when the writer types it.
 *
 * We only override what makes it READ as a hint (color + opacity) and
 * what would otherwise be wrong on a hint (no user-select). All the
 * per-element-type styling is asserted explicitly below for clarity,
 * even where it would inherit.
 */
.screenplay-page [data-placeholder] {
  position: relative;
}
.screenplay-page [data-placeholder]::before {
  content: attr(data-placeholder);
  position: absolute;
  inset: 0;
  padding: inherit;
  box-sizing: border-box;
  white-space: nowrap;
  color: var(--text-secondary);
  opacity: 0.45;
  font-family: var(--font-script);
  font-size: inherit;
  font-style: inherit;
  font-weight: inherit;
  text-transform: inherit;
  text-align: inherit;
  letter-spacing: inherit;
  line-height: inherit;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
/* Ghosts are screen-only chrome: in print/export an empty block renders
   as a true blank line. body.printing covers the printToPDF export path
   (it print-emulates this same DOM); @media print covers the OS dialog. */
body.printing .screenplay-page [data-placeholder]::before {
  content: none;
}
@media print {
  .screenplay-page [data-placeholder]::before {
    content: none;
  }
}

/* Per-element-type emphasis — redundant with inheritance, but states the
 * intent so a future stylesheet edit can't silently lose it. */
.scene-heading[data-placeholder]::before {
  font-weight: bold;
  text-transform: uppercase;
}
.character[data-placeholder]::before {
  text-transform: uppercase;
}
.parenthetical[data-placeholder]::before {
  font-style: italic;
}
.transition[data-placeholder]::before {
  text-transform: uppercase;
  text-align: right;
}
.shot[data-placeholder]::before {
  text-transform: uppercase;
}
.act-break[data-placeholder]::before {
  font-weight: bold;
  text-transform: uppercase;
}

/* Guessed character names lean darker and lose the all-caps casing
 * transform — the auto-guess stores the canonical form (already upper)
 * and we want it to read as a real-text suggestion the writer is about
 * to accept, not as a label. Tab inserts them as actual text. */
.screenplay-page [data-placeholder][data-placeholder-kind='guess']::before {
  opacity: 0.6;
}

/* ----------- Character-cue autocomplete popover -----------
 * Floating list of character names that match what the writer is
 * typing inside a `character` block. Positioned at the bottom-left
 * of the block via inline top/left set by the autocomplete plugin.
 * Appended to <body> so the editor's overflow doesn't clip it.
 */
.pm-autocomplete {
  position: absolute;
  min-width: 160px;
  max-width: 260px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  font-family: var(--font-script);
  font-size: 12pt;
  z-index: 9999;
  padding: 4px 0;
}
.pm-autocomplete-item {
  padding: 4px 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  cursor: pointer;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Mouse hover: a quiet neutral. Keyboard-active (the arrow-key cursor): the
 * brand accent with its contrasting text — `--bg-elevated` was nearly
 * invisible on the cream surface. `.active` after `:hover` so the keyboard
 * cursor still reads clearly even under the pointer. */
.pm-autocomplete-item:hover {
  background: var(--hover-wash);
}
/* Exception: the keyboard-driven cursor stays a bold solid accent so it
 * reads clearly while typing — distinct from the quiet mouse-hover wash. */
.pm-autocomplete-item.active {
  background: var(--accent);
  color: var(--accent-text);
}

/* ----------- Elements palette -----------
 * Cmd-/ or `/` at start of an empty block opens this popover. Same
 * positioning model as .pm-autocomplete (body-attached, fixed/absolute,
 * re-anchored on scroll/resize). Three columns per row: a square letter
 * chip, the element label, and the optional force-prefix hint.
 */
.pm-element-palette {
  position: absolute;
  min-width: 220px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  font-family: var(--font-page-ui);
  font-size: 13px;
  z-index: 9999;
  padding: 4px 0;
}
.pm-palette-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  cursor: pointer;
  color: var(--text-primary);
}
.pm-palette-item:hover {
  background: var(--hover-wash);
}
.pm-palette-item.active {
  background: var(--selected-wash);
}
.pm-palette-key {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated, rgba(0, 0, 0, 0.08));
  font-family: var(--font-mono, ui-monospace, monospace);
  font-weight: 600;
  font-size: 11px;
}
.pm-palette-item.active .pm-palette-key {
  background: var(--accent, #4a7afe);
  color: #fff;
}
.pm-palette-label {
  white-space: nowrap;
}
.pm-palette-item.is-current .pm-palette-label::after {
  content: ' ✓';
  color: var(--text-secondary, rgba(0, 0, 0, 0.5));
}
.pm-palette-hint {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  color: var(--text-secondary, rgba(0, 0, 0, 0.5));
}

/* ---------- Element dropdown listbox (portaled to <body>) ----------
 * Lives outside the overflow:hidden toolbar; positioned under its button
 * by createElementMenu. Shares the palette's surface tokens. */
.element-menu-list {
  position: absolute;
  margin: 0;
  padding: 5px;
  list-style: none;
  min-width: 200px;
  background: var(--bg-elevated);
  border: 1px solid var(--shell-divider);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  z-index: 9999;
}
.element-menu-list[hidden] {
  display: none;
}
.element-menu-list:focus {
  outline: none;
}
.element-menu-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: var(--menu-pad-y) 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-primary);
}
.element-menu-opt.is-active,
.element-menu-opt:hover {
  background: var(--hover-wash);
}
.element-menu-opt-label {
  white-space: nowrap;
}
/* Check on the element the caret is currently in. */
.element-menu-opt.is-current .element-menu-opt-label::after {
  content: ' ✓';
  color: var(--text-secondary);
}
.element-menu-opt.is-current {
  background: var(--selected-wash);
}
.element-menu-opt-accel {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ----------- Cmd-hold cheatsheet -----------
 * Bottom-anchored toast that appears after the writer holds ⌘ for
 * 350ms and disappears on ⌘ release or on any chord keystroke.
 * Always rendered into <body> so it floats above every workspace
 * pane regardless of stacking context.
 */
.cmd-cheatsheet {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%) translateY(8px);
  display: flex;
  gap: 28px;
  padding: 14px 18px;
  max-width: calc(100vw - 32px);
  overflow-x: auto;
  background: rgba(20, 22, 26, 0.96);
  color: #f3f4f6;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  font-family: var(--font-ui, system-ui, -apple-system, sans-serif);
  font-size: var(--text-sm);
  line-height: 1.4;
  pointer-events: none; /* the writer is still typing; never intercept */
  opacity: 0;
  transition:
    opacity var(--dur-2) var(--ease-out),
    transform var(--dur-2) var(--ease-out);
  z-index: 10000;
}
.cmd-cheatsheet.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.cmd-cheatsheet-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 164px;
}
.cmd-cheatsheet-group-title {
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: 4px;
  font-weight: var(--weight-strong);
}
.cmd-cheatsheet-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cmd-cheatsheet-chord {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-width: 56px;
  /* Three-key chords (⌘⌥N, ⌘⇧P) are wider than the 56px column; without
   * this the chord shrinks to the column and its chips paint over the
   * label. The label wraps instead. */
  flex-shrink: 0;
  white-space: nowrap;
}
.cmd-cheatsheet-key {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--text-xs);
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  min-width: 16px;
  text-align: center;
}
.cmd-cheatsheet-plus {
  color: rgba(255, 255, 255, 0.35);
  font-size: var(--text-2xs);
  margin: 0 1px;
}
.cmd-cheatsheet-label {
  color: rgba(255, 255, 255, 0.85);
}

/* ----------- Find & Replace bar -----------
 * Anchored above the timeline strip. Opens on ⌘F, closes on Esc.
 * Matches are painted in via the CSS Custom Highlight Registry so
 * the underlying DOM (and our contenteditable model) stays
 * untouched — only Range objects are tracked, never <mark> tags.
 */
/* Floats over the top-right of the page (VS Code's find widget) instead
 * of pushing the page down — the editor keeps its layout while finding. */
.find-bar {
  position: absolute;
  top: 8px;
  right: 24px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}

.find-bar.hidden {
  display: none;
}

.find-input,
.find-replace-input {
  width: 200px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--dur-2) var(--ease-out);
}

.find-input:focus,
.find-replace-input:focus {
  border-color: var(--accent);
}

.find-count {
  color: var(--text-muted);
  font-size: var(--text-xs);
  min-width: 78px;
  text-align: center;
}

.find-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 4px 8px;
  cursor: pointer;
  border-radius: var(--radius-xs);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}

.find-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border);
  color: var(--text-primary);
}

.find-close {
  margin-left: 4px;
}

.find-sep {
  color: var(--text-muted);
  opacity: 0.4;
  padding: 0 4px;
}

/* Text selection — neutral and brand-controlled. Without this rule the
 * selection falls back to the OS default (a blue-grey that matches
 * neither the grey accent nor the brand). Mid-grey at low alpha reads
 * against both the dark and the light page; text color is left to
 * inherit so the selected text stays legible. */
::selection {
  background: rgba(145, 145, 141, 0.35);
}

/* Highlight registry — matches paint in a pale yellow, the focused
 * match in a stronger orange. */
::highlight(find-matches) {
  background-color: rgba(255, 215, 0, 0.32);
  color: inherit;
}

::highlight(find-current) {
  background-color: rgba(255, 140, 0, 0.65);
  color: inherit;
}

body.printing .find-bar {
  display: none !important;
}

/* ----------- Editor status bar -----------
 * Slim bottom bar showing word count, page count, save status, and
 * the current draft number. Replaces the old toolbar Save button —
 * the bar shows whether the document is up to date, and ⌘S handles
 * the explicit-save path when the writer wants a discrete version.
 */
.editor-statusbar:empty,
.editor-statusbar.empty {
  display: none;
}

.statusbar-segment {
  white-space: nowrap;
}

.statusbar-segment:empty {
  display: none;
}

.statusbar-flex {
  flex: 1;
}

.statusbar-segment.status-unsaved {
  color: var(--accent);
}

.statusbar-segment.status-save-error {
  color: var(--red);
  font-weight: var(--weight-strong);
}

.statusbar-segment.status-saved {
  color: var(--text-secondary);
}

body.printing .editor-statusbar {
  display: none !important;
}

/* ----------- Writing streak: chip + popover (bottom bar) ----------- */
.streak-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.streak-chip {
  width: auto;
  height: 20px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px 0 4px;
  position: relative;
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.streak-chip.hidden {
  display: none;
}

.streak-chip svg {
  display: block;
  color: var(--brand-pink);
}

.streak-chip[data-status='none'] svg {
  color: var(--text-muted);
}

/* At risk = dimmed with an orange dot, the same treatment as the sprint
 * running dot so the bar keeps one vocabulary. */
.streak-chip[data-status='open'] {
  opacity: 0.6;
}

.streak-chip-dot {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 0 1px var(--bg-surface);
  display: none;
}

.streak-chip[data-status='open'] .streak-chip-dot {
  display: block;
}

.streak-popover {
  position: absolute;
  bottom: calc(100% + 10px);
  right: -10px;
  width: 248px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow:
    0 14px 40px rgba(0, 0, 0, 0.42),
    0 1px 0 rgba(255, 255, 255, 0.04) inset;
  padding: 14px 14px 12px;
  z-index: 200;
  user-select: none;
  font-family: var(--font-ui);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.streak-popover.hidden {
  display: none;
}

.streak-popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.streak-popover-head svg {
  color: var(--brand-pink);
}

.streak-eyebrow {
  font-size: var(--text-2xs);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.streak-popover-count {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--text-primary);
  font-size: var(--text-md);
}

.streak-popover-count strong {
  font-family: var(--font-script, ui-monospace, monospace);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-hero);
  font-weight: 500;
  line-height: 1;
}

.streak-popover-sub {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.streak-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.streak-cell {
  height: 22px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-sizing: border-box;
}

.streak-cell.is-earned {
  border: none;
  background: var(--streak-cell-color, var(--brand-pink));
}

.streak-cell.is-today.is-earned {
  background: var(--streak-fire);
  box-shadow:
    0 0 0 2px rgba(255, 42, 26, 0.3),
    0 0 16px rgba(255, 42, 26, 0.65);
}

.streak-cell.is-today:not(.is-earned) {
  border: 1.5px dashed var(--streak-fire);
}

.streak-grid-labels {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 6px;
}

.streak-popover-foot {
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.streak-popover-foot button {
  background: transparent;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}

.streak-popover-foot button:hover {
  color: var(--text-primary);
}

/* ----------- Writing streak: modal ----------- */
/* Entrance choreography. Everything keys off the overlay leaving
 * display:none, so the keyframes restart on every open without JS:
 * backdrop fades, the card settles up from 96%, the flame blooms, the
 * gradient track draws left→right, and the earned dots pop in order
 * (--i is set per day by streak.js#weekHtml). Under reduced motion every
 * transform collapses to a plain fade, per the modern-editor rule. */
#streak-overlay:not(.hidden) {
  animation: streak-overlay-in 200ms ease-out both;
}

#streak-overlay:not(.hidden) .streak-modal {
  animation: streak-card-in 360ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

#streak-overlay:not(.hidden) .streak-flame {
  animation: streak-flame-in 620ms cubic-bezier(0.22, 1, 0.36, 1) 120ms both;
}

#streak-overlay:not(.hidden) .streak-week-track {
  transform-origin: left center;
  animation: streak-track-in 520ms ease-out 240ms both;
}

#streak-overlay:not(.hidden) .streak-dot.is-earned {
  animation: streak-dot-in 380ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: calc(260ms + var(--i, 0) * 55ms);
}

#streak-overlay:not(.hidden) .streak-modal-trim {
  background-size: 200% 100%;
  animation: streak-trim-shine 1400ms ease-out 200ms both;
}

@keyframes streak-overlay-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes streak-card-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes streak-flame-in {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  60% {
    opacity: 1;
    transform: scale(1.12);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes streak-track-in {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

@keyframes streak-dot-in {
  from {
    opacity: 0;
    transform: scale(0.4);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes streak-trim-shine {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}

@keyframes streak-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  #streak-overlay:not(.hidden) .streak-modal,
  #streak-overlay:not(.hidden) .streak-flame,
  #streak-overlay:not(.hidden) .streak-dot.is-earned {
    animation: streak-fade-in 200ms ease-out both;
    animation-delay: 0ms;
  }

  #streak-overlay:not(.hidden) .streak-week-track,
  #streak-overlay:not(.hidden) .streak-modal-trim {
    animation: none;
  }
}

.streak-modal {
  position: relative;
  overflow: hidden;
  padding-top: 25px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.streak-modal-trim {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 4px;
  background: var(--streak-gold);
}

.streak-modal-trim::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 4px;
  height: 1px;
  background: rgba(243, 220, 140, 0.35);
}

.streak-modal-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding-top: 4px;
}

.streak-flame {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand-pink);
  background: radial-gradient(circle, rgba(255, 46, 139, 0.32) 0%, rgba(0, 0, 0, 0) 72%);
}

.streak-modal[data-kind='atrisk'] .streak-flame {
  color: var(--orange);
  background: radial-gradient(circle, rgba(176, 132, 88, 0.32) 0%, rgba(0, 0, 0, 0) 72%);
}

.streak-modal[data-kind='ended'] .streak-flame {
  color: var(--text-muted);
  background: radial-gradient(circle, rgba(154, 154, 147, 0.18) 0%, rgba(0, 0, 0, 0) 72%);
}

.streak-modal[data-kind='milestone'] .streak-eyebrow {
  color: var(--brand-pink);
}

.streak-modal[data-kind='atrisk'] .streak-eyebrow {
  color: var(--orange);
}

.streak-headline {
  margin: 0;
  font-size: var(--text-3xl);
  font-weight: var(--weight-strong);
  line-height: 1.2;
  color: var(--text-primary);
}

.streak-body {
  margin: 0;
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--text-secondary);
  max-width: 380px;
  text-wrap: pretty;
}

.streak-week {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 0 auto;
}

.streak-week-track {
  position: absolute;
  left: 15px;
  right: 15px;
  top: 13px;
  height: 4px;
  border-radius: 2px;
}

.streak-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: var(--text-2xs);
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.streak-dot {
  position: relative;
  z-index: 1;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  /* Opaque on purpose: the gradient track runs behind the row, and a
   * hollow (unearned) day must mask it, not show it cutting through. */
  background: var(--bg-surface);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.streak-dot.is-earned {
  border: none;
  background: var(--streak-dot-color, var(--brand-pink));
  box-shadow: 0 0 10px
    color-mix(in srgb, var(--streak-dot-color, var(--brand-pink)) 35%, transparent);
}

.streak-dot.is-today.is-earned {
  background: var(--streak-fire);
  box-shadow:
    0 0 0 3px rgba(255, 42, 26, 0.25),
    0 0 24px rgba(255, 42, 26, 0.7);
}

.streak-dot.is-today:not(.is-earned) {
  border: 1.5px dashed var(--streak-fire);
  box-shadow: 0 0 14px rgba(255, 42, 26, 0.35);
}

.streak-stats {
  display: flex;
  padding: 12px 4px;
  background: var(--bg-base);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
}

.streak-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.streak-stat + .streak-stat {
  border-left: 1px solid var(--border-soft);
}

.streak-stat-value {
  font-family: var(--font-script, ui-monospace, monospace);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-3xl);
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.1;
}

.streak-stat-value.is-accent {
  color: var(--brand-pink);
}

.streak-modal[data-kind='atrisk'] .streak-stat-value.is-accent {
  color: var(--orange);
}

.streak-stat-label {
  font-size: var(--text-2xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.streak-quote {
  margin: 0;
  padding: 16px 24px 0;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.streak-quote blockquote {
  margin: 0;
  font-family: var(--font-script);
  font-style: italic;
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--page-text);
  text-wrap: balance;
}

.streak-quote figcaption {
  font-size: var(--text-2xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.streak-quote.hidden {
  display: none;
}

.streak-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
  padding-left: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.streak-ghost:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.streak-ghost.hidden {
  display: none;
}

.streak-hour-select {
  background: var(--bg-base);
  border: 1px solid var(--control-border);
  color: var(--text-primary);
  padding: 6px 10px;
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
}

.streak-settings-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 4px 14px;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* ----------- Timeline strip -----------
 * Horizontal strip above the editor. Each scene is a clickable
 * segment with the scene number on top and the slug below. Segments
 * are proportional to scene length (character count) so the writer
 * can see at a glance which scenes are weighty and which are slim.
 * If the script outgrows the strip width it scrolls horizontally. */
.timeline-strip {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-soft);
  overflow-x: auto;
  overflow-y: hidden;
  height: 56px;
  scrollbar-width: thin;
}

.timeline-strip::-webkit-scrollbar {
  height: 6px;
}
.timeline-strip::-webkit-scrollbar-thumb {
  border-radius: 3px;
}

/* Expanded: pulled down past the threshold. Switching the container to a grid
 * makes the per-segment inline flex-grow (set in renderTimeline) a no-op, so
 * cards become uniform cells that wrap into rows — a scrollable scene grid.
 * The inline `height` (set by the drag) governs how many rows show. */
.timeline-strip.expanded {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  grid-auto-rows: 46px;
  align-content: start;
  overflow-x: hidden;
  overflow-y: auto;
}
.timeline-strip.expanded .timeline-segment {
  min-width: 0; /* the grid template owns width now; drop the one-row floor */
  border-bottom: 1px solid var(--border);
}
.timeline-strip.expanded::-webkit-scrollbar {
  width: 8px;
}

/* The drag handle on the strip's bottom edge — pull down to expand. */
.timeline-resize-handle {
  flex-shrink: 0;
  height: 7px;
  cursor: ns-resize;
  background: transparent;
  position: relative;
  z-index: 5;
  user-select: none;
}
.timeline-resize-handle::after {
  /* a centered grip, revealed on hover/focus/drag */
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease-out);
}
.timeline-resize-handle:hover::after,
.timeline-resize-handle.resizing::after,
.timeline-resize-handle:focus-visible::after {
  opacity: 1;
  background: var(--accent-border);
}
.timeline-resize-handle:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}
body.printing .timeline-resize-handle {
  display: none !important;
}

.timeline-segment {
  /* flex-basis 0 + grow value set inline lets each segment claim a
   * share of the strip width proportional to its scene length. The
   * grow weight is the character count, so the longest scenes get
   * the widest segments. min-width keeps the shortest scenes
   * readable; once min-widths sum past the strip width the strip
   * starts to scroll horizontally. */
  flex-shrink: 1;
  flex-grow: 1;
  flex-basis: 0;
  min-width: 60px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px;
  font-family: var(--font-ui);
  text-align: left;
  transition: background var(--dur-2) var(--ease-out);
  overflow: hidden;
}

.timeline-segment:last-child {
  border-right: 0;
}

.timeline-segment:hover {
  background: var(--bg-hover);
}

/* Three-act color story. The tints are deliberately faint so the
 * strip reads as one cohesive bar with subtle hue shifts at the act
 * boundaries, not three rainbow blocks. Each act has a slightly
 * stronger tint for its active segment plus a coloured underline. */
.timeline-segment.act-1 {
  background: rgba(96, 156, 240, 0.06);
}
.timeline-segment.act-2 {
  background: rgba(118, 192, 130, 0.06);
}
.timeline-segment.act-3 {
  background: rgba(240, 158, 78, 0.08);
}

.timeline-segment.act-1:hover {
  background: rgba(96, 156, 240, 0.12);
}
.timeline-segment.act-2:hover {
  background: rgba(118, 192, 130, 0.12);
}
.timeline-segment.act-3:hover {
  background: rgba(240, 158, 78, 0.14);
}

.timeline-segment.act-1.active {
  background: rgba(96, 156, 240, 0.2);
  box-shadow: inset 0 -2px 0 #609cf0;
}
.timeline-segment.act-2.active {
  background: rgba(118, 192, 130, 0.2);
  box-shadow: inset 0 -2px 0 #76c082;
}
.timeline-segment.act-3.active {
  background: rgba(240, 158, 78, 0.24);
  box-shadow: inset 0 -2px 0 #f09e4e;
}

.timeline-segment-number {
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.timeline-segment-label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

/* The toolbar's Timeline toggle reflects state via aria-pressed. */
#btn-toggle-timeline[aria-pressed='true'] {
  background: var(--accent-bg);
  color: var(--text-primary);
  border-color: var(--accent-border);
}

/* Print: timeline is editor chrome — hide it on the PDF. */
body.printing .timeline-strip {
  display: none !important;
}

/* ----------- Version-preview banner -----------
 * Shown above the page when the writer opens an older draft from the
 * History pane. Mirrors the Google-Docs version-history affordance:
 * a slim bar across the top of the editor with Back / Restore. */
.preview-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--accent-bg);
  border-bottom: 1px solid var(--accent-border);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  gap: 12px;
}

.preview-banner-label {
  color: var(--text-primary);
  font-weight: 500;
}

.preview-banner-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.screenplay-page.preview-mode {
  caret-color: transparent;
}

.checkpoint-item,
.checkpoint-draft {
  cursor: pointer;
}
.checkpoint-item:hover,
.checkpoint-draft:hover {
  background: var(--accent-bg);
}
.checkpoint-item.active,
.checkpoint-draft.active {
  background: var(--accent-bg);
  border-left: 2px solid var(--accent);
}

/* ----------- Settings overlay ----------- */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  backdrop-filter: blur(3px);
  -webkit-app-region: no-drag;
  animation: overlay-in var(--dur-2) var(--ease-out);
}

/* Every dialog is this one card: no border of its own — --shadow-3 carries
   a hairline ring, so the edge holds on the dark desk without a second
   line. It settles into place over the scrim's fade. */
/* A dialog that holds focus itself (app.js showConfirmModal, focus:
   'dialog') is not a control: the ring belongs to its buttons. */
.settings-modal[tabindex='-1']:focus,
.settings-modal[tabindex='-1']:focus-visible {
  outline: none;
}

.settings-modal {
  background: var(--bg-surface);
  border: 0;
  border-radius: var(--radius-xl);
  padding: 22px;
  width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-3);
  animation: dialog-in var(--dur-3) var(--ease-out);
}

@keyframes overlay-in {
  from {
    opacity: 0;
  }
}
/* The entrance keyframes animate the individual `translate` / `scale`
   properties, never `transform`: several of these surfaces are positioned
   or zoomed with their own transform, and a keyframed transform would
   replace it for the length of the animation. */
@keyframes dialog-in {
  from {
    opacity: 0;
    translate: 0 6px;
    scale: 0.985;
  }
}
@keyframes popover-in {
  from {
    opacity: 0;
    scale: 0.97;
  }
}
@keyframes pane-in {
  from {
    opacity: 0;
  }
}

/* Menus and popovers settle in as they open. Not the two that appear while
   typing in the script (.pm-autocomplete, .pm-element-palette): those must
   be there on the keystroke. */
.library-action-menu,
.branch-dropdown,
.file-menu,
.element-menu-list:not([hidden]),
.chat-session-menu,
.share-contacts-dropdown,
.slash-menu,
.board-menu,
.cmd-cheatsheet {
  animation: popover-in var(--dur-2) var(--ease-out);
}

/* Switching a Settings pane or a side-panel tab: the new content fades up
   instead of snapping, so the eye is told something changed. */
.settings-pane.is-active,
.ai-tab-panel.active {
  animation: pane-in var(--dur-2) var(--ease-out);
}

@media (prefers-reduced-motion: reduce) {
  .settings-overlay,
  .settings-modal,
  .upsell-card,
  .project-switcher-card,
  .library-action-menu,
  .branch-dropdown,
  .file-menu,
  .element-menu-list,
  .chat-session-menu,
  .share-contacts-dropdown,
  .slash-menu,
  .board-menu,
  .cmd-cheatsheet,
  .settings-pane.is-active,
  .ai-tab-panel.active {
    animation: none;
  }
  .btn:active,
  .tb-icon:active,
  .titlebar-btn:active {
    transform: none;
  }
}

/* ----------- Tabbed Settings shell ----------- */
/* Sized relative to the app window (the way Claude's and Cursor's
   settings sheets are), with a floor and a ceiling: at the 1000×600
   minimum window it is 820×492, which is the smallest frame the rail
   (ten panes under App / Account / Library, About and Contact pinned
   to its foot) fits without scrolling; on a large display it stops
   growing at 1120×760 so rows don't stretch into unreadable widths. */
.settings-modal-tabbed {
  display: flex;
  padding: 0;
  width: clamp(720px, 82vw, 1120px);
  max-width: 94vw;
  height: clamp(480px, 82vh, 760px);
  max-height: 92vh;
  overflow: hidden;
}

.settings-sidebar {
  flex: 0 0 196px;
  background: var(--bg-base);
  border-right: 1px solid var(--shell-divider);
  padding: 14px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

/* Brand header at the top of the rail: app icon + name + version. */
.settings-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 2px 6px 12px;
}

.settings-brand-icon {
  width: 26px;
  height: 26px;
  padding: 4px;
  box-sizing: border-box;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-brand-text {
  min-width: 0;
}

.settings-brand-name {
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  line-height: 1.2;
  color: var(--text-primary);
}

.settings-brand-version {
  font-size: var(--text-xs);
  line-height: 1.2;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-nav-group {
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-muted);
  padding: 10px 10px 4px;
}

/* The tabs' own column inside the rail: it grows to fill the rail so the
   spacer can still push About / Contact us to the bottom. */
.settings-tablist {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 0 auto;
}

.settings-sidebar-spacer {
  flex: 1 1 8px;
}

.settings-tab {
  appearance: none;
  background: transparent;
  border: none;
  text-align: left;
  font: inherit;
  font-size: var(--text-md);
  font-weight: var(--weight-regular);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 9px;
  height: var(--nav-row-h);
  padding: 0 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  flex-shrink: 0;
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out);
}

.settings-tab svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.settings-tab:hover {
  color: var(--text-primary);
  background: var(--hover-wash);
}

.settings-tab.is-active {
  background: var(--selected-wash);
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}

.settings-tab:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}

.settings-content {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 20px 22px 12px;
  overflow-y: auto;
}

/* Top-right X, the same 28px control as the BYOK sheet's close. It's
   absolutely placed inside the scrolling column, so it scrolls with a
   long pane rather than floating over the content. */
.settings-close {
  appearance: none;
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.settings-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.settings-close:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}

/* Sidebar search: same self-contained box as the chat-history search. */
.settings-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 4px 6px;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  cursor: text;
  flex: 0 0 auto;
}

.settings-search:focus-within {
  border-color: var(--accent);
}

.settings-search-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.settings-search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: var(--text-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
}

.settings-search-input::-webkit-search-cancel-button {
  appearance: none;
}

.settings-search-input::placeholder {
  color: var(--text-muted);
}

/* Tabs with no hits for the current query dim like any locked control. */
.settings-tab.is-dimmed {
  opacity: var(--locked-opacity);
}

.settings-sidebar-credit {
  padding: 10px 10px 2px;
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-sidebar-heart {
  font-size: var(--text-xs);
}

.settings-search-summary {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: -6px 0 14px;
}

.settings-search-result {
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
}

.settings-search-result:hover {
  background: var(--bg-hover);
}

.settings-search-result:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}

.settings-search-crumb {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: 2px;
}

.settings-search-hit {
  background: transparent;
  color: var(--accent);
  font-weight: var(--weight-strong);
}

.settings-search-empty {
  font-size: var(--text-md);
  color: var(--text-muted);
  padding: 8px 0;
}

/* A row the writer jumped to from search flashes once so the eye lands
   on it after the pane switch. */
@keyframes settings-row-flash {
  0% {
    box-shadow: 0 0 0 2px var(--accent);
  }
  100% {
    box-shadow: 0 0 0 2px transparent;
  }
}

.setting-row.is-flash {
  animation: settings-row-flash 1.2s ease-out forwards;
}

@media (prefers-reduced-motion: reduce) {
  .setting-row.is-flash {
    animation: none;
    box-shadow: 0 0 0 2px var(--accent);
  }
}

.settings-pane {
  display: none;
  flex: 1;
}

.settings-pane.is-active {
  display: block;
}

.settings-pane-header {
  font-size: var(--text-2xl);
  font-weight: var(--weight-strong);
  letter-spacing: -0.01em;
  margin-bottom: 16px;
  /* Room for the top-right X so long titles never sit under it. */
  padding-right: 40px;
}

/* A pane is a stack of labelled sections; each section's rows share one
   bordered card divided by hairlines (see .settings-group). */
.settings-section + .settings-section {
  margin-top: 16px;
}

/* Status lines (updater, sign-in, plan) reserve a min-height so a message
   never shifts a button under the cursor — but while empty, that reserve
   opens a gap between sections. Collapse them until they have something
   to say. */
.settings-content .settings-status:empty {
  display: none;
}

/* ----------- About pane: app-icon hero ----------- */
.about-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 4px 2px 16px;
}
.about-icon {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-xl);
  flex-shrink: 0;
}
.about-hero-text {
  min-width: 0;
}
.about-name {
  font-size: var(--text-xl);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  margin-bottom: 4px;
}
/* Icon-only "Follow on X" — the row's "Follow along" label already says
   what it's for, so the button is just the X mark in a square tap target. */
.about-social-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  line-height: 0;
}

/* The update status sits under the Updates card in General. A long
   updater error (it interpolates electron-updater's raw message) is
   clamped to 2 lines so it can't blow out the layout; the full text stays
   available via the title tooltip. The :empty guard keeps the id selector
   from overriding the shared collapse rule while there is no message. */
#about-update-status:not(:empty) {
  margin-top: 10px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

/* ----------- Contact pane: "Say hello" form ----------- */
.contact-intro {
  margin-bottom: 18px;
}
.contact-slug {
  display: block;
  font-family: var(--font-script, var(--font-ui));
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.contact-heading {
  font-size: var(--text-3xl);
  font-weight: var(--weight-strong);
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.contact-lede {
  max-width: 540px;
}
.contact-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.contact-field {
  display: flex;
  flex-direction: column;
}
.contact-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 620px) {
  .contact-field-row {
    grid-template-columns: 1fr;
  }
}
.contact-field input,
.contact-field textarea {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 11px;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.45;
  outline: none;
  transition: border-color var(--dur-2) var(--ease-out);
}
.contact-field input:focus,
.contact-field textarea:focus {
  border-color: var(--accent);
}
.contact-field textarea {
  resize: vertical;
  min-height: 130px;
}
/* Honeypot — present in the DOM, invisible to humans. */
.contact-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.contact-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.contact-note {
  font-size: var(--text-sm);
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
}
/* The shared .settings-status is green + right-aligned; the contact
   reply reads as a sentence, so left-align and soften the default. */
.contact-status {
  text-align: left;
  color: var(--text-secondary);
}

/* ===========================================================
 * Phase 1 subscription components.
 *
 * These all build on existing tokens; no new colors needed.
 * Tokens introduced here:
 *   --locked-opacity   dim factor for tier-gated controls
 *   --toggle-on        accent color for "on" toggle track
 *   --toggle-off       muted color for "off" toggle track
 *   --badge-bg         pill background
 *   --badge-text       pill text
 *   --danger           destructive action color (Cancel plan)
 *
 * Components:
 *   .settings-toggle        iOS-style switch (boolean rows)
 *   .settings-segmented     segmented control (cadence, quality)
 *   .tier-badge             "Pro" / "Hobbyist" pill next to titles
 *   .feature-locked         row-level dim+disable state
 *   .plan-cards             stack of three plan cards in Plan tab
 *   .upsell-card            small modal shown before navigating to Plan
 *   .is-hidden              utility: display:none with !important
 *   .row-action             flex container for inline button + badge
 * =========================================================== */

:root {
  --locked-opacity: 0.5;
  --toggle-on: var(--accent);
  --toggle-off: color-mix(in srgb, var(--text-primary) 22%, var(--bg-elevated));
  --badge-bg: var(--bg-elevated);
  --badge-text: var(--text-secondary);
  --danger: #c25c5c;
}

/* Tier badge ----------------------------------------------- */
/* One small tag for a plan or a state beside a title: Settings' "Pro",
   the AI pane's "Connected". It labels, it
   is not pressed, so it carries no outline at rest and is shorter than
   the words it sits beside (it was a bordered 19px box in strong caps,
   which read as a button and as the loudest thing on the row: owner, Nov
   20, 2026). The box is a flex line so the label is centred in it; the
   extra left padding is the tracking that trails the last letter. The
   border is the shell's: transparent in every theme but High Contrast,
   where a fill this close to the surface needs an edge. */
.tier-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  height: 14px;
  padding: 0 5px 0 calc(5px + var(--tracking-caps));
  border: 1px solid var(--shell-divider);
  border-radius: var(--radius-pill);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-caps);
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--badge-bg);
  color: var(--badge-text);
  vertical-align: middle;
  margin-left: 6px;
}

/* A title that carries a tag is one line with the tag on its middle,
   not hung from the baseline (which left it sitting low). */
.setting-title:has(> .tier-badge) {
  display: flex;
  align-items: center;
  gap: 6px;
}

.setting-title:has(> .tier-badge) > .tier-badge {
  margin-left: 0;
}

.tier-badge[data-tier='pro'] {
  background: var(--accent-bg);
  color: var(--text-body);
}

.tier-badge[data-tier='hobbyist'] {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Solid tag ------------------------------------------------- */
/* The one tag on a surface that is meant to be seen first: "Recommended"
   on a plan card, "Pro" on a History row behind the wall. Sentence case,
   filled, no outline, with room either side of the word (owner, Nov 20,
   2026: "with more spacing"). Two sizes: beside a title it is 20px so the
   title still leads; alone at the trailing edge of a row it is 24px. */
.plan-recommended,
.checkpoint-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  flex-shrink: 0;
  height: 20px;
  padding: 0 10px;
  border: 1px solid var(--shell-divider);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1;
  white-space: nowrap;
  background: var(--tag-solid-bg);
  color: var(--tag-solid-text);
}

/* Cloud sync status badge (Settings → Cloud sync tab). Shares the
   pill geometry with .tier-badge so it sits comfortably next to one
   in the same row. */
.cloud-status-badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  letter-spacing: 0.02em;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-soft);
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.cloud-status-badge.is-active {
  color: var(--green);
  border-color: color-mix(in srgb, var(--green) 40%, transparent);
  background: color-mix(in srgb, var(--green) 12%, var(--bg-elevated));
}

.cloud-status-badge.is-locked {
  color: var(--text-muted);
}

/* Toggle switch -------------------------------------------- */
.settings-toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

/* The real checkbox sits invisibly over the track and takes the click
   itself, so the switch works whether its wrapper is a <label> (built in
   JS, named by aria-label) or a <span> (static rows, where the row's
   visible title is the checkbox's one <label for>). */
.settings-toggle input[type='checkbox'] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

.settings-toggle input[type='checkbox']:disabled {
  cursor: not-allowed;
}

.settings-toggle-track {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--toggle-off);
  border-radius: var(--radius-pill);
  position: relative;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out);
}

.settings-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--dur-3) var(--ease-move);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.settings-toggle input[type='checkbox']:checked + .settings-toggle-track {
  background: var(--toggle-on);
}

/* On, the knob takes the accent's label colour: white on graphite in
   light, near-black on the ivory accent in dark, where a white knob would
   vanish into the track. */
.settings-toggle input[type='checkbox']:checked + .settings-toggle-track::after {
  transform: translateX(16px);
  background: var(--accent-text);
}

.settings-toggle input[type='checkbox']:focus-visible + .settings-toggle-track {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

.settings-toggle input[type='checkbox']:disabled + .settings-toggle-track {
  opacity: var(--locked-opacity);
  cursor: not-allowed;
}

/* Segmented control (reuses theme-picker visual grammar) --- */
.settings-segmented {
  display: inline-flex;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}

.segmented-option {
  position: relative;
  cursor: pointer;
}

.segmented-option input[type='radio'] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-option > span {
  display: inline-block;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out);
}

.segmented-option:hover > span {
  color: var(--text-primary);
}

.segmented-option input[type='radio']:checked + span {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.segmented-option input[type='radio']:focus-visible + span {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}

/* "2 months free" on the Yearly segment: a quiet fill in sentence case,
   no outline, so it reads as information, not a sale, and never as the
   selected segment (which a solid tag inside the switch would). The fill
   is a wash of the text colour, so it holds on the track and the thumb. */
.segmented-option span:has(> .segmented-badge) {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.segmented-badge {
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
  height: 16px;
  padding: 0 7px;
  border: 1px solid var(--shell-divider);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1;
  white-space: nowrap;
  background: color-mix(in srgb, var(--text-primary) 10%, transparent);
  color: var(--text-body);
}

/* Feature-locked state -------------------------------------- */
.feature-locked .setting-info {
  opacity: var(--locked-opacity);
}

/* Row inline action group (button + badge or two buttons) --- */
.row-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  color: var(--accent);
  font-size: var(--text-md);
  font-weight: 500;
  white-space: nowrap;
}

/* Plan cards ----------------------------------------------- */
/* On a studio seat the plan is the studio's: there is nothing here to
   buy, switch or manage, so the way into the plan sheet (where the
   prices now live) and the billing rows step aside. The id-level
   selectors are deliberate: the same rows are shown and hidden by class
   from renderPlanPane, and this has to win whichever way that goes. */
[data-settings-pane='account'][data-studio-seat='live']
  :is(#btn-plan-adjust, #plan-manage-row, #plan-overage-row) {
  display: none;
}

/* ---------- The plan row and the plan sheet ----------
   Account & plan says what the writer has in one row; every price lives
   in the sheet behind its button (owner's call, Nov 2026). The cards
   below keep their classes: they moved from the pane into the sheet. */
.plan-row {
  gap: 16px;
}
.plan-row-icon {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--text-primary);
}
.plan-row .setting-title {
  margin-bottom: 5px;
}
.plan-row-meta {
  margin-top: 3px;
  color: var(--text-muted);
}
.plan-row-meta:empty {
  display: none;
}
.plan-row-meta.is-alert {
  color: var(--danger);
}

.plan-sheet {
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-3);
  width: 880px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: dialog-in var(--dur-3) var(--ease-out);
}
.plan-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.plan-sheet-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}
.plan-sheet-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out);
}
.plan-sheet-close:hover {
  background: var(--hover-wash);
  color: var(--text-primary);
}
.plan-sheet-close:focus-visible,
.plan-sheet-tab:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}
.plan-sheet-body {
  padding: 18px 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}
.plan-sheet-reason {
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}
.plan-sheet-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.plan-sheet-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-lg);
  background: var(--bg-base);
}
.plan-sheet-tab {
  font: inherit;
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: var(--radius-md);
  padding: 7px 14px;
  cursor: pointer;
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out);
}
.plan-sheet-tab:hover {
  color: var(--text-primary);
}
.plan-sheet-tab.is-active {
  background: var(--selected-wash);
  color: var(--text-primary);
}
/* Held in place, unseen, on the studio tab: the bar keeps its height. */
.plan-sheet-cadence.is-invisible {
  visibility: hidden;
}
/* The two tabs' panels share one cell: the sheet is as tall as the
   taller one, and the shorter one's cards take up the difference. */
.plan-sheet-panels {
  display: grid;
}
.plan-sheet-panel {
  grid-area: 1 / 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.plan-sheet-panel.is-inactive {
  visibility: hidden;
}
.plan-sheet-panel > .plan-cards {
  flex: 1;
}
/* Pro and Pro+ grow; the Free line under them keeps its own height. */
#plan-sheet-you > .plan-cards {
  grid-template-rows: 1fr auto;
}

/* In the sheet the two plans a writer chooses between stand side by
   side; Free is the quiet line under them. */
.plan-sheet .plan-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
}
.plan-sheet .plan-card {
  border-radius: var(--radius-xl);
  padding: 20px;
  gap: 12px;
  border-color: var(--border-soft);
}
.plan-sheet .plan-card.is-recommended {
  border-color: var(--accent-border);
}
.plan-card-icon {
  display: none;
}
.plan-sheet .plan-card-icon {
  display: inline-flex;
  color: var(--text-primary);
}
.plan-sheet .plan-card header {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}
.plan-sheet .plan-card h3 {
  font-size: var(--text-xl);
}
.plan-sheet .plan-price {
  align-items: flex-start;
  text-align: left;
}
.plan-sheet .plan-card p {
  flex: 1;
}
.plan-sheet .plan-card-action {
  justify-content: stretch;
}
.plan-sheet .plan-card-action .btn {
  flex: 1;
  font-size: var(--text-md);
  padding: 9px 16px;
}
/* A quiet button here had the card's own fill and an edge 1.2:1 from it
   in dark, so "Downgrade" did not read as a button (owner, Nov 2026). In
   the sheet its edge is the form-field boundary, about 3:1 in every theme. */
.plan-sheet .btn-secondary {
  border-color: var(--control-border);
}
.plan-sheet .plan-card[data-plan='free'] {
  grid-column: 1 / -1;
  order: 3;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: transparent;
  border-color: transparent;
}
.plan-sheet .plan-card[data-plan='free'] .plan-card-icon svg {
  width: 26px;
  height: 26px;
}
.plan-sheet .plan-card[data-plan='free'] header {
  flex-direction: row;
  align-items: baseline;
  gap: 8px;
  flex-shrink: 0;
}
.plan-sheet .plan-card[data-plan='free'] h3 {
  font-size: var(--text-md);
}
.plan-sheet .plan-card[data-plan='free'] p {
  font-size: var(--text-sm);
}
.plan-sheet .plan-card[data-plan='free'] .plan-card-action {
  flex-shrink: 0;
}
.plan-sheet .plan-card[data-plan='free'] .plan-card-action .btn {
  flex: none;
  font-size: var(--text-sm);
  padding: 7px 12px;
}
.plan-sheet #plan-student-row {
  margin-bottom: 0;
  background: transparent;
  border-color: transparent;
  padding: 6px 14px;
}
.plan-sheet-note {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 4px 14px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.plan-sheet-note strong {
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}
.plan-sheet-note-icon {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--text-body);
}
.plan-sheet-note-icon svg {
  width: 26px;
  height: 26px;
}
/* A narrow window (Companion, a small editor): one plan per row. */
@media (max-width: 640px) {
  .plan-sheet .plan-cards {
    grid-template-columns: minmax(0, 1fr);
  }
  #plan-sheet-you > .plan-cards {
    grid-template-rows: none;
  }
  .plan-sheet-body {
    padding: 14px 16px 18px;
  }
  .plan-sheet .plan-card[data-plan='free'] {
    flex-direction: column;
    align-items: flex-start;
  }
}
@media (prefers-reduced-motion: reduce) {
  .plan-sheet {
    animation: none;
  }
}

.plan-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 14px;
}

.plan-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.plan-card.is-recommended {
  border-color: var(--accent-border);
}

.plan-card.is-current {
  background: var(--bg-hover);
  border-color: var(--text-tertiary, var(--border));
}

.plan-card.is-current h3 {
  font-weight: var(--weight-strong);
}

.plan-card header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.plan-card h3 {
  font-size: var(--text-lg);
  font-weight: var(--weight-strong);
  margin: 0;
  color: var(--text-primary);
}

/* The tag sits on the middle of the plan's name and takes no height of
   its own, so a card with one is as tall as a card without. */
.plan-card h3:has(> .plan-recommended) {
  display: flex;
  align-items: center;
  gap: 8px;
}

.plan-recommended {
  margin-block: -3px;
}

.plan-price {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  flex-shrink: 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* The dollar amount leads; yearly's "$12.50" should look as cheap as it is. */
.plan-price-lead strong {
  font-size: var(--text-lg);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}

.plan-price-note {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.plan-card p {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.5;
}

.plan-card-action {
  display: flex;
  justify-content: flex-end;
  margin-top: auto;
}

/* Plan result banner: success/failure feedback after a plan change.
   Inline (sits inside the Plan pane) rather than overlaid, so we don't
   stack a modal on top of the already-modal settings overlay. */
.plan-result-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: var(--text-md);
  line-height: 1.45;
  color: var(--text-primary);
  margin: 4px 0 12px;
}

.plan-result-banner.is-success {
  border-color: var(--accent-border);
  background: var(--accent-bg);
}

.plan-result-banner.is-error {
  border-color: var(--danger);
  color: var(--danger);
}

.plan-result-banner-body {
  flex: 1 1 auto;
  min-width: 0;
}

.plan-result-banner-dismiss {
  flex: 0 0 auto;
  background: transparent;
  border: 0;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  font-size: var(--text-xl);
  line-height: 1;
  padding: 0 4px;
}

.plan-result-banner-dismiss:hover {
  opacity: 1;
}

/* ----------- Tips toast (bottom-left cycling card) -----------
 * Persistent, unobtrusive tip rotation shown only while editing.
 * Visibility, persistence, and cycling are owned by tips/toast.js.
 * The chip styling is inherited by also applying .cmd-cheatsheet-key
 * to each chord key — no new tokens needed.
 */
.tips-toast {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: 308px;
  padding: 12px 14px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text-primary);
  opacity: 0;
  transform: translateY(12px);
  visibility: hidden;
  pointer-events: none;
  z-index: 60;
  transition:
    opacity 240ms ease-out,
    transform 240ms cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 240ms;
}
.tips-toast.visible {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
  transition:
    opacity 240ms ease-out,
    transform 240ms cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 0s;
}
/* OS-level reduced-motion: fade only, no slide. */
@media (prefers-reduced-motion: reduce) {
  .tips-toast {
    transform: none;
    transition:
      opacity 120ms linear,
      visibility 0s linear 120ms;
  }
  .tips-toast.visible {
    transform: none;
    transition:
      opacity 120ms linear,
      visibility 0s linear 0s;
  }
}
.tips-toast-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  padding-right: 18px; /* clear the × button */
}
.tips-toast-badge {
  display: inline-block;
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-secondary, var(--text-primary));
  background: var(--bg-hover);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 3px;
}
/* Theme-aware override for chord chips inside the tips toast. The
 * shared .cmd-cheatsheet-key class is tuned for the dark Cmd-hold
 * overlay (white-alpha on dark), which renders invisible against the
 * light-theme tips toast surface. */
.tips-toast-chip {
  background: var(--bg-hover);
  border-color: var(--border);
  color: var(--text-primary);
}
.tips-toast-plus {
  color: var(--text-muted, var(--text-secondary));
}
.tips-toast-count {
  font-size: var(--text-xs);
  color: var(--text-muted, rgba(255, 255, 255, 0.45));
}
.tips-toast-title {
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  margin-bottom: 4px;
}
.tips-toast-body {
  color: var(--text-secondary, rgba(255, 255, 255, 0.7));
  margin-bottom: 8px;
}
.tips-toast-chips {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 8px;
}
.tips-toast-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--text-xs);
  margin-top: 2px;
  gap: 8px;
}
.tips-toast-action {
  background: var(--accent-bg, rgba(255, 255, 255, 0.06));
  border: 1px solid var(--accent-border, rgba(255, 255, 255, 0.18));
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  font: inherit;
  font-size: var(--text-xs);
  opacity: 0.9;
}
.tips-toast-action:hover {
  opacity: 1;
}
.tips-toast-action:focus-visible {
  outline: 2px solid var(--accent, #bfbfba);
  outline-offset: 2px;
}
.tips-toast-next {
  background: transparent;
  border: 0;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px 0;
  font: inherit;
  font-size: var(--text-xs);
  opacity: 0.7;
}
.tips-toast-next:hover {
  opacity: 1;
}
.tips-toast-next:focus-visible {
  outline: 2px solid var(--accent, #bfbfba);
  outline-offset: 2px;
  border-radius: 2px;
}
.tips-toast-dismiss {
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: 0;
  color: inherit;
  opacity: 0.55;
  cursor: pointer;
  font-size: var(--text-xl);
  line-height: 1;
  padding: 0 4px;
}
.tips-toast-dismiss:hover {
  opacity: 1;
}
.tips-toast-dismiss:focus-visible {
  outline: 2px solid var(--accent, #bfbfba);
  outline-offset: 1px;
  border-radius: 2px;
}
@media print {
  .tips-toast {
    display: none !important;
  }
}
body.printing .tips-toast {
  display: none !important;
}

.plan-current-pill {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

/* Upsell modal --------------------------------------------- */
.upsell-card {
  background: var(--bg-surface);
  border: 0;
  border-radius: var(--radius-xl);
  padding: 22px;
  width: 420px;
  max-width: 92vw;
  box-shadow: var(--shadow-3);
  animation: dialog-in var(--dur-3) var(--ease-out);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upsell-header {
  font-size: var(--text-xl);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}

.upsell-body {
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 0;
}

.upsell-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* Account tab — email + Google sign-in ---------------------- */
.account-signin-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.account-signin-row input[type='email'] {
  flex: 1;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 11px;
  font-size: var(--text-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  outline: none;
  transition: border-color var(--dur-2) var(--ease-out);
}

.account-signin-row input[type='email']:focus {
  border-color: var(--accent);
}

/* Pull-on-open banner -------------------------------------- */
.cloud-banner {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  max-width: 560px;
  font-size: var(--text-md);
  color: var(--text-primary);
}

.cloud-banner-text {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cloud-banner-icon {
  font-size: var(--text-lg);
  color: var(--accent-border);
}

.cloud-banner-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Titlebar cloud indicator --------------------------------- */
.cloud-indicator {
  appearance: none;
  background: transparent;
  border: none;
  padding: 4px 6px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  color: var(--text-muted);
  font-size: var(--text-lg);
  line-height: 1;
  transition: color var(--dur-2) var(--ease-out);
}

.cloud-indicator:hover {
  color: var(--text-primary);
}

.cloud-indicator[data-state='syncing'] {
  color: var(--accent-border);
  animation: cloud-pulse 1.6s ease-in-out infinite;
}

.cloud-indicator[data-state='conflict'] {
  color: var(--danger);
}

.cloud-indicator[data-state='ok'] {
  color: var(--text-secondary);
}

@keyframes cloud-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

/* Titlebar update indicator -------------------------------- */
.update-indicator {
  appearance: none;
  background: transparent;
  border: none;
  padding: 4px 6px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  color: var(--text-muted);
  font-size: var(--text-lg);
  line-height: 1;
  transition: color var(--dur-2) var(--ease-out);
}

.update-indicator:hover {
  color: var(--text-primary);
}

.update-indicator[data-state='checking'],
.update-indicator[data-state='available'],
.update-indicator[data-state='downloading'] {
  color: var(--accent-border);
  animation: cloud-pulse 1.6s ease-in-out infinite;
}

.update-indicator[data-state='ready'] {
  color: var(--accent-border);
  animation: none;
}

.update-indicator[data-state='ready'] .update-indicator-glyph {
  /* Solid accent dot makes the "ready" state easy to recognize
     without reading the tooltip — the pulse stops and a steady mark
     remains. */
  display: inline-block;
}

.cloud-banner-subtle {
  display: block;
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin-top: 2px;
}

/* Utility --------------------------------------------------- */
.is-hidden {
  display: none !important;
}

.settings-header {
  font-size: var(--text-xl);
  font-weight: var(--weight-strong);
  letter-spacing: -0.005em;
  margin-bottom: 18px;
}

/* ----------- Section label (small uppercase divider) ----------- */
.settings-section-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-muted);
  margin: 14px 0 6px;
}

.settings-section-label:first-of-type,
.settings-section > .settings-section-label {
  margin-top: 0;
}

/* ----------- Setting row (title + desc on left, control on right) ----------- */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: var(--card-pad-y) 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  margin-bottom: 8px;
}

/* Rows grouped in one card: the card owns the border + radius, the rows
   stack with hairlines between them. Only rows that are always visible
   belong in a group — a hidden first row would leave a stray hairline
   at the top of the card. */
.settings-group {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  margin-bottom: 8px;
  overflow: hidden;
}

.settings-group > .setting-row {
  border: 0;
  border-radius: 0;
  margin-bottom: 0;
  padding: var(--card-pad-y) 16px;
}

/* --border, not --border-soft: in dark the soft line is one step from the
   card's own fill and the rows ran together. */
.settings-group > .setting-row + .setting-row {
  border-top: 1px solid var(--border);
}

.setting-row-stacked {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.setting-info {
  min-width: 0;
  flex: 1;
}

/* A segmented control never shrinks, so in a narrow window (Companion at
   its 360px minimum) the label beside it collapsed to zero width and the
   control painted over "Switch anytime.". Give the label a floor and let
   the row wrap: the control drops under the label only when both can't
   fit, and wide windows keep the one-line row. */
.setting-row:has(> .settings-segmented) {
  flex-wrap: wrap;
  row-gap: 10px;
}

.setting-row:has(> .settings-segmented) > .setting-info {
  flex: 1 1 140px;
  min-width: 140px;
}

.setting-title {
  font-size: var(--text-md);
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 3px;
}

/* A switch row's title is the switch's <label for>: clicking the words
   flips it too, as in the system settings apps. */
label.setting-title {
  display: block;
  cursor: pointer;
}

.setting-desc {
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text-secondary);
}
/* Who decides a control the writer cannot change here: a studio seat's
   role (js/shared/org-policy.js). A line of text, not a badge or a box. */
.setting-managed {
  margin-top: 6px;
  font-size: var(--text-sm);
  line-height: 1.45;
  font-weight: var(--weight-medium);
  color: var(--text-muted);
}
#byok-managed {
  margin: 0 0 var(--row-pad-y);
}
/* Surfaces that only mean something in the desktop app (the updater, a
   file on this computer, Companion Mode). The web editor marks <html> with
   data-client="web" (src/web/entry.js); the desktop never does, so there
   this rule matches nothing. */
html[data-client='web'] [data-desktop-only] {
  display: none !important;
}
/* The counterpart: surfaces only the web editor shows (the signed-out page
   below the sign-in hero, the way to the app). The desktop app never marks
   <html>, so there they never draw. */
html:not([data-client='web']) [data-web-only] {
  display: none !important;
}
/* What the Mac app has from the system instead (File, Edit and View: the
   menu bar at the top of the screen). A browser on a Mac says darwin too,
   so the app is the one without data-client="web". */
html[data-platform='darwin']:not([data-client='web']) [data-not-mac-app] {
  display: none !important;
}
/* A line in place of the editor (src/web/entry.js showNotice): signed out
   with no connection, or the sign-in window when it cannot close itself. */
.web-front-notice {
  max-width: 440px;
  margin: 18vh auto 0;
  padding: 0 24px;
  font-family: var(--font-ui);
  color: var(--text-primary);
  text-align: center;
}
.web-front-notice h1 {
  margin: 0 0 12px;
  font-size: 22px;
  font-weight: var(--weight-strong);
}
.web-front-notice p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
}
/* A browser tab draws no traffic lights in the bar, whatever the platform. */
html[data-client='web'] .titlebar-traffic {
  display: none;
}

/* The way to the app: one button wherever it is offered (the app-only
   dialog, Settings → AI on the web). js/app-only.js builds it. */
.app-cta,
.welcome-get-app-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}
.app-cta-glyph,
.welcome-get-app-btn svg {
  flex-shrink: 0;
}

/* "<feature> is in the Lastslate app" (js/app-only.js). The
   standard dialog card, narrower: one sentence and two buttons. */
.app-only-modal {
  width: 420px;
  max-width: calc(100vw - 32px);
  padding: 28px;
  /* Its own ink: the web's PDF notice is shown over the print view, where
     body.printing turns the page's text black, and an inherited colour
     made the title black on the dark card (the owner, Nov 2026). */
  color: var(--text-primary);
}
.app-only-icon {
  display: block;
  width: 44px;
  height: 44px;
  margin-bottom: var(--space-4);
  border-radius: 22%;
  background: #0a0a0a;
  box-shadow: var(--shadow-1);
}
.app-only-title {
  margin-bottom: var(--space-2);
  text-wrap: balance;
}
.app-only-body {
  margin-bottom: var(--space-5);
}
.app-only-actions {
  gap: var(--space-3);
}
/* The card while something is being made for the writer (the web's PDF;
   js/app-only.js notice({ busy })). The fox reads above the title and the
   panel spinner turns beside it; both hold still under reduced motion. */
.app-only-fox {
  margin-bottom: var(--space-4);
  line-height: 0;
}
.app-only-title .welcome-spinner {
  display: inline-block;
  margin-right: var(--space-2);
  vertical-align: -1px;
}

/* ---------- The mark and the menus: the head of the bar ----------
   The Lastslate mark is a button, bare at rest with a rounded wash on
   hover, that goes back to all scripts. File, Edit and View follow it
   (js/file-menu.js; owner's call, Nov 2026, in place of one menu under the
   mark): words, the same wash on hover and while open, no box. */
.tb-logo-btn,
.menu-bar-btn {
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out);
}
.tb-logo-btn {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
}
.tb-logo-btn:hover,
.menu-bar-btn:hover,
.menu-bar-btn[aria-expanded='true'] {
  background: var(--hover-wash);
}
.tb-logo-btn:focus-visible,
.menu-bar-btn:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}
.tb-logo-mark {
  width: 20px;
  height: 20px;
  pointer-events: none;
  user-select: none;
}
.menu-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  margin-left: -4px;
}
.menu-bar-anchor {
  position: relative;
  flex-shrink: 0;
}
.menu-bar-btn {
  height: 28px;
  padding: 0 8px;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  font-weight: var(--weight-regular);
}
.file-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  min-width: 248px;
  /* A short window scrolls the menu rather than losing its last rows. */
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 5px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-2);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--text-primary);
  transform-origin: top left;
}
/* On the window, beside its row (file-menu.js placeFlyout): inside the menu
   a scrolling one would clip it. */
.file-menu-flyout {
  position: fixed;
  min-width: 212px;
  max-height: calc(100vh - 16px);
}
.file-menu-item {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  padding: var(--menu-pad-y) 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-weight: var(--weight-regular);
  line-height: 1.5;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.file-menu-item:hover {
  background: var(--hover-wash);
}
.file-menu-item:focus,
.file-menu-item[aria-expanded='true'] {
  outline: none;
  background: var(--selected-wash);
}
.file-menu-item:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}
.file-menu-hint,
.file-menu-chevron {
  margin-left: auto;
  color: var(--text-muted);
}
.file-menu-hint {
  font-size: var(--text-xs);
}
.file-menu-keys {
  padding-left: var(--space-5);
}
.file-menu-chevron {
  flex-shrink: 0;
}
/* Groups are set apart by space, not a rule (one warm field, two
   hairlines). */
.file-menu-gap {
  flex: none;
  height: 0;
  margin: var(--space-1) 0;
}

/* Under the card: that it is free to start (claude.ai's line), then the
   way to the app, quiet, with the mark of the system it is for (data-os,
   set by app.js). */
.welcome-under-card {
  display: none;
}
.welcome.is-split .welcome-under-card {
  display: block;
}
.welcome-free {
  margin: 18px 0 0;
  font-size: var(--text-md);
  color: var(--text-muted);
  text-align: center;
}
.welcome-get-app {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}
.welcome-get-app-btn {
  height: 44px;
  padding: 0 18px;
}
.welcome-os-mark {
  display: none;
}
.welcome-get-app-btn[data-os='mac'] .welcome-os-mac,
.welcome-get-app-btn[data-os='windows'] .welcome-os-windows,
.welcome-get-app-btn:not([data-os='mac']):not([data-os='windows']) .welcome-os-other {
  display: block;
}

/* A short window: a size down, so the legal line stays on screen at the
   1000×600 minimum (lastslate.com steps down at the same height). */
@media (max-height: 780px) {
  .welcome.is-split .welcome-inner > .welcome-title {
    font-size: var(--text-poster-compact);
    margin-bottom: var(--space-2);
  }
  .welcome.is-split .welcome-subtitle {
    font-size: var(--text-2xl);
    margin-bottom: var(--space-5);
  }
  .welcome.is-split .welcome-logo {
    width: 44px;
    height: 44px;
    margin-bottom: var(--space-3);
  }
  .welcome-google-btn,
  .welcome-apple-btn,
  .welcome-signin-email,
  .welcome-signin-submit {
    height: 44px;
  }
}
@media (max-width: 640px) {
  .welcome.is-split .welcome-inner > .welcome-title {
    font-size: var(--text-hero);
  }
}

/* ----------- New-writer setup (js/onboarding.js) -----------
 * The sign-in column carries on after sign-in: the same split, the same
 * card, the title page on the right holding the writer's own page. A
 * step's heading is a size below the sign-in poster, so the screens read
 * as one sequence (owner's calls, Nov 2026, docs/onboarding/). */
.welcome[data-view='onboarding'] .welcome-logo,
.welcome[data-view='onboarding'] .welcome-under-card {
  display: none;
}
/* The signed-in pose (.is-lifted) belongs to the old centred picker; a
   heading that kept it from an earlier sign-in would ride up into the
   step counter. */
.welcome.is-split .welcome-title.is-lifted {
  transform: none;
}
.welcome-eyebrow {
  margin: 0 0 var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
.welcome.is-split .welcome-inner > .welcome-title.is-step {
  font-size: var(--text-hero);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-3);
}
.welcome.is-split .welcome-subtitle.is-step {
  font-size: var(--text-xl);
  line-height: 1.45;
  margin-bottom: 28px;
}
.welcome-onboarding {
  text-align: left;
  -webkit-app-region: no-drag;
}
/* Read by onboardingNudgeOffered(): the desktop-app step exists only where
   data-web-only surfaces show. */
.ob-step {
  --ob-offered: 1;
}
html:not([data-client='web']) .ob-step[data-web-only] {
  --ob-offered: 0;
}
.ob-card {
  box-sizing: border-box;
  padding: 24px 28px 28px;
  border-radius: var(--radius-2xl);
  background: var(--welcome-card);
  border: 0.5px solid var(--welcome-card-line);
}
.ob-promise {
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.ob-promise li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: var(--space-3);
  align-items: start;
}
.ob-glyph {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--welcome-field);
  display: grid;
  place-items: center;
  color: var(--text-secondary);
}
.ob-promise strong {
  display: block;
  font-size: var(--text-lg);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  margin-bottom: 3px;
}
.ob-promise span {
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--text-secondary);
}
.ob-note {
  margin: 0 0 var(--space-5);
  padding-top: 14px;
  border-top: 0.5px solid var(--welcome-field-line);
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.ob-primary {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-lg);
  font-size: var(--text-lg);
}
.ob-label {
  display: block;
  font-size: var(--text-md);
  color: var(--text-secondary);
  margin: 0 0 var(--space-2);
}
.ob-field {
  box-sizing: border-box;
  width: 100%;
  height: 44px;
  padding: 0 14px;
  margin: 0 0 var(--space-4);
  font-family: var(--font-ui);
  font-size: var(--text-lg);
  color: var(--text-primary);
  background: var(--welcome-field);
  border: 1px solid var(--welcome-field-line);
  border-radius: var(--radius-lg);
  outline: none;
}
.ob-field:focus {
  border-color: var(--focus-color);
}
.ob-options {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin: 0 0 var(--space-5);
}
.ob-option {
  position: relative;
  display: grid;
  grid-template-columns: 28px 1fr 16px;
  gap: var(--space-3);
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out);
}
.ob-option:hover {
  background: var(--hover-wash);
}
.ob-option:has(input:checked) {
  background: var(--selected-wash);
}
.ob-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.ob-option:has(input:focus-visible) {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}
.ob-option-text {
  display: flex;
  flex-direction: column;
}
.ob-option-name {
  font-size: var(--text-lg);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}
.ob-option-meta {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: 1px;
}
.ob-radio {
  width: 16px;
  height: 16px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 1.5px solid var(--text-muted);
}
.ob-option:has(input:checked) .ob-radio {
  border: 5px solid var(--accent);
}
.ob-under {
  display: flex;
  justify-content: center;
  margin-top: var(--space-4);
}
.ob-under .welcome-link {
  font-size: var(--text-md);
}
.ob-reasons {
  list-style: none;
  margin: 0 0 var(--space-5);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  font-size: var(--text-lg);
  color: var(--text-body);
}
.ob-reasons li {
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.ob-reasons li::before {
  content: '';
  flex: none;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  translate: 0 -2px;
}
.ob-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}
.ob-download[data-os='mac'] .welcome-os-mac,
.ob-download[data-os='windows'] .welcome-os-windows,
.ob-download:not([data-os='mac']):not([data-os='windows']) .welcome-os-other {
  display: block;
}
.welcome-page-ep {
  margin-top: 1.98em;
}
@media (prefers-reduced-motion: reduce) {
  .ob-option {
    transition: none;
  }
}

/* The first script's one-time line above the page (showFirstScriptHint). */
.first-script-hint {
  position: fixed;
  top: calc(var(--bar-h) + 12px);
  left: 50%;
  translate: -50% 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 6px 6px 6px 14px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-2);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  color: var(--text-secondary);
  white-space: nowrap;
  animation: popover-in var(--dur-2) var(--ease-out);
}
.first-script-hint-close {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  cursor: pointer;
}
.first-script-hint-close:hover {
  background: var(--hover-wash);
  color: var(--text-primary);
}
.first-script-hint-close:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  .first-script-hint {
    animation: none;
  }
}

/* ----------- The scripts page (signed in, nothing open) -----------
 * After claude.ai's chat history (owner's call, Nov 2026, docs/onboarding/
 * picker.html ?dir=claude): "Your scripts" with New script, a large search,
 * All / Shared with me, two-line rows on hairlines, a quiet footer. No
 * app icon or wordmark over it; the account sits at the top right. */
.welcome[data-view='cloud'] {
  align-items: flex-start;
  padding-top: max(56px, 9vh);
}
.welcome[data-view='cloud'] .welcome-logo,
.welcome[data-view='cloud'] .welcome-title,
.welcome[data-view='cloud'] .welcome-subtitle {
  display: none;
}
.welcome[data-view='cloud'] .welcome-inner,
.welcome[data-view='cloud'] .welcome-cloud {
  max-width: 760px;
}
.welcome[data-view='cloud'] .welcome-inner {
  padding: 0 28px;
  box-sizing: border-box;
}
/* The account sits at the top right here, so its menu hangs from the
   row's right edge (Settings, Sign out). */
.welcome[data-view='cloud'] .account-anchor-start .account-menu {
  left: auto;
  right: 0;
}
/* Pinned in the window's corner, the row's button as far from the top edge
   as from the right (owner, Nov 2026). The header's padding and the
   anchor's negative margin, there to line the avatar up in a column, are
   dropped here so the two insets are the one number. */
.welcome[data-view='cloud'] .welcome-cloud-header {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 2;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  -webkit-app-region: no-drag;
}
.welcome[data-view='cloud'] .welcome-cloud-header .account-anchor-start {
  margin: 0;
}
.project-picker.is-page .scripts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin: 0 0 22px;
}
.project-picker.is-page .scripts-title {
  margin: 0;
  font-size: var(--text-hero);
  font-weight: var(--weight-strong);
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.scripts-new {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.project-picker.is-page .project-picker-search {
  padding: 0;
}
.project-picker.is-page .project-picker-input {
  height: 48px;
  padding: 0 16px 0 42px;
  font-size: var(--text-lg);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border-color: color-mix(in srgb, var(--text-primary) 12%, transparent);
}
.project-picker.is-page .project-picker-search-icon {
  left: 15px;
  top: 16px;
}
.scripts-chips {
  display: flex;
  gap: 6px;
  margin: 16px 0 6px;
}
.scripts-chips[hidden] {
  display: none;
}
.scripts-chip {
  padding: 5px 11px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out);
}
.scripts-chip:hover {
  background: var(--hover-wash);
}
.scripts-chip[aria-pressed='true'] {
  background: var(--selected-wash);
  color: var(--text-primary);
}
.scripts-chip:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}
.welcome-picker-mount .project-picker.is-page .project-picker-body {
  max-height: calc(100vh - 330px);
  margin-top: var(--space-2);
}
.welcome-picker-mount.has-companion .project-picker.is-page .project-picker-body {
  max-height: calc(100vh - 400px);
}
.project-picker.is-page .project-picker-item {
  min-height: 64px;
  padding-top: 10px;
  padding-bottom: 10px;
  border-radius: var(--radius-lg);
  box-shadow: 0 -0.5px 0 color-mix(in srgb, var(--text-primary) 10%, transparent);
}
.project-picker.is-page .project-picker-tree > .project-picker-item:first-child,
.project-picker.is-page .project-picker-item:hover,
.project-picker.is-page .project-picker-item.is-active,
.project-picker.is-page .project-picker-item:hover + .project-picker-item,
.project-picker.is-page .project-picker-item.is-active + .project-picker-item {
  box-shadow: none;
}
.project-picker.is-page .project-picker-item-name {
  font-size: var(--text-lg);
}
.project-picker.is-page .project-picker-item-meta {
  font-size: var(--text-md);
  margin-top: 2px;
}
.project-picker.is-page .project-picker-item:not(.project-picker-folder) .project-picker-item-icon {
  display: none;
}
.project-picker.is-page .scripts-foot {
  border-top: 0;
  margin-top: var(--space-3);
  padding: 0;
  justify-content: flex-start;
}
.project-picker.is-page .project-picker-action {
  font-size: var(--text-md);
  padding: 8px 10px;
}
.project-picker.is-page .welcome-companion {
  margin-top: var(--space-4);
}
.scripts-start {
  margin-top: var(--space-4);
  padding: 24px;
  border-radius: var(--radius-xl);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-1);
}
.scripts-start-title {
  margin: 0 0 4px;
  font-size: var(--text-3xl);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}
.scripts-start-lead {
  margin: 0 0 var(--space-4);
  font-size: var(--text-lg);
  color: var(--text-secondary);
}
.scripts-start-rows {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.scripts-start-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-lg);
  background: transparent;
  font-family: var(--font-ui);
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out);
}
.scripts-start-row:hover {
  background: var(--hover-wash);
}
.scripts-start-row:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}
.scripts-start-name {
  font-size: var(--text-lg);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}
.scripts-start-meta {
  font-size: var(--text-sm);
  color: var(--text-muted);
}
@media (prefers-reduced-motion: reduce) {
  .scripts-chip,
  .scripts-start-row {
    transition: none;
  }
}

/* Web editor: own accounts live in the app; one sentence and the way there. */
.byok-app-only .btn {
  margin-top: var(--space-4);
}
/* A long description rests at two lines; the "More" button after it opens
   the rest (js/shared/clamp.js). Visual only — the full text stays in the
   DOM for screen readers, Settings search and aria-describedby. */
.setting-desc-clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.setting-desc-clamp.is-expanded {
  display: block;
  overflow: visible;
}
.setting-desc-more {
  appearance: none;
  margin: 3px 0 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-xs);
  background: none;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  cursor: pointer;
}
.setting-desc-more:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}
/* A short description whose last sentence waits behind More: the button
   follows the words on their line, and the waiting part
   (.setting-desc-rest) is unseen but never removed, so a screen reader
   and the Settings search still read all of it. */
.setting-desc--inline {
  display: inline;
}
.setting-desc-more--inline {
  display: inline;
  margin: 0 0 0 2px;
}
.setting-desc-rest {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.is-expanded > .setting-desc-rest {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip-path: none;
  white-space: normal;
}
/* A description that is an alert (a failed renewal): the error red the
   status lines use, so it reads as a warning rather than a caption. */
.setting-desc.is-alert {
  color: #c0392b;
  font-weight: 500;
}
.setting-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
/* Two actions that must not be confused (Export, Delete account): one
   above the other, full-size, the same width. */
.setting-row-actions--stacked {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-width: 168px;
}
/* The block that closes a settings page stands apart from what is above. */
.settings-end-block {
  margin-top: 24px;
}
.consent-modal {
  width: 520px;
}
.consent-modal .settings-group {
  margin-bottom: 16px;
}

.settings-explainer {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 18px;
}

.settings-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-muted);
  margin-bottom: 6px;
}

.settings-modal input[type='password'],
.settings-modal input[type='email'] {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 9px 11px;
  font-size: var(--text-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  outline: none;
  transition: border-color var(--dur-2) var(--ease-out);
}

.setting-row input[type='password'] {
  margin-bottom: 0;
}

.settings-modal input[type='password']:focus,
.settings-modal input[type='email']:focus {
  border-color: var(--accent);
}

.settings-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* A confirm with a lot to say (js/shared/confirm-body.js): what is
   affected as a list, then one closing line set apart from it. */
.settings-explainer-list {
  margin: -6px 0 16px;
  padding-left: 18px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
}
.settings-explainer-list li + li {
  margin-top: 4px;
}
.settings-explainer-note {
  color: var(--text-muted);
}

/* Stacked variant: each action is a full-width row, primary on top.
   Used by the disable-cloud-backup three-way modal so the writer
   doesn't have to weigh three side-by-side buttons. */
.settings-actions.is-stacked {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.settings-actions.is-stacked .btn {
  width: 100%;
}

.settings-actions-right {
  display: flex;
  gap: 8px;
}

.settings-status {
  margin-top: 10px;
  font-size: var(--text-xs);
  color: var(--green);
  min-height: 14px;
  text-align: right;
}

/* ----------- Per-file cloud upsell banner (paid users only) ----------- */
.cloud-upsell-banner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px auto;
  padding: 10px 14px;
  max-width: 8.5in;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-md);
  box-shadow: var(--shadow-2);
}

.cloud-upsell-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.cloud-upsell-text {
  flex: 1;
  min-width: 0;
  color: var(--text-secondary);
  line-height: 1.4;
}

.cloud-upsell-text strong {
  color: var(--text-primary);
  font-weight: var(--weight-strong);
}

.cloud-upsell-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.cloud-upsell-error {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--red, #d44);
}

/* ----------- Theme picker (Settings modal) ----------- */
.theme-picker {
  display: flex;
  flex-wrap: wrap;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

.setting-row .theme-picker {
  margin-bottom: 0;
}

.theme-option {
  position: relative;
  cursor: pointer;
}

.theme-option input[type='radio'] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-option span {
  display: inline-block;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out);
}

.theme-option:hover span {
  color: var(--text-primary);
}

.theme-option input[type='radio']:checked + span {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.theme-option input[type='radio']:focus-visible + span {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}

/* ----------- Theme preview (Settings) ----------- */
/* Renders a mini scene using the LIVE theme tokens, so it repaints the
   instant a theme is selected (data-theme changes on <html>). */
.theme-preview {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 0 0 1px var(--page-edge, transparent);
  padding: 14px 18px;
  font-family: var(--font-script);
  font-size: 12px;
  line-height: 1.32;
}
.tp-scene {
  color: var(--el-scene);
  font-weight: bold;
  text-transform: uppercase;
}
.tp-action {
  color: var(--el-action);
  margin-top: 7px;
}
.tp-character {
  color: var(--el-character);
  text-transform: uppercase;
  margin-top: 7px;
  padding-left: 120px;
}
.tp-paren {
  color: var(--el-parenthetical);
  font-style: italic;
  padding-left: 95px;
}
.tp-dialogue {
  color: var(--el-dialogue);
  padding-left: 60px;
  padding-right: 40px;
}
.tp-transition {
  color: var(--el-transition);
  text-transform: uppercase;
  text-align: right;
  margin-top: 7px;
}

/* ----------- Appearance pane (Settings) ----------- */
/* The live preview: a miniature of the window built from the same tokens
   as the real chrome, so every pick below repaints it at once. Sizes are
   fixed px (it is a picture, not a control) except where a density token
   is the thing being previewed. */
.appearance-preview {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-shell);
  box-shadow: inset 0 0 0 1px var(--border);
  margin-bottom: 20px;
  font-size: var(--text-xs);
  line-height: 1.3;
  user-select: none;
}
.ap-bar {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  align-items: center;
  height: 32px;
  padding: 0 10px;
  border-bottom: 1px solid var(--shell-divider);
}
.ap-dots {
  display: flex;
  gap: 5px;
  margin-right: 12px;
}
.ap-dots i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--text-primary) 16%, transparent);
}
/* Window controls sit in this bar on macOS only. */
html:not([data-platform='darwin']) .ap-dots {
  display: none;
}
.ap-title {
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}
.ap-switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-md);
  background: var(--segment-track);
}
.ap-switch b,
.ap-switch span {
  padding: 2px 9px;
  border-radius: var(--radius-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}
.ap-switch b {
  background: var(--segment-thumb);
  color: var(--text-primary);
  box-shadow:
    var(--shadow-1),
    0 0 0 1px var(--segment-ring);
}
.ap-share {
  justify-self: end;
  padding: 2px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--titlebar-btn-border);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}
.ap-body {
  display: grid;
  grid-template-columns: minmax(120px, 22%) 1fr minmax(130px, 24%);
  height: 184px;
}
.ap-list {
  padding: 0 6px;
  overflow: hidden;
  border-right: 1px solid var(--pane-divider);
}
.ap-list-head {
  display: flex;
  align-items: center;
  height: calc(var(--bar-h) * 0.72);
  padding: 0 8px;
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}
.ap-row {
  display: flex;
  gap: 8px;
  padding: calc(var(--row-pad-y) * 0.75) 8px;
  margin-bottom: 1px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  transition: padding var(--dur-3) var(--ease-move);
}
.ap-row b {
  font-weight: var(--weight-regular);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.ap-row.is-active {
  background: var(--selected-wash);
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}
.ap-row.is-active b {
  color: var(--text-primary);
}
.ap-desk {
  background: var(--bg-base);
  padding: 12px 18px 0;
  overflow: hidden;
}
.ap-desk .theme-preview {
  height: 100%;
  border: 0;
  border-radius: 2px 2px 0 0;
  box-shadow: var(--shadow-page);
  font-size: 11px;
}
.ap-chat {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 12px 10px 10px;
  background: var(--bg-surface);
  border-left: 1px solid var(--pane-divider);
}
.ap-bubble {
  align-self: flex-end;
  max-width: 100%;
  padding: 5px 9px;
  border-radius: var(--radius-lg);
  background: var(--user-bubble-bg);
  color: var(--user-bubble-text);
}
.ap-answer i {
  display: block;
  height: 4px;
  margin-bottom: 6px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--text-primary) 14%, transparent);
}
.ap-answer i:nth-child(1) {
  width: 92%;
}
.ap-answer i:nth-child(2) {
  width: 78%;
}
.ap-answer i:nth-child(3) {
  width: 54%;
}
.ap-controls {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ap-toggle {
  position: relative;
  width: 26px;
  height: 15px;
  border-radius: var(--radius-pill);
  background: var(--toggle-on);
  transition: background var(--dur-2) var(--ease-out);
}
.ap-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent-text);
}
.ap-primary {
  padding: 3px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: var(--weight-medium);
  transition: background var(--dur-2) var(--ease-out);
}

/* Theme cards: each thumbnail is painted in the theme it stands for (its
   desk, page and ink), not in the theme currently showing — so the --tc-*
   values below are literal copies of those themes' tokens. */
/* Always one row of six: auto-fill left High Contrast alone on a second
   row at the minimum window size. */
.theme-cards {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}
.theme-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 7px;
  cursor: pointer;
  --tc-desk: #191817;
  --tc-page: #222120;
  --tc-ink: #d4d4ce;
  --tc-edge: transparent;
}
.theme-card[data-theme-card='light'] {
  --tc-desk: #efede6;
  --tc-page: #ffffff;
  --tc-ink: #33332c;
}
.theme-card[data-theme-card='midnight'] {
  --tc-desk: #0e1015;
  --tc-page: #1b1f27;
  --tc-ink: #d4dae3;
}
.theme-card[data-theme-card='parchment'] {
  --tc-desk: #e9dcc0;
  --tc-page: #f3e9d2;
  --tc-ink: #463a26;
}
.theme-card[data-theme-card='high-contrast'] {
  --tc-desk: #000000;
  --tc-page: #000000;
  --tc-ink: #ffffff;
  --tc-edge: #8a8a8a;
}
.theme-card input[type='radio'] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.theme-card-thumb {
  display: block;
  aspect-ratio: 16 / 10;
  padding: 12% 14% 0;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--tc-desk);
  box-shadow: inset 0 0 0 1px var(--border);
  transition:
    box-shadow var(--dur-2) var(--ease-out),
    transform var(--dur-2) var(--ease-out);
}
.theme-card-page {
  display: block;
  height: 100%;
  padding: 12% 12% 0;
  border-radius: 3px 3px 0 0;
  background: var(--tc-page);
  box-shadow: 0 0 0 1px var(--tc-edge);
}
.theme-card-page i {
  display: block;
  height: 3px;
  margin-bottom: 5px;
  border-radius: 2px;
  background: var(--tc-ink);
}
.theme-card-page i:nth-child(1) {
  width: 52%;
}
.theme-card-page i:nth-child(2) {
  width: 88%;
  opacity: 0.45;
}
.theme-card-page i:nth-child(3) {
  width: 70%;
  opacity: 0.45;
}
/* System: half light, half dark, the way the OS pickers draw it. */
.theme-card[data-theme-card='system'] .theme-card-thumb {
  background: linear-gradient(105deg, #efede6 50%, #191817 50%);
}
.theme-card[data-theme-card='system'] .theme-card-page {
  background: linear-gradient(105deg, #ffffff 50%, #222120 50%);
}
.theme-card[data-theme-card='system'] .theme-card-page i {
  background: #8d8a82;
}
.theme-card-name {
  font-size: var(--text-sm);
  text-align: center;
  color: var(--text-secondary);
}
.theme-card:hover .theme-card-thumb {
  transform: translateY(-1px);
}
.theme-card:hover .theme-card-name {
  color: var(--text-primary);
}
.theme-card input:checked + .theme-card-thumb {
  box-shadow:
    inset 0 0 0 1px var(--border),
    0 0 0 2px var(--bg-surface),
    0 0 0 4px var(--accent);
}
.theme-card input:checked ~ .theme-card-name {
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}
.theme-card input:focus-visible + .theme-card-thumb {
  outline: 2px solid var(--focus-color);
  outline-offset: 5px;
}
.appearance-note {
  margin: 10px 2px 0;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* Accent swatches. A dot shows the colour the accent takes in the theme
   on screen (--accent-d by default, --accent-l on the light side), from
   the same pairs the html[data-accent] rules use. */
.accent-swatches {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  transition: opacity var(--dur-2) var(--ease-out);
}
.accent-swatches.is-locked {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}
.accent-swatch {
  position: relative;
  display: block;
  width: 22px;
  height: 22px;
  cursor: pointer;
}
.accent-swatch input[type='radio'] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.accent-swatch-dot {
  --sw: var(--accent-d);
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--sw);
  transition:
    box-shadow var(--dur-2) var(--ease-out),
    transform var(--dur-2) var(--ease-out);
}
@media (prefers-color-scheme: light) {
  html:not([data-theme]) .accent-swatch-dot {
    --sw: var(--accent-l);
  }
}
html[data-theme='light'] .accent-swatch-dot,
html[data-theme='parchment'] .accent-swatch-dot {
  --sw: var(--accent-l);
}
.accent-swatch:hover .accent-swatch-dot {
  transform: scale(1.1);
}
.accent-swatch input:checked + .accent-swatch-dot {
  box-shadow:
    0 0 0 2px var(--bg-elevated),
    0 0 0 4px var(--sw);
}
.accent-swatch input:focus-visible + .accent-swatch-dot {
  outline: 2px solid var(--focus-color);
  outline-offset: 5px;
}
.appearance-locked-note {
  margin-top: 4px;
}
@media (prefers-reduced-motion: reduce) {
  .theme-card:hover .theme-card-thumb,
  .accent-swatch:hover .accent-swatch-dot {
    transform: none;
  }
}

/* ----------- New Project (template picker) modal ----------- */
.new-project-modal {
  width: 560px;
  max-height: 88vh;
  overflow-y: auto;
}

/* Title-page editor reuses the .settings-modal shell + the
 * .new-project-modal input styling below. */
.titlepage-modal {
  width: 520px;
  max-height: 88vh;
  overflow-y: auto;
}

.titlepage-modal input[type='text'] {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 9px 11px;
  font-size: var(--text-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  outline: none;
  transition: border-color var(--dur-2) var(--ease-out);
  margin-bottom: 14px;
}

.titlepage-modal input[type='text']:focus {
  border-color: var(--accent);
}

.new-project-modal input[type='text'] {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 9px 11px;
  font-size: var(--text-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  outline: none;
  transition: border-color var(--dur-2) var(--ease-out);
  margin-bottom: 14px;
}

.new-project-modal input[type='text']:focus {
  border-color: var(--accent);
}

.format-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

/* ----------- Feedback prompt modal -----------
 * Shares the .settings-modal shell; a star row + textarea. */

.feedback-prompt-modal {
  width: 480px;
}

.feedback-stars {
  display: flex;
  gap: 4px;
  margin: 4px 0 18px;
}

.feedback-star {
  background: transparent;
  border: none;
  padding: 4px 6px;
  font-size: var(--text-display);
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    color var(--dur-1) var(--ease-out),
    transform var(--dur-1) var(--ease-out);
  -webkit-app-region: no-drag;
  opacity: 0.45;
}

.feedback-star:hover,
.feedback-star.is-active {
  color: var(--accent);
  opacity: 1;
}

.feedback-star:active {
  transform: scale(0.92);
}

.feedback-star:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

.feedback-text {
  width: 100%;
  /* Border-box so the 12px horizontal padding is folded into the
   * declared width — otherwise width:100% + padding overflows the
   * modal. */
  box-sizing: border-box;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: var(--text-md);
  line-height: 1.5;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  outline: none;
  transition: border-color var(--dur-2) var(--ease-out);
  resize: vertical;
  /* Breathing room before the Skip / Send feedback row. Without this
   * the buttons crowd the textarea visually. */
  margin-bottom: 16px;
}

.feedback-text:focus {
  border-color: var(--accent);
}

/* 5★ only. The wrappers carry [hidden]; .setting-row sets display:flex
 * and would override it if the attribute sat on the row itself. */
.feedback-quote {
  margin-bottom: 16px;
}

.feedback-quote-credit {
  margin-top: 12px;
}

.feedback-quote-credit .feedback-text {
  margin-bottom: 0;
}

.format-card {
  position: relative;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  cursor: pointer;
  transition:
    border-color var(--dur-2) var(--ease-out),
    background var(--dur-2) var(--ease-out);
  text-align: left;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}

/* "New" pill on freshly added format cards. Dismissed on the writer's
 * first selection — see markFormatPillSeen / hasSeenFormatPill in
 * app.js. Positioned top-right inside the relatively-positioned card. */
.format-card-pill {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--tag-solid-bg);
  color: var(--tag-solid-text);
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  line-height: 1;
  padding: 3px 6px;
  border-radius: var(--radius-xs);
  pointer-events: none;
}

.format-card:hover {
  background: var(--bg-hover);
  border-color: var(--accent-border);
}

.format-card.selected {
  background: var(--accent-bg);
  border-color: var(--accent);
}

.format-card-title {
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  margin-bottom: 4px;
  color: var(--text-primary);
}

.format-card-description {
  color: var(--text-secondary);
  line-height: 1.4;
}

#new-project-status.error {
  color: var(--red);
  text-align: left;
}

/* ----------- AI pane ----------- */
.ai-pane {
  width: 300px;
  /* A chrome surface with a real edge, like the Scenes panel opposite —
     on the desk colour with --border-soft the seam vanished in light. The
     composer keeps its own --bg-elevated, so the input box still stands
     out. */
  background: var(--bg-surface);
  border-left: 1px solid var(--pane-divider);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.ai-pane.collapsed {
  display: none;
}

/* Pane header row, as tall as the Scenes header opposite. The tabs are
 * chips: the active one takes the same wash a picked scene row does, so
 * "this one is selected" looks the same everywhere in the window. */
.ai-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  height: var(--bar-h);
  padding: 0 8px;
  flex-shrink: 0;
}

.ai-tab {
  flex: none;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  padding: 0 10px;
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  cursor: pointer;
  font-family: var(--font-ui);
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out);
}

.ai-tab:hover {
  color: var(--text-primary);
  background: var(--hover-wash);
}

.ai-tab.active {
  color: var(--text-primary);
  background: var(--selected-wash);
}

.ai-tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 12px;
  overflow-y: auto;
}

.ai-tab-panel.active {
  display: flex;
}

/* Collaborator */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-right: 4px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  /* The sticky-bottom latch in app.js owns the scroll position; browser
     scroll anchoring would fight it while streamed content grows. */
  overflow-anchor: none;
}

/* ===== Chat history (Direction B popover + full-screen list) ===== */

.chat-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 2px 8px;
  flex: 0 0 auto;
}

.chat-header-title {
  flex: 1;
  min-width: 0;
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  /* Clip to a single line — long auto-titles end in an ellipsis. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-actions {
  display: flex;
  gap: 5px;
  flex: 0 0 auto;
}

.chat-header-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  /* No outline at rest: the glyph is the control. A panel of outlined
     squares, chips and cards is what made this column busy. */
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  transition:
    background var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out);
}

.chat-header-btn:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--hover-wash);
}

.chat-header-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.chat-header-btn[aria-expanded='true'] {
  background: var(--accent-bg);
  border-color: var(--accent-border);
  color: var(--text-primary);
}

.chat-header-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chat-ico {
  width: 16px;
  height: 16px;
  display: block;
}

/* --- Direction B: history popover --- */

.chat-history-popover {
  position: absolute;
  top: calc(100% - 2px);
  right: 0;
  width: 290px;
  max-width: calc(100% - 4px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow:
    0 8px 28px rgba(0, 0, 0, 0.18),
    0 2px 6px rgba(0, 0, 0, 0.12);
  z-index: 60;
  overflow: hidden;
}

.chat-pop-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-muted);
}

.chat-pop-search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: var(--text-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
}

.chat-pop-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
}

.chat-pop-more {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-md);
  font-weight: 500;
  font-family: var(--font-ui);
  cursor: pointer;
}

.chat-pop-more:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.chat-pop-more:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* --- Direction A "more" screen: full-panel list --- */

.chat-history-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chat-history-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 2px 10px;
  flex: 0 0 auto;
}

.chat-history-heading {
  flex: 1;
  min-width: 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}

.chat-history-newbtn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: var(--font-ui);
  cursor: pointer;
  flex: 0 0 auto;
}

.chat-history-newbtn:hover:not(:disabled) {
  background: var(--bg-hover);
}

.chat-history-newbtn:disabled {
  opacity: 0.4;
  cursor: default;
}

.chat-history-newbtn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chat-history-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin-bottom: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  flex: 0 0 auto;
}

.chat-history-search:focus-within {
  border-color: var(--accent);
}

.chat-history-search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: var(--text-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
}

.chat-history-list {
  flex: 1;
  overflow-y: auto;
}

/* --- shared session rows (used by both popover + full list) --- */

.chat-session-group {
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  padding: 9px 8px 4px;
}

.chat-session-row {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: var(--radius-md);
  /* Highlight the WHOLE row (text + actions) as one inset pill, and leave a
     gap between rows so adjacent highlights don't merge. */
  margin: 2px 0;
  padding-right: 4px;
}

/* Accent-tinted wash (same idiom as the row "⋯" menu) so the highlight reads
   clearly against the panel in BOTH themes — the flat --bg-hover/--accent-bg
   surfaces were nearly invisible against the dark editor-matched background. */
.chat-session-row:hover,
.chat-session-row:focus-within {
  background: var(--hover-wash);
}

.chat-session-row.is-active {
  background: var(--selected-wash);
}

.chat-session-row-main {
  flex: 1;
  min-width: 0;
  display: block;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border: 0;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-ui);
  color: var(--text-primary);
}

.chat-session-row-main:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.chat-session-title {
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-session-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-session-row.is-archived .chat-session-row-main {
  opacity: 0.75;
}

.chat-session-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  margin-left: 4px;
}

.chat-session-act {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
}

.chat-session-act:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.chat-session-act:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  opacity: 1;
}

/* Restore on archived rows is an icon-only button (undo glyph + "Restore"
   tooltip); visuals come from .chat-session-act. */

.chat-session-menu {
  /* Portaled to <body> and positioned via JS (positionRowMenu) so the
     popover/list overflow can't clip it. */
  position: fixed;
  width: 172px;
  z-index: 1000;
  padding: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
}

.chat-session-menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: var(--text-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
  cursor: pointer;
  text-align: left;
}

.chat-session-menu-item:hover,
.chat-session-menu-item:focus-visible {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  outline: none;
}

.chat-session-menu-item.is-danger {
  color: var(--danger);
}

.chat-session-menu-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

.chat-session-rename-input {
  width: 100%;
  font-size: var(--text-md);
  font-family: var(--font-ui);
  color: var(--text-primary);
  background: var(--bg-base);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  outline: none;
}

.chat-session-empty {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
  padding: 20px 12px;
  font-style: italic;
}

.chat-archived-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 10px 8px 5px;
  border: 0;
  background: transparent;
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  cursor: pointer;
  font-family: var(--font-ui);
}

.chat-archived-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.chat-archived-chev {
  width: 14px;
  height: 14px;
  transition: transform var(--dur-2) var(--ease-out);
}

.chat-archived-toggle[aria-expanded='true'] .chat-archived-chev {
  transform: rotate(90deg);
}

@media (prefers-reduced-motion: reduce) {
  .chat-archived-chev {
    transition: none;
  }
}

.chat-msg {
  font-size: var(--text-lg);
  line-height: 1.6;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  max-width: 100%;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Markdown-rendered assistant messages — block elements supply their
   own spacing, so we drop the default pre-wrap that plain messages use. */
.chat-msg.markdown {
  white-space: normal;
}
.chat-msg.markdown > :first-child {
  margin-top: 0;
}
.chat-msg.markdown > :last-child {
  margin-bottom: 0;
}
.chat-msg.markdown p {
  margin: 0 0 11px 0;
}
.chat-msg.markdown h1,
.chat-msg.markdown h2,
.chat-msg.markdown h3,
.chat-msg.markdown h4,
.chat-msg.markdown h5,
.chat-msg.markdown h6 {
  margin: 12px 0 6px 0;
  font-weight: var(--weight-strong);
  line-height: 1.3;
  color: var(--text-primary);
}
.chat-msg.markdown h1 {
  font-size: var(--text-2xl);
}
.chat-msg.markdown h2 {
  font-size: var(--text-xl);
}
.chat-msg.markdown h3 {
  font-size: var(--text-xl);
}
.chat-msg.markdown h4,
.chat-msg.markdown h5,
.chat-msg.markdown h6 {
  font-size: var(--text-lg);
}
.chat-msg.markdown ul,
.chat-msg.markdown ol {
  margin: 0 0 8px 0;
  padding-left: 20px;
}
.chat-msg.markdown li {
  margin: 5px 0;
}
.chat-msg.markdown li > p {
  margin: 0;
}
.chat-msg.markdown blockquote {
  margin: 0 0 8px 0;
  padding: 4px 10px;
  border-left: 2px solid var(--border);
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 0 4px 4px 0;
}
.chat-msg.markdown code {
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: var(--text-sm);
  padding: 1px 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
}
.chat-msg.markdown pre {
  margin: 0 0 8px 0;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  white-space: pre;
}
.chat-msg.markdown pre code {
  background: transparent;
  padding: 0;
  font-size: var(--text-sm);
  line-height: 1.5;
}
.chat-msg.markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}
.chat-msg.markdown a {
  color: var(--accent, #6db3f2);
  text-decoration: underline;
  cursor: pointer;
}
.chat-msg.markdown a:hover {
  filter: brightness(1.15);
}
/* A scene the answer cites ("Scene 12"): reads as part of the sentence,
   a dotted underline says it goes somewhere, a wash on hover. No fill or
   outline at rest — the panel rests — and not the accent of an outside
   link. The negative margin cancels the padding so the wash never moves
   the line. */
.chat-msg.markdown .chat-scene-ref {
  color: inherit;
  padding: 0 2px;
  margin: 0 -2px;
  border-radius: var(--radius-xs);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  cursor: pointer;
  transition: background-color var(--dur-1) var(--ease-out);
}
.chat-msg.markdown .chat-scene-ref:hover {
  filter: none;
  background: var(--hover-wash);
  text-decoration-style: solid;
}
.chat-msg.markdown .chat-scene-ref:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}
/* Heavier, never brighter: an answer names things in bold every line or
   two, and bold at headline brightness turned the column into a field of
   white flecks. */
.chat-msg.markdown strong {
  font-weight: var(--weight-strong);
  color: inherit;
}
.chat-msg.markdown em {
  font-style: italic;
}

.chat-msg.user {
  background: var(--user-bubble-bg);
  border: 1px solid var(--user-bubble-border);
  color: var(--user-bubble-text);
  align-self: flex-end;
}

/* An answer is text on the panel, not a card: no fill and no outline, the
   way a page of notes reads. The 2px inset lines it up with the panel's
   title above. */
.chat-msg.assistant {
  background: transparent;
  color: var(--text-body);
  border: 0;
  padding: 2px;
}

/* Wrap around bubble + action toolbar. The wrap owns alignment so
   the actions can sit outside the bubble while staying aligned to it
   (left for assistant, right for user). New wraps fade + slide in;
   `prefers-reduced-motion` skips the motion entirely. */
.chat-msg-wrap {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  animation: chat-msg-enter 220ms ease-out both;
}
@keyframes chat-msg-enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@media (prefers-reduced-motion: reduce) {
  .chat-msg-wrap {
    animation: none;
  }
}
.chat-msg-wrap.user {
  align-self: flex-end;
  align-items: flex-end;
}
.chat-msg-wrap.assistant {
  align-self: flex-start;
  align-items: flex-start;
}
.chat-msg-wrap > .chat-msg {
  align-self: stretch;
}

/* Per-message action toolbar — icon-only ghost buttons sitting just
   below the bubble. Space is always reserved (height + margin) so the
   layout doesn't jump on hover; only opacity toggles. */
.chat-msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 4px;
  height: 22px;
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease-out);
}
.chat-msg-wrap:hover .chat-msg-actions,
.chat-msg-wrap:focus-within .chat-msg-actions {
  opacity: 1;
}
/* While the answer is still streaming, keep Copy / 👍👎 hidden even on hover —
 * a half-formed reply isn't worth copying or rating. The wrap drops
 * .is-streaming when the stream finalizes (success or Stop). Height stays
 * reserved so the bar fades in without a layout shift. */
.chat-msg-wrap.is-streaming .chat-msg-actions {
  opacity: 0 !important;
  pointer-events: none;
}
.chat-msg-wrap.user .chat-msg-actions {
  justify-content: flex-end;
}
.chat-msg-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-family: inherit;
}
.chat-msg-action:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}
.chat-msg-action svg {
  flex-shrink: 0;
}
.chat-msg-action.is-copied {
  color: var(--text-primary);
}

/* Thumbs feedback shares the hover-revealed action bar (same as Copy), so the
   rating unmistakably belongs to the AI answer you're pointing at and never
   floats next to the following question. Selected rating: semantic green (up)
   / red (down), legible on both themes. */
.chat-msg-action.chat-feedback-up.is-selected {
  color: #2ea043;
}
.chat-msg-action.chat-feedback-down.is-selected {
  color: #cf444c;
}
/* "Report a problem" sits with the thumbs but carries a label: writers who
   don't know what a flag icon means still need to find it (CLAUDE.md
   "Target audience"). Same 22px height as its neighbours. */
.chat-msg-action.chat-report {
  width: auto;
  padding: 0 7px;
  gap: 5px;
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
}

/* The report sheet. */
.ai-report-modal {
  width: 480px;
}
.ai-report-reasons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.ai-report-reason {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  color: var(--text-primary);
  cursor: pointer;
  transition:
    border-color var(--dur-2) var(--ease-out),
    background var(--dur-2) var(--ease-out);
}
.ai-report-reason:hover {
  background: var(--bg-hover);
}
.ai-report-reason input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}
.ai-report-reason:has(input:checked) {
  border-color: var(--accent-border);
}
.ai-report-reason:has(input:focus-visible) {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}
.ai-report-radio {
  width: 14px;
  height: 14px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 1.5px solid var(--accent-border);
  flex-shrink: 0;
}
.ai-report-reason:has(input:checked) .ai-report-radio {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 3px var(--bg-elevated);
}
.ai-report-optional {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}
.ai-report-note {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 72px;
  padding: 9px 11px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.45;
  color: var(--text-primary);
  resize: vertical;
  margin-bottom: 14px;
}
.ai-report-note:focus-visible {
  outline: none;
  border-color: var(--accent-border);
}
.ai-report-privacy {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-secondary);
}
.ai-report-privacy svg {
  flex-shrink: 0;
  margin-top: 1px;
}
.ai-report-privacy strong {
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}

/* Inline chart blocks rendered from ```chart fences in assistant messages. */
.chart-block {
  margin: 8px 0;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.chart-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  margin-bottom: 6px;
  text-align: center;
}
.chart-block svg {
  display: block;
  color: var(--text-primary);
}

/* ---------- chat graphics (Mermaid / Vega) — expandable ---------- */
/* A rendered diagram/chart with a corner "expand" button that opens the
   same SVG in a full-window lightbox. The chat panel is narrow, so dense
   graphics need a way to be viewed large. */
.chat-graphic {
  position: relative;
  margin: 8px 0;
}
.chat-graphic-canvas svg {
  display: block;
  max-width: 100%;
  height: auto;
}
.chat-graphic-expand {
  position: absolute;
  top: 6px;
  right: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease-out);
}
/* Keep the affordance discoverable: faintly visible at rest, full on hover. */
.chat-graphic:hover .chat-graphic-expand,
.chat-graphic:focus-within .chat-graphic-expand {
  opacity: 0.85;
}
.chat-graphic-expand:hover {
  opacity: 1;
  border-color: var(--text-muted);
}
.chat-graphic-expand svg {
  flex-shrink: 0;
  pointer-events: none;
}

/* Shown when a chart/diagram fence can't be rendered — a calm "couldn't
 * render" line with the source behind a disclosure, instead of dumping raw
 * JSON at a non-technical writer. */
.chat-graphic-fallback {
  margin: 8px 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  font-size: var(--text-sm);
}
.chat-graphic-fallback-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-graphic-fallback-icon {
  color: var(--text-muted);
}
.chat-graphic-fallback-msg {
  color: var(--text-secondary);
}
.chat-graphic-fallback-toggle {
  margin-left: auto;
  padding: 2px 8px;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
}
.chat-graphic-fallback-toggle:hover {
  border-color: var(--text-muted);
}
.chat-graphic-fallback-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.chat-graphic-fallback-source {
  margin: 10px 0 0;
  padding: 10px;
  max-height: 280px;
  overflow: auto;
  background: var(--bg-base, var(--bg-elevated));
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Callout cards (> [!WARNING] etc.) — see remark-callout.js + MarkdownBlock. */
.chat-callout {
  margin: 10px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
}
.chat-callout > :last-child {
  margin-bottom: 0;
}
.chat-callout-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-muted);
}
.chat-callout-note {
  border-left-color: var(--accent);
}
.chat-callout-tip {
  border-left-color: var(--green);
}
.chat-callout-important {
  border-left-color: var(--accent);
}
.chat-callout-warning {
  border-left-color: #c98a2f;
}
.chat-callout-caution {
  border-left-color: var(--red);
}

/* Progress / strength meters (```lastslate-meter) — see Meter.jsx. */
.chat-meter {
  margin: 8px 0;
}
.chat-meter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  font-size: var(--text-sm);
}
.chat-meter-label {
  color: var(--text-secondary);
}
.chat-meter-value {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.chat-meter-track {
  height: 8px;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  overflow: hidden;
}
.chat-meter-fill {
  height: 100%;
  border-radius: var(--radius-xs);
  background: var(--accent);
  transition: width var(--dur-3) var(--ease-out);
}
.chat-meter-good .chat-meter-fill {
  background: var(--green);
}
.chat-meter-warn .chat-meter-fill {
  background: #c98a2f;
}
.chat-meter-bad .chat-meter-fill {
  background: var(--red);
}
.chat-meter-neutral .chat-meter-fill {
  background: var(--accent);
}
@media (prefers-reduced-motion: reduce) {
  .chat-meter-fill {
    transition: none;
  }
}

/* Inline markdown images (data: URIs only; remote URLs render as alt text). */
.chat-md-img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}
.chat-md-img-alt {
  color: var(--text-muted);
  font-style: italic;
}

.chat-graphic-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.72);
  animation: chat-graphic-lightbox-in 120ms ease-out;
}
@keyframes chat-graphic-lightbox-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.chat-graphic-lightbox-canvas {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  /* A concrete width is required: an SVG sized purely from a viewBox with
     `width:auto` collapses to zero inside a shrink-to-fit parent. */
  width: min(92vw, 1600px);
  max-height: 90vh;
  overflow: auto;
  padding: 16px;
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-3);
}
/* Zoom wrapper: transform scales visually and grows the scrollable area of the
   overflow:auto canvas so the user can pan a zoomed-in graphic. */
.chat-graphic-lightbox-scaler {
  width: 100%;
  transform-origin: top center;
  transition: transform 80ms ease-out;
}
/* Fill the container width and derive height from the viewBox aspect ratio.
   `max-width:100%` overrides Mermaid's inline px cap so small diagrams scale
   up; viewBox + preserveAspectRatio keep tall ones undistorted within max. */
.chat-graphic-lightbox-scaler svg {
  width: 100% !important;
  height: auto !important;
  max-width: 100% !important;
  max-height: 84vh !important;
}
.chat-graphic-lightbox-toolbar {
  position: fixed;
  top: 16px;
  right: 16px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: rgba(20, 20, 20, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(6px);
}
.chat-graphic-lightbox-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: #fff;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease-out);
}
.chat-graphic-lightbox-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.18);
}
.chat-graphic-lightbox-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.chat-graphic-lightbox-btn svg {
  pointer-events: none;
}
.chat-graphic-lightbox-zoom {
  min-width: 44px;
  padding: 0 2px;
  color: #fff;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  text-align: center;
  user-select: none;
}
/* The close button sits slightly apart from the zoom/download cluster. */
.chat-graphic-lightbox-close {
  margin-left: 4px;
  border-left: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0 7px 7px 0;
}

.chat-msg.system {
  font-size: var(--text-md);
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  background: transparent;
  border: none;
  padding: 4px 0;
}

/* ---------- chat status indicator (the fox + phase words) ----------
   Flat on the panel like an answer: no card, no outline. The fox carries
   the motion; the words say which phase. */

.chat-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
  font-size: var(--text-md);
  color: var(--text-muted);
  align-self: flex-start;
  max-width: 100%;
}

.chat-status .mascot {
  flex: 0 0 auto;
}

.chat-status-label {
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  transition: opacity var(--dur-2) var(--ease-out);
}
.chat-status-hint {
  color: var(--text-muted);
  transition: opacity var(--dur-2) var(--ease-out);
}
.chat-status-label.fade,
.chat-status-hint.fade {
  opacity: 0;
}

/* ---------- chat error notice ---------- */

.chat-error {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: rgba(220, 80, 80, 0.08);
  border: 1px solid rgba(220, 80, 80, 0.35);
  color: var(--text-primary);
  font-size: var(--text-md);
  line-height: 1.5;
  max-width: 100%;
}
.chat-error.code-network,
.chat-error.code-timeout {
  background: rgba(220, 160, 60, 0.08);
  border-color: rgba(220, 160, 60, 0.4);
}
.chat-error-icon {
  font-size: var(--text-lg);
  line-height: 1.4;
  flex: 0 0 auto;
  color: rgba(220, 100, 80, 0.95);
}
.chat-error.code-network .chat-error-icon,
.chat-error.code-timeout .chat-error-icon {
  color: rgba(220, 160, 60, 0.95);
}
.chat-error-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-error-text {
  color: var(--text-primary);
}
.chat-error-actions {
  display: flex;
  gap: 6px;
}

/* Chat composer — single bordered container, no separate Send button.
   The keyboard model (Enter to send) is documented in the input's
   placeholder. Container has a focus glow when the textarea is focused
   so the writer sees the active surface as one object. */
/* The text bar: what the writer types, and Send on the same row. Anything
   else that joins it takes a full row — queued and attached chips above
   the input, the hint below it. */
.chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-1);
  padding: 8px 10px;
  /* Positioning context for the absolutely-anchored "Jump to latest"
     button, which floats just above the composer's top edge. */
  position: relative;
  transition:
    border-color var(--dur-2) var(--ease-out),
    box-shadow var(--dur-2) var(--ease-out);
}

/* Focused, the bar takes the soft border a whole pane takes, not the
   full-strength focus colour: at full strength it was a white outline and
   halo around the largest control in the panel (owner, Nov 2026). The
   caret says where typing goes. */
.chat-composer:focus-within {
  border-color: var(--accent-border);
}

.chat-input {
  width: 100%;
  background: transparent;
  color: var(--text-primary);
  border: 0;
  padding: 6px 4px;
  font-family: var(--font-ui);
  font-size: var(--text-lg);
  line-height: 1.45;
  resize: none;
  outline: none;
  /* One line at rest, like the one-line placeholder it holds. JS
     autoresize grows it as the writer types, up to max-height. */
  min-height: 32px;
  max-height: 280px;
  box-sizing: border-box;
  overflow-y: auto;
  display: block;
}
/* No scrollbar for a placeholder: an empty box has nothing to scroll, and
   a wrapped hint at a narrow pane width would otherwise grow one. */
.chat-input:placeholder-shown {
  overflow-y: hidden;
}

.chat-input::placeholder {
  color: var(--text-muted);
  opacity: 1; /* WCAG 1.4.3: don't stack opacity on the token — kills contrast */
}

/* ---------- Streaming controls: Stop, queued chips, jump-to-latest ---------- */

/* Stop button — only shown (un-hidden) while a response is streaming.
   Icon only: the label lives in aria-label / title. */
.composer-stop-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  cursor: pointer;
  transition:
    color var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out);
}
.composer-stop-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}
.composer-stop-btn[hidden] {
  display: none;
}
.composer-stop-glyph {
  font-size: var(--text-2xs);
  line-height: 1;
}

/* Send: the visible affordance; same footprint as Stop, which replaces it
   while a response streams. Brand accent like every primary action. */
.composer-send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-text);
  border: 1px solid var(--accent);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.composer-send-btn:hover {
  background: var(--btn-primary-hover);
  border-color: var(--btn-primary-hover);
}
.composer-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}
.composer-send-btn[hidden] {
  display: none;
}
.composer-send-glyph {
  font-size: var(--text-sm);
  line-height: 1;
}

/* Queued messages waiting their turn — one chip each, above the textarea. */
.chat-pending-chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.chat-pending-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--accent) 9%, var(--bg-base));
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  font-size: var(--text-md);
}
.chat-pending-chip-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-pending-chip-x {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-xs);
  line-height: 1;
  padding: 2px 4px;
  border-radius: var(--radius-xs);
}
.chat-pending-chip-x:hover {
  color: var(--text-primary);
}

/* Context the writer attached to the next question (highlighted selection,
   @scene, @character, @draft, @note). Same tray as the queued-message
   chips; a preview chip (unresolved @-mention) has no remove button. */
.chat-attachment-chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.chat-attachment-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--accent) 9%, var(--bg-base));
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  font-size: var(--text-md);
  min-width: 0;
}
.chat-attachment-chip.is-preview {
  opacity: 0.7;
}
.chat-attachment-chip-glyph {
  flex: none;
  font-size: var(--text-sm);
}
.chat-attachment-chip-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-attachment-chip-x {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-xs);
  line-height: 1;
  padding: 2px 4px;
  border-radius: var(--radius-xs);
}
.chat-attachment-chip-x:hover {
  color: var(--text-primary);
}

/* Attached quotes shown above a sent user message. */
.chat-msg-attachments {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 8px;
}
/* Colors derive from the user bubble's own text color, not the page's
   --text-* tokens: in dark mode the bubble is light while --text-secondary
   is light too, which left the quote invisible. */
.chat-msg-attachment {
  margin: 0;
  padding: 4px 8px;
  border-left: 2px solid var(--accent);
  border-radius: 0 6px 6px 0;
  background: color-mix(in srgb, var(--user-bubble-text) 8%, transparent);
  color: var(--user-bubble-text);
  font-size: var(--text-sm);
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  gap: 2px;
  white-space: normal;
}
.chat-msg-attachment-label {
  font-weight: var(--weight-strong);
  opacity: 0.85;
}
.chat-msg-attachment-text {
  opacity: 0.7;
  font-style: italic;
}

/* Floating "Ask about this" button beside a text selection. Lives in
   <body> with position:fixed — never inside the page card — so it can't
   move a single block (pagination stability). */
.ask-selection-btn {
  position: fixed;
  z-index: 9998;
  box-shadow: var(--shadow-2);
}
.ask-selection-btn::before {
  content: '✦ ';
  color: var(--accent);
}

/* "Stopped" marker under a partially-streamed bubble. */
.chat-stopped-tag {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

/* Dev-mode-only ( --dev ) per-request cost readout under an assistant
   bubble: cost · model · input / cache-read / cache-write / output
   tokens. Main never attaches the data in production, so this class
   simply never renders for writers. */
.chat-cost-tag {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
  user-select: text;
}

/* Floating "Jump to latest" — hidden until the reader scrolls away from
   the streaming tail; anchored just above the composer's top edge. */
.chat-jump-latest {
  display: none;
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  margin-bottom: 8px;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
  z-index: 6;
  white-space: nowrap;
}
.chat-jump-latest:hover {
  border-color: var(--accent);
}
.chat-jump-latest.is-visible {
  display: inline-flex;
}
.chat-jump-latest-glyph {
  font-size: var(--text-sm);
  line-height: 1;
}

/* ---------- Composer footer (role pill, future Unblock + icons) ---------- */
.chat-composer > * {
  grid-column: 1 / -1;
}

.chat-composer > .chat-input {
  grid-column: 1;
  order: 1;
}

.chat-composer > .composer-footer {
  grid-column: 2;
  order: 1;
}

.chat-composer > .chat-composer-hint {
  order: 2;
}

/* Send sits level with the last line of the input as it grows. */
.composer-footer {
  display: flex;
  align-items: center;
  padding: 0 0 4px 6px;
}

.composer-footer-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---------- Pickers under the text bar ----------
   Seat and model, as two quiet labels. The row is the positioning context
   for their menus, which open upward over the bar and are capped to the
   row's width so they stay inside the pane at its 240px floor. A label
   sits 9px inside its hover wash, so the row is inset to line the first
   label up with the text in the bar above. */
.chat-pickers {
  position: relative;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 6px;
  margin-top: 10px;
  padding: 0 5px;
  flex: 0 0 auto;
}

/* No bar, no pickers: chat history open, or AI off. */
.chat-composer.hidden + .chat-pickers {
  display: none;
}

/* ---------- Role selector pill ---------- */
.role-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out);
  white-space: nowrap;
}

.role-pill:hover {
  color: var(--text-primary);
  background: var(--hover-wash);
}

.role-pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Accent treatment when the writer has chosen a specific role —
   communicates "you've made a choice here." Matches the green
   "Ask" pill in the design reference. */
.role-pill--accent {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.role-pill--accent:hover {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
}

.role-pill-glyph {
  font-size: var(--text-md);
  line-height: 1;
}

/* Auto is the resting state, so its pill is the word alone; a seat the
   writer picked keeps its glyph. The popover rows keep the mark. */
.role-pill-glyph:has(.script-mark) {
  display: none;
}

.role-popover-item-glyph .script-mark {
  display: block;
  margin: 0 auto;
}

.role-pill-label {
  line-height: 1;
  /* A long model name (bring-your-own-key) truncates rather than pushing
     the pill out of the composer. */
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.role-pill {
  flex-shrink: 0;
  max-width: 100%;
}

.role-pill-chev {
  opacity: 0.7;
  margin-left: 1px;
}

/* ---------- Role picker popover ---------- */
.role-popover {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  width: 220px;
  /* Never wider than the picker row it floats above — the model catalog's
     272px variant would otherwise clip at the pane's 240px floor. */
  max-width: 100%;
  max-height: 340px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow:
    0 8px 28px rgba(0, 0, 0, 0.4),
    0 2px 6px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow: hidden;
}

.role-popover.hidden {
  display: none;
}

.role-popover-filter {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  padding: 8px 10px;
  outline: none;
}

.role-popover-filter::placeholder {
  color: var(--text-muted);
}

.role-popover-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.role-popover-group {
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 12px 4px;
}

.role-popover-item {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  padding: 7px 12px;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-1) var(--ease-out);
}

.role-popover-item--highlight,
.role-popover-item:focus-visible {
  background: var(--hover-wash);
  outline: none;
}

.role-popover-item--selected {
  color: var(--text-primary);
}

.role-popover-item-glyph {
  font-size: var(--text-lg);
  line-height: 1;
  width: 16px;
  text-align: center;
  flex: 0 0 auto;
}

.role-popover-item-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.role-popover-item-name {
  font-size: var(--text-md);
  line-height: 1.3;
}

.role-popover-item-sub {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.35;
}

.role-popover-item-check {
  color: var(--accent);
  font-size: var(--text-sm);
  margin-left: 6px;
  flex: 0 0 auto;
}

.role-popover-empty {
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding: 12px;
  text-align: center;
}

/* ---------- Chat empty-state welcome ----------
   The fox, one line of title, the no-edit promise ("I analyze; you
   write" surfaces the constraint from the very first interaction) and
   three starters. Nothing here is outlined: the composer below is the
   only box on a new chat. The starters pre-fill the input but never
   auto-submit (avoids surprise sends). */
.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin: auto 0;
  padding: 12px;
  gap: 4px;
  color: var(--text-muted);
}

.chat-empty.hidden {
  display: none;
}

.chat-empty-mascot {
  display: flex;
  margin-bottom: 8px;
}

.chat-empty-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}

.chat-empty-body {
  font-size: var(--text-md);
  line-height: 1.55;
  margin-bottom: 14px;
}

.chat-empty-prompts {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  max-width: 320px;
}

.chat-empty-prompt {
  appearance: none;
  display: flex;
  gap: 8px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 7px 10px;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  text-align: left;
  cursor: pointer;
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out);
}

/* The arrow is what says "this is a button" now that the outline is gone. */
.chat-empty-prompt::before {
  content: '\2197';
  flex: 0 0 auto;
}

.chat-empty-prompt:hover {
  background: var(--hover-wash);
  color: var(--text-primary);
}

.chat-empty-prompt:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
  color: var(--text-primary);
}

/* ---------- The fox (js/shared/mascot.js) ----------
   One pose per data-state; the drawing is an 11×10 pixel grid, so every
   length below is in grid cells (1px = one pixel of the fox, whatever
   size it is drawn at). Keyframes move parts with translate / scale /
   rotate, never transform, and each one ends on its resting pose so the
   reduced-motion rule (which jumps an animation to its last frame)
   leaves a still, correct fox. */
.mascot {
  overflow: visible;
}

.mascot * {
  transform-box: fill-box;
}

.mascot-fur {
  fill: var(--mascot-fur);
}

.mascot-eye {
  fill: var(--mascot-eye);
}

.mascot-pupil {
  fill: var(--mascot-pupil);
}

.mascot-z {
  fill: var(--text-muted);
}

.mascot-zz {
  opacity: 0;
}

.mascot-head {
  transform-origin: 50% 100%;
}

.mascot-ear-l {
  transform-origin: 100% 100%;
}

.mascot-ear-r {
  transform-origin: 0 100%;
}

.mascot-eyes {
  transform-origin: 50% 50%;
}

.mascot-ear-l,
.mascot-ear-r,
.mascot-head,
.mascot-eyes,
.mascot-pupil {
  transition:
    scale var(--dur-3) var(--ease-out),
    rotate var(--dur-3) var(--ease-out),
    opacity var(--dur-3) var(--ease-out);
}

/* A new chat: the fox pops up once. Re-showing the welcome restarts it. */
.chat-empty .mascot-all {
  animation: mascot-pop 520ms var(--ease-out) 1 both;
}

.mascot[data-state='rest'] .mascot-eyes {
  animation: mascot-blink 5s infinite;
}

.mascot[data-state='rest'] .mascot-ear-r {
  animation: mascot-ear 7s infinite;
}

.mascot[data-state='listen'] .mascot-ear-l,
.mascot[data-state='listen'] .mascot-ear-r {
  scale: 1 1.3;
}

.mascot[data-state='listen'] .mascot-head {
  rotate: 6deg;
}

.mascot[data-state='listen'] .mascot-eyes {
  animation: mascot-blink 3.2s infinite;
}

.mascot[data-state='think'] .mascot-head {
  animation: mascot-tilt 2.4s ease-in-out infinite;
}

.mascot[data-state='think'] .mascot-pupil-l {
  animation: mascot-look-up-l 2.4s infinite;
}

.mascot[data-state='think'] .mascot-pupil-r {
  animation: mascot-look-up-r 2.4s infinite;
}

.mascot[data-state='read'] .mascot-all {
  animation: mascot-bob 1.4s ease-in-out infinite;
}

.mascot[data-state='read'] .mascot-pupil-l {
  animation: mascot-read-l 1.4s linear infinite;
}

.mascot[data-state='read'] .mascot-pupil-r {
  animation: mascot-read-r 1.4s linear infinite;
}

.mascot[data-state='write'] .mascot-all {
  animation: mascot-bob 700ms ease-in-out infinite;
}

.mascot[data-state='write'] .mascot-ear-l {
  animation: mascot-ear 1.4s infinite;
}

.mascot[data-state='write'] .mascot-ear-r {
  animation: mascot-ear 1.4s 700ms infinite;
}

.mascot[data-state='sleep'] .mascot-ear-l {
  rotate: -10deg;
}

.mascot[data-state='sleep'] .mascot-ear-r {
  rotate: 10deg;
}

.mascot[data-state='sleep'] .mascot-eyes {
  transform-origin: 50% 100%;
  scale: 1 0.5;
}

.mascot[data-state='sleep'] .mascot-pupil {
  opacity: 0;
}

.mascot[data-state='sleep'] .mascot-head {
  animation: mascot-breathe 3.2s ease-in-out infinite;
}

.mascot[data-state='sleep'] .mascot-zz {
  animation: mascot-zz 3.2s ease-out infinite;
}

@keyframes mascot-pop {
  0% {
    translate: 0 6px;
    opacity: 0;
  }
  60% {
    translate: 0 -1.2px;
    opacity: 1;
  }
  100% {
    translate: 0 0;
    opacity: 1;
  }
}

@keyframes mascot-blink {
  0%,
  94%,
  100% {
    scale: 1 1;
  }
  97% {
    scale: 1 0.1;
  }
}

@keyframes mascot-ear {
  0%,
  80%,
  100% {
    rotate: 0deg;
  }
  88% {
    rotate: 14deg;
  }
  94% {
    rotate: -4deg;
  }
}

@keyframes mascot-tilt {
  0%,
  100% {
    rotate: -5deg;
  }
  50% {
    rotate: 5deg;
  }
}

@keyframes mascot-look-up-l {
  0%,
  45% {
    translate: -1px -1px;
  }
  50%,
  95% {
    translate: 0 -1px;
  }
  100% {
    translate: -1px -1px;
  }
}

@keyframes mascot-look-up-r {
  0%,
  45% {
    translate: 0 -1px;
  }
  50%,
  95% {
    translate: 1px -1px;
  }
  100% {
    translate: 0 -1px;
  }
}

@keyframes mascot-read-l {
  0% {
    translate: -1px 0;
  }
  70%,
  92% {
    translate: 0 0;
  }
  100% {
    translate: -1px 0;
  }
}

@keyframes mascot-read-r {
  0% {
    translate: 0 0;
  }
  70%,
  92% {
    translate: 1px 0;
  }
  100% {
    translate: 0 0;
  }
}

@keyframes mascot-bob {
  50% {
    translate: 0 -0.6px;
  }
}

@keyframes mascot-breathe {
  50% {
    scale: 1 1.05;
  }
}

@keyframes mascot-zz {
  0% {
    translate: 0 2px;
    opacity: 0;
  }
  30% {
    opacity: 0.9;
  }
  100% {
    translate: 1.5px -2px;
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mascot * {
    animation: none !important;
    transition: none !important;
  }
}

.structure-bar {
  display: flex;
  height: 14px;
  border-radius: var(--radius-xs);
  overflow: hidden;
  background: var(--bg-elevated);
}

.structure-act {
  height: 100%;
  transition: width var(--dur-3) var(--ease-out);
}
.act-1 {
  background: var(--act-1);
}
.act-2 {
  background: var(--act-2);
}
.act-3 {
  background: var(--act-3);
}

.scene-length-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.scene-length-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-2xs);
  cursor: pointer;
}

.scene-length-row:hover .scene-length-name {
  color: var(--text-primary);
}

.scene-length-num {
  color: var(--text-muted);
  min-width: 22px;
  font-variant-numeric: tabular-nums;
}

.scene-length-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
}

.scene-length-fill {
  height: 100%;
  background: var(--text-muted);
}

.scene-length-name {
  color: var(--text-muted);
  min-width: 0;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* History */
.checkpoint-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checkpoint-empty {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 16px 0;
}

.checkpoint-item,
.checkpoint-draft {
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}

/* The wall: Free-tier rows older than the history window. Kept visible
   (greyed via muted text, not opacity, so contrast stays AA) behind the
   Pro gate — clicking opens the upgrade modal instead of a preview. */
/* The row is the button (it opens the upgrade prompt), so its "Pro" tag
   sits where a row's action would: at the trailing edge, on the middle of
   the row, in a column of its own that the name wraps beside and never
   runs under. */
.checkpoint-item--capped {
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 12px;
  align-items: center;
}

.checkpoint-item--capped > .checkpoint-badge {
  grid-column: 2;
  grid-row: 1 / span 2;
  height: 24px;
  padding: 0 13px;
  font-size: var(--text-sm);
}

.checkpoint-item--capped .checkpoint-name {
  color: var(--text-muted);
  font-weight: 400;
}

.checkpoint-item--capped:hover {
  background: var(--bg-hover);
}

.checkpoint-item--capped:focus-visible,
.checkpoint-wall-more:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

.checkpoint-wall-more {
  cursor: pointer;
}

/* Active/hovered rows sit on --accent-bg / --bg-hover, where the muted
   text tier falls just under 4.5:1 in the light theme (#6a6a66 on
   #e5e4df ≈ 4.3:1) — step those states up one text tier so the history
   pane holds AA in every row state. */
.checkpoint-item.active .checkpoint-time,
.checkpoint-draft.active .checkpoint-time,
.checkpoint-draft:hover .checkpoint-time,
.checkpoint-item:hover .checkpoint-time,
.checkpoint-item--capped:hover .checkpoint-name {
  color: var(--text-secondary);
}

/* Notes (scratchpad).
 *
 * Design intent: feel like Apple Notes / Linear / Notion, not a
 * form. The pane is one continuous writing surface, not two boxed
 * inputs. Hierarchy comes from type weight + spacing, not borders.
 * Scene title up top reads like a real slugline; script pad sits
 * below a hairline divider with quieter typography so it doesn't
 * compete for attention.
 *
 * Override the tab-panel's default 12px padding so the notes pane
 * can use its own breathing room — the body padding lives on the
 * pane itself so the divider can stretch edge-to-edge.
 */
.ai-tab-panel[data-panel='notes'] {
  padding: 0;
}

.notes-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 18px 16px 4px;
  gap: 4px;
}

.notes-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.notes-section-scene {
  flex: 1 1 62%;
}

.notes-section-script {
  flex: 1 1 38%;
  padding-bottom: 14px;
}

.notes-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 8px;
  padding: 0 2px;
}

.notes-section-title {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  letter-spacing: 0.02em;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* Mirror the editor's .scene-heading text-transform so the Notes
 * label shows "INT. COFFEESHOP - DAY", not the raw typed form. */
#notes-scene-label {
  text-transform: uppercase;
}

/* Script-side title sits at a lower visual weight — it's the
 * always-on pad, less load-bearing than the scene context. */
.notes-section-title-secondary {
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}

.notes-section-status {
  font-size: var(--text-2xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-height: 12px;
  opacity: 0;
  transition: opacity var(--dur-3) var(--ease-out);
}

.notes-section-status:not(:empty) {
  opacity: 1;
}

/* Live-rendering markdown editor surface. The mount point is a
 * plain div — ProseMirror inserts its own contenteditable inside.
 * Same flex slot, padding, and font as the rest of the panel so the
 * editor feels native to the inspector, not bolted on. */
.notes-editor {
  flex: 1;
  min-height: 0;
  width: 100%;
  border-radius: var(--radius-md);
  background: transparent;
  transition: background var(--dur-3) var(--ease-out);
  display: flex;
  flex-direction: column;
  min-height: 80px;
}

.notes-editor:hover,
.notes-editor:focus-within {
  background: var(--bg-surface);
}

/* The ProseMirror EditorView root sits directly under .notes-editor
 * with a .ProseMirror class. We let it fill the slot, scroll
 * internally, and own the visible padding so the writer's caret
 * lines up with the wrapper bg-tint on focus. */
.notes-editor .ProseMirror {
  flex: 1;
  min-height: 0;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-lg);
  line-height: 1.55;
  padding: 10px 12px;
  box-sizing: border-box;
  overflow-y: auto;
  caret-color: var(--accent);
}

.notes-editor-secondary .ProseMirror {
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--text-secondary);
}
.notes-editor-secondary:focus-within .ProseMirror {
  color: var(--text-primary);
}

/* Empty-state placeholder. The notes editor plugin sets
 * data-placeholder + data-empty on the ProseMirror element; we paint
 * the placeholder via ::before so it sits in the same text flow as
 * the writer's first keystroke. */
.notes-editor .ProseMirror[data-empty]::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  font-style: italic;
  pointer-events: none;
  position: absolute;
  /* Match the editor's own padding so the placeholder lands where
   * the writer's text will. */
  padding: inherit;
}
.notes-editor .ProseMirror {
  position: relative;
}

/* Block formatting inside the editor. Tighten the default margins so
 * the scratchpad feels like notes, not a page in a document. */
.notes-editor .ProseMirror > :first-child {
  margin-top: 0;
}
.notes-editor .ProseMirror > :last-child {
  margin-bottom: 0;
}
.notes-editor .ProseMirror p,
.notes-editor .ProseMirror ul,
.notes-editor .ProseMirror ol,
.notes-editor .ProseMirror blockquote {
  margin: 0 0 0.5em;
}
.notes-editor .ProseMirror h1,
.notes-editor .ProseMirror h2,
.notes-editor .ProseMirror h3 {
  margin: 0.2em 0 0.35em;
  font-weight: 600;
  line-height: 1.3;
}
.notes-editor .ProseMirror h1 {
  font-size: 1.2em;
}
.notes-editor .ProseMirror h2,
.notes-editor .ProseMirror h3 {
  font-size: 1.05em;
}
.notes-editor .ProseMirror ul,
.notes-editor .ProseMirror ol {
  padding-left: 1.4em;
}
.notes-editor .ProseMirror li {
  margin: 0.1em 0;
}
.notes-editor .ProseMirror blockquote {
  border-left: 2px solid var(--border);
  padding-left: 0.8em;
  color: var(--text-secondary);
  font-style: italic;
}
.notes-editor .ProseMirror code {
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 0.92em;
  background: var(--bg-elevated);
  border-radius: 3px;
  padding: 1px 4px;
}
.notes-editor .ProseMirror pre {
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin: 0 0 0.5em;
  overflow-x: auto;
}
.notes-editor .ProseMirror pre code {
  background: transparent;
  padding: 0;
}
.notes-editor .ProseMirror a {
  color: var(--accent-border);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.notes-editor .ProseMirror a:hover {
  color: var(--text-primary);
}
.notes-editor .ProseMirror hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.6em 0;
}

.notes-divider {
  border: none;
  height: 1px;
  background: var(--border-soft);
  margin: 6px 2px 12px;
  flex-shrink: 0;
}

/* Scene-list badge — a small outlined "N" pill that surfaces
 * "this scene has notes" at a glance. Outline + letter is more
 * explicit than a generic dot (writers don't have to guess what a
 * tiny accent dot means) and stays unobtrusive against the rest of
 * the sidebar. Hidden by default; the renderer toggles .has-note on
 * the scene-item.
 *
 * Sized to align with the scene-name baseline. min-width keeps the
 * pill from looking cramped on narrow letterforms; padding adds a
 * little breathing room on either side. The border is thin and uses
 * the text color so the pill reads as a tag, not a button. */
.scene-note-pip {
  /* No box until the row has one: two invisible badges used to reserve
     about 60px of every row, a third of the name's width. */
  display: none;
  align-items: center;
  justify-content: center;
  /* A bare letter, not a boxed one: with every scene on the board the
     list wore a column of 191 outlined squares. The letter keeps the
     meaning explicit (N = notes, B = on the board) and its tooltip says
     which; hover and the current row bring it up to full strength. */
  border: 0;
  padding: 0;
  font-family: var(--font-page-ui);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: transparent;
  flex-shrink: 0;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out);
}

.scene-item.has-note .scene-note-pip {
  display: inline-flex;
  opacity: 1;
  /* The base rule disables pointer-events (the invisible pip must not
   * eat row clicks) — re-enable when visible so the note-preview
   * tooltip can actually fire on hover. */
  pointer-events: auto;
}

.scene-item.has-note.active .scene-note-pip,
.scene-item.has-note:hover .scene-note-pip {
  color: var(--text-primary);
}

.checkpoint-name {
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.checkpoint-time {
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

/* History change view (app.js historyPaginationPaused). Removed words are on
   the page, so the version's page breaks would be wrong: one continuous
   sheet, no page numbers. Colours reuse the diff/status tokens every theme
   defines; underline and strikethrough carry the meaning without colour. */
.page-container.changes-view .screenplay-page,
.version-preview-page {
  background-image: none;
}
/* Mirrors .page-container's geometry and zoom for a cloud version on its own
   surface (app.js showVersionSurface); it is never paginated. */
.version-preview-container {
  --in: 96px;
  position: relative;
  width: calc(8.5 * var(--in));
  margin: 0 auto;
  transform: scale(var(--zoom, 1));
  transform-origin: top center;
}
.page-container.changes-view .page-numbers {
  display: none;
}
ins.chg-ins {
  color: inherit;
  background: var(--diff-added-bg);
  text-decoration: underline;
  text-decoration-color: var(--green);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
/* Old words sit right before their replacement; keep them apart. */
del.chg-del {
  margin-right: 0.5ch;
}
del.chg-del,
.chg-removed del {
  color: inherit;
  background: var(--diff-removed-bg);
  text-decoration: line-through;
  text-decoration-color: var(--red);
  text-decoration-thickness: 2px;
}
.chg-added {
  background: var(--diff-added-bg);
  text-decoration: underline;
  text-decoration-color: var(--green);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
.chg-added,
.chg-edited,
.chg-removed {
  position: relative;
}
/* The margin bar sits outside the text column, so it never moves a line. */
.chg-added::after,
.chg-edited::after,
.chg-removed::after {
  content: '';
  position: absolute;
  left: -18px;
  top: 2px;
  bottom: 2px;
  width: 3px;
  border-radius: 2px;
  background: var(--orange);
}
.chg-added::after {
  background: var(--green);
}
.chg-removed::after {
  background: var(--red);
}
.chg-removed {
  margin-bottom: 1em;
}
.chg-removed-line + .chg-removed-line {
  margin-top: 0.25em;
}
.chg-removed-toggle {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--page-text);
  background: var(--diff-removed-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 4px 10px;
  cursor: pointer;
}
.chg-removed-toggle:hover {
  border-color: var(--red);
}
.chg-removed-toggle:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}
.chg-removed-toggle + .chg-removed-lines {
  margin-top: 0.5em;
}
.preview-banner-detail {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* History grouped by day: a heading over today's and yesterday's rows, and
   one folded row per older day with several versions. */
.checkpoint-day {
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 4px 0;
}
.checkpoint-day-row {
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
}
.checkpoint-day-row:hover {
  background: var(--accent-bg);
}
.checkpoint-day-row:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}
.checkpoint-day-chevron {
  display: inline-block;
  width: 1em;
  color: var(--text-secondary);
  transition: transform 0.15s;
}
.checkpoint-day-row[aria-expanded='true'] .checkpoint-day-chevron {
  transform: rotate(90deg);
}
@media (prefers-reduced-motion: reduce) {
  .checkpoint-day-chevron {
    transition: none;
  }
}

/* What changed in that save, filled in by the History summary queue. */
.checkpoint-detail {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.checkpoint-item:focus-visible,
.checkpoint-draft:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

/* ----------- Status bar (zoom) ----------- */
.editor-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* 34px: the 22px element button sits with 6px of air above and below,
   * so the bar reads as a row, not a strip pinned to the window edge. */
  height: var(--statusbar-h);
  padding: 0 12px 0 10px;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  background: var(--bg-shell);
  border-top: 1px solid var(--shell-divider);
  flex-shrink: 0;
  user-select: none;
}

.statusbar-left,
.statusbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.statusbar-left {
  gap: 4px;
}

/* A status-bar chip: a readout that is also a button (the page count, the
   zoom). Same borderless shape as the element button beside it; its
   popover opens upward from it. */
.status-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out);
}
.status-chip:hover,
.status-chip[aria-expanded='true'] {
  background: var(--hover-wash);
  color: var(--text-primary);
}
.status-chip-caret {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: rotate var(--dur-2) var(--ease-out);
}
.status-chip[aria-expanded='true'] .status-chip-caret {
  rotate: 180deg;
}
.status-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: 200;
  min-width: 190px;
  display: flex;
  flex-direction: column;
  padding: 5px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-2);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  animation: popover-in var(--dur-2) var(--ease-out);
}
.status-popover-end {
  left: auto;
  right: 0;
}

/* ---------- Account menu ----------
   Who is signed in and on which studio seat, then the three things a
   writer does about an account (js/account-menu.js). It hangs
   under the avatar at the far right of the top bar; the welcome screen's
   account row borrows the same element and hangs it under itself. No
   rule between the identity and the actions: space separates them, as
   everywhere in the chrome. */
.account-anchor {
  min-width: 0;
}
.tb-account .user-avatar {
  --avatar-size: 22px;
}
.tb-account[data-signed-in='true'] .tb-account-anon,
.tb-account:not([data-signed-in='true']) .user-avatar {
  display: none;
}
.account-menu {
  top: calc(100% + 6px);
  bottom: auto;
  left: auto;
  right: 0;
  min-width: 220px;
  max-width: 280px;
}
/* The welcome row: its menu hangs from the row's left edge. */
.account-anchor-start {
  margin: -4px -6px;
}
.account-anchor-start .account-menu {
  left: 0;
  right: auto;
}
.account-menu-who {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
  padding: 8px 10px 10px;
}
.account-menu-who .user-avatar {
  flex: none;
}
.account-menu-who-text {
  min-width: 0;
  flex: 1;
}
.account-menu-name,
.account-menu-line {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-menu-name {
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}
.account-menu-line {
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text-secondary);
}
.account-menu-item {
  display: block;
  width: 100%;
  padding: var(--menu-pad-y) 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}
.account-menu-item:hover {
  background: var(--hover-wash);
}
.account-menu-item:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}
/* Script details: one readout per line. An empty one (no draft yet, no
   beats on the board) takes no line. */
#status-details-popover > * {
  padding: var(--menu-pad-y) 10px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-align: left;
  white-space: nowrap;
}
#status-details-popover > .statusbar-beats {
  color: var(--text-primary);
}
#status-details-popover > .statusbar-beats:hover {
  background: var(--hover-wash);
}
/* Zoom: step down, slider, step up on one line; reset under them. */
.zoom-popover {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 6px 8px;
  padding: 10px 10px 6px;
  min-width: 232px;
}
.zoom-reset {
  grid-column: 1 / -1;
  padding: var(--menu-pad-y) 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}
.zoom-reset:hover {
  background: var(--hover-wash);
  color: var(--text-primary);
}
@media (prefers-reduced-motion: reduce) {
  .status-popover {
    animation: none;
  }
  .status-chip-caret {
    transition: none;
  }
}

.page-indicator {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.zoom-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 20px;
  height: 20px;
  font-size: var(--text-lg);
  line-height: 1;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-family: var(--font-ui);
  transition: all var(--dur-2) var(--ease-out);
}

.zoom-btn:hover {
  background: var(--hover-wash);
  color: var(--text-primary);
}

.zoom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 140px;
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  accent-color: var(--accent);
}

.zoom-slider::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
}
/* The popover is itself --bg-elevated, so the track there takes the
   switch's off colour or it would not be drawn at all. */
.zoom-popover .zoom-slider,
.zoom-popover .zoom-slider::-webkit-slider-runnable-track {
  background: var(--toggle-off);
}
.zoom-popover .zoom-slider {
  width: 100%;
  min-width: 140px;
}

.zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--text-secondary);
  border: none;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out);
}

.zoom-slider:hover::-webkit-slider-thumb {
  background: var(--text-primary);
}

.zoom-value {
  font-variant-numeric: tabular-nums;
}

/* ----------- Scrollbars ----------- */
/* Every scrollbar rests invisible and fades in only while in use: while its
 * scroller scrolls, for a moment after, and when the pointer moves onto its
 * gutter (js/shared/scrollbars.js); a thumb under the pointer or being
 * dragged stays painted on its own. Only the thumb's paint changes — the
 * gutter keeps its width, so nothing reflows and page breaks are never
 * involved. A rule that gives one scroller's thumb its own background
 * brings back the permanent bar; set its size or shape instead, as the two
 * below do.
 *
 * The paint is --scrollbar-alpha: 0 at rest, 1 in use, animated between by
 * the script. Registered so it can be animated as a number; not inherited,
 * so a scroller inside a scrolling one keeps its own state and animating it
 * on the script's scroller restyles that one element, never the pages in
 * it. A scrollbar part reads its scroller's value with an explicit
 * `inherit`. */
@property --scrollbar-alpha {
  syntax: '<number>';
  inherits: false;
  initial-value: 0;
}
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  --scrollbar-alpha: inherit;
  background: color-mix(
    in srgb,
    var(--scrollbar-thumb) calc(var(--scrollbar-alpha) * 100%),
    transparent
  );
  border-radius: 3px;
  /* Long lists shrink the thumb to an ungrabbable dot — keep a floor. */
  min-height: 24px;
  min-width: 24px;
}
/* Safari cannot be trusted with the `inherit` above. In Safari 26.6 a
 * scrollbar part reads its scroller's --scrollbar-alpha wrongly: on one
 * scroller it stays 0 (a bar that never appears), on another it sticks at
 * 1 after the first use (a bar that never leaves); both were seen in the
 * editor, and Playwright's WebKit build shows neither, so only the real
 * browser does. What Safari does do reliably is restyle a part when a
 * selector that reaches it starts or stops matching. So there the alpha is
 * left out of it: the thumb is transparent, and the class the script sets
 * while a scroller is in use paints it, on the same clock; the fade is the
 * levels below.
 * `font: -apple-system-body` is a value only Safari's engine has; Chromium
 * (the desktop app, Chrome, Edge) never enters this block and keeps the
 * fade. background-color, not background: the script's own thumb keeps
 * its background-clip. The hover rule below still wins under the pointer. */
@supports (font: -apple-system-body) {
  ::-webkit-scrollbar-thumb {
    background-color: transparent;
  }
  .is-scrolling::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
  }
  /* The fade, told to Safari as eight levels of opacity the script walks
   * through on the same clock as the fade elsewhere (--scrollbar-fade-in /
   * -out; js/shared/scrollbars.js fadeInSteps). After the class rule, so a
   * level decides while a fade is running, in or out. */
  [data-scrollbar-fade='0']::-webkit-scrollbar-thumb {
    background-color: color-mix(in srgb, var(--scrollbar-thumb) 0%, transparent);
  }
  [data-scrollbar-fade='1']::-webkit-scrollbar-thumb {
    background-color: color-mix(in srgb, var(--scrollbar-thumb) 12.5%, transparent);
  }
  [data-scrollbar-fade='2']::-webkit-scrollbar-thumb {
    background-color: color-mix(in srgb, var(--scrollbar-thumb) 25%, transparent);
  }
  [data-scrollbar-fade='3']::-webkit-scrollbar-thumb {
    background-color: color-mix(in srgb, var(--scrollbar-thumb) 37.5%, transparent);
  }
  [data-scrollbar-fade='4']::-webkit-scrollbar-thumb {
    background-color: color-mix(in srgb, var(--scrollbar-thumb) 50%, transparent);
  }
  [data-scrollbar-fade='5']::-webkit-scrollbar-thumb {
    background-color: color-mix(in srgb, var(--scrollbar-thumb) 62.5%, transparent);
  }
  [data-scrollbar-fade='6']::-webkit-scrollbar-thumb {
    background-color: color-mix(in srgb, var(--scrollbar-thumb) 75%, transparent);
  }
  [data-scrollbar-fade='7']::-webkit-scrollbar-thumb {
    background-color: color-mix(in srgb, var(--scrollbar-thumb) 87.5%, transparent);
  }
  [data-scrollbar-fade='8']::-webkit-scrollbar-thumb {
    background-color: color-mix(in srgb, var(--scrollbar-thumb) 100%, transparent);
  }
}

/* Safari's engine only: what paginating costs, never where anything sits.
 * A pass first takes back the last pass's page-break margins, which moves
 * blocks up the page. WebKit then lays out every later block again, in case
 * it now sits beside a float left where the blocks above used to be (the
 * float check in its block layout compares against their OLD position). On a
 * 97-page script that was 6 of the 12 ms a pass took; a block moving down
 * costs 1. A block that starts its own flow and has a width that is not
 * `auto` cannot be narrowed by a float, so the check is skipped. The page has
 * no floats, and fill-available is the width `auto` gives.
 * Only the plain script blocks, nearly all of a page: a note or an outline
 * block is as wide as its words, and fill-available would stretch it. At zero
 * specificity, so a block with a display or a width of its own keeps it. Not
 * `contain: layout`, which would make every block a layer and put a
 * collaborator's name under the block below it.
 * test/ui/safari-block-layout.spec.js holds the geometry. */
@supports (font: -apple-system-body) {
  :where(body:not(.printing) .screenplay-page)
    > :where(.scene-heading, .action, .character, .dialogue, .parenthetical, .transition) {
    display: flow-root;
    width: -webkit-fill-available;
  }
}
::-webkit-scrollbar-thumb:hover,
::-webkit-scrollbar-thumb:active {
  background: var(--scrollbar-thumb-hover);
}
/* Editor scrollbar: writers on long scripts couldn't catch the 6px global
 * bar. 14px gutter, 10px thumb when shown (2px transparent inset). Widening
 * the gutter can't move page breaks — .page-container is a fixed-width
 * centered block and pagination measures inside it. */
.editor-scroll::-webkit-scrollbar {
  width: 14px;
  height: 14px;
}
.editor-scroll::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  background-clip: content-box;
  border-radius: var(--radius-md);
  /* A ~100-page script would otherwise render a tiny ball of a thumb.
   * No max: thumb length is the user's cue for how much of the script
   * the viewport covers, so short docs keep their large thumb. */
  min-height: 48px;
  min-width: 48px;
}
/* Chromium paints the unstyled corner opaque white once any scrollbar
   part is customized — keep it transparent so the pane bg shows. */
::-webkit-scrollbar-corner {
  background: transparent;
}

/* ============================================================
 * Print / PDF Export
 * ------------------------------------------------------------
 * Activated by body.printing (set by exportPdf) and @media print.
 * Renders the screenplay as paginated Letter pages with
 * industry-standard margins. Page breaks are the editor's: the
 * export stamps each page start as a forced break (#199), so the
 * PDF breaks where the editor does; the keep-together hints only
 * matter for native Print, which reflows.
 * ============================================================ */

@page {
  size: letter;
  /* WGA submission margins: 1" top/right/bottom, 1.5" left. Setting
   * margins on @page (not as padding on .screenplay-page) is what
   * makes the second and later pages have the same top spacing as
   * page one — padding only applies once on the wrapping block.
   * Bottom is 2/96in short (#199): slack for integer editor pixels vs
   * fractional print points. PRINT_MARGINS in main.js matches. */
  margin: 1in 1in 0.97917in 1.5in;
}

body.printing {
  background: #fff !important;
}
/* ---------- Web: the page's margins are ours ----------
 * A browser prints its own date, title, address and page count in a page's
 * margins unless the page claims them. Claiming all ten margin boxes keeps
 * them out (Chrome, Edge; owner, Nov 2026: "disable date, time and
 * website"), and the top-right one carries the desktop's page numbers:
 * none on the title page or the first script page, then "2.", "3." at the
 * desktop's place (src/main/print-pdf.js: right edge 1in from the paper's,
 * 0.5in down). Named pages keep this to the web: the desktop's printToPDF
 * is Chromium too and stamps its own numbers afterwards. Safari and
 * Firefox draw no margin boxes; there only their print window's "headers
 * and footers" switch removes the browser's lines.
 * The title page restarts the count at 0, and a number under 2 prints as
 * nothing, so the first number is "2." with a title page or without. */
@counter-style ls-page-blank {
  system: cyclic;
  symbols: '\200B';
  suffix: '';
}
@counter-style ls-page {
  system: numeric;
  symbols: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9';
  range: 2 infinite;
  fallback: ls-page-blank;
}
@counter-style ls-page-dot {
  system: cyclic;
  symbols: '.';
  range: 2 infinite;
  fallback: ls-page-blank;
}
@page web {
  @top-left-corner {
    content: '\a0';
  }
  @top-left {
    content: '\a0';
  }
  @top-center {
    content: '\a0';
  }
  @top-right-corner {
    content: '\a0';
  }
  @bottom-left-corner {
    content: '\a0';
  }
  @bottom-left {
    content: '\a0';
  }
  @bottom-center {
    content: '\a0';
  }
  @bottom-right {
    content: '\a0';
  }
  @bottom-right-corner {
    content: '\a0';
  }
  @top-right {
    content: counter(page, ls-page) counter(page, ls-page-dot);
    font:
      12pt Courier,
      'Courier New',
      monospace;
    line-height: 12pt;
    vertical-align: top;
    padding-top: 36pt;
    color: #000;
  }
}
/* With a title page the count restarts at 0 on it, so the first script page
 * is 1 (unnumbered) and the next "2.". One page name for the whole print:
 * Chrome starts a new page wherever the name changes, and naming the title
 * page on its own put an empty page in front of it. */
@page web-titled {
  @top-left-corner {
    content: '\a0';
  }
  @top-left {
    content: '\a0';
  }
  @top-center {
    content: '\a0';
  }
  @top-right-corner {
    content: '\a0';
  }
  @bottom-left-corner {
    content: '\a0';
  }
  @bottom-left {
    content: '\a0';
  }
  @bottom-center {
    content: '\a0';
  }
  @bottom-right {
    content: '\a0';
  }
  @bottom-right-corner {
    content: '\a0';
  }
  @top-right {
    content: counter(page, ls-page) counter(page, ls-page-dot);
    font:
      12pt Courier,
      'Courier New',
      monospace;
    line-height: 12pt;
    vertical-align: top;
    padding-top: 36pt;
    color: #000;
  }
}
@page web-titled:first {
  counter-reset: page 0;
}
html[data-client='web'] body.printing #editor-layout {
  page: web;
}
html[data-client='web'] body.printing:has(#print-title-page) #editor-layout {
  page: web-titled;
}
/* Safari (WebKit) prints a CSS pixel at 0.8pt where Chromium and the
 * desktop print it at 0.75pt: WebKit lays the page out 1.25 × the page's
 * width in points wide (540px for our 6in column) and fits that to the
 * paper, so every inch measure in this file came out 16/15 too big and
 * lines wrapped narrower, breaking pages away from the editor's (owner's
 * Safari PDF, Nov 2026: 140 pages to Chrome's 129). 15/16 undoes exactly
 * that. `font: -apple-system-body` is understood by WebKit alone, so
 * Chromium (Chrome, Edge, the desktop's printToPDF) never applies this.
 * test/ui/pdf-three-way.spec.js + scripts/pdf-parity.mjs measure it. */
@media print {
  @supports (font: -apple-system-body) {
    body.printing {
      zoom: 0.9375;
    }
    /* WebKit's own style for editable text (the page is contenteditable)
     * keeps the space at the end of a wrapped line ON the line
     * (line-break: after-white-space). Printed, a line that fills the
     * column then reached a space past the margin, and WebKit shrank every
     * page to fit it (1/60 on the reference script: cues 2.4pt off, lines
     * rewrapped), and a wrapped right-aligned transition sat a space left.
     * Chromium lists the same value but does not act on it. */
    body.printing .screenplay-page,
    body.printing .screenplay-page * {
      line-break: auto !important;
      -webkit-line-break: auto !important;
    }
    /* WebKit's page margins for this print (0.5in less at the top for the
     * number band, and its 1.5pt baseline) are set by app.js
     * (WEBKIT_PRINT_PAGE): WebKit reads @page only at a stylesheet's top
     * level, never inside @media or @supports, and a top-level rule here
     * would reach Chromium and the desktop too. */
    /* Page numbers. WebKit draws no page-margin boxes, so the export puts a
     * 0.5in band at the head of each page (addPrintPageBands in app.js),
     * holding "2.", "3."… right-aligned at the desktop's place. A band at a
     * page break carries the break itself, so the page never breaks twice. */
    body.printing .print-page-band {
      display: block !important;
      height: 0.5in;
      margin: 0 !important;
      padding: 0 !important;
      text-align: right;
      font:
        12pt/12pt Courier,
        'Courier New',
        monospace;
      color: #000 !important;
      white-space: nowrap;
    }
    body.printing #print-title-page {
      margin-top: 0.5in;
    }
    body.printing .screenplay-page > .print-page-band--break,
    body.printing.print-measure .dialogue-break > .print-page-band--break {
      break-before: page;
      page-break-before: always;
    }
    body.printing .screenplay-page > .print-page-band--break + div[data-print-break],
    body.printing.print-measure .dialogue-break > .print-page-band--break + .contd-cue {
      break-before: auto !important;
      page-break-before: auto !important;
    }
    /* A split paragraph's spacer holds its page's band: let it be the
     * band's height (the plain spacer rule further down sets 0; this one
     * is more specific so it wins wherever it sits). */
    body.printing.print-measure .screenplay-page .page-break-spacer:not(.dialogue-break) {
      height: auto !important;
    }
  }
}

/* Allowlist, not denylist: the screenplay (and its print title page) live
 * entirely inside #editor-layout, so hide every OTHER direct child of <body>
 * outright. This is what keeps stray body-level nodes out of the export —
 * the chat lightbox portal, the welcome/project-switcher screens, and most
 * importantly any orphaned graphic a failed render leaves on <body> (e.g.
 * mermaid's "Syntax error in text" node). Naming chrome to hide one-by-one
 * always missed the next new thing; this can't. */
body.printing > *:not(#editor-layout) {
  display: none !important;
}
/* The one exception: the web editor's notice that the browser's print
 * window comes next (src/web/bridge/downloads.js exportPdf), asked while
 * the window is already in its print view. Named, and only while the
 * bridge says it is asking; it is closed before anything prints. */
/* (:not(#editor-layout) carries the rule above's id-level weight.) */
body.printing.print-notice > .app-only-overlay:not(#editor-layout) {
  display: flex !important;
}

/* Chrome that lives INSIDE #editor-layout (so the rule above can't reach it). */
body.printing .titlebar,
body.printing .sidebar,
body.printing .ai-pane,
/* Pane dividers are pure chrome. The sidebar/AI handles are vertical
 * bars that collapse to zero height in the print block flow, but the
 * board divider in the STACKED split is a full-width 7px horizontal
 * bar — left visible it sat above the title page, pushing the 9in
 * (one-page, unsplittable) title block onto page 2 and leaving page 1
 * blank. Hide them all; they're never content. */
body.printing .resize-handle,
body.printing .editor-statusbar,
body.printing .settings-overlay,
body.printing .page-numbers,
/* .editor-banner-slot is the canonical home for every dynamically-mounted
 * above-editor banner (Move-to-cloud, cloud-version preview, anything future
 * mountEditorBanner adds) — hiding the wrapper hides them all, so we don't name
 * each banner and miss the next new one. .preview-banner is the static
 * local-version banner, which sits in the same column and would leak the same
 * way. */
body.printing .editor-banner-slot,
body.printing .preview-banner,
/* Outline & annotation blocks (sections, synopses, notes) are non-printing
 * by definition — the writer's structure and notes never belong in the
 * delivered PDF. This is also what keeps the EXPORT paginating on script
 * content only, even though the editor shows these inline; the export's
 * measuring pass (`print-measure`, #199) hides them too. */
body.printing .nonprinting,
body.print-measure .nonprinting,
/* The dual-dialogue authoring chip is an editing affordance, never content —
 * keep it out of the exported PDF (a caret left in an eligible cluster at
 * export time would otherwise render the button into the page). */
body.printing .dual-chip,
body.print-measure .dual-chip,
/* A collaborator's caret and name flag (y-prosemirror) are presence, not
 * content. Printed, the flag also hung past the right margin after a
 * right-aligned transition, and Chromium shrank the whole export to fit it
 * (to ~89% on Windows): smaller type, longer lines, different breaks. */
body.printing .ProseMirror-yjs-cursor,
body.print-measure .ProseMirror-yjs-cursor,
/* Native Print (no print-measure) reflows: no soft spacer stays in the flow. */
body.printing:not(.print-measure) .page-break-spacer {
  display: none !important;
}

/* Save As PDF / Print Preview (#199): every stamped block is a forced break. */
body.printing .screenplay-page > div[data-print-break] {
  page-break-before: always;
  break-before: page;
  margin-top: 0 !important;
}
/* A split paragraph's spacer becomes a zero-height forced break. */
body.printing.print-measure .page-break-spacer:not(.dialogue-break) {
  display: block !important;
  height: 0 !important;
  page-break-before: always;
  break-before: page;
}
/* The editor already applied 2/2 widows/orphans to every forced break. */
body.printing.print-measure .screenplay-page > div {
  orphans: 1;
  widows: 1;
}

/* Dialogue (MORE)/(CONT'D) in the export. Unlike the plain spacer, this one
 * prints. The editor's flex gap is collapsed (the PDF has real page geometry);
 * (MORE) stays at the bottom of the current page (right after the last
 * dialogue line) and the repeated cue forces a page break, landing it at the
 * top of the next page above the carried-over dialogue. The split dialogue
 * itself is released from `break-inside: avoid` so Chromium honors the break
 * we placed (an unsplit speech keeps `avoid` and stays whole). */
body.printing.print-measure .dialogue-break {
  display: block;
  height: auto !important;
}
body.printing.print-measure .dialogue-break .contd-cue {
  page-break-before: always;
  break-before: page;
}
body.printing .more-marker,
body.printing .dialogue-break .contd-cue {
  padding-left: 2in !important;
  /* As in the editor rule above: a wrapped cue is a line never reserved. */
  margin-left: -1in !important;
  margin-right: -1.5in !important;
  white-space: nowrap;
  text-transform: uppercase;
}
/* Only under stamps: a reflow (native Print, the PDF safety net) has no
 * (MORE)/(CONT'D), so a speech must stay whole there. */
body.printing.print-measure .dialogue.dialogue-split {
  page-break-inside: auto;
  break-inside: auto;
}

/* A manual page break (`===`) must force a real page break in the export —
 * NOT be hidden. Collapse its editor chrome (the dashed rule + label) but
 * keep the element so `page-break-after` fires. */
body.printing .ProseMirror-yjs-selection {
  background: none !important;
}
@media print {
  .ProseMirror-yjs-cursor {
    display: none !important;
  }
  .ProseMirror-yjs-selection {
    background: none !important;
  }
}

body.printing .page-break-manual {
  height: 0;
  margin: 0;
  border: none;
  page-break-after: always;
  break-after: page;
}
body.printing .page-break-manual::after {
  display: none !important;
}

body.printing,
body.printing .editor-layout,
body.printing .editor-body,
body.printing .center-split,
body.printing .editor-center,
body.printing .editor-scroll {
  background: #fff !important;
  color: #000 !important;
  overflow: visible !important;
  width: auto !important;
  height: auto !important;
  padding: 0 !important;
  margin: 0 !important;
  display: block !important;
}

body.printing .page-container {
  /* DON'T force width: 8.5in here. @page already carves 1in/1.5in
   * margins out of the Letter sheet, leaving a 6in content area —
   * if the container is 8.5in wide, Chromium scales the whole flow
   * down to ~70.6% to fit, and every CSS indent and line-height
   * silently shrinks with it. */
  width: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  background: #fff !important;
  /* Export must render at 100% — never the on-screen display-zoom transform.
     (The print path also calls applyZoom(1); this is the belt-and-suspenders.) */
  transform: none !important;
  /* Drop the on-screen page-card frame; the PDF carries its own page edges. */
  box-shadow: none !important;
}

body.printing .screenplay-page {
  /* Page margins are now owned by @page above so they apply to every
   * page in a multi-page export. The screenplay-page itself fills
   * the content area without its own padding. */
  width: auto !important;
  min-height: 0 !important;
  padding: 0 !important;
  background: #fff !important;
  background-image: none !important;
  color: #000 !important;
  /* Reset the screen-only tonal hierarchy to pure black. Custom properties
   * inherit, so defining them here cascades to every typed block
   * (.scene-heading/.action/.character/.dialogue/.parenthetical/.transition)
   * — the exported PDF stays standard black-on-white. */
  --el-scene: #000 !important;
  --el-character: #000 !important;
  --el-dialogue: #000 !important;
  --el-action: #000 !important;
  --el-transition: #000 !important;
  --el-parenthetical: #000 !important;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace !important;
  font-size: 12pt !important;
  /* 6 lines per inch on every platform; see .screenplay-page. */
  line-height: 12pt !important;
  border: none !important;
  box-shadow: none !important;
  caret-color: transparent !important;
}

body.printing .screenplay-page > div {
  /* Real-inch indents in print mode (no --in zoom variable). The
   * per-element rules below (.character, .dialogue, .parenthetical,
   * .transition) own padding-left / padding-right — DON'T reset them
   * here, or specificity wars override the indents and every block
   * collapses to the left margin in the PDF preview. */
  margin: 1em 0 0 !important;
}

body.printing .screenplay-page > div:first-child {
  margin-top: 0 !important;
}

body.printing .scene-heading {
  font-weight: bold;
  text-transform: uppercase;
  /* 24pt = ~2 lines space-before */
  margin-top: 24pt !important;
  page-break-after: avoid;
  break-after: avoid;
}

/* Title-page sibling. Lives in .page-container next to #screenplay-page
 * (NOT inside it) so ProseMirror's domObserver can't re-parse it
 * through a schema that has no title-page node type. Hidden in normal
 * editing mode; revealed only during print. */
#print-title-page {
  display: none;
}
/* The page-number bands the export adds while printing (addPrintPageBands):
 * only WebKit's print shows them (the @supports block above). */
.print-page-band {
  display: none;
}

body.printing #print-title-page {
  display: flex !important;
  page-break-after: always !important;
  break-after: page !important;
}

/* Title page: centred title block, optional lower-left footer for
 * draft date / contact. Sized to fill the printable area so the
 * script proper starts on the next page. */
body.printing .title-page {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 9in;
  page-break-after: always;
  break-after: page;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace !important;
  font-size: 12pt !important;
  color: #000 !important;
  text-align: center;
}

body.printing .title-page-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  flex: 1;
  text-align: center;
  /* ~1/3 down the 9in printable area, matching WGA / Final Draft convention. */
  padding-top: 2.5in;
}

body.printing .title-page-title {
  font-weight: normal;
  text-transform: uppercase;
  text-decoration: underline;
  letter-spacing: 0.05em;
}

body.printing .title-page-credit,
body.printing .title-page-author,
body.printing .title-page-source {
  font-weight: normal;
}

/* Spacing is sibling-relational so the layout stays correct when any
   center-block field is omitted (e.g. title-only, no credit, no source). */
body.printing .title-page-center > * + * {
  margin-top: 24pt;
}

body.printing .title-page-center > .title-page-title + * {
  margin-top: 36pt;
}

body.printing .title-page-center > * + .title-page-source {
  margin-top: 60pt;
}

/* Episode line: sits between title and credit in the centre block.
 * Sibling spacing inherits from .title-page-center > * + * (24pt)
 * and the after-title rule (36pt when directly under title). Italic
 * to read as a sub-line of the literary title, not as a peer. */
body.printing .title-page-episode {
  font-style: italic;
}

/* Production strip: muted band that sits naturally above the footer
 * (.title-page-center's flex: 1 absorbs the free space above, so this
 * stack — production then footer — lands at the bottom of the page).
 * Surfaces episodic / vertical metadata without competing with the
 * literary cover. */
body.printing .title-page-production {
  text-align: center;
  font-size: 11pt;
  color: #555 !important;
  margin-bottom: 24pt;
}

body.printing .title-page-series {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

body.printing .title-page-series + .title-page-episode-meta,
body.printing .title-page-series + .title-page-format-note,
body.printing .title-page-episode-meta + .title-page-format-note {
  margin-top: 4pt;
}

body.printing .title-page-format-note {
  font-style: italic;
}

body.printing .title-page-footer {
  text-align: left;
  font-size: 12pt;
}

body.printing .action {
  padding-left: 0 !important;
  padding-right: 0 !important;
}

body.printing .character {
  text-transform: uppercase;
  /* 3.5" from page edge → 2.0" inside the 1.5" left margin.
     7.25" right edge → 0.25" right padding. */
  padding-left: 2in !important;
  padding-right: 0.25in !important;
  page-break-after: avoid;
  break-after: avoid;
}

body.printing .dialogue {
  /* 2.5" left → 1.0" extra. 6.0" right → 1.5" right pad. */
  padding-left: 1in !important;
  padding-right: 1.5in !important;
}

body.printing .parenthetical {
  /* 3.0" left → 1.5" extra. 5.5" right → 2.0" right pad. */
  padding-left: 1.5in !important;
  padding-right: 2in !important;
  font-style: italic;
  color: #000 !important;
  page-break-after: avoid;
  break-after: avoid;
}

body.printing .transition {
  /* 5.5"–7.1": 4.0" left pad, 0.4" right pad, right-aligned. */
  padding-left: 4in !important;
  padding-right: 0.4in !important;
  text-align: right;
  text-transform: uppercase;
}

/* Keep dialogue clusters together where possible */
body.printing .character + .parenthetical,
body.printing .character + .dialogue,
body.printing .parenthetical + .dialogue,
body.printing .dialogue + .parenthetical,
body.printing .dialogue + .dialogue {
  margin-top: 0 !important;
}

body.printing .character,
body.printing .parenthetical,
body.printing .dialogue {
  page-break-inside: avoid;
  break-inside: avoid;
}

/* Dual dialogue in print. The `.dual-dialogue` / `.dual-column` flex pair
 * (defined once near the block CSS) renders in both screen and print, so
 * these are only the print-specific overrides: the screen rules can't beat
 * `body.printing .character`'s `!important` 2in indent, so re-assert the
 * column-local padding here at higher specificity. Keep the container's
 * flex untouched — it carries over from the screen rule. */
body.printing .dual-dialogue {
  break-inside: avoid;
  page-break-inside: avoid;
}
body.printing .dual-column .character {
  padding-left: 0 !important;
  padding-right: 0 !important;
  text-align: center;
}
body.printing .dual-column .dialogue,
body.printing .dual-column .parenthetical {
  padding-left: 0.15in !important;
  padding-right: 0.15in !important;
}

/* ----------- Sprint Timer ----------- */
.sprint-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-right: 4px;
}

.sprint-btn {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.sprint-btn svg {
  display: block;
}

.sprint-btn-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--bg-surface);
  display: none;
}

.sprint-btn[data-running='1'] .sprint-btn-dot {
  display: block;
  animation: sprint-dot-pulse 1.4s ease-in-out infinite;
}

@keyframes sprint-dot-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.sprint-popover {
  position: absolute;
  bottom: calc(100% + 10px);
  right: -10px;
  width: 248px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow:
    0 14px 40px rgba(0, 0, 0, 0.42),
    0 1px 0 rgba(255, 255, 255, 0.04) inset;
  padding: 14px 14px 12px;
  z-index: 200;
  user-select: none;
  font-family: var(--font-ui);
}

.sprint-popover.hidden {
  display: none;
}

.sprint-view.hidden {
  display: none;
}

/* ---- Segmented tabs ---- */
.sprint-tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-base);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 2px;
  margin-bottom: 14px;
}

.sprint-tab {
  position: relative;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  padding: 6px 0;
  cursor: pointer;
  border-radius: var(--radius-sm);
  z-index: 1;
  transition: color var(--dur-2) var(--ease-out);
}

.sprint-tab:hover {
  color: var(--text-primary);
}

.sprint-tab.is-active {
  color: var(--accent-text);
}

.sprint-tabs-indicator {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc(50% - 2px);
  background: var(--accent);
  border-radius: var(--radius-sm);
  transition: transform var(--dur-3) var(--ease-out);
  z-index: 0;
}

.sprint-tabs[data-mode='stopwatch'] .sprint-tabs-indicator {
  transform: translateX(100%);
}

/* ---- Progress ring + display ---- */
.sprint-ring-wrap {
  position: relative;
  width: 160px;
  height: 160px;
  margin: 0 auto 10px;
}

.sprint-ring {
  display: block;
  width: 100%;
  height: 100%;
}

.sprint-ring-track {
  fill: none;
  stroke: var(--border-soft);
  stroke-width: 4;
}

.sprint-ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  /* Circumference of r=68: 2 * π * 68 ≈ 427.26. Set in JS too. */
  stroke-dasharray: 427.26;
  stroke-dashoffset: 427.26;
  transition: stroke-dashoffset 0.25s linear;
}

.sprint-ring-wrap[data-mode='stopwatch'] .sprint-ring-progress {
  /* Stopwatch: subtle constant ring (no progress concept). */
  stroke-dashoffset: 0;
  opacity: 0.18;
}

.sprint-ring-wrap[data-state='idle'] .sprint-ring-progress {
  stroke-dashoffset: 0;
  opacity: 0.25;
}

.sprint-ring-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.sprint-display {
  pointer-events: auto;
  font-family: var(--font-script, ui-monospace, SFMono-Regular, monospace);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-display);
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1;
  text-align: center;
  color: var(--text-primary);
  background: transparent;
  border: none;
  padding: 0;
}

.sprint-display-input {
  width: 96px;
  -moz-appearance: textfield;
}

.sprint-display-input::-webkit-outer-spin-button,
.sprint-display-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.sprint-display-input:focus {
  outline: none;
  color: var(--accent);
}

.sprint-display-readout {
  letter-spacing: 1px;
}

.sprint-display-unit {
  margin-top: 6px;
  font-size: var(--text-2xs);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ---- Preset chips ---- */
.sprint-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-bottom: 12px;
}

.sprint-presets[hidden] {
  display: none;
}

.sprint-preset {
  background: transparent;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  padding: 4px 0;
  cursor: pointer;
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out);
}

.sprint-preset:hover {
  color: var(--text-primary);
  border-color: var(--border);
}

.sprint-preset.is-active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--accent-border);
}

/* ---- Actions ---- */
.sprint-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.sprint-action[hidden] {
  display: none;
}

.sprint-action-wide {
  width: 100%;
  padding: 8px 12px;
  font-weight: 500;
}

.sprint-action-end {
  align-self: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  letter-spacing: 0.02em;
  padding: 2px 6px;
  margin-top: 2px;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--border-soft);
  text-underline-offset: 3px;
  transition:
    color var(--dur-2) var(--ease-out),
    text-decoration-color var(--dur-2) var(--ease-out);
}

.sprint-action-end:hover {
  color: var(--text-primary);
  text-decoration-color: var(--accent-border);
}

/* ---- Celebrate view ---- */
.sprint-view-celebrate {
  text-align: center;
  padding: 4px 0 0;
}

.sprint-celebrate-eyebrow {
  font-size: var(--text-2xs);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.sprint-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 12px 4px;
  background: var(--bg-base);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  margin-bottom: 14px;
}

.sprint-summary-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.sprint-summary-cell + .sprint-summary-cell {
  border-left: 1px solid var(--border-soft);
}

.sprint-summary-value {
  font-family: var(--font-script, ui-monospace, SFMono-Regular, monospace);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-3xl);
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.1;
}

.sprint-summary-label {
  font-size: var(--text-2xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sprint-celebrate-primary {
  width: 100%;
  padding: 8px 12px;
  font-weight: 500;
  margin-bottom: 8px;
}

.sprint-celebrate-share-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  cursor: pointer;
  padding: 2px 4px;
  margin-bottom: 12px;
  transition: color var(--dur-2) var(--ease-out);
}

.sprint-celebrate-share-link:hover {
  color: var(--text-primary);
}

.sprint-stats {
  border-top: 1px solid var(--border-soft);
  padding-top: 8px;
}

.sprint-stats summary {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  list-style: none;
  padding: 2px 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.sprint-stats summary::-webkit-details-marker {
  display: none;
}

.sprint-stats summary::before {
  content: '›';
  display: inline-block;
  transition: transform var(--dur-2) var(--ease-out);
  font-size: var(--text-lg);
  line-height: 1;
}

.sprint-stats[open] summary::before {
  transform: rotate(90deg);
}

.sprint-stats-body {
  padding-top: 8px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.sprint-stats-empty {
  color: var(--text-muted);
  font-style: italic;
}

.sprint-stats-today {
  font-size: var(--text-md);
  color: var(--text-primary);
  margin-bottom: 6px;
}

.sprint-stats-streak {
  margin-bottom: 8px;
}

.sprint-stats-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.sprint-stats-table th,
.sprint-stats-table td {
  text-align: right;
  padding: 2px 4px;
  font-weight: normal;
}

.sprint-stats-table th:first-child,
.sprint-stats-table td:first-child {
  text-align: left;
}

.sprint-stats-table thead th {
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-soft);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
}

.sprint-stats-table tbody tr.today td {
  color: var(--text-primary);
  font-weight: 500;
}

/* Completion banner. Visually aligned with the Driver.js guided-tour
   popover (below) so toast affordances across the app share one
   surface: bg-surface body, neutral border, and an accent-coloured
   action button rather than the default-pale .btn fallback. */
.sprint-banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  display: flex;
  align-items: center;
  gap: 12px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  box-shadow: var(--shadow-3);
  z-index: 1000;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  color: var(--text-primary);
  opacity: 0;
  transition:
    opacity var(--dur-3) var(--ease-out),
    transform var(--dur-3) var(--ease-out);
  pointer-events: none;
}

.sprint-banner:not(.hidden) {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.sprint-banner.hidden {
  display: none;
}

.sprint-banner-text::before {
  content: '✓ ';
  color: var(--accent);
  font-weight: var(--weight-strong);
}

/* OK button — matches .driver-popover-next-btn so the action reads
   the same as the guided-tour primary. Without this it falls through
   to the default .btn .btn-small style, which renders pale on dark
   (the washed-out chip in the report). */
.sprint-banner .sprint-banner-ok {
  display: inline-block;
  box-sizing: border-box;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.3;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  background-color: var(--accent);
  color: var(--accent-text);
  border: 1px solid var(--accent);
  cursor: pointer;
  transition: all var(--dur-2) var(--ease-out);
}

.sprint-banner .sprint-banner-ok:hover,
.sprint-banner .sprint-banner-ok:focus {
  background-color: var(--btn-primary-hover);
  border-color: var(--btn-primary-hover);
}

/* ----------- Connectivity banner -----------
 * Full-width strip below the titlebar — coarser, more visible
 * signal than the per-draft #cloud-indicator pill. Three states
 * via data-state: 'offline' (persistent amber), 'reconnecting'
 * (neutral, transient), 'online' (green, auto-dismiss). The .hidden
 * class drives display; data-state drives tone. */
.connectivity-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  font-weight: 500;
  line-height: 1.3;
  border-bottom: 1px solid var(--border);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  transition:
    background-color var(--dur-3) var(--ease-out),
    color var(--dur-3) var(--ease-out);
}

.connectivity-banner.hidden {
  display: none;
}

.connectivity-banner[data-state='offline'] {
  background-color: var(--banner-warn-bg);
  color: #fff;
  border-bottom-color: var(--banner-warn-bg);
}

.connectivity-banner[data-state='reconnecting'] {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

.connectivity-banner[data-state='online'] {
  background-color: var(--banner-ok-bg);
  color: #fff;
  border-bottom-color: var(--banner-ok-bg);
}

.connectivity-banner-text::before {
  display: inline-block;
  margin-right: 6px;
  font-weight: var(--weight-strong);
}

.connectivity-banner[data-state='offline'] .connectivity-banner-text::before {
  content: '⚠';
}

.connectivity-banner[data-state='reconnecting'] .connectivity-banner-text::before {
  content: '⟳';
}

.connectivity-banner[data-state='online'] .connectivity-banner-text::before {
  content: '✓';
}

/* WCAG 2.3.3: honor reduced-motion for the two banners that slide/fade
   and weren't already covered by an existing guard. Keep centering, drop
   the Y-slide + color cross-fade. */
@media (prefers-reduced-motion: reduce) {
  .sprint-banner {
    transition: opacity var(--dur-2) var(--ease-out);
    transform: translateX(-50%);
  }
  .sprint-banner:not(.hidden) {
    transform: translateX(-50%);
  }
  .connectivity-banner {
    transition: none;
  }
}

/* ----------------- Toast notifications -----------------
 * Transient app-action confirmations (export, backup, revert, cloud
 * sync). These used to render as `system` messages inside the AI chat
 * thread, which read as the collaborator "speaking". They now float over
 * the editor instead.
 *
 * Floating overlay on purpose — position:fixed, so the stack never
 * reflows .editor-scroll / .page-container. Layout/pagination stability
 * is the release-blocking priority, so a toast must not push the page
 * card. Bottom-CENTER because the tips carousel owns bottom-left. */
.toast-stack {
  position: fixed;
  bottom: 56px; /* clear of the status bar */
  left: 50%;
  transform: translateX(-50%);
  z-index: 10001; /* above settings modals (9999/10000) so it's never hidden */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none; /* clicks pass through the empty stack */
  width: max-content;
  max-width: min(520px, calc(100vw - 32px));
}

.toast {
  pointer-events: auto; /* but the toast card itself is interactive */
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 100%;
  padding: 10px 14px;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  line-height: 1.35;
  color: var(--text-primary);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-left-width: 3px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity var(--dur-3) var(--ease-out),
    transform var(--dur-3) var(--ease-out);
}

/* JS flips this on after mount to animate in; removes it to animate out. */
.toast.toast--visible {
  opacity: 1;
  transform: translateY(0);
}

.toast--success {
  border-left-color: var(--green);
}

.toast--error {
  border-left-color: var(--orange);
}

.toast__icon {
  flex: 0 0 auto;
  font-weight: var(--weight-strong);
}

.toast--success .toast__icon {
  color: var(--green);
}

.toast--error .toast__icon {
  color: var(--orange);
}

/* A question (the post-export feedback ask), not a result: accent rule,
 * no icon, and a star row in place of a single action. */
.toast--ask {
  border-left-color: var(--accent);
}

.toast__stars {
  flex: 0 0 auto;
  display: flex;
  gap: 2px;
}

.toast__star {
  border: none;
  background: transparent;
  padding: 2px 3px;
  font-family: inherit;
  font-size: var(--text-lg);
  line-height: 1;
  color: var(--text-secondary);
  opacity: 0.45;
  cursor: pointer;
  border-radius: var(--radius-xs);
  transition:
    color var(--dur-1) var(--ease-out),
    opacity var(--dur-1) var(--ease-out);
}

.toast__star.is-active {
  color: var(--accent);
  opacity: 1;
}

.toast__star:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}

.toast__text {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere; /* long file paths shouldn't blow out the card */
}

.toast__action,
.toast__close {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--text-secondary, var(--text-primary));
  font-family: inherit;
  cursor: pointer;
  border-radius: var(--radius-xs);
}

.toast__action {
  padding: 4px 8px;
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  color: var(--accent, var(--green));
}

.toast__action:hover {
  background-color: var(--bg-hover, rgba(127, 127, 127, 0.14));
}

.toast__close {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
  line-height: 1;
}

.toast__close:hover {
  background-color: var(--bg-hover, rgba(127, 127, 127, 0.14));
  color: var(--text-primary);
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: opacity var(--dur-2) var(--ease-out);
    transform: none;
  }
  .toast.toast--visible {
    transform: none;
  }
}

/* ----------- Guided tour — Driver.js theme overrides -----------
 * Vendor driver.css ships a white popover with a Helvetica stack and
 * default-looking buttons. These overrides re-skin it with theme tokens
 * so the tour matches .settings-modal and follows light/dark switching.
 * The vendor file uses `all: unset` on the close button and footer
 * buttons, so those rules must re-declare every property explicitly. */
.driver-popover {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-3);
  font-family: var(--font-ui);
  min-width: 260px;
  max-width: 320px;
}

.driver-popover * {
  font-family: var(--font-ui);
}

.driver-popover-title {
  color: var(--text-primary);
  font: 600 15px/1.4 var(--font-ui);
}

.driver-popover-description {
  color: var(--text-secondary);
  font: 400 13px/1.5 var(--font-ui);
  margin-top: 6px;
}

.driver-popover-progress-text {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.driver-popover-close-btn {
  color: var(--text-muted);
  top: 8px;
  right: 10px;
}

.driver-popover-close-btn:hover,
.driver-popover-close-btn:focus {
  color: var(--text-primary);
}

.driver-popover-footer {
  margin-top: 16px;
}

/* Vendor uses `all: unset` — re-declare every property the .btn family relies on. */
.driver-popover-footer button {
  display: inline-block;
  box-sizing: border-box;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.3;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background-color: transparent;
  color: var(--text-primary);
  cursor: pointer;
  text-shadow: none;
  transition: all var(--dur-2) var(--ease-out);
}

/* Specificity note: .driver-popover-footer button is (0,2,0) and would
 * otherwise win over a bare .driver-popover-prev-btn (0,1,0) — so each
 * variant rule below matches that specificity by scoping under .driver-popover-footer. */
.driver-popover-footer .driver-popover-prev-btn {
  background-color: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border);
}

.driver-popover-footer .driver-popover-prev-btn:hover,
.driver-popover-footer .driver-popover-prev-btn:focus {
  background-color: var(--bg-hover);
}

.driver-popover-footer .driver-popover-next-btn {
  background-color: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.driver-popover-footer .driver-popover-next-btn:hover,
.driver-popover-footer .driver-popover-next-btn:focus {
  background-color: var(--btn-primary-hover);
  border-color: var(--btn-primary-hover);
}

.driver-popover-navigation-btns button + button {
  margin-left: 6px;
}

/* The vendor sets all four border colors on the arrow, then each side
 * variant overrides three of them to `transparent` — the remaining
 * "pointing" side inherits the base color. Retinting the base alone
 * makes every arrow side match the popover surface. */
.driver-popover-arrow {
  border-color: var(--bg-surface);
}

/* ── Share for Review ────────────────────────────────────────────── */

.share-modal {
  width: min(820px, 90vw);
  max-height: 90vh;
  padding: 0;
  overflow: hidden;
  /* Flex column so the header + footer (Close) stay pinned and only the body
     scrolls — the footer can never get pushed off-screen / under the toolbar. */
  display: flex;
  flex-direction: column;
}

.share-modal .modal-header {
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.share-modal .modal-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}

.share-modal .modal-body {
  padding: 18px 24px;
  flex: 1 1 auto;
  /* Floor the body tall enough that the address-book dropdown (absolute,
     up to 240px below the input) renders fully instead of being clipped by
     the body's own overflow. Capped to (90vh − chrome) so the pinned footer
     still fits on short windows. */
  min-height: min(480px, calc(90vh - 150px));
  overflow-y: auto;
}

.share-modal .modal-footer {
  padding: 12px 24px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
}

.share-description {
  font-size: var(--text-md);
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: 14px;
}

.share-copied {
  font-size: var(--text-sm);
  color: var(--accent);
  margin-top: 8px;
  margin-bottom: 10px;
}

.share-active-links {
  margin-top: 12px;
}

.share-active-header {
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  margin-bottom: 8px;
}

.share-link-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}

.share-link-item:last-child {
  border-bottom: none;
}

.share-link-item-url {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: var(--weight-strong);
}

.share-link-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.share-link-item-label {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* A labelled link leads with its label; the URL drops to secondary. */
.share-link-item-label + .share-link-item-url {
  font-weight: 400;
  color: var(--text-secondary);
}
.share-link-item-meta {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--text-muted);
}
.share-link-item.is-expired {
  opacity: 0.5;
}
.share-create-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
/* Full-width first line; the expiry select + button wrap onto the next. */
.share-link-label-input {
  flex: 1 1 100%;
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  outline: none;
}
.share-link-label-input::placeholder {
  color: var(--text-muted);
}
.share-link-label-input:focus-visible {
  border-color: var(--accent-border);
}
.share-link-label-input:disabled,
.share-expiry-select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}
.share-link-limit {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: 8px;
}
.share-expiry-label {
  font-size: var(--text-sm);
  color: var(--text-muted);
}
/* Native select with the native arrow hidden; the wrap draws the same
   10px stroke chevron the role pill uses so it matches in both themes. */
.share-expiry-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  /* Kill the inline baseline slack so the wrap is exactly the select's
     height and centres with the button beside it. */
  line-height: 0;
}
/* The select and the button share one explicit height; padding-derived
   heights differ by a pixel or two between platforms and read as
   misaligned. */
.share-create-row .btn {
  height: 30px;
  padding-top: 0;
  padding-bottom: 0;
  display: inline-flex;
  align-items: center;
}
.share-expiry-wrap svg {
  position: absolute;
  right: 9px;
  pointer-events: none;
  color: var(--text-muted);
}
.share-expiry-select {
  appearance: none;
  -webkit-appearance: none;
  height: 30px;
  padding: 0 26px 0 10px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
}
.share-expiry-select:hover {
  background: var(--bg-hover);
}
.share-expiry-select:focus-visible {
  outline: none;
  border-color: var(--accent-border);
}
.share-link-item-revoke {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  padding: 2px 7px;
  cursor: pointer;
  flex-shrink: 0;
}

.share-link-item-revoke:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.share-link-item-copy {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  padding: 3px 6px;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
}
.share-link-item-copy:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}
.share-link-item-copy.is-copied {
  color: var(--accent);
  border-color: var(--accent);
}

.share-error {
  font-size: var(--text-sm);
  color: var(--danger, #ff453a);
  margin-top: 8px;
}

/* ── Share Script sections (collaborators / review / advanced) ────── */
.share-section {
  padding: 16px 0;
  border-top: 1px solid var(--border);
}
.share-section:first-child {
  padding-top: 0;
  border-top: none;
}
.share-section:last-child {
  padding-bottom: 0;
}

.share-section-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  margin-bottom: 8px;
}

.share-section-desc {
  font-size: var(--text-md);
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0 0 12px;
}

.share-invite-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.share-invite-field {
  flex: 1;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: var(--text-md);
  padding: 7px 10px;
  outline: none;
}
.share-invite-field:focus {
  border-color: var(--accent);
}

.share-members {
  margin-top: 14px;
}

.share-members-header {
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  margin-bottom: 6px;
}

.share-member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-md);
}
.share-member-item:last-child {
  border-bottom: none;
}

.share-member-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  color: #fff;
  text-transform: uppercase;
}

.share-member-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
}

.share-member-role {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  flex-shrink: 0;
}
.share-member-role.is-pending {
  color: var(--accent);
}

.share-member-revoke {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: var(--text-xl);
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  flex-shrink: 0;
}
.share-member-revoke:hover {
  color: var(--danger, #ff453a);
}

.share-members-empty {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding: 6px 0;
}

/* ── Address book recipient picker ─────────────────────────────────── */
/* The Collaborators field is a chip/token input backed by the writer's
   address book. All colors are tokens so the picker tracks every theme.
   Selection + primary belong to the neutral --accent; --brand-pink is
   never used here (it's reserved for comment attention). */
.share-recipients {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
}
.share-recipients:focus-within {
  border-color: var(--accent);
}
/* Three classes so this beats the global `.settings-modal input[type='email']`
   rule, which would otherwise paint a border + bg inside the chip field. */
.share-recipients-wrap .share-recipients .share-recipients-input {
  flex: 1;
  min-width: 140px;
  width: auto;
  background: transparent;
  border: none;
  border-radius: 0;
  outline: none;
  color: var(--text-primary);
  font-size: var(--text-md);
  padding: 3px 2px;
}

.share-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  padding: 2px 4px 2px 4px;
  font-size: var(--text-sm);
  max-width: 100%;
}
.share-chip-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  background: var(--accent);
  color: var(--accent-text);
  text-transform: uppercase;
}
.share-chip-label {
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-chip-remove {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: var(--text-xl);
  line-height: 1;
  padding: 0 3px;
  cursor: pointer;
  flex-shrink: 0;
}
.share-chip-remove:hover {
  color: var(--text-primary);
}

.share-recipients-wrap {
  position: relative;
}
/* Floats over the content below (matches the app's popover style) so opening
   it never changes the modal height. */
.share-contacts-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 9999;
  margin-top: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  overflow: hidden auto;
  max-height: 240px;
}
.share-dd-header {
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  padding: 8px 12px 4px;
}
.share-dd-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
.share-dd-row:hover,
.share-dd-row.is-active {
  background: var(--hover-wash);
}
.share-dd-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  line-height: 1;
  background: var(--bg-selected, var(--bg-hover));
  color: var(--text-secondary);
  text-transform: uppercase;
}
/* Invite (new email) row: email full-width on top, Save toggle on its own
   line below so a long address is never clipped. */
.share-dd-row.is-invite {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.share-dd-invite-top {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.share-dd-row.is-invite .share-dd-name {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
}
.share-dd-row.is-invite .share-dd-save {
  margin-left: 0;
  padding-left: 0;
  font-size: var(--text-sm);
}
.share-dd-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.share-dd-name {
  font-size: var(--text-md);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-dd-sub {
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-dd-invite-pre {
  color: var(--text-secondary);
}
.share-dd-invite-email {
  color: var(--text-primary);
  font-weight: 500;
}
.share-dd-save {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  cursor: pointer;
}
/* Neutral accent on the checkbox — selection, not attention. Never pink.
   margin:0 strips the UA default so the box lines up exactly under the
   email text on the line above (avatar 26px + 10px gap = the 36px indent). */
.share-dd-save input[type='checkbox'] {
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}
.share-dd-status {
  padding: 10px 12px;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.share-recipients-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.share-recipients-row .share-recipients {
  flex: 1;
  min-width: 0;
}
.share-recipients-row > .btn {
  flex-shrink: 0;
}

.share-undo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding: 9px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-size: var(--text-md);
  color: var(--text-secondary);
}
.share-undo-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: var(--weight-strong);
  font-size: var(--text-md);
  cursor: pointer;
  flex-shrink: 0;
  padding: 2px 4px;
}
.share-undo-btn:hover {
  text-decoration: underline;
}

/* ── Settings → Address book management ────────────────────────────── */
.contacts-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.contacts-toolbar .share-invite-field {
  flex: 1;
}
.contacts-add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.contacts-add-form .share-invite-field {
  flex: 1;
  min-width: 140px;
}
.contacts-manage-list {
  display: flex;
  flex-direction: column;
}
.contacts-manage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.contacts-manage-item:last-child {
  border-bottom: none;
}
.contacts-manage-main {
  flex: 1;
  min-width: 0;
}
.contacts-manage-name {
  font-size: var(--text-md);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.contacts-manage-sub {
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.contacts-manage-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.contacts-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    color var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out),
    background var(--dur-2) var(--ease-out);
}
.contacts-action-btn svg {
  display: block;
  width: 16px;
  height: 16px;
}
.contacts-action-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
/* Destructive action signals red on hover/focus only. */
.contacts-action-btn.is-danger:hover {
  color: var(--red);
  border-color: var(--red);
}
.contacts-action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.contacts-manage-empty {
  font-size: var(--text-md);
  color: var(--text-secondary);
  padding: 12px 0;
}
.contacts-rename-input {
  width: 100%;
}

/* ── Live collaborator presence ───────────────────────────────────── */
/* Faces in the titlebar (js/presence-stack.js): three, then a +N button
   that opens the list of everyone online. Hidden entirely when nobody
   else is in the draft. */
.presence-anchor {
  margin-right: 8px;
}
/* Hidden while nobody else is here. A class renderPresenceStack sets, not
   :has(> .presence-stack:empty): Safari does not re-check that rule when
   faces are added later, so a collaborator who joined after the script
   opened never showed (the owner, Nov 2026). */
.presence-anchor.is-empty {
  display: none;
}
.presence-stack {
  display: inline-flex;
  align-items: center;
}
/* The signed-in writer's own avatar (Account row, Welcome header).
   Sized per call site through --avatar-size; the per-user background is
   set inline by user-avatar.js from CollabColors so initials keep the
   same color the writer's caret shows collaborators. */
.user-avatar {
  --avatar-size: 24px;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: calc(var(--avatar-size) * 0.4);
  font-weight: var(--weight-strong);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  user-select: none;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.setting-row-identity .user-avatar {
  margin-right: -4px; /* the row's 16px gap reads wide next to a circle */
}
/* An email has no break opportunity, so a long one (Apple's Hide My Email
   relay) ran under the Sign out button; clip it with an ellipsis instead
   (the title attribute carries the full address). */
.setting-row-identity .setting-title,
.setting-row-identity .setting-desc {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.presence-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  color: #fff;
  border: 1.5px solid var(--bg-base, #fff);
  margin-left: -6px;
  box-sizing: border-box;
  /* It's a <button> — strip native chrome; the per-user color is inline. */
  padding: 0;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition:
    transform var(--dur-2) var(--ease-out),
    box-shadow var(--dur-2) var(--ease-out);
}
.presence-avatar:hover {
  transform: translateY(-1px) scale(1.08);
  z-index: 1;
}
.presence-avatar:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}
.presence-avatar:first-child {
  margin-left: 0;
}
/* A face with a photo: the image fills the circle; the caret colour
   behind it only shows while it loads. */
.presence-avatar,
.presence-list-face {
  overflow: hidden;
}
.presence-avatar img,
.presence-list-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
/* +N: a face-sized button in a neutral tone, never a collaborator's
   colour, so it doesn't read as one more person. */
.presence-avatar-more {
  min-width: 22px;
  width: auto;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.presence-avatar-more:hover,
.presence-avatar-more[aria-expanded='true'] {
  transform: none;
  background: var(--bg-hover);
}
.presence-list {
  top: calc(100% + 6px);
  bottom: auto;
  left: 0;
  min-width: 220px;
  max-width: 280px;
}
.presence-list-title {
  padding: 8px 10px 6px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.presence-list-rows {
  display: flex;
  flex-direction: column;
  max-height: min(320px, 60vh);
  overflow-y: auto;
}
.presence-list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: var(--menu-pad-y) 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}
.presence-list-row:hover {
  background: var(--hover-wash);
}
.presence-list-row:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}
.presence-list-face {
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  color: #fff;
}
.presence-list-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Remote carets + selections, rendered by y-prosemirror's yCursorPlugin
   inside #screenplay-page. The caret is a thin colored bar; the floating
   div is the collaborator's name flag (color set inline per user). */
.ProseMirror-yjs-cursor {
  position: relative;
  margin-left: -1px;
  margin-right: -1px;
  border-left: 1px solid;
  border-right: 1px solid;
  border-color: inherit;
  word-break: normal;
  pointer-events: none;
}
.ProseMirror-yjs-cursor > div {
  position: absolute;
  top: -1.4em;
  left: -1px;
  font-size: 11px;
  font-family: var(--font-page-ui);
  font-style: normal;
  font-weight: 600;
  line-height: normal;
  user-select: none;
  color: #fff;
  padding: 1px 6px;
  border-radius: 4px 4px 4px 0;
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
}

/* ── Focus mode ─────────────────────────────────────────────────── */
/* A transient distraction-free state. Hide chrome via this body class
   rather than each pane's own .collapsed/.hidden so exiting restores
   exactly the pane visibility the writer had before. */

body.focus-mode-active .titlebar,
body.focus-mode-active #sidebar,
body.focus-mode-active #ai-pane,
body.focus-mode-active #timeline-strip,
/* The sidebar/AI grippers are hover-only chrome whose panes are now
   hidden — shed them. But NOT #resize-handle-board: it's the
   always-visible Split divider (the only handle between board and
   script), so hiding it left focus-mode Split with no way to resize and
   a gap in the middle. Keep it. */
body.focus-mode-active .resize-handle:not(#resize-handle-board) {
  display: none !important;
}

body.focus-mode-active .review-comment-highlight,
body.focus-mode-active .review-comment-highlight:hover,
body.focus-mode-active .review-comment-highlight.is-active {
  background: transparent;
  cursor: text;
}

#btn-focus-toggle.is-active {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ── Review comment highlight in the editor ─────────────────────── */

.review-comment-highlight {
  background: rgba(255, 46, 139, 0.28);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.12s;
}

.review-comment-highlight:hover,
.review-comment-highlight.is-active {
  background: rgba(255, 46, 139, 0.48);
}

@media (prefers-reduced-motion: reduce) {
  .review-comment-highlight {
    transition: none;
  }
}

/* ── Comment sidebar ────────────────────────────────────────────── */

.comment-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 280px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 80;
  overflow: hidden;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.15);
}

.comment-sidebar.hidden {
  display: none;
}

.comment-sidebar-header {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.comment-sidebar-title {
  flex: 1;
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.comment-count-badge {
  background: rgba(255, 46, 139, 0.25);
  color: var(--text-primary);
  border-radius: var(--radius-lg);
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
}

/* No count → no pill (renderCommentCards empties the text at zero). */
.comment-count-badge:empty {
  display: none;
}

.comment-sidebar-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--text-2xl);
  padding: 0 4px;
  line-height: 1;
}

.comment-sidebar-close:hover {
  color: var(--text-primary);
}

.comment-sidebar-controls {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.comment-show-resolved {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.comment-cards-list {
  flex: 1;
  overflow-y: auto;
}

.comment-card {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.comment-card:hover {
  background: var(--bg-hover, rgba(255, 255, 255, 0.04));
}

.comment-card.is-active {
  background: rgba(255, 46, 139, 0.08);
}

.comment-card.is-resolved {
  opacity: 0.55;
}

.comment-card-quote {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-secondary);
  background: var(--bg-base);
  border-left: 2px solid rgba(255, 46, 139, 0.5);
  border-radius: 0 4px 4px 0;
  padding: 3px 8px;
  margin-bottom: 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comment-card-author {
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}

.comment-card-body {
  font-size: var(--text-md);
  color: var(--text-secondary);
  line-height: 1.5;
  margin-top: 4px;
}

.comment-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.comment-card-resolve-btn {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  padding: 2px 7px;
  cursor: pointer;
}

.comment-card-resolve-btn:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.comment-resolved-badge {
  background: var(--bg-base);
  border-radius: var(--radius-xs);
  padding: 1px 6px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.comment-card.is-orphaned .comment-card-quote {
  border-left-color: rgba(255, 149, 0, 0.5);
  opacity: 0.7;
}

.comment-orphaned-badge {
  font-size: var(--text-xs);
  color: #ff9500;
  margin-bottom: 6px;
}

.comment-empty-state {
  padding: 24px 16px;
  font-size: var(--text-md);
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.5;
}

/* ── Toolbar comment count badge ────────────────────────────────── */

.toolbar-comment-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 5px;
  margin-left: 5px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-text);
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  line-height: 1;
}

.toolbar-comment-count:empty {
  display: none;
}

/* ── Reply threads ───────────────────────────────────────────────── */

.comment-replies {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 6px;
}

.comment-reply-item {
  padding: 6px 0 6px 10px;
  border-left: 2px solid var(--border);
  margin-left: 4px;
  margin-bottom: 4px;
}

.comment-reply-author {
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}

.comment-reply-body {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.45;
  margin-top: 2px;
}

.comment-reply-time {
  font-size: var(--text-2xs);
  color: var(--text-muted);
  margin-top: 3px;
}

.comment-card-reply-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  cursor: pointer;
  padding: 2px 0;
  font-family: inherit;
}

.comment-card-reply-btn:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

/* Author-only delete control on the writer's own replies. */
.comment-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: var(--text-xs);
  cursor: pointer;
  padding: 2px 0;
  font-family: inherit;
  margin-left: 10px;
}

.comment-delete-btn:hover {
  color: var(--red);
  text-decoration: underline;
}

/* Inline reply form embedded in the comment card */
.comment-reply-form {
  margin-top: 8px;
  display: none;
}

.comment-reply-form.is-open {
  display: block;
}

.comment-reply-form-name {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.comment-reply-form-name input {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  font-size: var(--text-xs);
  font-family: inherit;
  padding: 3px 7px;
  outline: none;
  max-width: 140px;
}

.comment-reply-form-name input:focus {
  border-color: rgba(255, 46, 139, 0.6);
}

.comment-reply-form-name a {
  color: rgba(255, 46, 139, 0.8);
  text-decoration: none;
  font-size: var(--text-xs);
}

.comment-reply-form-name a:hover {
  text-decoration: underline;
}

.comment-reply-form textarea {
  width: 100%;
  min-height: 54px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: inherit;
  padding: 7px 9px;
  outline: none;
  resize: vertical;
}

.comment-reply-form textarea:focus {
  border-color: rgba(255, 46, 139, 0.6);
}

.comment-reply-form-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  justify-content: flex-end;
}

.btn-reply-cancel {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  padding: 3px 9px;
  cursor: pointer;
  font-family: inherit;
}

.btn-reply-cancel:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.btn-reply-submit {
  background: rgba(255, 46, 139, 0.15);
  border: 1px solid rgba(255, 46, 139, 0.4);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  font-size: var(--text-xs);
  padding: 3px 9px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
}

.btn-reply-submit:hover:not(:disabled) {
  background: rgba(255, 46, 139, 0.25);
}

.btn-reply-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.comment-reply-form-error {
  font-size: var(--text-xs);
  color: #ff453a;
  margin-top: 4px;
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .comment-card {
    transition: none;
  }
}

/* ===================================================================== */
/*  Skills (Settings → Skills tab) + the chat "/" command menu            */
/* ===================================================================== */

.skills-intro {
  margin: 0 0 16px;
  line-height: 1.55;
}
.skills-intro code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.92em;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
}

.skills-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

/* Empty state — cloned from the chat-empty pattern. */
.skills-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 28px 12px 18px;
  gap: 8px;
  color: var(--text-muted);
}
.skills-empty-glyph {
  font-size: var(--text-hero);
  line-height: 1;
  margin-bottom: 4px;
}
.skills-empty-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}
.skills-empty-body {
  font-size: var(--text-md);
  line-height: 1.55;
  max-width: 340px;
  margin: 2px 0 12px;
}
.skills-empty-emphasis {
  color: var(--text-primary);
  font-weight: var(--weight-strong);
  font-family: var(--font-mono, ui-monospace, monospace);
}
.skills-empty-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.skills-empty-example {
  appearance: none;
  margin-top: 10px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: var(--text-md);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Skill list */
.skills-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.skills-group-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-muted);
  margin: 10px 2px 2px;
}
.skill-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
}
.skill-row-main {
  min-width: 0;
  flex: 1;
}
.skill-row-cmd {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}
.skill-row-arg {
  color: var(--text-muted);
  font-weight: 400;
}
.skill-row-desc {
  font-size: var(--text-md);
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.skill-row-example {
  font-size: var(--text-sm);
  color: var(--text-muted);
  opacity: 0.85;
  margin-top: 3px;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.skill-row-badge {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 1px 7px;
}
.skill-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Register / edit form (a standalone view — replaces the list) */
.skill-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 8px;
  max-width: 640px; /* keep inputs a comfortable reading width on the wide modal */
}
.skill-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.skill-form-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}
.skill-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.skill-field-label {
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}
.skill-optional {
  font-weight: 400;
  color: var(--text-muted);
}
.skill-field-hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.skill-field-hint code,
.skill-form-warning code {
  font-family: var(--font-mono, ui-monospace, monospace);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 0 4px;
}
.skill-input {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: var(--text-md);
  color: var(--text-primary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
}
.skill-input:focus {
  outline: none;
  border-color: var(--accent);
}
.skill-textarea {
  resize: vertical;
  min-height: 88px;
  line-height: 1.5;
}
.skill-cmd-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.skill-cmd-slash {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--text-xl);
  color: var(--text-muted);
}
.skill-form-warning {
  font-size: var(--text-md);
  line-height: 1.5;
  color: #8a6d00;
  background: color-mix(in srgb, #f4b400 14%, transparent);
  border: 1px solid color-mix(in srgb, #f4b400 45%, transparent);
  border-radius: var(--radius-md);
  padding: 8px 10px;
}
.skill-form-error {
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--danger, #c0392b);
}
.skill-form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.skill-form-spacer {
  flex: 1;
}

/* The chat "/" command menu (floats above the composer). */
.chat-composer {
  position: relative;
}
/* Always-visible accuracy notice under the composer (the pattern every
   modern assistant ships, and a check in docs/AIUC1-STAGING-TEST-PLAN.md
   § 6). Static copy, not a tip: it never dismisses. The owner asked for
   it gone (Nov 2026) and settled on keeping the words at the smallest
   size the app sets, so do not grow it back and do not remove it.
   Balanced so a narrow pane breaks it into two even lines instead of
   leaving one word on its own. */
.chat-disclosure {
  margin: 6px 0 0;
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  line-height: 1.45;
  color: var(--text-muted);
  text-align: center;
  text-wrap: balance;
  flex: 0 0 auto;
}

/* A new chat has no answer to check yet, so the notice waits for the first
   message; from then on it is always under the composer. */
.chat-messages:has(> .chat-empty:not(.hidden)) ~ .chat-disclosure {
  display: none;
}
.slash-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  max-height: 260px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  z-index: 40;
  padding: 5px;
}
.slash-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 9px;
  border-radius: var(--radius-md);
  cursor: pointer;
}
.slash-item.is-active,
.slash-item:hover {
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-elevated));
}
.slash-item-cmd {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}
.slash-item-arg {
  color: var(--text-muted);
  font-weight: 400;
}
.slash-item-glyph {
  font-size: var(--text-sm);
}

/* One-line status under the textarea: "@ZED has no lines", etc. Clears
   on the next keystroke. */
.chat-composer-hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding: 4px 2px 0;
}
.slash-item-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.slash-add {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding: 9px;
  font-size: var(--text-md);
  color: var(--accent);
  cursor: pointer;
  border-radius: var(--radius-md);
}
.slash-add:hover {
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-elevated));
}

/* ════════════════════════════════════════════════════════════════════
 * Beat Board
 *
 * Visual story planning: color-railed beat cards on a pan/zoom canvas,
 * connections, groups/stacks, a page-calibrated structure overlay, and
 * live collaboration. Rendered by the board island (generated/
 * board.bundle.js); these styles are the only place its visuals live.
 *
 * Beat color tokens: a deliberately DESATURATED eight — visually a
 * different species from the 8 vivid presence colors (collab-colors.js)
 * and clear of the red/green revision + status hues. Color is applied
 * as a 3px left rail, never a card fill, and every swatch has a spoken
 * name (WCAG 1.4.1 — color is never the only signal).
 * ════════════════════════════════════════════════════════════════════ */

:root {
  --beat-stone: #91918d;
  --beat-terracotta: #c27b66;
  --beat-ochre: #c2a05a;
  --beat-moss: #8fa371;
  --beat-teal: #6fa3a0;
  --beat-slate: #7c90ad;
  --beat-plum: #a282a8;
  --beat-rose: #b5838f;
}

@media (prefers-color-scheme: light) {
  :root {
    --beat-stone: #757571;
    --beat-terracotta: #a65a45;
    --beat-ochre: #8f7335;
    --beat-moss: #6b7f4e;
    --beat-teal: #44807c;
    --beat-slate: #5a6e8c;
    --beat-plum: #7e5b85;
    --beat-rose: #91606e;
  }
}

html[data-theme='dark'] {
  --beat-stone: #91918d;
  --beat-terracotta: #c27b66;
  --beat-ochre: #c2a05a;
  --beat-moss: #8fa371;
  --beat-teal: #6fa3a0;
  --beat-slate: #7c90ad;
  --beat-plum: #a282a8;
  --beat-rose: #b5838f;
}

html[data-theme='light'] {
  --beat-stone: #757571;
  --beat-terracotta: #a65a45;
  --beat-ochre: #8f7335;
  --beat-moss: #6b7f4e;
  --beat-teal: #44807c;
  --beat-slate: #5a6e8c;
  --beat-plum: #7e5b85;
  --beat-rose: #91606e;
}

/* Screen-reader-only utility (first user: the board's live region). */
.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;
}

/* ---------- view-mode switcher (editor toolbar) ---------- */

/* Segmented control: a tinted track with the pressed segment raised on
 * the elevated surface (the macOS / Linear idiom), no hairline dividers. */
.view-mode-switch {
  display: flex;
  gap: 2px;
  /* 4px of track shows all round the picked segment, so it reads as a
     raised key in a well rather than a fill; the segment's radius is the
     track's less this padding, which keeps the two curves concentric. */
  padding: 4px;
  background: var(--segment-track);
  border-radius: var(--radius-lg);
  flex-shrink: 0;
}
/* Sized to be FOUND: at 11px / 22px tall the way back to the script from
   the board was the thing play testers couldn't locate. 26px tall still
   fits the 36px control row. */
.view-mode-btn,
.split-dir-btn {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 16px;
  min-height: 26px;
  padding: 5px 14px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out),
    box-shadow var(--dur-2) var(--ease-out);
}
.view-mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.view-mode-btn svg {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
}
.view-mode-btn:hover,
.split-dir-btn:hover {
  color: var(--text-primary);
}
.view-mode-btn[aria-pressed='true'] {
  background: var(--segment-thumb);
  color: var(--text-primary);
  box-shadow:
    var(--shadow-1),
    0 0 0 1px var(--segment-ring);
}
.view-mode-btn:focus-visible,
.split-dir-btn:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}

/* Orientation toggle — an ACTION button inside the switcher pill, not a
 * mode segment (no aria-pressed). Only rendered while Split is active;
 * the icon pair previews the layout the click switches TO. */
.split-dir-btn {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
}
.split-dir-btn.hidden {
  display: none;
}
.split-dir-btn .split-dir-icon-stack,
.split-dir-btn .split-dir-icon-beside {
  display: none;
}
.split-dir-btn[data-dir='row'] .split-dir-icon-stack {
  display: block;
}
.split-dir-btn[data-dir='column'] .split-dir-icon-beside {
  display: block;
}

/* ---------- pane & view modes ---------- */

.board-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-base);
  font-family: var(--font-ui);
  flex-shrink: 0;
}
.board-pane.hidden {
  display: none;
}
/* Beside Split: the board's width is a percent of #center-split (set
 * inline) so the board:script ratio survives a resize. This floor keeps
 * the board usable — and its toolbar un-clipped — when the ratio would
 * otherwise drive it too narrow; below this the script yields instead.
 * (Stacked uses min-height, defined with .board-split-stacked above.) */
.editor-body.board-mode-split:not(.board-split-stacked) #board-pane {
  min-width: 400px;
}
.editor-body.board-mode-board .editor-center {
  display: none;
}
.editor-body.board-mode-board .board-pane {
  flex: 1 1 auto;
  width: auto !important;
  /* A stale inline height from a stacked-split drag must not constrain
   * full-Board mode either. */
  height: auto !important;
}

.board-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Same height as the title bar row above it, so Board mode reads as
   * two 44px bars, not a bar and a half. */
  height: 44px;
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
.board-toolbar-flex {
  flex: 1;
}

.board-viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: var(--bg-base);
  cursor: default;
}
/* The ring is a layer above the canvas, not an outline: an outline paints
   under the viewport's positioned children, so every card at the edge cut
   it into pieces (test/ui/beat-board.spec.js "focus ring stays whole").
   Under the scrollbars and the floating controls, which sit inside it. */
.board-viewport:focus-visible {
  outline: none;
}
.board-viewport:focus-visible::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid var(--accent-border);
  pointer-events: none;
  z-index: 24;
}

.board-canvas {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}
/* Infinite dot grid: painted on the viewport, position/size synced to
 * pan/zoom from applyTransform — covers negative canvas space too. */
.board-viewport {
  background-image: radial-gradient(var(--board-dot) 1px, transparent 1px);
  background-size: 24px 24px;
}
.board-viewport.zoomed-out {
  background-image: none;
}

/* ---------- structure lanes ---------- */

/* Equal-width columns cards snap into (LANE_W / LANE_GAP in types.ts).
   Page ranges live in the header, not in the geometry. The act tint is
   only a dot, so the lanes stay neutral against the canvas. */
.board-lanes {
  position: absolute;
  left: 0;
  top: 0;
}
.board-lanes.hidden {
  display: none;
}
.board-lane {
  position: absolute;
  width: 284px;
  min-height: 560px;
  box-sizing: border-box;
  padding: 8px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: color-mix(in srgb, var(--bg-surface) 82%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
}
.board-lane.drop-target {
  background: var(--bg-surface);
  border-color: var(--accent-border);
  box-shadow: 0 0 0 1px var(--accent-border);
}
.board-lane-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 22px;
  padding: 0 4px;
  user-select: none;
  white-space: nowrap;
}
.board-lane-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.board-lane.tint-1 .board-lane-dot {
  background: rgb(96, 156, 240);
}
.board-lane.tint-2 .board-lane-dot {
  background: rgb(118, 192, 130);
}
.board-lane.tint-3 .board-lane-dot {
  background: rgb(240, 158, 78);
}
.board-lane-name {
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-primary);
}
.board-lane-pages,
.board-lane-count {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.board-lane-count {
  margin-left: auto;
}
.board-lane-coach {
  margin: -2px 4px 0;
  font-size: var(--text-xs);
  line-height: 1.4;
  color: var(--text-secondary);
}
.board-lane-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.board-lane-body .board-card.stacked {
  width: 100%;
}
.board-lane-empty {
  padding: 22px 12px;
  border: 1px dashed var(--control-border);
  border-radius: var(--radius-md);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-secondary);
}
.board-guide {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  box-sizing: border-box;
  padding: 9px 12px;
  border: 1px dashed var(--control-border);
  border-radius: var(--radius-md);
  background: transparent;
  font-family: var(--font-ui);
  text-align: left;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
}
.board-guide:hover {
  background: var(--bg-hover);
}
.board-guide:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}
.board-guide.drop-target {
  border-style: solid;
  border-color: var(--accent-border);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 1px var(--accent-border);
}
.board-guide-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.board-guide-name {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
}
.board-guide-page {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.board-guide-coach {
  font-size: var(--text-xs);
  line-height: 1.4;
  color: var(--text-secondary);
}
/* Where a dragged card will land. Absolutely placed inside the lane so
   showing it never reflows the column under the pointer. */
.board-lane-insert {
  position: absolute;
  left: 10px;
  right: 10px;
  height: 2px;
  border-radius: 1px;
  background: var(--accent-border);
  pointer-events: none;
}
.board-lane-insert::before {
  content: '';
  position: absolute;
  left: -4px;
  top: -3px;
  width: 8px;
  height: 8px;
  box-sizing: border-box;
  border: 2px solid var(--accent-border);
  border-radius: 50%;
  background: var(--bg-surface);
}
@media (prefers-reduced-motion: reduce) {
  .board-guide {
    transition: none;
  }
}

/* ---------- connections ---------- */

.board-conns {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  overflow: visible;
}
.board-conn {
  fill: none;
  stroke-width: 1.5px;
}
.board-conn.selected {
  stroke-width: 2.5px;
}
.board-conn-head {
  stroke: none;
}
.board-conn-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14px;
  pointer-events: stroke;
  cursor: pointer;
}
.board-conn-temp {
  stroke: var(--control-border);
  stroke-dasharray: 4 4;
}
.board-conn-labels {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}
.board-conn-label,
.board-conn-label-input {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 8px;
  white-space: nowrap;
  cursor: pointer;
}
.board-conn-label:hover {
  border-color: var(--control-border);
}
.board-conn-label-input {
  width: 140px;
  cursor: text;
  color: var(--text-primary);
}

/* ---------- groups ---------- */

.board-groups {
  position: absolute;
  left: 0;
  top: 0;
}
.board-group {
  position: absolute;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.board-group.layout-free {
  background: color-mix(in srgb, var(--bg-surface) 55%, transparent);
  pointer-events: none;
}
.board-group.layout-free .board-group-header {
  pointer-events: auto;
}
.board-group.layout-hstack,
.board-group.layout-vstack {
  padding: 0 10px 10px;
}
.board-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 8px;
  margin: 0 -10px;
  cursor: grab;
  border-radius: 9px 9px 0 0;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
  user-select: none;
}
.board-group.layout-free .board-group-header {
  margin: 0;
}
.board-group-title.untitled {
  color: var(--text-muted);
  font-style: italic;
}
.board-group-title-input {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  background: var(--bg-base);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 2px 6px;
  width: 140px;
}
.board-group-count {
  color: var(--text-muted);
  font-size: var(--text-xs);
}
.board-group-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.board-group-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
}
.board-group.layout-hstack .board-group-body {
  flex-direction: row;
}

/* ---------- cards ---------- */

.board-cards {
  position: absolute;
  left: 0;
  top: 0;
}
.board-card {
  position: absolute;
  width: 260px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 11px 9px 15px;
  cursor: default;
  user-select: none;
  box-sizing: border-box;
  /* Own stacking context: the ports' and grip's z-index stay INSIDE the
     card, so a card underneath can't float its grip over the card on top. */
  isolation: isolate;
}
.board-card.wide {
  width: 520px;
}
.board-card.stacked {
  position: relative;
  width: 240px;
}
.board-card.stacked.wide {
  width: 240px;
}
/* The beat guide a lane card fills ("CATALYST · P.12"). */
.board-card-slot {
  margin-bottom: 4px;
  font-size: 10px;
  font-weight: var(--weight-strong);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.board-card:hover {
  border-color: var(--control-border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.board-card.selected,
.board-card.is-focus,
.board-card:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}
/* Mouse affordance: a card reads as draggable on hover, and the fist
 * closes while it moves. The editor's inputs keep their text cursor. */
.board-card:not(.editing):hover {
  cursor: grab;
}
.board-card.dragging {
  opacity: 0.92;
  box-shadow: var(--shadow-2);
  z-index: 30;
  cursor: grabbing;
}
.board-card.remote-dragging {
  transition: transform 0.08s linear;
  z-index: 20;
}
.board-card.remote-selected {
  outline: 2px solid var(--remote-color, var(--accent-border));
  outline-offset: 2px;
}
.board-card.remote-selected::after {
  content: attr(data-remote-name);
  position: absolute;
  top: -20px;
  left: -2px;
  font-size: var(--text-xs);
  color: #fff;
  background: var(--remote-color, var(--accent-border));
  border-radius: var(--radius-xs);
  padding: 1px 6px;
  white-space: nowrap;
}
.board-card.connect-candidate {
  outline: 2px dashed var(--accent-border);
  outline-offset: 2px;
}
/* "The scene the script cursor is in" must NOT look like a selection
   (play testers read the accent border as a stuck highlight). It gets a
   wider rail and a ▶ on the scene chip instead — never the accent outline. */
.board-card.is-current-scene .board-card-rail {
  width: 6px;
}
.board-card.is-current-scene .board-scene-chip:not(.broken) {
  font-weight: var(--weight-strong);
}
.board-card.is-current-scene .board-scene-chip:not(.broken)::before {
  content: '▶ ';
  font-size: var(--text-2xs);
}
.board-card-rail {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 8px 0 0 8px;
}
/* Whole-card tint from the beat color. A 3px rail alone was invisible at
   a glance ("I can't tell the beats apart"); a 14% wash of the color over
   the card surface + a tinted border reads from across the room while
   keeping body text ≥ 6:1 in every built-in theme (don't exceed ~20%).
   Stone stays the neutral default. The color NAME remains in the picker
   and the rail, so color is never the only carrier (WCAG 1.4.1). */
.board-card[data-color]:not([data-color='stone']) {
  background: color-mix(in srgb, var(--card-tint) 14%, var(--bg-elevated));
  border-color: color-mix(in srgb, var(--card-tint) 45%, var(--border));
}
.board-card[data-color='terracotta'] {
  --card-tint: var(--beat-terracotta);
}
.board-card[data-color='ochre'] {
  --card-tint: var(--beat-ochre);
}
.board-card[data-color='moss'] {
  --card-tint: var(--beat-moss);
}
.board-card[data-color='teal'] {
  --card-tint: var(--beat-teal);
}
.board-card[data-color='slate'] {
  --card-tint: var(--beat-slate);
}
.board-card[data-color='plum'] {
  --card-tint: var(--beat-plum);
}
.board-card[data-color='rose'] {
  --card-tint: var(--beat-rose);
}
/* High contrast: no wash — the rail and a solid tinted border carry it. */
html[data-theme='high-contrast'] .board-card[data-color]:not([data-color='stone']) {
  background: var(--bg-elevated);
  border-color: var(--card-tint);
}
.board-card-media {
  position: relative; /* anchors the edit-mode Replace/Delete overlay */
  margin: -9px -11px 8px -15px;
  border-radius: 7px 7px 0 0;
  overflow: hidden;
  max-height: 120px;
  background: var(--bg-hover);
}
.board-card-media img {
  display: block;
  width: 100%;
  max-height: 120px;
  object-fit: cover;
  /* Faces live in the top third of most stills; centered cover crops
     heads. Keep the crop biased upward. */
  object-position: 50% 25%;
  /* The CARD drags, never the picture (a native image drag would cancel
     the pointer gesture and snap the card back). */
  -webkit-user-drag: none;
  user-select: none;
}
/* "Show whole image" (card menu): letterbox instead of crop. */
.board-card.image-contain .board-card-media {
  max-height: none;
}
.board-card.image-contain .board-card-media img {
  max-height: 200px;
  object-fit: contain;
  object-position: 50% 50%;
}
/* Edit-mode controls: Replace / Delete, centered over a dark tint so the
   buttons keep contrast on ANY image (light, busy, low-contrast). Present
   only while the beat is being edited (appended/removed in view.ts). */
.board-card-media-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.46);
  animation: board-media-overlay-in var(--dur-2) var(--ease-out);
}
@keyframes board-media-overlay-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
/* Replace / Delete — matches the board zoom control exactly: one elevated,
   bordered, rounded shell with borderless segmented buttons inside, lit
   (background + color) on hover. */
.board-card-media-actions {
  display: inline-flex;
  align-items: stretch;
  font-family: var(--font-ui);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.board-card-media-btn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  min-height: 24px;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  transition:
    background var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out);
}
.board-card-media-btn + .board-card-media-btn {
  border-left: 1px solid var(--border);
}
.board-card-media-btn:hover {
  color: var(--text-primary);
  background: var(--control-hover, var(--bg-hover, transparent));
}
.board-card-media-btn.danger:hover {
  color: var(--red);
}
.board-card-media-btn:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
  color: var(--text-primary);
}
.board-card-media-btn svg {
  flex-shrink: 0;
  width: 13px;
  height: 13px;
  pointer-events: none;
}
@media (prefers-reduced-motion: reduce) {
  .board-card-media-overlay {
    animation: none;
  }
  .board-card-media-btn {
    transition: none;
  }
}
.board-card-title {
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 3px;
  overflow-wrap: anywhere;
}
.board-card-title.untitled {
  color: var(--text-muted);
  font-weight: 500;
}
/* A kept-but-empty beat: dashed edge + italic placeholder so it reads as
   "fill me in", not as a finished card. */
.board-card.is-empty:not(.editing) {
  border-style: dashed;
}
.board-card.is-empty .board-card-title.untitled {
  font-style: italic;
}
/* WGA disclosure badge on AI-suggested beats. Precedes the title in the
   DOM and floats right so it rides the title's first line; the title text
   wraps around it. Text/background come straight from the theme tokens
   (--text-secondary on --bg-surface clears 4.5:1 in every built-in theme),
   so the badge is never the only signal — the card's aria-label says
   "AI-suggested" too. No motion, so nothing to gate on reduced-motion. */
.board-card-origin {
  float: right;
  margin: 1px 0 0 6px;
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  letter-spacing: 0.06em;
  line-height: 1;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 2px 4px;
  user-select: none;
}
.board-card-origin.hidden {
  display: none;
}
/* The float must not leak under the body text once the title is short. */
.board-card-title::after {
  content: '';
  display: block;
  clear: both;
}
.board-card-body {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.board-card-body.hidden {
  display: none;
}
.board-card-body p {
  margin: 0 0 4px;
}
.board-card-body p:last-child {
  margin-bottom: 0;
}
/* Emphasis has to be visible on 12px secondary-colored notes: browser
   default bold in muted grey barely registered ("isn't that supposed to be
   bold?"). Bold and italic step up to the primary text color. */
.board-card-body strong {
  font-weight: 700;
  color: var(--text-primary);
}
.board-card-body em {
  font-style: italic;
  color: var(--text-primary);
}
.board-card-body ul,
.board-card-body ol {
  margin: 0 0 4px;
  padding-left: 16px;
}
.board-card-body code {
  font-family: var(--font-script);
  font-size: var(--text-xs);
  background: var(--bg-hover);
  border-radius: 3px;
  padding: 0 3px;
}
.board-card-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
}
/* view.ts sets is-empty (no scene chip, no connections); a :has(:empty)
   rule is not re-checked by Safari when the count changes. */
.board-card-foot.is-empty {
  display: none;
}
.board-scene-chip {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 7px;
  cursor: pointer;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board-scene-chip:hover {
  border-color: var(--control-border);
  color: var(--text-primary);
}
.board-scene-chip.broken {
  color: var(--orange);
  border-color: var(--orange);
}
.board-scene-chip.hidden {
  display: none;
}
.board-card-conncount {
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Connection ports — visible on hover; ::before pads the hit area to
 * ~24px (WCAG 2.5.8); the keyboard path is the A key. */
.board-port {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1.5px solid var(--control-border);
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease-out);
  cursor: crosshair;
  z-index: 5;
  box-sizing: border-box;
}
.board-port::before {
  content: '';
  position: absolute;
  inset: -7px;
}
.board-card:hover .board-port,
.board-card.selected .board-port {
  opacity: 1;
}
.board-port.port-top {
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
}
.board-port.port-bottom {
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
}
.board-port.port-left {
  left: -5px;
  top: 50%;
  transform: translateY(-50%);
}
/* Corner resize grip. Pointer path only (aria-hidden); the keyboard
   path is ⌥⌘ + arrows and "Reset size" lives in the card menu. ::before
   pads the hit target to 26px (WCAG 2.5.8). */
.board-card-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease-out);
  z-index: 5;
}
.board-card-resize::before {
  content: '';
  position: absolute;
  inset: -6px;
}
.board-card-resize::after {
  content: '';
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--control-border);
  border-bottom: 2px solid var(--control-border);
  border-radius: 0 0 2px 0;
}
.board-card:hover .board-card-resize,
.board-card.selected .board-card-resize,
.board-card:focus-within .board-card-resize {
  opacity: 1;
}
.board-card.resizing .board-card-resize::after {
  border-color: var(--accent-border);
}
.board-card.stacked .board-card-resize,
.board-card.editing .board-card-resize {
  display: none;
}
.board-card.resizing {
  box-shadow: var(--shadow-2);
  z-index: 30;
}
/* An explicit height floor means "show my notes" — drop the 6-line clamp. */
.board-card.sized-h .board-card-body {
  -webkit-line-clamp: unset;
}
/* Cursor lock for the gesture. Deliberately NOT body.is-resizing: that
   one is col-resize and disables pointer-events (we rely on capture). */
body.board-card-resizing,
body.board-card-resizing .board-viewport,
body.board-card-resizing .board-card {
  cursor: nwse-resize !important;
  user-select: none;
}
@media (prefers-reduced-motion: reduce) {
  .board-card-resize {
    transition: none;
  }
}
.board-port.port-right {
  right: -5px;
  top: 50%;
  transform: translateY(-50%);
}

/* In-place editing — no modals, ever. */
.board-card.editing {
  cursor: text;
}
.board-card-title-input,
.board-card-body-input {
  font-family: var(--font-ui);
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 3px 6px;
  box-sizing: border-box;
}
.board-card-title-input {
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
}
.board-card-body-input {
  font-size: var(--text-sm);
  line-height: 1.45;
  min-height: 64px;
  resize: vertical;
  margin-top: 4px;
}
.board-card-edit-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------- marquee / chips / remotes ---------- */

.board-marquee {
  position: absolute;
  border: 1px solid var(--accent-border);
  background: color-mix(in srgb, var(--accent-border) 8%, transparent);
  pointer-events: none;
  z-index: 40;
}
/* Zoom control — segmented [−] [100%] [+] pill in the viewport corner.
 * The magnifier buttons step the zoom; the middle readout fits-to-view. */
.board-zoom-control {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 25;
  display: inline-flex;
  align-items: stretch;
  font-family: var(--font-ui);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.board-zoom-btn,
.board-zoom-level {
  appearance: none;
  background: transparent;
  border: 0;
  margin: 0;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
}
.board-zoom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  min-height: 24px;
  padding: 0;
}
.board-zoom-level {
  min-width: 46px;
  padding: 0 6px;
  font-size: var(--text-xs);
  line-height: 24px;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.board-zoom-btn:hover,
.board-zoom-level:hover {
  color: var(--text-primary);
  background: var(--control-hover, var(--bg-hover, transparent));
}
.board-zoom-btn:focus-visible,
.board-zoom-level:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
  color: var(--text-primary);
}
.board-scene-chipbar {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  cursor: pointer;
  z-index: 25;
  white-space: nowrap;
}
.board-scene-chipbar:hover {
  border-color: var(--control-border);
  color: var(--text-primary);
}
.board-remotes {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}
.board-remote-cursor {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: flex-start;
  gap: 3px;
  transition: transform 0.08s linear;
  z-index: 50;
}
.board-remote-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid var(--bg-base);
}
.board-remote-tag {
  font-size: var(--text-xs);
  color: #fff;
  border-radius: var(--radius-xs);
  padding: 1px 6px;
  white-space: nowrap;
}

/* ---------- empty state ---------- */

.board-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.board-empty.hidden {
  display: none;
}
.board-empty-box {
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px;
}
.board-empty-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  margin: 0;
  text-align: center;
}
.board-empty-sub {
  font-size: var(--text-md);
  color: var(--text-secondary);
  margin: 0 0 8px;
  text-align: center;
  line-height: 1.5;
}
.board-starter {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: var(--font-ui);
}
.board-starter:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--control-border);
}
.board-starter:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.board-starter:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}
.board-starter-label {
  font-size: var(--text-md);
  font-weight: 500;
  color: var(--text-primary);
}
.board-starter-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
}
/* Recommended starter — the context-best path (Pull beats when scenes
   exist, else Start from a structure). Gives the empty state one clear
   default instead of three co-equal options. */
.board-starter--primary {
  background: var(--accent);
  border-color: var(--accent);
}
.board-starter--primary .board-starter-label {
  color: var(--accent-text);
}
.board-starter--primary .board-starter-desc {
  color: var(--accent-text);
  opacity: 0.78;
}
.board-starter--primary:hover:not(:disabled) {
  background: var(--btn-primary-hover);
  border-color: var(--btn-primary-hover);
}
.board-empty-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-align: center;
  margin: 6px 0 0;
}

/* ---------- menus / pickers / sheet ---------- */

.board-menu {
  position: fixed;
  z-index: 10002;
  min-width: 200px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 5px;
  box-shadow: var(--shadow-2);
  font-family: var(--font-ui);
}
.board-menu-item {
  /* Column so sentence-length descriptions stack UNDER the label as
   * one clean left-aligned line (inline right-aligned explainers made
   * a ragged middle edge). Keyboard hints stay inline in the row. */
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  width: 100%;
  padding: var(--menu-pad-y) 10px;
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-ui);
}
.board-menu-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.board-menu-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.4;
}
.board-menu-item:hover:not(:disabled),
.board-menu-item:focus-visible {
  background: var(--hover-wash);
  outline: none;
}
.board-menu-item:disabled {
  color: var(--text-muted);
  cursor: default;
}
.board-menu-item.danger {
  color: var(--red);
}
.board-menu-hint {
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.board-menu-check {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}
.board-menu-sep {
  height: 1px;
  background: var(--border-soft);
  margin: 4px 6px;
}
.board-menu-colors {
  display: flex;
  gap: 7px;
  padding: 8px 10px;
}
.board-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.25);
  cursor: pointer;
  padding: 0;
}
.board-swatch[data-color='stone'] {
  background: var(--beat-stone);
}
.board-swatch[data-color='terracotta'] {
  background: var(--beat-terracotta);
}
.board-swatch[data-color='ochre'] {
  background: var(--beat-ochre);
}
.board-swatch[data-color='moss'] {
  background: var(--beat-moss);
}
.board-swatch[data-color='teal'] {
  background: var(--beat-teal);
}
.board-swatch[data-color='slate'] {
  background: var(--beat-slate);
}
.board-swatch[data-color='plum'] {
  background: var(--beat-plum);
}
.board-swatch[data-color='rose'] {
  background: var(--beat-rose);
}
.board-swatch.selected,
.board-swatch:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 2px var(--bg-elevated),
    0 0 0 4px var(--accent-border);
}
.board-scene-picker {
  width: 300px;
  padding: 8px;
}
.board-scene-picker-input {
  width: 100%;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  padding: 6px 8px;
  background: var(--bg-base);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  margin-bottom: 6px;
  box-sizing: border-box;
}
.board-scene-picker-list {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.board-scene-picker-item {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
}
.board-scene-picker-item:hover:not(:disabled),
.board-scene-picker-item.active {
  background: var(--bg-hover);
}
.board-scene-picker-item[aria-selected='true'] {
  background: var(--bg-selected);
}
.board-scene-picker-item:disabled {
  color: var(--text-muted);
  cursor: default;
}
.board-scene-picker-unlink {
  color: var(--text-secondary);
  font-style: italic;
}
.board-scene-picker-num {
  font-size: var(--text-xs);
  color: var(--text-muted);
  min-width: 18px;
}
.board-scene-picker-heading {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board-scene-picker-empty {
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding: 8px;
}
.board-pages-pop {
  width: 270px;
  padding: 12px;
}
.board-pages-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.board-pages-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.board-pages-input {
  width: 72px;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  padding: 5px 8px;
  background: var(--bg-base);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
}
.board-pages-unit {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-right: auto;
}
.board-pages-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: 8px;
}
.board-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 10003;
  display: flex;
  align-items: center;
  justify-content: center;
}
.board-sheet {
  width: 430px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  font-family: var(--font-ui);
}
.board-sheet-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  margin: 0 0 6px;
}
.board-sheet-group {
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 20px 0 9px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border);
  font-weight: var(--weight-strong);
}
.board-sheet-group:first-of-type {
  margin-top: 11px;
}
.board-sheet-rows {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 4px 12px;
  margin: 0;
  font-size: var(--text-sm);
}
.board-sheet-rows dt {
  color: var(--text-secondary);
}
.board-sheet-rows dd {
  margin: 0;
  color: var(--text-primary);
}
.board-sheet-close {
  margin-top: 14px;
}

/* ---------- timeline pips (linked beats on the scene strip) ---------- */

.timeline-pips {
  display: flex;
  gap: 3px;
  align-items: center;
}
.timeline-pip {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  display: block;
}
.timeline-pip-more {
  font-size: var(--text-2xs);
  color: var(--text-muted);
  line-height: 1;
}

/* Print: the board is editor chrome. */
body.printing .board-pane {
  display: none !important;
}

/* Reduced motion: positions still update, nothing glides or fades. */
@media (prefers-reduced-motion: reduce) {
  .board-remote-cursor,
  .board-card.remote-dragging,
  .board-port {
    transition: none;
  }
}

/* Landing pulse when a beat's scene chip jumps the script to its
 * slugline. Reduced motion: a static accent bar instead of the fade. */
@keyframes boardScenePulse {
  0% {
    background: var(--bg-selected);
  }
  100% {
    background: transparent;
  }
}
.scene-heading.board-scene-pulse,
[data-block-type='scene-heading'].board-scene-pulse {
  animation: boardScenePulse 1.2s ease-out 1;
}
@media (prefers-reduced-motion: reduce) {
  .scene-heading.board-scene-pulse,
  [data-block-type='scene-heading'].board-scene-pulse {
    animation: none;
    box-shadow: inset 3px 0 0 var(--accent-border);
  }
}

/* ---------- Chat: suggested story beats (lastslate-beats fence) ----------
 * The model writes prose + a fence; this card is what the writer sees.
 * One action — Add to board — wired through LastslateActions. */
.chat-beats {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  padding: 10px 12px;
  margin: 8px 0;
  font-family: var(--font-ui);
}
.chat-beats-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}
.chat-beats-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}
.chat-beats-count {
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 0 7px;
  line-height: 16px;
}
.chat-beats-list {
  list-style: none;
  margin: 0 0 9px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.chat-beat {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.chat-beat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.chat-beat-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.chat-beat-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
}
.chat-beat-summary {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.45;
}
.chat-beat-scene {
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.chat-beats-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.chat-beats-add {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  /* Primary treatment: this is the card's ONE action — the writer
   * asked for beats; placing them is the obvious next step. */
  color: var(--accent-text);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  cursor: pointer;
}
.chat-beats-add:hover {
  background: var(--btn-primary-hover);
  border-color: var(--btn-primary-hover);
}
.chat-beats-add:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}
.chat-beats-added {
  font-size: var(--text-sm);
  color: var(--green);
}
.chat-beats-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Exactly ONE switcher per mode, always in the roomiest toolbar:
 *   Script -> editor toolbar (centered; board pane is hidden anyway)
 *   Board  -> board toolbar (the editor toolbar is display:none)
 *   Split  -> board toolbar (the editor pane is too narrow; indicator
 *             + switcher + actions overlapped — the board side has
 *             only +Beat / Structure / ?)
 * The duplicate-copy approach exists because Board mode hides
 * .editor-center; these rules keep the copies mutually exclusive. */
.board-toolbar .view-mode-switch {
  display: none;
  margin: 0;
}

/* Split divider: ALWAYS visible (discoverability-first — the sidebar
 * and AI-pane handles stay invisible-until-hover, but writers must be
 * able to SEE that the board/script split is draggable). A hairline
 * runs the full height of the 7px hit area with a centered grip pill;
 * hover/drag tints both with the accent. */
#resize-handle-board {
  width: 7px;
}
#resize-handle-board:hover,
#resize-handle-board.resizing {
  background: transparent;
}
#resize-handle-board::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
}
#resize-handle-board::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 44px;
  border-radius: var(--radius-pill);
  background: var(--control-border);
}
#resize-handle-board:hover::before,
#resize-handle-board.resizing::before,
#resize-handle-board:hover::after,
#resize-handle-board.resizing::after {
  background: var(--accent-border);
}
#resize-handle-board.hidden {
  display: none;
}

/* Stacked split: same divider rotated 90° — full-width hit area, the
 * hairline runs horizontally, the grip pill lies flat. */
.editor-body.board-split-stacked #resize-handle-board {
  width: auto;
  height: 7px;
  cursor: row-resize;
}
.editor-body.board-split-stacked #resize-handle-board::before {
  left: 0;
  right: 0;
  top: 3px;
  bottom: auto;
  width: auto;
  height: 1px;
}
.editor-body.board-split-stacked #resize-handle-board::after {
  width: 44px;
  height: 3px;
}

/* ---------- Board navigation: pointer tools + overlay scrollbars ---------- */

/* Pointer tools (Move/Select + Hand) float over the canvas bottom-left,
 * mirroring the zoom control bottom-right — a self-contained pill, out of
 * the toolbar so they never crowd the mode switcher. The lit (aria-pressed)
 * tool reflects the active mode, so the way back to selecting is visible. */
.board-tool-group {
  position: absolute;
  /* Docked beside the zoom control (bottom-right) so every canvas tool
     lives in ONE corner — testers hunted across the board for them. */
  right: 128px;
  bottom: 10px;
  z-index: 25;
  display: inline-flex;
  align-items: stretch;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
/* Strip the .btn-secondary chrome — the pill itself is the frame, the
 * buttons read like the zoom control's (transparent, divided, hover-lit). */
.board-tool-group .btn {
  appearance: none;
  width: 28px;
  min-height: 24px;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: var(--text-secondary);
}
.board-tool-group .btn + .btn {
  border-left: 1px solid var(--border);
}
.board-tool-group .btn:hover {
  color: var(--text-primary);
  background: var(--control-hover, var(--bg-hover, transparent));
}
/* The lit tool shows which mode you're in. */
.board-tool-group .btn[aria-pressed='true'] {
  color: var(--text-primary);
  background: var(--accent-bg);
}
.board-tool-group .btn:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
  color: var(--text-primary);
}

/* Grab cursors: the hand tool shows the open hand; an active pan drag
 * closes it to a fist. */
.board-viewport.hand-mode,
.board-viewport.space-pan {
  cursor: grab;
}
.board-viewport.is-panning {
  cursor: grabbing;
}
.board-viewport.hand-mode .board-card,
.board-viewport.hand-mode .board-port,
.board-viewport.hand-mode .board-group-header,
.board-viewport.space-pan .board-card,
.board-viewport.space-pan .board-port,
.board-viewport.space-pan .board-group-header,
.board-viewport.is-panning .board-card,
.board-viewport.is-panning .board-port,
.board-viewport.is-panning .board-group-header {
  cursor: inherit;
}

/* The board pans a canvas rather than scrolling a box, so its scrollbars
 * are DOM, drawn to be the script's: the same 14px gutter and 10px thumb,
 * the same two colours, and the same life — in quickly while panning or
 * zooming (or with the pointer on a thumb), out slowly a moment after
 * (view.ts takes the linger from js/shared/scrollbars.js). Hidden entirely
 * when the content fits. */
.board-scrollbar {
  position: absolute;
  z-index: 28;
  opacity: 0;
  transition: opacity var(--scrollbar-fade-out) ease-out;
  pointer-events: none;
}
.board-scrollbar.active,
.board-scrollbar:has(.board-scrollbar-thumb:hover),
.board-scrollbar:has(.board-scrollbar-thumb:active) {
  opacity: 1;
  transition-duration: var(--scrollbar-fade-in);
}
.board-scrollbar.fits {
  display: none;
}
.board-scrollbar-h {
  left: 0;
  right: 14px;
  bottom: 0;
  height: 14px;
}
.board-scrollbar-v {
  top: 0;
  bottom: 14px;
  right: 0;
  width: 14px;
}
.board-scrollbar-thumb {
  position: absolute;
  border-radius: var(--radius-md);
  background: var(--scrollbar-thumb);
  pointer-events: auto;
  cursor: default;
}
.board-scrollbar-thumb:hover,
.board-scrollbar-thumb:active {
  background: var(--scrollbar-thumb-hover);
}
.board-scrollbar-h .board-scrollbar-thumb {
  top: 2px;
  bottom: 2px;
  left: var(--thumb-pos, 0%);
  width: var(--thumb-size, 20%);
}
.board-scrollbar-v .board-scrollbar-thumb {
  left: 2px;
  right: 2px;
  top: var(--thumb-pos, 0%);
  height: var(--thumb-size, 20%);
}
@media (prefers-reduced-motion: reduce) {
  .board-scrollbar {
    transition: none;
  }
}

/* Markdown headings inside beat bodies — compact (a card is an index
 * card, not a document): two visual sizes, primary-colored. */
.board-card-body h1,
.board-card-body h2 {
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  margin: 6px 0 2px;
  line-height: 1.3;
}
.board-card-body h3,
.board-card-body h4,
.board-card-body h5,
.board-card-body h6 {
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  margin: 5px 0 1px;
  line-height: 1.3;
}
.board-card-body h1:first-child,
.board-card-body h2:first-child,
.board-card-body h3:first-child,
.board-card-body h4:first-child,
.board-card-body h5:first-child,
.board-card-body h6:first-child {
  margin-top: 0;
}

/* ---------- Beats-first progress surfaces ---------- */

/* Statusbar "Beats 9/15" — a real button styled as a segment. */
.statusbar-beats {
  font-family: var(--font-ui);
  font-size: inherit;
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.statusbar-beats:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.statusbar-beats:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: -1px;
}
.statusbar-beats.hidden {
  display: none;
}

/* Board toolbar progress chip: reads as live status, not just a button. */
.board-progress {
  color: var(--text-primary);
  font-weight: 500;
}

/* Beat badge "B" — identical pill language to the Notes "N"
 * (.scene-note-pip above); painted when the scene is linked to one or
 * more beats on the board. */
.scene-beat-pip {
  /* No box until the row has one: two invisible badges used to reserve
     about 60px of every row, a third of the name's width. */
  display: none;
  align-items: center;
  justify-content: center;
  /* A bare letter, not a boxed one: with every scene on the board the
     list wore a column of 191 outlined squares. The letter keeps the
     meaning explicit (N = notes, B = on the board) and its tooltip says
     which; hover and the current row bring it up to full strength. */
  border: 0;
  padding: 0;
  font-family: var(--font-page-ui);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: transparent;
  flex-shrink: 0;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out);
}
.scene-item.has-beats .scene-beat-pip {
  display: inline-flex;
  opacity: 1;
  pointer-events: auto;
  color: var(--pip-color, var(--text-muted));
}
.scene-item.has-beats.active .scene-beat-pip,
.scene-item.has-beats:hover .scene-beat-pip {
  color: var(--pip-color, var(--text-primary));
}

/* Order clash: the board plan puts this scene's beat in an EARLIER act
 * than its clamped sidebar position. Tint is a hint — the tooltip and
 * aria-label carry the actual message (color never the sole signal). */
.scene-item.has-beats .scene-beat-pip.plan-mismatch {
  color: var(--orange);
}

/* ---------- Toolbar responsive degradation ----------
 * Toolbars never wrap or bleed into neighboring panes: nowrap + clip,
 * compact labels below 720px pane width (board-compact via the
 * island's ResizeObserver), and the centered switcher falls back into
 * flow when there's no centered room. */
.board-toolbar {
  overflow: hidden;
}
.board-toolbar .btn,
.board-progress,
.view-mode-btn {
  white-space: nowrap;
  flex-shrink: 0;
}
.board-btn-compact {
  display: none;
}
/* Hide the full label ONLY on buttons that carry a .board-btn-compact
 * twin to swap in (Structure, progress). The old blanket hide also
 * blanked the + Beat button through the compact band (520–720px): its
 * only alternative span (.board-btn-xs-compact "+") doesn't appear
 * until board-compact-xs, leaving an empty pill in between. */
.board-pane.board-compact :has(> .board-btn-compact) > .board-btn-full {
  display: none;
}
.board-pane.board-compact .board-btn-compact {
  display: inline;
}
/* board-switch-tight: the island measured that the centered switcher
 * would collide with the toolbar's left or right cluster (long
 * Structure label, wide progress counter) — same fallback as compact:
 * the switcher drops into flow. It's seated in the DOM just before the
 * flex spacer (injectBoardModeSwitch), so flow lays it out with the
 * primary +Beat / Structure controls — the flex spacer then pushes the
 * ? / popout cluster to the right edge, clear of the switcher. */
.board-pane.board-compact .board-toolbar .view-mode-switch,
.board-pane.board-switch-tight .board-toolbar .view-mode-switch {
  position: static;
  transform: none;
  margin-left: 0;
}

.editor-center {
  min-width: 0;
}

/* Extra-small board pane: shed what has a keyboard twin. */
.board-btn-xs-compact {
  display: none;
}
.board-pane.board-compact-xs .board-btn-new .board-btn-full {
  display: none;
}
.board-pane.board-compact-xs .board-btn-new .board-btn-xs-compact {
  display: inline;
}
/* Narrowest pane: also shed the help glyph (a pure keyboard twin, ?).
 * The pointer tools are already gone at board-compact above. The mode
 * switcher must stay whole — it's the only way out of Split here. */
.board-pane.board-compact-xs .board-btn-help {
  display: none;
}
.board-pane.board-compact-xs .view-mode-btn {
  padding: 5px 10px;
}
.board-pane.board-compact-xs .split-dir-btn {
  padding: 5px 8px;
}

/* ---------- Beat board popout (satellite window) ----------
 * The satellite renderer hides the entire normal app shell and shows
 * only a draggable titlebar + the board pane. Chrome elements are
 * built in JS (initBoardPopoutWindow); these rules give them layout. */
body.board-popout-window {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
body.board-popout-window #welcome,
body.board-popout-window #editor-layout {
  display: none !important;
}
.popout-titlebar {
  -webkit-app-region: drag;
  height: 40px;
  display: flex;
  align-items: center;
  /* Left padding clears the hiddenInset traffic lights. */
  padding: 0 14px 0 84px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  user-select: none;
}
.popout-title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.board-popout-window .board-pane {
  flex: 1;
  min-height: 0;
}

/* Collaborator image still syncing from the owner's machine: calm
 * labeled state instead of a broken-image glyph. */
.board-card-media.asset-pending {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.board-card-media.asset-pending img {
  display: none;
}
.board-card-media.asset-pending::after {
  content: 'Image syncing…';
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ---------- Bring-your-own-key (js/byok.js) ----------
   Reuses the role pill / popover chrome in the composer and the
   .setting-row card in the setup sheet + Settings › AI. */
.role-popover--wide {
  width: 272px;
}

/* Cursor-shaped model picker rows: one line — name, then cost / tag /
   check on the right. Group headers name the account, so rows don't. */
.role-popover-item--compact {
  gap: 8px;
  padding: 6px 12px;
}
.role-popover-item--compact .role-popover-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Locked = a plan the writer doesn't have. Dimmed like every disabled
   control, but still clickable — the click opens the upgrade path. */
.role-popover-item--locked .role-popover-item-name,
.role-popover-item--locked .model-cost {
  opacity: var(--locked-opacity);
}
.model-tag {
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
  flex: 0 0 auto;
}
/* "Managed by <studio>" on a model the seat's role does not allow: a
   name, so sentence case and room to truncate. */
.model-tag--managed {
  font-weight: var(--weight-regular);
  letter-spacing: 0;
  text-transform: none;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 14em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.model-tag--upgrade {
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
  border-radius: var(--radius-pill);
  padding: 1px 6px;
}
/* $ to $$$$: lit dollars count, dim ones keep the width steady. */
.model-cost {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--text-xs);
  letter-spacing: 0.02em;
  flex: 0 0 auto;
}
.model-cost-lit {
  color: var(--text-secondary);
}
.model-cost-dim {
  color: var(--text-muted);
  opacity: 0.35;
}
.model-auto-row {
  cursor: pointer;
}
.model-auto-row .settings-toggle {
  margin-left: 4px;
}
.role-popover-foot {
  appearance: none;
  width: 100%;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  border-radius: 0 0 10px 10px;
}
.role-popover-foot:hover,
.role-popover-foot:focus-visible {
  background: var(--hover-wash);
  color: var(--text-primary);
  outline: none;
}

.byok-new-tag {
  display: inline-block;
  margin-left: 8px;
  font-size: var(--text-2xs);
  font-weight: var(--weight-strong);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
  border-radius: var(--radius-pill);
  padding: 1px 6px;
  vertical-align: middle;
  align-self: flex-start;
}

/* The setup sheet opens from Settings → AI, so it must paint above the
   Settings overlay (same .settings-overlay class, z-index 60, and it
   precedes Settings in the DOM). */
#byok-setup-overlay {
  z-index: 61;
}

.byok-setup-modal {
  width: 520px;
  max-width: 92vw;
  /* The head and the Cancel/Continue row stay pinned; only the step body
     scrolls when a key explainer outgrows the sheet. */
  display: flex;
  flex-direction: column;
}

#byok-setup-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.byok-setup-head,
.byok-setup-actions {
  flex: 0 0 auto;
}

.byok-setup-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.byok-setup-head .settings-label {
  margin-bottom: 3px;
}

.byok-setup-head .settings-header {
  margin-bottom: 14px;
}

.byok-setup-close {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.byok-setup-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.byok-choice-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* A selectable row: same card as .setting-row, ring when chosen. */
.byok-choice {
  appearance: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: var(--font-ui);
}

.byok-choice.is-selected {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
}

.byok-choice:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.byok-connected-badge {
  margin-left: 8px;
}

.byok-input {
  width: 100%;
  flex: 1;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 11px;
  font-size: var(--text-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  outline: none;
  transition: border-color var(--dur-2) var(--ease-out);
}

.byok-input:focus {
  border-color: var(--accent);
}

.byok-key-row {
  margin-top: 8px;
}

.byok-inline-actions {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}

.byok-optional {
  margin-left: 8px;
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--text-muted);
}

.byok-verify-status {
  margin-top: 8px;
  min-height: 1.4em;
}

.byok-verify-status.is-ok {
  color: var(--green);
}

.byok-trust {
  margin-top: 8px;
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text-muted);
}

.byok-more {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  padding: 4px 14px 0;
  text-align: left;
  cursor: pointer;
}

.byok-more:hover {
  color: var(--text-primary);
}

.byok-setup-actions {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.byok-section-label {
  margin-top: 12px;
}

.byok-section-desc {
  margin: -4px 0 10px;
}

/* Settings → AI: service cards (mark + name + blurb / status + actions). */
.byok-provider-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.byok-provider-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 0;
}
.byok-provider-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.byok-provider-mark {
  flex: none;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  color: var(--text-primary);
}
.byok-provider-mark svg {
  width: 20px;
  height: 20px;
}
.byok-choice .byok-provider-mark {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  margin-right: 12px;
}
.byok-choice .byok-provider-mark svg {
  width: 16px;
  height: 16px;
}
.byok-provider-name {
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.byok-provider-desc {
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text-secondary);
}
.byok-provider-actions {
  margin-top: auto;
  display: flex;
  gap: 8px;
}

/* ============ Plan tab: included-AI usage ============ */
.plan-usage {
  width: 100%;
}
.plan-usage-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.plan-usage-renews,
.plan-usage-range {
  flex: none;
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* The bar spans the allowance, plus the spend limit once pay-as-you-go
   is on: accent for included usage, orange beyond it, a dashed mark at
   the allowance boundary. */
.plan-usage-meter {
  position: relative;
  display: flex;
  height: 6px;
  margin-top: 8px;
  border-radius: 3px;
  background: var(--border-soft);
}
.plan-usage-bar,
.plan-usage-bar-beyond {
  flex: none;
  height: 100%;
  width: 0;
  transition: width 0.3s ease;
}
.plan-usage-bar {
  border-radius: 3px 0 0 3px;
  background: var(--accent);
}
.plan-usage-bar.is-spent {
  background: var(--orange);
}
.plan-usage-bar-beyond {
  background: var(--orange);
  border-radius: 0 3px 3px 0;
}
.plan-usage-mark {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 0;
  border-left: 1px dashed var(--text-muted);
}
.plan-usage-caption {
  margin-top: 6px;
}
.plan-usage-hint {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  margin-top: 8px;
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text-secondary);
}
.plan-usage-link {
  background: transparent;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.plan-usage-link:hover {
  color: var(--btn-primary-hover);
}
.plan-usage-link:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
  border-radius: 3px;
}
.plan-usage-subhead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}
.plan-usage-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}
/* One thin bar per cycle day; height relative to the busiest day. The
   column is the hover / focus target and carries the label as a CSS
   tooltip (data-tip = date, data-tip-sub = amount and count) that floats
   above the chart, over the subhead. */
.plan-usage-days {
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: 36px;
  margin-top: 4px;
  padding-top: 2px;
}
.plan-usage-day-col {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  cursor: default;
}
.plan-usage-day {
  width: 100%;
  min-height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
}
.plan-usage-day.is-empty {
  background: var(--border-soft);
}
.plan-usage-day.is-today {
  box-shadow: 0 0 0 1px var(--accent-border);
}
.plan-usage-day-col:hover .plan-usage-day.is-empty,
.plan-usage-day-col:focus-visible .plan-usage-day.is-empty {
  background: var(--text-muted);
}
.plan-usage-day-col:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
  border-radius: 2px;
}
.plan-usage-day-col::after {
  content: attr(data-tip) '\A' attr(data-tip-sub);
  white-space: pre;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  padding: 5px 8px;
  font-size: var(--text-xs);
  line-height: 1.4;
  text-align: center;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  pointer-events: none;
  z-index: 2;
}
.plan-usage-day-col.is-edge-start::after {
  left: 0;
  transform: none;
  text-align: left;
}
.plan-usage-day-col.is-edge-end::after {
  left: auto;
  right: 0;
  transform: none;
  text-align: right;
}
.plan-usage-day-col:hover::after,
.plan-usage-day-col:focus-visible::after {
  display: block;
}
.plan-usage-inline {
  margin-top: 6px;
}
@media (prefers-reduced-motion: reduce) {
  .plan-usage-bar,
  .plan-usage-bar-beyond {
    transition: none;
  }
}

/* ============ Plan tab: pay-as-you-go spend limit ============ */
.plan-overage-cap {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.plan-overage-cap-field {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-primary);
}
.plan-overage-cap-field input {
  width: 5em;
  padding: 5px 8px;
  font: inherit;
  color: var(--text-primary);
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  -moz-appearance: textfield;
  appearance: textfield;
}
.plan-overage-cap-field input::-webkit-outer-spin-button,
.plan-overage-cap-field input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.plan-overage-cap-field input:focus {
  outline: 2px solid var(--focus-color);
  outline-offset: 1px;
}

/* ---------- What's new (js/whats-new/modal.js) ----------
 * Once-per-update release notes. The hero bleeds edge to edge, so the
 * modal drops .settings-modal's padding and the body carries it. Pink
 * is the brand-moment accent here (see --brand-pink), never a button
 * fill — the primary stays the neutral --accent. */
#whats-new-overlay {
  z-index: 61;
}
.whats-new-modal {
  width: 480px;
  padding: 0;
  overflow: hidden auto;
  animation: whats-new-enter 180ms ease-out both;
}
/* The dialog takes focus on open (see modal.js) so no button is
   highlighted for pointer users; keyboard users get the design-system
   ring on Tab instead of the UA default. */
.whats-new-modal:focus {
  outline: none;
}
.whats-new-modal .btn:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}
@keyframes whats-new-enter {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .whats-new-modal {
    animation: whats-new-fade 150ms ease-out both;
  }
  @keyframes whats-new-fade {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }
}
.whats-new-hero {
  height: 160px;
  overflow: hidden;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.whats-new-hero svg {
  display: block;
  width: 100%;
  height: 100%;
}
/* Twinkling sparks. Each star scales about its own box so the parent
   <g>'s placement transform is untouched; staggered negative delays and
   varied durations keep them out of phase so the field never pulses in
   unison. Under prefers-reduced-motion the stars hold their mid-state. */
@keyframes wn-twinkle {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.7);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}
@keyframes wn-twinkle-soft {
  0%,
  100% {
    opacity: 0.8;
    transform: scale(0.94);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}
.whats-new-hero .wn-star {
  transform-box: fill-box;
  transform-origin: center;
  animation: wn-twinkle 2.8s ease-in-out infinite;
}
.whats-new-hero .wn-star-main {
  animation-name: wn-twinkle-soft;
  animation-duration: 3.6s;
}
.whats-new-hero .wn-star-2 {
  animation-duration: 2.2s;
  animation-delay: -0.7s;
}
.whats-new-hero .wn-star-3 {
  animation-duration: 3.1s;
  animation-delay: -1.9s;
}
.whats-new-hero .wn-star-4 {
  animation-duration: 2.5s;
  animation-delay: -1.2s;
}
.whats-new-hero .wn-star-5 {
  animation-duration: 3.3s;
  animation-delay: -0.4s;
}
.whats-new-hero .wn-star-6 {
  animation-duration: 2s;
  animation-delay: -1.5s;
}
@media (prefers-reduced-motion: reduce) {
  .whats-new-hero .wn-star {
    animation: none;
    opacity: 0.7;
  }
  .whats-new-hero .wn-star-main {
    opacity: 1;
  }
}
.whats-new-body {
  padding: 20px 22px 22px;
}
.whats-new-body .settings-label {
  margin-bottom: 8px;
}
.whats-new-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-strong);
  letter-spacing: -0.01em;
  line-height: 1.25;
  color: var(--text-primary);
  margin: 0 0 16px;
}
.whats-new-features {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.whats-new-feature {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding-left: 16px;
  position: relative;
}
.whats-new-feature::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand-pink);
}
.whats-new-feature-text {
  flex: 1;
  min-width: 0;
}
.whats-new-feature-title {
  font-size: var(--text-md);
  font-weight: var(--weight-strong);
  color: var(--text-primary);
  margin-bottom: 3px;
}
.whats-new-feature-body {
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-secondary);
}
.whats-new-feature .btn {
  flex-shrink: 0;
  margin-top: -2px;
}

/* ---------- AI off (master switch / covered-work lock) ---------- */
/* Replaces the chat composer while AI is unavailable; copy comes from
   js/shared/ai-policy.js. Calm, not an error: the writer chose this. */
.chat-ai-notice {
  margin: 8px 12px 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: var(--text-md);
  line-height: 1.5;
}
.chat-ai-notice.hidden {
  display: none;
}
.chat-ai-notice-inline {
  align-self: center;
  margin: 4px 0;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.4;
}
.statusbar-ai-lock {
  color: var(--text-secondary);
}
.statusbar-ai-lock.hidden {
  display: none;
}
.tp-lock-row {
  /* 18px below = the gap every settings dialog leaves between its
     explanatory text and the action buttons (.settings-explainer). */
  margin: 14px 0 18px;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft, var(--border));
}
.tp-lock-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-md);
  color: var(--text-primary);
  cursor: pointer;
}
.tp-lock-label input {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--accent);
}
.tp-lock-help {
  margin: 6px 0 0 23px;
}

/* Name check (#168): modal rows + the stepper that stays until Done/Esc. */
.name-check-list {
  max-height: 50vh;
  overflow-y: auto;
  margin: 8px 0 16px;
}
.name-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.name-check-row-text {
  flex: 1;
  min-width: 0;
  font-size: var(--text-md);
  color: var(--text-primary);
}
.name-check-row-scenes {
  display: block;
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.name-check-empty {
  padding: 12px 0;
  font-size: var(--text-md);
  color: var(--text-muted);
}
.name-check-stepper {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  color: var(--text-primary);
}
.name-check-stepper.hidden {
  display: none;
}
