/* ==========================================================================
   Plotorium design system
   A warm, editorial writing workspace: paper-toned light theme, warm charcoal
   dark theme, one ink-blue accent. Inter for the interface, Literata for
   titles and manuscript prose. Colours are tokens only — components never use
   literal colours, so both themes stay consistent.
   ========================================================================== */

:root {
    /* Surfaces */
    --bg: #f5f2eb;
    --surface: #fffdf8;
    --surface-sunken: #efebe2;
    --surface-hover: #ece7dc;
    --surface-raised: #ffffff;
    --border: #e1dacc;
    --border-strong: #cbc2b1;

    /* Text */
    --text: #22201b;
    --text-muted: #6d665a;
    --text-faint: #958d7f;

    /* Accent: ink blue */
    --accent: #33508a;
    --brand: #0050c9;
    --accent-hover: #27406f;
    --accent-text: #ffffff;
    --accent-tint: rgba(51, 80, 138, 0.09);
    --accent-tint-strong: rgba(51, 80, 138, 0.16);
    --accent-glow: rgba(51, 80, 138, 0.18);

    /* Semantic */
    --danger: #b0402f;
    --danger-tint: rgba(176, 64, 47, 0.09);
    --success: #2e7550;
    --success-tint: rgba(46, 117, 80, 0.1);
    --warning: #8f6211;
    --warning-tint: rgba(143, 98, 17, 0.1);
    --ai: #6a4c93;
    --ai-tint: rgba(106, 76, 147, 0.08);

    /* Type */
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-serif: 'Literata', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: 0.9rem;
    --text-md: 1rem;
    --text-lg: 1.2rem;
    --text-xl: 1.6rem;
    --text-2xl: 2.1rem;

    /* Space (4px base) */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;

    /* Shape */
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(60, 45, 20, 0.06);
    --shadow-md: 0 6px 20px rgba(60, 45, 20, 0.09);
    --shadow-lg: 0 18px 48px rgba(40, 30, 10, 0.18);
    --focus-ring: 0 0 0 3px var(--accent-tint-strong);

    --sidebar-width: 236px;
    --topbar-h: 53px; /* the phone layout's top bar */
    --prose-width: 68ch;

    /* The manuscript, as the writer set it up (Settings › Preferences; see the data-editor-* rules below). */
    --font-prose: var(--font-serif);
    --prose-size: 1.12rem;
    --prose-leading: 1.85;
    --manuscript-width: var(--prose-width);

    /* Avatar colours a writer can pick; each avatar tints its background from its own colour. */
    --av-ink: #33508a;
    --av-plum: #7a4a86;
    --av-moss: #4f6b33;
    --av-rust: #a24a2a;
    --av-ochre: #8a6512;
    --av-slate: #4d5a66;
    --av-rose: #a43d63;
    --av-teal: #1f6e6e;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #161512;
    --surface: #1d1c18;
    --surface-sunken: #121110;
    --surface-hover: #26241f;
    --surface-raised: #23211d;
    --border: #312e28;
    --border-strong: #46423a;

    --text: #ece7dc;
    --text-muted: #a69f91;
    --text-faint: #7d776b;

    --accent: #93acde;
    --brand: #8fb3ff;
    --accent-hover: #b0c4ea;
    --accent-text: #11161f;
    --accent-tint: rgba(147, 172, 222, 0.11);
    --accent-tint-strong: rgba(147, 172, 222, 0.22);
    --accent-glow: rgba(147, 172, 222, 0.16);

    --danger: #e58a78;
    --danger-tint: rgba(229, 138, 120, 0.12);
    --success: #85c79e;
    --success-tint: rgba(133, 199, 158, 0.12);
    --warning: #e0b762;
    --warning-tint: rgba(224, 183, 98, 0.12);
    --ai: #c3a8e8;
    --ai-tint: rgba(195, 168, 232, 0.1);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.5);

    --av-ink: #9fb6e4;
    --av-plum: #cfa6dd;
    --av-moss: #a9c78a;
    --av-rust: #eb9a7b;
    --av-ochre: #e2c06f;
    --av-slate: #a9b6c2;
    --av-rose: #ec9bb9;
    --av-teal: #7fcaca;
    color-scheme: dark;
}

:root[data-editor-font="sans"] { --font-prose: var(--font-ui); }
:root[data-editor-font="mono"] { --font-prose: ui-monospace, 'Cascadia Mono', 'SF Mono', Menlo, Consolas, monospace; }
:root[data-editor-size="small"] { --prose-size: 1rem; }
:root[data-editor-size="large"] { --prose-size: 1.26rem; }
:root[data-editor-size="extralarge"] { --prose-size: 1.42rem; }
:root[data-editor-spacing="compact"] { --prose-leading: 1.55; }
:root[data-editor-spacing="airy"] { --prose-leading: 2.15; }
:root[data-editor-width="narrow"] { --manuscript-width: 58ch; }
:root[data-editor-width="wide"] { --manuscript-width: 86ch; }

/* ---------- Base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
::selection { background: var(--accent-tint-strong); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

.icon { width: 16px; height: 16px; vertical-align: -3px; flex-shrink: 0; }
.serif { font-family: var(--font-serif); }
.muted { color: var(--text-muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.boot-loader { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; background: var(--bg); color: var(--text); font-family: var(--font-ui); }
.boot-loader-mark { font-family: var(--font-serif); font-size: 1.6rem; font-weight: 600; }
.boot-loader-status { margin-top: 0.5rem; color: var(--text-muted); font-size: 0.85rem; text-align: center; }

/* ---------- App shell ---------- */
.layout { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: var(--sidebar-width); background: var(--surface-sunken); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; padding: var(--space-4) var(--space-3); transition: transform 0.2s ease; }
.sidebar-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.content { flex: 1; overflow-y: auto; min-width: 0; }
.content-inner { max-width: 1240px; margin: 0 auto; padding: var(--space-6) var(--space-6) var(--space-7); }
.content-inner.wide { max-width: none; }
.content-inner.full-bleed { max-width: none; padding: 0; }

.brand { display: flex; align-items: center; gap: 0.55rem; padding: 0 0.4rem; margin-bottom: var(--space-4); color: var(--text); text-decoration: none; }
.brand:hover { color: var(--text); }
/* The logo is drawn as a mask so it takes the theme's brand colour (the PNG's own blue is too dark on the dark theme). */
.brand-mark, .brand-word { display: inline-block; background: var(--brand); -webkit-mask: var(--logo) center / contain no-repeat; mask: var(--logo) center / contain no-repeat; flex-shrink: 0; }
.brand-mark { --logo: url("img/logo-mark.png"); width: 17px; height: 32px; }
.brand-word { --logo: url("img/logo-wordmark.png"); width: 96px; height: 21px; margin-top: 3px; }

.sidebar-search { display: flex; align-items: center; gap: var(--space-2); width: 100%; padding: 0.45rem 0.6rem; margin-bottom: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text-muted); font: inherit; font-size: var(--text-sm); cursor: pointer; text-align: left; }
.sidebar-search:hover { border-color: var(--border-strong); color: var(--text); }
.sidebar-search kbd { margin-left: auto; }
kbd { font-family: var(--font-ui); font-size: 0.68rem; padding: 0.05rem 0.35rem; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; color: var(--text-muted); background: var(--surface); }

.project-switch { display: block; padding: var(--space-2) 0.6rem; margin-bottom: var(--space-2); border-radius: var(--radius); text-decoration: none; color: var(--text); }
.project-switch:hover { background: var(--surface-hover); color: var(--text); }
.project-switch-label { display: block; font-size: var(--text-xs); color: var(--text-faint); }
.project-switch-name { display: block; font-family: var(--font-serif); font-weight: 600; font-size: 0.98rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-link { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.6rem; border-radius: var(--radius-sm); color: var(--text-muted); text-decoration: none; font-size: var(--text-sm); font-weight: 500; transition: background 0.12s, color 0.12s; }
.nav-link .icon { color: currentColor; opacity: 0.9; }
.nav-link:hover { background: var(--surface-hover); color: var(--text); }
.nav-link.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm), inset 2px 0 0 var(--accent); }
.nav-link .nav-count { margin-left: auto; font-size: var(--text-xs); font-weight: 600; color: var(--accent); background: var(--accent-tint); border-radius: 999px; padding: 0 0.45rem; }
.nav-section { font-size: 0.68rem; text-transform: uppercase; color: var(--text-faint); margin: var(--space-4) 0 var(--space-1); padding: 0 0.6rem; letter-spacing: 0.08em; font-weight: 600; }
.nav-more > summary { list-style: none; cursor: pointer; }
.nav-more > summary::-webkit-details-marker { display: none; }
.nav-more > summary .chevron { margin-left: auto; transition: transform 0.15s; }
.nav-more[open] > summary .chevron { transform: rotate(90deg); }

.sidebar-account { flex-shrink: 0; padding-top: var(--space-3); margin-top: var(--space-3); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.sidebar-account-row { display: flex; align-items: center; gap: 0.4rem; }
.sidebar-account-row .nav-link { flex: 1; }
.nav-link-button { width: 100%; background: none; border: none; font: inherit; font-size: var(--text-sm); text-align: left; cursor: pointer; }

.theme-toggle { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--radius-sm); background: transparent; border: 1px solid var(--border); color: var(--text-muted); cursor: pointer; }
.theme-toggle:hover { background: var(--surface-hover); color: var(--text); }
.theme-toggle .icon { width: 15px; height: 15px; vertical-align: -2px; }

.mobile-topbar { display: none; }
.mobile-menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: var(--radius-sm); background: transparent; border: 1px solid var(--border); color: var(--text); cursor: pointer; }
.mobile-menu-btn .icon { width: 18px; height: 18px; }
.sidebar-backdrop { display: none; }

/* ---------- Page header & breadcrumbs ---------- */
.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; font-size: var(--text-sm); color: var(--text-faint); margin-bottom: var(--space-2); }
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--text); text-decoration: underline; }
.breadcrumb .sep { color: var(--text-faint); }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: var(--space-3); margin-bottom: var(--space-5); }
.page-header-text { min-width: 0; }
.page-title { font-family: var(--font-serif); font-size: var(--text-xl); font-weight: 600; letter-spacing: -0.015em; line-height: 1.2; color: var(--text); }
/* Blazor's FocusOnNavigate focuses the page's h1 for screen readers; headings aren't interactive, so don't draw a focus box around them. */
h1:focus, h1:focus-visible, .page-title:focus, .page-title:focus-visible { outline: none; box-shadow: none; }
.page-subtitle { color: var(--text-muted); font-size: var(--text-base); margin-top: var(--space-1); max-width: 65ch; }
.page-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.section-title { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); margin: var(--space-6) 0 var(--space-3); }
.section-title:first-child { margin-top: 0; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0.48rem 0.95rem; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer; font-family: var(--font-ui); font-size: var(--text-sm); font-weight: 600; line-height: 1.3; text-decoration: none; white-space: nowrap; transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); color: var(--accent-text); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.btn-ghost.active { background: var(--accent-tint); color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-tint); color: var(--danger); }
.btn-sm { padding: 0.28rem 0.62rem; font-size: var(--text-xs); }
.btn-lg { padding: 0.7rem 1.35rem; font-size: var(--text-md); }
.btn-icon { padding: 0.4rem; }
.btn-ai { background: var(--ai-tint); color: var(--ai); border-color: transparent; }
.btn-ai:hover:not(:disabled) { background: var(--ai-tint); border-color: var(--ai); color: var(--ai); }
.link-button { background: none; border: none; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-button:hover { color: var(--accent-hover); }

/* ---------- Cards & lists ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4) var(--space-4); margin-bottom: var(--space-3); box-shadow: var(--shadow-sm); }
.card-title { font-weight: 600; margin-bottom: 0.3rem; font-size: var(--text-md); color: var(--text); display: flex; align-items: center; flex-wrap: wrap; gap: 0.35rem; }
.card-meta { font-size: var(--text-sm); color: var(--text-muted); display: flex; align-items: center; flex-wrap: wrap; gap: 0.3rem; }
.search-hit { cursor: pointer; }
.search-excerpt { font-family: var(--font-serif); line-height: 1.6; color: var(--text); margin: 0.35rem 0 0.25rem; }
mark { background: var(--warning-tint); color: inherit; border-radius: 2px; padding: 0 1px; box-shadow: inset 0 -2px 0 var(--warning); }
.card-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
/* Edit/delete on list cards are secondary: quiet until the card is hovered or focused (always
   fully visible on touch screens and to keyboard users via :focus-within). */
.card-actions:has(.btn-danger) .btn-secondary { background: transparent; border-color: transparent; color: var(--text-muted); }
.card-actions:has(.btn-danger) .btn-secondary:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.card-actions .btn-danger { border-color: transparent; }
@media (hover: hover) {
    .card > .card-actions:has(.btn-danger) { opacity: 0.55; transition: opacity 0.12s; }
    .card:hover > .card-actions, .card:focus-within > .card-actions { opacity: 1; }
}
a.card, .card-link { display: block; text-decoration: none; color: inherit; transition: border-color 0.12s, box-shadow 0.12s; }
a.card:hover, .card-link:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); color: inherit; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-3); }
.card-grid > .card { margin-bottom: 0; }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; }
.list-row:last-child { border-bottom: none; }
a.list-row:hover { background: var(--surface-hover); color: inherit; }
.list-row-main { flex: 1; min-width: 0; }
.list-row-title { font-weight: 600; color: var(--text); }
.list-row-sub { font-size: var(--text-sm); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-meta { font-size: var(--text-xs); color: var(--text-faint); white-space: nowrap; }

.avatar { flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; background: var(--accent-tint); color: var(--accent); font-weight: 600; font-size: var(--text-sm); }

/* ---------- Badges & chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; line-height: 1.5; white-space: nowrap; text-decoration: none; }
.badge-accent { background: var(--accent-tint); color: var(--accent); }
.badge-muted { background: var(--surface-hover); color: var(--text-muted); }
.badge-success { background: var(--success-tint); color: var(--success); }
.badge-danger { background: var(--danger-tint); color: var(--danger); }
.badge-warning { background: var(--warning-tint); color: var(--warning); }
.badge-ai { background: var(--ai-tint); color: var(--ai); }

/* ---------- Forms ---------- */
.form-group { margin-bottom: var(--space-3); }
label { display: block; font-size: var(--text-sm); color: var(--text); margin-bottom: 0.3rem; font-weight: 500; }
.field-hint { font-size: var(--text-xs); color: var(--text-muted); margin-top: 0.25rem; }
.optional { color: var(--text-faint); font-weight: 400; }
input, textarea, select { width: 100%; background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem 0.65rem; color: var(--text); font-size: var(--text-base); font-family: inherit; line-height: 1.45; transition: border-color 0.12s ease, box-shadow 0.12s ease; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:hover, textarea:hover, select:hover { border-color: var(--border-strong); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
.inline-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5); margin-bottom: var(--space-5); box-shadow: var(--shadow-md); }
.inline-form h3 { font-family: var(--font-serif); font-size: var(--text-lg); font-weight: 600; }
.form-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-4); }
.more-fields { margin: var(--space-2) 0 var(--space-3); }
.more-fields > summary { cursor: pointer; font-size: var(--text-sm); font-weight: 500; color: var(--accent); margin-bottom: var(--space-3); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--space-4); }

/* ---------- Feedback ---------- */
.loading { color: var(--text-muted); padding: var(--space-6); text-align: center; font-size: var(--text-base); }
.loading::before { content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 0.5rem; vertical-align: -2px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error { color: var(--danger); background: var(--danger-tint); border-radius: var(--radius); padding: 0.55rem 0.8rem; font-size: var(--text-sm); margin: var(--space-2) 0; }
.alert { display: flex; gap: var(--space-2); align-items: flex-start; border-radius: var(--radius); padding: 0.65rem 0.85rem; font-size: var(--text-sm); margin-bottom: var(--space-3); border: 1px solid transparent; }
.alert-info { background: var(--accent-tint); color: var(--text); }
.alert-warning { background: var(--warning-tint); color: var(--text); border-color: var(--warning-tint); }
.alert-success { background: var(--success-tint); color: var(--text); }
.empty { color: var(--text-muted); text-align: center; padding: var(--space-6); font-size: var(--text-base); }
.empty-state { text-align: center; padding: var(--space-7) var(--space-5); border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); background: var(--surface); }
.empty-state-icon { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent-tint); color: var(--accent); margin-bottom: var(--space-3); }
.empty-state-icon .icon { width: 20px; height: 20px; vertical-align: 0; }
.empty-state-title { font-family: var(--font-serif); font-size: var(--text-lg); font-weight: 600; margin-bottom: var(--space-1); color: var(--text); }
.empty-state-text { color: var(--text-muted); font-size: var(--text-base); max-width: 46ch; margin: 0 auto var(--space-4); }

.save-status { display: inline-flex; align-items: center; gap: 0.35rem; font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; }
.save-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.save-status.unsaved::before { background: var(--warning); }
.save-status.saving::before { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.save-status.failed { color: var(--danger); }
.save-status.failed::before { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }

.toaster { position: fixed; right: var(--space-5); bottom: var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); z-index: 1100; pointer-events: none; }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); padding: 0.6rem 0.95rem; border-radius: var(--radius); font-size: var(--text-sm); box-shadow: var(--shadow-lg); max-width: 360px; animation: toast-in 0.18s ease-out; }
.toast.toast-error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 16, 10, 0.45); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: var(--space-4); }
.modal-card { background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5); max-width: 420px; width: 100%; box-shadow: var(--shadow-lg); }
.modal-title { font-family: var(--font-serif); font-weight: 600; font-size: var(--text-lg); margin-bottom: var(--space-2); }
.modal-message { color: var(--text-muted); line-height: 1.55; margin-bottom: var(--space-5); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }
/* Confirmations can be asked from inside another dialog (e.g. Restore in the compare view). */
.modal-backdrop.modal-confirm { z-index: 1100; }

/* Chapter history */
.history-item { padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.history-item:last-of-type { border-bottom: none; }
.history-label { font-weight: 600; }
.history-actions { display: flex; gap: var(--space-3); margin-top: 0.2rem; font-size: var(--text-sm); }
.history-alt { display: flex; align-items: center; gap: var(--space-2); margin: var(--space-2) 0; font-size: var(--text-sm); }
.history-alt input { width: auto; }
.compare-card { max-width: 860px; max-height: calc(100vh - 2 * var(--space-4)); display: flex; flex-direction: column; }
.compare-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-3); }
.compare-tabs { border-bottom: none; }
.compare-legend { margin-bottom: var(--space-2); }
.compare-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); margin-bottom: var(--space-4); background: var(--surface); }
ins { background: var(--success-tint); text-decoration: none; border-radius: 2px; }
del { background: var(--danger-tint); color: var(--text-muted); border-radius: 2px; }
/* Story-bible entry history */
.entry-history { margin-top: var(--space-3); font-size: var(--text-sm); }
.entry-history > summary { cursor: pointer; color: var(--text-muted); font-weight: 500; width: fit-content; }
.entry-history > summary:hover { color: var(--text); }
.entry-history[open] > summary { margin-bottom: var(--space-2); }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); max-height: 26rem; overflow-y: auto; }
.history-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.55rem 0.75rem; background: var(--surface); }
.history-head { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.3rem; }
.history-field { font-weight: 600; color: var(--text); }
.history-when { color: var(--text-faint); font-size: var(--text-xs); margin-left: auto; }
.history-change { line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 12rem; overflow-y: auto; }
.history-actions { display: flex; justify-content: flex-end; margin-top: 0.25rem; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 0.5rem 0.75rem; margin-bottom: -1px; font: inherit; font-size: var(--text-sm); font-weight: 600; color: var(--text-muted); cursor: pointer; display: inline-flex; align-items: center; gap: 0.35rem; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Home & project overview ---------- */
.welcome { font-family: var(--font-serif); font-size: var(--text-2xl); font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.resume-card { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-5); border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md); text-decoration: none; color: inherit; }
.resume-card:hover { border-color: var(--accent); color: inherit; }
.resume-eyebrow { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; color: var(--accent); }
.resume-title { font-family: var(--font-serif); font-size: var(--text-lg); font-weight: 600; margin: 0.15rem 0; }
.resume-excerpt { font-family: var(--font-serif); color: var(--text-muted); font-size: var(--text-base); line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.resume-card .btn { margin-left: auto; flex-shrink: 0; }
.project-card-title { font-family: var(--font-serif); font-size: var(--text-lg); font-weight: 600; color: var(--text); }
.project-card-premise { font-size: var(--text-sm); color: var(--text-muted); margin: var(--space-1) 0 var(--space-3); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--space-5); align-items: start; }
.bible-glance { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: var(--space-2); }
.cast-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--space-2); }
.cast-card { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text); min-width: 0; }
.cast-card:hover { border-color: var(--border-strong); color: var(--text); }
.cast-text { display: flex; flex-direction: column; min-width: 0; }
.cast-name { font-weight: 600; font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cast-sub { font-size: var(--text-xs); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bible-glance a { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3); border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text); font-size: var(--text-sm); }
.bible-glance a:hover { border-color: var(--border-strong); color: var(--text); }
.bible-glance .count { margin-left: auto; color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* ---------- Writing studio ---------- */
.studio { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; height: 100vh; }
.studio-outline { width: 220px; border-right: 1px solid var(--border); background: var(--surface-sunken); overflow-y: auto; padding: var(--space-4) var(--space-2); }
.studio-outline-title { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); padding: 0 var(--space-2); margin-bottom: var(--space-2); display: flex; align-items: center; justify-content: space-between; }
.outline-item { display: block; padding: 0.4rem var(--space-2); border-radius: var(--radius-sm); text-decoration: none; color: var(--text-muted); font-size: var(--text-sm); line-height: 1.35; }
.outline-item:hover { background: var(--surface-hover); color: var(--text); }
.outline-item.current { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }
.outline-item .num { color: var(--text-faint); font-variant-numeric: tabular-nums; margin-right: 0.35rem; }
.studio-main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.studio-toolbar { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--border); background: var(--bg); min-height: 52px; }
.studio-toolbar .breadcrumb { min-width: 0; flex-wrap: nowrap; overflow: hidden; white-space: nowrap; }
.studio-toolbar .breadcrumb a { overflow: hidden; text-overflow: ellipsis; }
.studio-toolbar .breadcrumb { margin: 0; }
.studio-toolbar .spacer { flex: 1; }
.studio-scroll { flex: 1; overflow-y: auto; }
.manuscript { max-width: var(--manuscript-width); margin: 0 auto; padding: var(--space-6) var(--space-5) 30vh; }
.manuscript-title { width: 100%; border: none; background: transparent; font-family: var(--font-serif); font-size: var(--text-2xl); font-weight: 600; letter-spacing: -0.02em; color: var(--text); padding: 0; margin-bottom: var(--space-1); }
.manuscript-title:hover, .manuscript-title:focus { border: none; box-shadow: none; }
.manuscript-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--text-faint); margin-bottom: var(--space-5); }
.manuscript-text { width: 100%; border: none; background: transparent; box-shadow: none; padding: 0; resize: none; field-sizing: content; min-height: 60vh; font-family: var(--font-prose); font-size: var(--prose-size); line-height: var(--prose-leading); color: var(--text); }
.manuscript-text:hover, .manuscript-text:focus { border: none; box-shadow: none; }
.manuscript-read { font-family: var(--font-prose); font-size: var(--prose-size); line-height: var(--prose-leading); white-space: pre-wrap; color: var(--text); }
.chapter-content { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); font-family: var(--font-serif); line-height: 1.8; white-space: pre-wrap; }
.studio-details { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); padding: var(--space-4); margin-bottom: var(--space-5); }
.studio-section { margin-top: var(--space-7); padding-top: var(--space-5); border-top: 1px solid var(--border); }
.studio-section > summary { cursor: pointer; font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); }

.studio-panel { width: 340px; border-left: 1px solid var(--border); background: var(--surface-sunken); display: flex; flex-direction: column; height: 100vh; min-width: 0; }
.studio-panel .tabs { padding: 0 var(--space-3); background: var(--surface-sunken); }
.studio-panel-body { flex: 1; overflow-y: auto; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-5); }

.panel-section { display: flex; flex-direction: column; gap: var(--space-2); }
.panel-heading { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); margin: 0; }
details.panel-section > summary.panel-heading { cursor: pointer; }
.panel-entity { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.75rem; background: var(--surface); display: flex; flex-direction: column; gap: 0.2rem; font-size: var(--text-sm); }
.panel-entity-head { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; font-weight: 600; }
.panel-entity-head a { color: var(--text); text-decoration: none; }
.panel-entity-head a:hover { color: var(--accent); text-decoration: underline; }
.panel-fact { line-height: 1.45; color: var(--text); }
.panel-fact-label { color: var(--text-faint); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; margin-right: 0.25rem; }
.panel-fact-value { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.panel-alias-edit { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.panel-alias-edit input { flex: 1 1 8rem; min-width: 0; }
.panel-thread { display: flex; align-items: baseline; gap: 0.4rem; flex-wrap: wrap; font-size: var(--text-sm); }
.panel-idea { font-size: var(--text-sm); padding: 0.4rem 0.6rem; border-left: 2px solid var(--accent); background: var(--surface); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.panel-capture { min-height: 3.2rem; font-size: var(--text-sm); }

.ai-card { border: 1px solid var(--border); border-left: 3px solid var(--ai); border-radius: var(--radius); background: var(--surface); padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.ai-label { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ai); }
.ai-card-text { font-family: var(--font-serif); font-size: 0.95rem; line-height: 1.6; color: var(--text); white-space: pre-wrap; }
.ai-actions { display: flex; flex-wrap: wrap; gap: var(--space-1); }

/* Legacy two-column chapter layout (kept for any page still using it) */
.chapter-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--space-5); align-items: start; }
.chapter-main { min-width: 0; }
.chapter-panel { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.chapter-details { margin-bottom: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.8rem; background: var(--surface); }
.chapter-details > summary { cursor: pointer; font-weight: 600; font-size: var(--text-base); }

/* ---------- Ploto chat ---------- */
.chat-container { display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 420px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; box-shadow: var(--shadow-sm); }
.chat-messages { flex: 1; overflow-y: auto; padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-3); }
.chat-message { display: flex; }
.chat-message.user { justify-content: flex-end; }
.chat-message.assistant { justify-content: flex-start; }
.chat-bubble { max-width: 78%; padding: 0.65rem 0.95rem; border-radius: 14px; line-height: 1.55; font-size: var(--text-base); }
.chat-message.user .chat-bubble { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.chat-message.assistant .chat-bubble { background: var(--bg); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-markdown > *:first-child { margin-top: 0; }
.chat-markdown > *:last-child { margin-bottom: 0; }
.chat-markdown p { margin: 0 0 0.6em; }
.chat-markdown ul, .chat-markdown ol { margin: 0 0 0.6em; padding-left: 1.3em; }
.chat-markdown li { margin: 0.2em 0; }
.chat-markdown code { background: var(--surface-hover); border-radius: 4px; padding: 0.1em 0.35em; font-size: 0.85em; }
.chat-markdown pre { background: var(--surface-hover); border: 1px solid var(--border); border-radius: 8px; padding: 0.6em 0.8em; overflow-x: auto; margin: 0 0 0.6em; }
.chat-markdown pre code { background: none; padding: 0; }
.chat-markdown blockquote { border-left: 3px solid var(--border-strong); margin: 0 0 0.6em; padding-left: 0.8em; color: var(--text-muted); }
.chat-typing { color: var(--text-muted); font-style: italic; }
.chat-input-bar { display: flex; gap: var(--space-2); padding: var(--space-3); border-top: 1px solid var(--border); background: var(--surface); }
.chat-input-bar textarea { flex: 1; min-height: 44px; max-height: 160px; resize: vertical; }
.chat-input-bar .btn { align-self: flex-end; }
.chat-history-select { max-width: 16rem; min-width: 0; width: auto; padding: 0.45rem 0.6rem; font-size: var(--text-sm); }
.proposal-list { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-1) 0 var(--space-1) var(--space-4); }
.proposal-card { margin-bottom: 0; border-left: 3px solid var(--ai); }

/* ---------- Review: patches & diagnostics ---------- */
.patch-change { border-left: 2px solid var(--border-strong); padding-left: var(--space-3); display: flex; flex-direction: column; gap: 0.35rem; }
.patch-diff { background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.75rem; white-space: pre-wrap; line-height: 1.6; font-size: var(--text-base); max-height: 22rem; overflow-y: auto; }
.patch-diff del { background: var(--danger-tint); color: var(--danger); text-decoration: line-through; }
.patch-diff ins { background: var(--success-tint); color: var(--success); text-decoration: none; }
.patch-warning { color: var(--warning); font-size: var(--text-sm); }
.diag-group { margin-bottom: var(--space-5); }
.diag-group-title { font-weight: 600; margin-bottom: var(--space-2); text-transform: uppercase; font-size: var(--text-xs); letter-spacing: 0.06em; color: var(--text-faint); }

/* ---------- Other existing pages ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-5); }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4); text-align: center; }
.stat-value { font-family: var(--font-serif); font-size: 1.75rem; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-label { font-size: var(--text-xs); color: var(--text-muted); margin-top: 0.2rem; }
.search-bar { display: flex; gap: var(--space-2); margin-bottom: var(--space-4); }
.search-bar input { flex: 1; font-size: var(--text-md); padding: 0.65rem 0.85rem; }
.timeline-split { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); align-items: start; }
.timeline-column { min-width: 0; }
.timeline-column-title { font-family: var(--font-serif); font-size: var(--text-md); font-weight: 600; margin-bottom: 0.15rem; }
.timeline-column-hint { font-size: var(--text-xs); color: var(--text-muted); margin-bottom: var(--space-3); }
.drag-card { cursor: grab; }
.drag-card.dragging { opacity: 0.4; cursor: grabbing; }
.drag-card.drag-over { border-color: var(--accent); background: var(--accent-tint); }
.drag-handle { color: var(--text-faint); margin-right: 0.4rem; letter-spacing: -2px; }
.battle-board { display: flex; gap: var(--space-4); overflow-x: auto; padding-bottom: var(--space-2); }
.battle-side-column { flex: 0 0 220px; min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-3); }
.battle-side-column.drag-over { border-color: var(--accent); background: var(--accent-tint); }
.battle-side-column h3 { font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--space-2); display: flex; align-items: center; gap: 0.4rem; }
.battle-side-column .card { margin-bottom: var(--space-2); padding: 0.5rem 0.6rem; }
.battle-side-column .card input { margin-top: 0.3rem; font-size: var(--text-xs); padding: 0.3rem 0.5rem; }
.battle-side-add { flex: 0 0 180px; min-width: 180px; background: transparent; border: 1px dashed var(--border-strong); }
.nav-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--space-3); }
.nav-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4); text-align: center; text-decoration: none; color: var(--text); display: block; }
.nav-card:hover { border-color: var(--border-strong); color: var(--text); }
.nav-card-icon { color: var(--accent); margin-bottom: var(--space-2); display: flex; justify-content: center; }
.nav-card-icon .icon { width: 22px; height: 22px; }
.nav-card-label { font-size: var(--text-sm); font-weight: 600; }
.recent-list { list-style: none; }
.recent-item { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); padding: 0.55rem 0; border-bottom: 1px solid var(--border); font-size: var(--text-sm); }
.recent-item:last-child { border-bottom: none; }
.appears-in a { font-weight: 600; text-decoration: none; padding: 0 0.15rem; }
.appears-in a:hover { text-decoration: underline; }

/* ---------- Public pages (landing, sign in) ---------- */
.public-layout { min-height: 100vh; display: flex; flex-direction: column; }
.public-header { padding: var(--space-4) var(--space-6); display: flex; justify-content: space-between; align-items: center; }
.public-header .brand { margin-bottom: 0; }
.public-content { flex: 1; display: flex; flex-direction: column; align-items: center; padding: var(--space-6) var(--space-4); }
.hero-glow { display: none; }
.eyebrow { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.25rem 0.7rem; border-radius: 999px; background: var(--accent-tint); color: var(--accent); font-size: var(--text-xs); font-weight: 600; margin-bottom: var(--space-4); }
.landing-hero { max-width: 680px; text-align: center; margin: var(--space-7) auto var(--space-6); }
.landing-hero h1 { font-family: var(--font-serif); font-size: 3rem; font-weight: 600; letter-spacing: -0.025em; line-height: 1.1; margin-bottom: var(--space-4); color: var(--text); }
.landing-tagline { color: var(--text-muted); font-size: 1.1rem; line-height: 1.65; margin: 0 auto var(--space-6); max-width: 560px; }
.landing-actions { display: flex; gap: var(--space-3); justify-content: center; flex-wrap: wrap; }
.landing-actions .btn { padding: 0.7rem 1.5rem; font-size: var(--text-md); }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-4); max-width: 920px; width: 100%; margin: var(--space-4) auto var(--space-7); }
.feature-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5); text-align: left; }
.feature-icon { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-tint); color: var(--accent); display: flex; align-items: center; justify-content: center; margin-bottom: var(--space-3); }
.feature-icon .icon { width: 18px; height: 18px; }
.feature-title { font-family: var(--font-serif); font-size: var(--text-md); font-weight: 600; margin-bottom: 0.3rem; }
.feature-desc { font-size: var(--text-sm); color: var(--text-muted); line-height: 1.55; }
.public-content .inline-form { box-shadow: var(--shadow-md); }
[id^="google-signin-btn"] { max-width: 100%; overflow: hidden; display: flex; justify-content: center; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
    .studio-outline { display: none; }
    .studio-outline.open { display: block; position: fixed; left: 0; top: 0; bottom: 0; z-index: 30; box-shadow: var(--shadow-lg); }
}
@media (max-width: 1100px) {
    .chapter-workspace { grid-template-columns: minmax(0, 1fr); }
    .studio-panel.open { position: fixed; right: 0; top: 0; bottom: 0; z-index: 30; box-shadow: var(--shadow-lg); width: min(380px, 92vw); }
    .overview-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 780px) {
    .mobile-topbar { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-4); background: var(--surface-sunken); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
    .layout { display: block; height: auto; min-height: 100%; overflow: visible; }
    .sidebar { position: fixed; top: 0; left: 0; height: 100vh; height: 100dvh; width: 270px; max-width: 82vw; transform: translateX(-100%); z-index: 50; }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(20, 16, 10, 0.45); z-index: 40; }
    .content { overflow: visible; }
    .content-inner { padding: var(--space-5) var(--space-4) var(--space-6); }
    .grid-2 { grid-template-columns: 1fr; }
    .page-title { font-size: 1.4rem; }
    .welcome { font-size: 1.6rem; }
    .landing-hero { margin-top: var(--space-5); }
    .landing-hero h1 { font-size: 2.2rem; }
    .studio { display: block; height: auto; }
    .studio-main { height: auto; }
    .studio-toolbar { position: sticky; top: var(--topbar-h); z-index: 10; padding: var(--space-2) var(--space-3); gap: var(--space-1); }
    .studio-toolbar .breadcrumb, .studio-toolbar .word-count { display: none; }
    .studio-scroll { overflow: visible; }
    .manuscript { padding: var(--space-4) var(--space-4) var(--space-7); }
    .manuscript-title { font-size: 1.6rem; }
    .manuscript-text, .manuscript-read { font-size: calc(var(--prose-size) * 0.94); }
    .studio-panel { height: auto; }
    .resume-card { flex-direction: column; align-items: flex-start; }
    .resume-card .btn { margin-left: 0; }
    .timeline-split { grid-template-columns: 1fr; }
    .chat-container { height: calc(100dvh - 230px); }
    .chat-bubble { max-width: 90%; }
    .toaster { left: var(--space-4); right: var(--space-4); bottom: var(--space-4); }
    .public-header { padding: var(--space-3) var(--space-4); }
}

/* A section title with a link on the right ("Cast · All characters"); spaced like a section title. */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); margin: var(--space-6) 0 var(--space-3); }
.section-head:first-child { margin-top: 0; }
.section-head > .section-title { margin: 0; }

/* Overview hero: title + premise beside an at-a-glance card; the page runs wider than other pages. */
.content-inner:has(> .overview-page) { max-width: 1480px; }
.overview-hero { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--space-5); align-items: end; margin-bottom: var(--space-5); }
.premise { color: var(--text-muted); font-size: var(--text-md); margin-top: var(--space-3); max-width: 75ch; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; line-clamp: 4; overflow: hidden; }
.premise.open { display: block; -webkit-line-clamp: unset; }
.link-btn { background: none; border: 0; padding: 0; margin-top: var(--space-1); color: var(--accent); font: inherit; font-size: var(--text-sm); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.glance-card { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-4); border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); }
.glance-card > .btn { align-self: flex-end; }
.glance-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2); }
.glance-stats > div { display: flex; flex-direction: column; min-width: 0; }
.glance-stats strong { font-size: var(--text-xl); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); line-height: 1.2; }
.glance-stats span { font-size: var(--text-xs); color: var(--text-muted); }
@media (max-width: 900px) {
    .overview-hero { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
    .glance-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.mobile-topbar .brand { margin-bottom: 0; padding: 0; }

/* Ploto's sources: the story passages a reply drew on */
sup.cite { font-family: var(--font-ui); font-size: 0.68em; font-weight: 600; color: var(--accent); background: var(--accent-tint); border-radius: 3px; padding: 0 0.25em; margin-left: 1px; cursor: default; }
.sources { margin-top: var(--space-3); padding-top: var(--space-2); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.15rem; font-size: var(--text-sm); }
.sources-heading { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-faint); }
.sources details > summary { cursor: pointer; margin-top: var(--space-1); }
.source { display: flex; gap: var(--space-2); padding: 0.35rem 0.4rem; margin: 0 -0.4rem; border-radius: var(--radius); color: inherit; text-decoration: none; }
.source:hover { background: var(--surface-hover); }
.source-num { flex-shrink: 0; min-width: 1.3em; height: 1.3em; display: inline-flex; align-items: center; justify-content: center; font-size: 0.72rem; font-weight: 600; color: var(--accent); background: var(--accent-tint); border-radius: 3px; margin-top: 0.15rem; }
.source-body { display: flex; flex-direction: column; min-width: 0; }
.source-label { font-weight: 600; }
.source-excerpt { color: var(--text-muted); font-family: var(--font-serif); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Continuity findings */
.finding { border: 1px solid var(--border); border-left: 3px solid var(--warning); border-radius: var(--radius); padding: var(--space-3); background: var(--surface); display: flex; flex-direction: column; gap: var(--space-2); }
.finding-high { border-left-color: var(--danger); }
.finding-low { border-left-color: var(--border-strong); }
.finding.dismissed { opacity: 0.7; border-left-color: var(--border); }
.finding-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2); }
.finding-title { font-weight: 600; }
.finding-severity { margin-left: auto; }
.finding-explanation { margin: 0; line-height: 1.5; font-size: var(--text-sm); }
.finding-quote { display: flex; flex-direction: column; gap: 0.1rem; text-align: left; width: 100%; background: var(--surface-sunken); border: 1px solid transparent; border-radius: var(--radius); padding: 0.4rem 0.6rem; font: inherit; color: inherit; cursor: pointer; }
.finding-quote:hover { border-color: var(--border-strong); }
.finding-quote-source { font-size: var(--text-xs); font-weight: 600; color: var(--text-faint); letter-spacing: 0.04em; text-transform: uppercase; }
.finding-quote-text { font-family: var(--font-serif); line-height: 1.5; font-size: var(--text-sm); }
.finding-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.finding-actions input { flex: 1 1 14rem; }
.finding-list { display: flex; flex-direction: column; gap: var(--space-3); }
.check-chapters { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.check-chapter { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.check-chapter:last-child { border-bottom: none; }
.check-chapter .num { font-variant-numeric: tabular-nums; color: var(--text-faint); min-width: 2.5ch; }
.check-chapter .title { font-weight: 600; flex: 1 1 auto; min-width: 0; }
.finding-quote.static { cursor: default; }
.finding-quote.static:hover { border-color: transparent; }

/* Passages a canon change affects */
.impact { margin-top: var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: var(--space-2); }
.impact-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); }
.impact-title { font-weight: 600; }
.impact-passage { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-2) 0; }
.impact-passage input[type=checkbox] { width: auto; margin-top: 0.3rem; flex-shrink: 0; }
.impact-passage.done .impact-body { opacity: 0.55; }
.impact-body { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; flex: 1 1 auto; }
.impact-meta { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

/* Plot threads through the manuscript */
.thread-track { display: flex; flex-wrap: wrap; gap: 0.25rem var(--space-4); font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-2); }
.chapter-chip { display: inline-flex; align-items: center; justify-content: center; min-width: 1.6em; height: 1.4em; padding: 0 0.3em; margin-left: 0.2em; border-radius: 3px; background: var(--accent-tint); color: var(--accent); font-size: var(--text-xs); font-weight: 600; text-decoration: none; font-variant-numeric: tabular-nums; }
.chapter-chip:hover { background: var(--accent-tint-strong); }
.chat-chapter-label { display: block; font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.04em; opacity: 0.8; margin-bottom: 0.2rem; }

/* Craft guide */
.craft-filters { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-5); }
.craft-card { display: block; color: inherit; text-decoration: none; }
.craft-card:hover { border-color: var(--border-strong); }
.craft-card:hover .card-title { color: var(--accent); }
.craft-detail { max-width: var(--prose-width); display: flex; flex-direction: column; gap: var(--space-4); }
.craft-prose { font-family: var(--font-serif); font-size: 1rem; line-height: 1.7; margin: 0; }
.craft-section-title { font-weight: 600; text-transform: uppercase; font-size: var(--text-xs); letter-spacing: 0.06em; color: var(--text-faint); margin-bottom: var(--space-2); }
.craft-example { background: var(--surface-sunken); border-left: 3px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0; padding: var(--space-3) var(--space-4); }
.craft-try { background: var(--accent-tint); border-radius: var(--radius); padding: var(--space-3) var(--space-4); }
.craft-try p { margin: 0; line-height: 1.55; }
.craft-list { margin: 0; padding-left: 1.2em; line-height: 1.6; }
.craft-list li { margin: 0.2em 0; }
.craft-related { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.craft-disclaimer { font-style: italic; }
.craft-tip { display: flex; align-items: flex-start; gap: 0.45rem; font-size: var(--text-sm); line-height: 1.45; color: var(--text); text-decoration: none; padding: 0.45rem 0.6rem; border-radius: var(--radius-sm); background: var(--accent-tint); }
.craft-tip:hover { background: var(--accent-tint-strong); }
.craft-tip .icon { color: var(--accent); flex-shrink: 0; margin-top: 0.1rem; }
.craft-tip strong { font-weight: 600; }
.craft-tip-line { color: var(--text-muted); }

/* Story shape (three-act bar) */
.story-shape { display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-5); }
.story-shape-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-2); }
.story-shape-planned { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-muted); margin: 0; }
.story-shape-planned input { width: 4.5rem; padding: 0.3rem 0.45rem; }
/* Labels sit in the top half and chapter ticks in the bottom half, so ticks never cover a label. */
.act-bar { position: relative; display: flex; height: 2.75rem; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.act-band { display: flex; align-items: flex-start; padding-top: 0.3rem; justify-content: center; font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.04em; color: var(--text-faint); text-transform: uppercase; }
.act-band + .act-band { border-left: 1px dashed var(--border-strong); }
.act-1, .act-3 { background: var(--surface-sunken); }
.act-2 { background: var(--surface); }
.act-band span { pointer-events: none; }
.act-tick { position: absolute; bottom: 0.3rem; height: 0.95rem; width: 4px; margin-left: -2px; border-radius: 2px; background: var(--border-strong); }
.act-tick:hover { background: var(--accent); }
.act-tick.beat { background: var(--accent); width: 6px; margin-left: -3px; }
.act-beats { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.story-shape-hint { display: flex; flex-direction: column; gap: var(--space-2); border-left: 3px solid var(--warning); padding-left: var(--space-3); }
.story-shape-hint p { margin: 0; font-size: var(--text-sm); line-height: 1.5; }
.story-shape-acts summary { cursor: pointer; font-size: var(--text-sm); font-weight: 600; color: var(--text-muted); }
.story-shape-acts p { font-size: var(--text-sm); line-height: 1.5; margin: var(--space-2) 0; }
.story-shape-line { margin-bottom: var(--space-3); }
.story-shape-line .icon { color: var(--accent); }

/* Craft tab (chapter side panel) */
.studio-panel .tabs { overflow-x: auto; scrollbar-width: none; }
.studio-panel .tab { padding: 0.5rem 0.55rem; flex-shrink: 0; }
.craft-panel-text { margin: 0; font-size: var(--text-sm); line-height: 1.5; }
.craft-signal { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3); border: 1px solid var(--border); border-left: 3px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); }
.craft-signal.look { border-left-color: var(--warning); }
.craft-signal-head { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; font-size: var(--text-sm); }
.craft-signal-hide { margin-left: auto; padding: 0.15rem; }
.craft-note { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3); border: 1px solid var(--border); border-left: 3px solid var(--ai); border-radius: var(--radius); background: var(--surface); }
.craft-note.strength { border-left-color: var(--success); }
.craft-note.dismissed { opacity: 0.6; }
.craft-note-suggestion { color: var(--text-muted); }
.chat-markdown a.craft-link { color: inherit; text-decoration: underline dotted var(--accent); text-underline-offset: 3px; }
.chat-markdown a.craft-link:hover { color: var(--accent); }

/* Screens that snap on a phone (the Overview): each fills the screen; a small scroll springs back,
   a swipe moves exactly one screen. On wider layouts they're plain blocks. */
@media (min-width: 781px) {
    .mobile-only { display: none !important; }
    .snap-screen + .snap-screen > .section-head:first-child { margin-top: var(--space-6); }
}
.snap-next { display: flex; align-items: center; justify-content: center; gap: 0.3rem; align-self: center; margin-top: auto; padding: var(--space-4) var(--space-3) 0; background: none; border: 0; font: inherit; font-size: var(--text-sm); font-weight: 600; color: var(--text-muted); cursor: pointer; }
.snap-next .icon { transform: rotate(90deg); }
@media (max-width: 780px) {
    .desktop-only { display: none !important; }
    html:has(.snap-screens) { scroll-snap-type: y mandatory; scroll-padding-top: var(--topbar-h); }
    /* Typing (the keyboard opening, the browser scrolling the field into view) must never fight the snapping. */
    html:has(.snap-screens :is(input, textarea, select):focus) { scroll-snap-type: none; }
    .content-inner:has(> .snap-screens) { padding-top: 0; padding-bottom: 0; }
    .snap-screen { min-height: calc(100svh - var(--topbar-h)); scroll-snap-align: start; scroll-snap-stop: always; display: flex; flex-direction: column; padding: var(--space-5) 0; }
    .snap-screen .resume-card { margin-bottom: var(--space-4) !important; }
    .overview-grid { gap: 0; }
}

/* World-building */
.world-summary { display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-5); }
.world-strip { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.world-chip { border: 1px solid var(--border); border-radius: 999px; padding: 0.2rem 0.65rem; font: inherit; font-size: var(--text-xs); font-weight: 600; cursor: pointer; background: var(--surface); color: var(--text-muted); }
.world-chip.open { background: var(--warning-tint); color: var(--warning); border-color: transparent; }
.world-chip.touched { background: var(--accent-tint); color: var(--accent); border-color: transparent; }
.world-chip.developed { background: var(--success-tint); color: var(--success); border-color: transparent; }
.world-section { margin-bottom: var(--space-6); }
.world-section > .card-meta { margin-bottom: var(--space-3); }
.world-dimensions { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: var(--space-4); align-items: start; }
.world-dimension { margin-bottom: 0; display: flex; flex-direction: column; gap: var(--space-3); scroll-margin-top: var(--space-5); }
.world-questions { display: flex; flex-direction: column; gap: var(--space-2); }
.world-question { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.world-dimension .world-question { background: var(--bg); }
.world-question.from-ploto { border-left: 3px solid var(--ai); }
.world-question-text { margin: 0; font-family: var(--font-serif); line-height: 1.5; }
.world-based-on { gap: 0.35rem; }
.world-answer { min-height: 5rem; font-size: var(--text-sm); }
@media (max-width: 780px) {
    .world-dimensions { grid-template-columns: minmax(0, 1fr); }
    .world-dimension { scroll-margin-top: calc(var(--topbar-h) + var(--space-3)); }
}

/* Canon / tentative */
.badge-tentative { background: transparent; color: var(--text-muted); border: 1px dashed var(--border-strong); font-style: italic; }
.canon-toggle { font-size: var(--text-xs); font-weight: 600; margin-left: 0.35rem; }
.canon-toggle.quiet { color: var(--text-faint); font-weight: 500; }
.canon-toggle.quiet:hover { color: var(--accent); }

/* Rename everywhere (Proposed changes) */
.rename-form { margin-top: var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: var(--space-2); }
.rename-form > label { font-weight: 600; font-size: var(--text-sm); }
.rename-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.rename-row input { flex: 1 1 10rem; min-width: 0; }

/* ---------- Writer avatar ---------- */
.avatar.writer { --av: var(--av-ink); background: color-mix(in srgb, var(--av) 16%, transparent); color: var(--av); font-family: var(--font-serif); letter-spacing: 0.02em; }
.avatar.av-plum { --av: var(--av-plum); } .avatar.av-moss { --av: var(--av-moss); } .avatar.av-rust { --av: var(--av-rust); }
.avatar.av-ochre { --av: var(--av-ochre); } .avatar.av-slate { --av: var(--av-slate); } .avatar.av-rose { --av: var(--av-rose); }
.avatar.av-teal { --av: var(--av-teal); }
.avatar.sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar.lg { width: 64px; height: 64px; font-size: 1.4rem; }
.sidebar-me { display: flex; align-items: center; gap: var(--space-2); padding: 0.35rem 0.5rem; border-radius: var(--radius-sm); text-decoration: none; color: var(--text); min-width: 0; }
.sidebar-me:hover { background: var(--surface-hover); color: var(--text); }
.sidebar-me.active { background: var(--surface); box-shadow: var(--shadow-sm); }
.sidebar-me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.sidebar-me-name { font-weight: 600; font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-me-sub { font-size: var(--text-xs); color: var(--text-faint); }

/* ---------- Settings ---------- */
.settings-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--space-6); align-items: start; }
.settings-nav { position: sticky; top: var(--space-4); display: flex; flex-direction: column; gap: 2px; }
.settings-body { max-width: 720px; min-width: 0; }
.settings-intro { color: var(--text-muted); font-size: var(--text-base); margin-bottom: var(--space-5); max-width: 62ch; }
.settings-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5); margin-bottom: var(--space-4); box-shadow: var(--shadow-sm); }
.settings-card > h2 { font-family: var(--font-serif); font-size: var(--text-lg); font-weight: 600; margin-bottom: 0.2rem; }
.settings-card > .card-lede { color: var(--text-muted); font-size: var(--text-sm); margin-bottom: var(--space-4); max-width: 62ch; }
.settings-card.danger { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
/* Plan & usage */
.usage-row { margin-bottom: var(--space-3); }
.usage-label { display: flex; justify-content: space-between; gap: var(--space-2); font-size: var(--text-sm); margin-bottom: 0.3rem; }
.usage-label span:last-child { color: var(--text-muted); }
.meter { height: 8px; border-radius: 999px; background: var(--surface-hover); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.plan-features { margin: 0 0 var(--space-4); padding-left: 1.2rem; display: grid; gap: 0.3rem; font-size: var(--text-sm); }
.plan-options { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-2); }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); padding: var(--space-3) 0; border-top: 1px solid var(--border); }
.setting-row:first-of-type { border-top: none; padding-top: 0; }
.setting-row-text { min-width: 0; }
.setting-row-title { font-weight: 600; font-size: var(--text-sm); color: var(--text); }
.setting-row-hint { font-size: var(--text-xs); color: var(--text-muted); margin-top: 0.1rem; }
.settings-savebar { position: sticky; bottom: var(--space-3); display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); margin-top: var(--space-4); border-radius: var(--radius-lg); background: var(--surface-raised); border: 1px solid var(--border-strong); box-shadow: var(--shadow-md); z-index: 5; }
.settings-savebar .spacer { flex: 1; }
.settings-savebar .save-status { font-size: var(--text-sm); }
.status-pill { display: inline-flex; align-items: center; gap: 0.3rem; font-size: var(--text-xs); font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 999px; }
.status-pill.ok { background: var(--success-tint); color: var(--success); }
.status-pill.warn { background: var(--warning-tint); color: var(--warning); }
.status-pill.off { background: var(--surface-hover); color: var(--text-muted); }

/* Choice cards: a radio group that reads like a set of options rather than a form. */
.choice-group { border: none; padding: 0; margin: 0 0 var(--space-4); min-width: 0; }
.choice-group > legend { font-size: var(--text-sm); font-weight: 500; color: var(--text); margin-bottom: 0.4rem; padding: 0; }
.choice-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(var(--choice-min, 140px), 1fr)); gap: var(--space-2); }
.choice { position: relative; display: flex; flex-direction: column; gap: 0.1rem; padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-raised); cursor: pointer; margin: 0; font-weight: 400; transition: border-color 0.12s, background 0.12s, box-shadow 0.12s; }
.choice:hover { border-color: var(--border-strong); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-label { font-weight: 600; font-size: var(--text-sm); color: var(--text); }
.choice-hint { font-size: var(--text-xs); color: var(--text-muted); line-height: 1.4; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-tint); box-shadow: inset 0 0 0 1px var(--accent); }
.choice:has(input:focus-visible) { box-shadow: var(--focus-ring), inset 0 0 0 1px var(--accent); }
.choice-group.compact .choice { padding: 0.45rem 0.6rem; align-items: center; text-align: center; }

/* Switch: a checkbox with role="switch", so screen readers announce on/off. */
.switch { position: relative; display: inline-flex; flex-shrink: 0; width: 40px; height: 22px; margin: 0; cursor: pointer; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; width: 100%; height: 100%; }
.switch-track { width: 100%; height: 100%; border-radius: 999px; background: var(--border-strong); transition: background 0.15s; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface-raised); box-shadow: var(--shadow-sm); transition: transform 0.15s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus-ring); }

/* Tag picker: suggested tags to toggle, plus the writer's own. */
.tag-picker { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.25rem 0.65rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-raised); color: var(--text-muted); font: inherit; font-size: var(--text-xs); font-weight: 500; cursor: pointer; }
.tag:hover { border-color: var(--border-strong); color: var(--text); }
.tag[aria-pressed="true"] { background: var(--accent-tint); border-color: var(--accent); color: var(--accent); }
.tag .icon { width: 12px; height: 12px; vertical-align: -1px; }
.tag-add { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
.tag-add input { flex: 1; min-width: 0; }

.swatches { display: flex; flex-wrap: wrap; gap: var(--space-2); border: none; padding: 0; margin: 0; }
.swatch { position: relative; width: 30px; height: 30px; border-radius: 50%; margin: 0; cursor: pointer; background: var(--av); box-shadow: inset 0 0 0 2px var(--surface); border: 2px solid transparent; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch:has(input:checked) { border-color: var(--text); }
.swatch:has(input:focus-visible) { box-shadow: var(--focus-ring), inset 0 0 0 2px var(--surface); }
.identity-head { display: flex; gap: var(--space-4); align-items: center; margin-bottom: var(--space-4); }

.prose-preview { font-family: var(--font-prose); font-size: var(--prose-size); line-height: var(--prose-leading); max-width: var(--manuscript-width); color: var(--text); padding: var(--space-4); border-radius: var(--radius); background: var(--bg); border: 1px dashed var(--border-strong); margin-top: var(--space-2); }
.ai-preview { font-family: ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace; font-size: var(--text-xs); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3); margin: var(--space-2) 0 0; color: var(--text); }
.ai-preview-label { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-faint); margin-top: var(--space-3); }

.session-list { display: flex; flex-direction: column; }
.session-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; border-top: 1px solid var(--border); }
.session-row:first-child { border-top: none; padding-top: 0; }
.session-main { flex: 1; min-width: 0; }
.session-device { font-weight: 600; font-size: var(--text-sm); display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.session-meta { font-size: var(--text-xs); color: var(--text-muted); }
.contents-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-2); margin: var(--space-3) 0; padding: 0; list-style: none; }
.contents-list li { display: flex; flex-direction: column; padding: var(--space-2) var(--space-3); border-radius: var(--radius); background: var(--surface-sunken); }
.contents-list strong { font-size: var(--text-lg); font-variant-numeric: tabular-nums; }
.contents-list span { font-size: var(--text-xs); color: var(--text-muted); }

/* ---------- Home: today's writing ---------- */
.home-top { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: var(--space-4); margin-bottom: var(--space-6); align-items: stretch; }
.home-top > .resume-card { margin-bottom: 0 !important; }
.today-card { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.today-head { display: flex; align-items: center; gap: var(--space-3); }
.goal-ring { --pct: 0; width: 56px; height: 56px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--surface-hover) 0); }
.goal-ring.met { background: conic-gradient(var(--success) 100%, var(--success) 0); }
.goal-ring::before { content: ""; grid-area: 1 / 1; width: 44px; height: 44px; border-radius: 50%; background: var(--surface); }
.goal-ring > span { grid-area: 1 / 1; font-size: var(--text-xs); font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); z-index: 1; }
.today-words { font-family: var(--font-serif); font-size: var(--text-xl); font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.today-sub { font-size: var(--text-sm); color: var(--text-muted); }
.day-bars { display: grid; grid-template-columns: repeat(14, 1fr); gap: 3px; align-items: end; height: 36px; }
.day-bars > span { display: block; border-radius: 2px; background: var(--accent-tint-strong); min-height: 3px; }
.day-bars > span.hit { background: var(--accent); }
.day-bars > span.today { outline: 1px solid var(--accent); outline-offset: 1px; }
.today-tip { font-size: var(--text-sm); color: var(--text-muted); border-top: 1px solid var(--border); padding-top: var(--space-3); }

@media (max-width: 900px) {
    .settings-layout { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
    .settings-nav { position: static; flex-direction: row; overflow-x: auto; gap: var(--space-1); padding-bottom: var(--space-1); border-bottom: 1px solid var(--border); }
    .settings-nav .nav-link { white-space: nowrap; flex-shrink: 0; }
    .settings-nav .nav-link.active { box-shadow: inset 0 -2px 0 var(--accent); }
    .home-top { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
    .settings-card { padding: var(--space-4); }
    .setting-row { flex-direction: column; align-items: flex-start; }
}
