/* Design tokens. This block is the "Studio" skin in light mode; every other skin
   (css/themes.css) overrides the same tokens. Dark mode is [data-mode="dark"], which
   app.js resolves from the user's choice (auto/light/dark) and the system setting. */
:root {
  --bg: #f5f0e6;
  --surface: #fffdf8;
  --surface-2: #efe8da;
  --surface-3: #e7dfcd;
  --ink: #2a2520;
  --ink-2: #554d43;
  --muted: #877d70;
  --line: #e1d8c6;
  --line-strong: #cfc3ad;
  --accent: #b4532a;
  --accent-ink: #fffaf5;
  --accent-soft: #f4e2d6;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgb(60 40 20 / .06), 0 4px 14px rgb(60 40 20 / .06);
  --shadow-lg: 0 10px 40px rgb(40 25 10 / .18);

  --s-idea: #a39a88;
  --s-outlined: #5b7fa6;
  --s-drafting: #d49a2a;
  --s-revising: #8a6bb0;
  --s-done: #4f8a5b;

  --t-part: #4f6d5a;
  --t-chapter: #b4532a;
  --t-section: #8a7d6b;

  --ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Literata', 'Iowan Old Style', Georgia, serif;   /* reading & writing text */
  --display: var(--serif);                                  /* headings & titles */
  --display-w: 600;
  --ui-size: 14px;
  --editor-size: 19px;
  --prose-scale: 1;
  --prose-leading: 1.75;
  --prose-width: 820px;
  --radius: 10px;
  --radius-sm: 8px;
  --texture: none;                                          /* background-image over --bg */
  --glow: var(--accent-soft);                               /* welcome screen wash */
  --binder-bg: var(--surface-2);
  --topbar-bg: var(--surface);
  --note-mix: 38%;
  color-scheme: light;
}
:root[data-mode="dark"] {
  --bg: #1b1916; --surface: #23201c; --surface-2: #2c2823; --surface-3: #36312a;
  --ink: #ede6d9; --ink-2: #c7bdae; --muted: #948a7a; --line: #38332c; --line-strong: #4a443b;
  --accent: #e27d51; --accent-ink: #1b1916; --accent-soft: #3e2a1f; --danger: #f2887f;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 14px rgb(0 0 0 / .25);
  --shadow-lg: 0 10px 40px rgb(0 0 0 / .45);
  --s-idea: #8f8676; --t-part: #7fa38b; --t-chapter: #e27d51; --t-section: #a89a86;
  --note-mix: 20%;
  color-scheme: dark;
}
html.skin-switching, html.skin-switching * { transition: background-color .35s, color .35s, border-color .35s, box-shadow .35s !important; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--texture), var(--bg); background-attachment: fixed; color: var(--ink); font: var(--ui-size)/1.45 var(--ui); -webkit-font-smoothing: antialiased; }
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.eyebrow { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.eyebrow .icon { width: 13px; height: 13px; }
.empty { color: var(--muted); text-align: center; padding: 24px; }
kbd { font: 11px var(--ui); color: var(--muted); }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 500; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { color: var(--danger); }
.btn .icon { width: 14px; height: 14px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 500; font-size: 12.5px; }
.link:hover { text-decoration: underline; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-sm); border: 0; background: transparent; color: var(--ink-2); }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.small { width: 26px; height: 26px; }
:where(input:not([type=checkbox]):not([type=range]), select, textarea) {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 9px; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: none; line-height: 1.45; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- welcome ---------- */
.welcome { min-height: 100%; display: grid; place-items: center; padding: 32px 16px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--glow), transparent 60%), var(--texture), var(--bg); }
.welcome-card { max-width: 760px; text-align: center; }
.welcome-card .lede { max-width: 540px; margin-left: auto; margin-right: auto; }
.welcome h1 { font: var(--display-w) 44px/1.1 var(--display); margin: 18px 0 12px; letter-spacing: -.01em; }
.lede { font: 18px/1.55 var(--serif); color: var(--ink-2); margin: 0 0 28px; }
.welcome-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.welcome-actions .btn { justify-content: center; }
@media (max-width: 420px) { .welcome-actions { grid-template-columns: 1fr; } }
.welcome-actions .btn { padding: 11px 18px; font-size: 15px; }
.fine { color: var(--muted); font-size: 13px; margin-top: 28px; line-height: 1.55; }
.logo-blocks { display: inline-grid; grid-template-columns: 1fr 1fr; gap: 5px; width: 64px; }
.logo-blocks i { display: block; aspect-ratio: 1; border-radius: 5px; }
.logo-blocks i:nth-child(1) { grid-column: 1 / span 2; justify-self: center; width: calc(50% - 2.5px); background: var(--t-part); }
.logo-blocks i:nth-child(2) { background: var(--accent); }
.logo-blocks i:nth-child(3) { background: var(--s-drafting); }
.logo-blocks.small { width: 22px; gap: 2px; }
.logo-blocks.small i { border-radius: 2px; }
.logo-blocks.small i:nth-child(1) { width: calc(50% - 1px); }

/* bookshelf of recent projects */
.shelf { margin: 34px auto 0; max-width: min(760px, calc(100vw - 32px)); }
.shelf-head { display: flex; justify-content: center; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.shelf-row { display: flex; gap: 18px; justify-content: safe center; align-items: flex-end; overflow-x: auto; padding: 12px 12px 0;
  border-bottom: 9px solid color-mix(in srgb, var(--line-strong) 85%, var(--ink) 15%); box-shadow: 0 10px 12px -10px rgb(0 0 0 / .35); }
.book { --cover-bg: color-mix(in oklab, var(--cover) 80%, #000); position: relative; flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px; width: 118px; padding-bottom: 10px; }
[data-mode="dark"] .book { --cover-bg: color-mix(in oklab, var(--cover) 55%, #000); }
.book-cover { width: 118px; height: 158px; display: flex; flex-direction: column; gap: 6px; text-align: left; padding: 14px 10px 12px 15px; border: 0; color: #fffaf2;
  border-radius: 3px 8px 8px 3px; background: linear-gradient(90deg, rgb(0 0 0 / .28) 0 7px, rgb(255 255 255 / .12) 7px 8px, transparent 8px), var(--cover-bg);
  box-shadow: 0 2px 3px rgb(0 0 0 / .2), 0 8px 18px -6px rgb(0 0 0 / .35); transition: transform .2s, box-shadow .2s; }
.book-cover:hover, .book-cover:focus-visible { transform: translateY(-7px) rotate(-1.5deg); box-shadow: 0 4px 6px rgb(0 0 0 / .2), 0 16px 26px -8px rgb(0 0 0 / .4); }
.cover-title { font: var(--display-w) clamp(13px, 1.9vh, 15px)/1.2 var(--display); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow-wrap: break-word; hyphens: auto; }
.book-words { margin-top: auto; font-size: 11px; opacity: .8; font-variant-numeric: tabular-nums; }
.book-progress { height: 3px; border-radius: 2px; background: rgb(255 255 255 / .25); overflow: hidden; }
.book-progress i { display: block; height: 100%; background: #fffaf2; }
.book-when { font-size: 11px; color: var(--muted); }
.book-remove { position: absolute; top: -8px; right: -8px; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); display: grid; place-items: center; padding: 0; opacity: 0; transition: opacity .15s; }
.book-remove .icon { width: 12px; height: 12px; }
.book:hover .book-remove, .book:focus-within .book-remove { opacity: 1; }
@media (hover: none) { .book-remove { opacity: 1; } }

/* ---------- shell ---------- */
#app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; flex-direction: column; border-bottom: 1px solid var(--line); background: var(--topbar-bg); flex: none; position: relative; z-index: 10; }
.topbar-row { display: flex; align-items: center; gap: 10px; padding: 8px 14px; min-width: 0; }
.topbar-row + .topbar-row { padding-top: 0; }
button.brand { border: 0; background: none; border-radius: var(--radius-sm); padding: 4px; }
button.brand:hover { background: var(--surface-2); }

/* stage row: Desk · ①Gather ②Plan ③Draft ④Revise ⑤Share │ sub-views · guidance */
.stage-row { gap: 12px; }
.desk-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: var(--radius-sm); padding: 5px 11px; font-weight: 500; font-size: 13px; white-space: nowrap; }
.desk-btn .icon { width: 14px; height: 14px; }
.desk-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.desk-btn.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.stages { display: flex; align-items: center; counter-reset: none; }
.stage { position: relative; display: inline-flex; align-items: center; gap: 7px; border: 0; background: none; padding: 6px 10px 8px; border-radius: var(--radius-sm); color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; }
.stage + .stage::before { content: ''; position: absolute; left: -6px; top: 50%; width: 10px; height: 1px; background: var(--line-strong); }
.stage { margin-left: 4px; }
.stage::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: 2px; height: 2px; border-radius: 2px; background: linear-gradient(90deg, color-mix(in srgb, var(--s-done) 70%, transparent) var(--pct), var(--surface-3) var(--pct)); opacity: .9; }
.stage:hover { color: var(--ink); background: var(--surface-2); }
.stage-n { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid currentColor; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }
.stage.on { color: var(--ink); }
.stage.on .stage-n { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.subtabs { padding-left: 3px; }
.stage-row .subtabs { margin-left: 2px; }
.stage-guide { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 360px; }
.brand { display: grid; place-items: center; padding: 0 4px; }
.book-title { border: 1px solid transparent !important; background: transparent !important; font: var(--display-w) 16px var(--display) !important; max-width: 280px; box-shadow: none !important; }
.book-title:hover, .book-title:focus { border-color: var(--line) !important; background: var(--surface) !important; }
.tabs { display: flex; align-items: stretch; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.bar-cluster { display: flex; align-items: center; gap: 2px; padding-left: 8px; border-left: 1px solid var(--line); }
.tab { white-space: nowrap; border: 0; background: transparent; padding: 5px 13px; border-radius: calc(var(--radius-sm) - 2px); color: var(--ink-2); font-weight: 500; font-size: 13px; }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.status { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); }
.topbar-row .book-title { max-width: 360px; }
.status .total { font-variant-numeric: tabular-nums; white-space: nowrap; }
.status { flex: none; }
.status .saved { position: relative; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; cursor: default; border-radius: 6px; padding: 2px 4px; outline: none; }
.status .saved:hover, .status .saved:focus-visible { color: var(--ink-2); background: var(--surface-2); }
.saved-file { display: none; position: absolute; top: calc(100% + 8px); right: 0; z-index: 30; padding: 6px 10px; border-radius: 8px; background: var(--ink); color: var(--bg); font-size: 12px; font-style: normal; white-space: nowrap; box-shadow: var(--shadow-lg); }
.status .saved:hover .saved-file, .status .saved:focus-visible .saved-file { display: block; }
.status .saved .icon { color: var(--s-done); width: 14px; height: 14px; }
.status .saved.pending { font-style: italic; }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; min-width: 240px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 5px; }
.menu-pop > button { display: flex; width: 100%; justify-content: space-between; align-items: center; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: calc(var(--radius-sm) - 2px); }
.menu-pop > button:hover { background: var(--surface-2); }
.menu-pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu-pop.right { left: auto; right: 0; }
.look-pop { width: 340px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.look-foot { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 12px; }
.look-foot .seg-control, .kv .seg-control { margin: 0; justify-self: start; }
.seg-control button { display: inline-flex; align-items: center; gap: 5px; }
.seg-control button .icon { width: 13px; height: 13px; }
.seg-control button:disabled { opacity: .45; cursor: default; }

/* skin picker: each option previews its own colours and type, whatever skin is active */
.skin-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.skin-opt { display: flex; flex-direction: column; align-items: stretch; gap: 3px; padding: 4px 4px 7px; border: 1px solid transparent; border-radius: var(--radius-sm); background: none; text-align: left; }
.skin-opt:hover { background: var(--surface-2); }
.skin-opt.on { border-color: var(--accent); background: var(--accent-soft); }
.skin-swatch { position: relative; display: block; height: 58px; border-radius: calc(var(--radius-sm) - 2px); background: var(--sw-bg); border: 1px solid color-mix(in srgb, var(--sw-ink) 12%, transparent); overflow: hidden; margin-bottom: 3px; }
.sw-card { position: absolute; left: 10px; right: -6px; top: 10px; bottom: -6px; background: var(--sw-card); border-radius: 4px; box-shadow: 0 2px 8px rgb(0 0 0 / .12); padding: 6px 8px; display: flex; flex-direction: column; gap: 4px; }
.sw-card b { font: 500 17px/1 var(--sw-font); color: var(--sw-ink); }
.sw-card i { display: block; height: 3px; border-radius: 2px; background: color-mix(in srgb, var(--sw-ink) 22%, transparent); width: 80%; }
.sw-card i + i { width: 55%; background: var(--sw-accent); }
.skin-name { font-weight: 600; font-size: 12.5px; padding: 0 3px; }
.skin-vibe { font-size: 11px; color: var(--muted); line-height: 1.3; padding: 0 3px; }
dialog.settings .skin-picker { margin-bottom: 14px; }
.vibe { margin-top: 34px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.skin-picker.compact { grid-template-columns: repeat(5, 84px); justify-content: center; }
.skin-picker.compact .skin-swatch { height: 46px; }
.skin-picker.compact .skin-name { text-align: center; }
@media (max-width: 520px) { .skin-picker.compact { grid-template-columns: repeat(3, 84px); } }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 270px minmax(0, 1fr) 310px; }
body.focus .binder, body.focus .binder-tab, body.focus .inspector { display: none; }
body.focus .workspace { grid-template-columns: 1fr; }
body.focus .topbar { opacity: .25; transition: opacity .2s; }
body.focus .topbar:hover { opacity: 1; }
body.focus .direction, body.focus .crumbs, body.focus .contains, body.focus .write-foot { display: none; }

/* ---------- binder ---------- */
.binder { border-right: 1px solid var(--line); background: var(--binder-bg); display: flex; flex-direction: column; min-height: 0; }
.binder-search { position: relative; padding: 10px 10px 6px; }
.binder-search .icon { position: absolute; left: 20px; top: 50%; transform: translateY(-30%); color: var(--muted); width: 14px; height: 14px; }
.binder-search { display: flex; align-items: center; gap: 4px; }
.binder-search input { padding-left: 30px; background: var(--surface); order: 0; }
.binder-hide { order: 1; flex: none; color: var(--muted); }
.binder-hide:hover { color: var(--ink); }
.tree { position: relative; flex: 1; overflow: auto; padding: 4px 6px 16px; }
.row { position: relative; display: flex; align-items: center; gap: 6px; width: 100%; padding: 5px 8px 5px calc(6px + var(--depth, 0) * 16px); border-radius: 7px; cursor: pointer; border: 0; background: none; text-align: left; min-height: 30px; }
.row:hover { background: var(--surface-3); }
.row.selected { background: var(--surface); box-shadow: var(--shadow); }
.row.root { font-weight: var(--display-w); font-family: var(--display); font-size: 15px; margin-bottom: 4px; }
.row.type-part .row-title { font-weight: 600; }
.row.type-chapter .row-title { font-weight: 500; }
.row.type-section .row-title { color: var(--ink-2); }
.row-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .wc { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .type-icon { color: var(--muted); }
.row-actions { display: none; gap: 2px; }
.row-btn { border: 0; background: var(--surface); border-radius: 5px; width: 22px; height: 22px; padding: 0; display: grid; place-items: center; color: var(--ink-2); }
.row-btn:hover { color: var(--ink); background: var(--surface-3); }
.row-btn .icon { width: 13px; height: 13px; }
.row-btn:last-child .icon { stroke-width: 3.2; }
.row:hover .row-actions, .row:focus-within .row-actions, .row.ctx-target .row-actions { display: inline-flex; }
.row:hover .wc, .row:focus-within .wc, .row.ctx-target .wc { display: none; }
.row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.row.multi { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.row.multi.selected { background: color-mix(in srgb, var(--accent-soft) 70%, var(--surface)); }
.row.ctx-target:not(.selected):not(.multi) { background: var(--surface-3); }
.row.renaming { background: var(--surface); box-shadow: var(--shadow); }
.row-rename { flex: 1; min-width: 0; padding: 2px 6px !important; font: inherit; border-color: var(--accent) !important; box-shadow: 0 0 0 3px var(--accent-soft) !important; }
.row.just-added { animation: just-added 1.2s ease-out; }
@keyframes just-added { from { background: var(--accent-soft); } }
.multi-bar { display: flex; align-items: center; gap: 6px; margin: 0 8px 8px; padding: 6px 6px 6px 12px; border-radius: var(--radius-sm); background: var(--ink); color: var(--bg); font-size: 12.5px; font-weight: 500; box-shadow: var(--shadow-lg); }
.multi-bar[hidden] { display: none; }
.multi-bar span { flex: 1; }
.multi-bar .link { color: var(--bg); text-decoration: underline; text-underline-offset: 2px; }
.multi-bar .icon-btn { color: var(--bg); }
.multi-bar .icon-btn:hover { background: color-mix(in srgb, var(--bg) 18%, transparent); color: var(--bg); }
.caret { border: 0; background: none; width: 16px; height: 16px; padding: 0; display: grid; place-items: center; color: var(--muted); transition: transform .15s; }
.caret .icon { width: 12px; height: 12px; }
.caret.open { transform: rotate(90deg); }
.caret.hidden { visibility: hidden; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--s-idea); }
.status-idea { --s: var(--s-idea); } .status-outlined { --s: var(--s-outlined); } .status-drafting { --s: var(--s-drafting); } .status-revising { --s: var(--s-revising); } .status-done { --s: var(--s-done); }
.dot[class*=status-] { background: var(--s); }
.add-row { display: flex; align-items: center; gap: 6px; margin: 6px 4px; padding: 6px 8px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: none; color: var(--muted); width: calc(100% - 8px); font-size: 12.5px; }
.add-row:hover { color: var(--ink); border-color: var(--muted); }
.notebook-link { border-top: 1px solid var(--line); border-radius: 0; padding: 12px 14px; min-height: 44px; }
.dragging { opacity: .4; }
.drop-line { position: absolute; right: 8px; height: 2px; margin-top: -1px; background: var(--accent); border-radius: 2px; pointer-events: none; z-index: 3; transition: top .08s, left .12s; }
.drop-line::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--accent); background: var(--surface); box-sizing: border-box; }
.drop-label { position: absolute; right: 0; top: -9px; padding: 1px 8px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 10.5px; font-weight: 600; white-space: nowrap; max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
.drop-line.inside { height: 0; background: none; }
.drop-line.inside::before { display: none; }
.drag-ghost { position: fixed; top: -100px; left: 0; padding: 6px 12px; border-radius: 8px; background: var(--ink); color: var(--bg); font: 600 12.5px var(--ui); white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; box-shadow: var(--shadow-lg); }
.drop-before { box-shadow: inset 0 2px 0 var(--accent) !important; }
.drop-after { box-shadow: inset 0 -2px 0 var(--accent) !important; }
.drop-inside { background: var(--accent-soft) !important; outline: 2px solid var(--accent); outline-offset: -2px; }
.card.drop-before { box-shadow: -3px 0 0 var(--accent), var(--shadow) !important; }
.card.drop-after { box-shadow: 3px 0 0 var(--accent), var(--shadow) !important; }

/* ---------- main ---------- */
.main { overflow: auto; min-width: 0; }
.write, .board, .outline, .notebook { padding: 28px clamp(16px, 5vw, 64px) 80px; }
.write { max-width: var(--prose-width); margin: 0 auto; }
body.focus .write { padding-top: 12vh; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.crumb { border: 0; background: none; padding: 2px 4px; border-radius: 4px; color: var(--muted); }
button.crumb:hover { background: var(--surface-2); color: var(--ink); }
.crumb.current { color: var(--ink-2); }
.sep { opacity: .6; }
.title-row { display: flex; align-items: center; gap: 10px; }
.type-badge { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; padding: 3px 7px; border-radius: 5px; color: #fff; flex: none; }
.type-badge.type-part { background: var(--t-part); }
.type-badge.type-chapter { background: var(--t-chapter); }
.type-badge.type-section { background: var(--t-section); }
.title-input { border: 1px solid transparent !important; background: transparent !important; box-shadow: none !important; font: var(--display-w) 30px/1.2 var(--display) !important; padding: 4px 6px !important; margin-left: -6px; }
.title-input:hover { border-color: var(--line) !important; }
.author-input { border: 0 !important; background: transparent !important; box-shadow: none !important; font: italic 16px var(--serif) !important; color: var(--ink-2); padding: 0 !important; margin: 2px 0 18px; }

.direction { margin: 16px 0 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 16px; }
.direction summary { cursor: pointer; padding: 11px 0; font-weight: 600; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); list-style-position: inside; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary-peek { text-transform: none; letter-spacing: 0; font-weight: 400; font-family: var(--serif); font-style: italic; font-size: 14px; }
.direction[open] { padding-bottom: 14px; }
.direction-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.direction-grid.wide { margin: 8px 0 22px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.direction-grid .field { margin-top: 0; }
.field-label { font-size: 11.5px; font-weight: 600; color: var(--ink-2); }
.field textarea { font-family: var(--serif); font-size: 14.5px; background: var(--bg); }
.neighbors { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.neighbor { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 9px 12px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: none; font-size: 13px; min-width: 0; }
.neighbor:not(.empty):hover { border-style: solid; background: var(--bg); }
.neighbor .muted { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-family: var(--serif); }
.neighbor.empty { cursor: default; opacity: .7; }

.contains { margin: 0 0 18px; }
.contains-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.contains-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.contains-list li + li { border-top: 1px solid var(--line); }
.contains-item { display: flex; align-items: baseline; gap: 8px; width: 100%; padding: 9px 12px; border: 0; background: none; text-align: left; }
.contains-item:hover { background: var(--bg); }
.contains-item .muted { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: var(--serif); }
.contains-item .wc { font-size: 11.5px; color: var(--muted); }

.toolbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; row-gap: 2px; align-items: center; gap: 2px; padding: 6px; margin: 0 -6px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.tb { border: 0; background: none; min-width: 30px; height: 30px; border-radius: 6px; font-family: var(--serif); font-size: 15px; color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.tb.wide { padding: 0 9px; font-family: var(--ui); font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.tb:hover { background: var(--surface-2); color: var(--ink); }
.tb[data-cmd].on { background: var(--accent-soft); color: var(--accent); }
.tb .down-chev { width: 11px; height: 11px; transform: rotate(90deg); opacity: .6; margin-left: -1px; }
.tb.style-pick { min-width: 104px; justify-content: space-between; border: 1px solid var(--line); background: var(--surface); }
.tb.style-pick:hover { border-color: var(--line-strong); }
.tb .aa { font-family: var(--serif); font-size: 14px; font-weight: 600; }
.tb-sep { width: 1px; height: 18px; background: var(--line-strong); margin: 0 6px; }
.tb-count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.editor { min-height: 50vh; outline: none; padding: 22px 0 40px; }
.prose { font: calc(var(--editor-size) * var(--prose-scale))/var(--prose-leading) var(--serif); color: var(--ink); caret-color: var(--accent); }
.prose p { margin: 0 0 1em; }
/* Paragraph styles (Format › Paragraphs): every paragraph indented, printed-book style
   (flush after the start, a heading, a quote or a scene break), or spaced with no indent. */
.prose.para-indent p, .prose.para-book p { margin: 0; text-indent: 1.6em; }
.prose.para-book > p:first-child, .prose.para-book > :is(h2, h3, hr, blockquote, ul, ol) + p { text-indent: 0; }
.prose :is(blockquote, li) p { text-indent: 0; }
.prose.para-indent > :is(h2, h3, blockquote, ul, ol, hr) + p, .prose.para-book > :is(blockquote, ul, ol) + p { margin-top: .6em; }
.prose h3 { font-size: 1.05em; margin: 1.2em 0 .5em; letter-spacing: .02em; }
.prose h2 { font-size: 1.25em; margin: 1.4em 0 .6em; }
.prose blockquote { margin: 1em 0; padding-left: 1em; border-left: 3px solid var(--line-strong); color: var(--ink-2); font-style: italic; }
.prose hr { border: 0; text-align: center; margin: 1.6em 0; height: 1em; }
.prose hr::after { content: '✱  ✱  ✱'; color: var(--muted); letter-spacing: .4em; font-size: .8em; }
.editor:empty::before { content: attr(data-placeholder); color: var(--muted); font-style: italic; }
.write-foot { display: flex; gap: 8px; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 14px; }

/* overview */
.overview .title-input { font-size: 38px !important; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat-num { font: var(--display-w) 24px var(--display); font-variant-numeric: tabular-nums; }
.stat-num.input { border: 0 !important; padding: 0 !important; background: transparent !important; box-shadow: none !important; }
.stat-label { font-size: 12px; color: var(--muted); }
.progress { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin: 14px 0 10px; }
.progress.small { height: 4px; margin: 10px 0 4px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.status-strip { display: flex; gap: 3px; border-radius: 6px; overflow: hidden; }
.seg { background: var(--s); color: #fff; font-size: 11px; font-weight: 600; padding: 4px 8px; white-space: nowrap; overflow: hidden; min-width: 0; }
.section-head { font: 600 13px var(--ui); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 28px 0 10px; }
.part-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.part-card { display: flex; flex-direction: column; gap: 6px; text-align: left; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--t-part); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.part-card:hover { border-color: var(--line-strong); border-left-color: var(--t-part); }
.part-card strong { font: var(--display-w) 17px var(--display); }
.part-card .muted { font-family: var(--serif); }
.part-card .wc { font-size: 12px; color: var(--muted); margin-top: auto; }
.part-card.add { align-items: center; justify-content: center; flex-direction: row; border: 1px dashed var(--line-strong); box-shadow: none; color: var(--muted); background: none; }

/* ---------- board ---------- */
.board-head { margin-bottom: 18px; }
.board-head h2, .outline-head h2 { font: var(--display-w) 28px var(--display); margin: 6px 0 4px; }
.board-head p, .outline-head p { margin: 0; max-width: 70ch; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card { position: relative; display: flex; flex-direction: column; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--s); border-radius: var(--radius-sm); padding: 10px 12px 10px; box-shadow: var(--shadow); cursor: grab; min-height: 180px;
  background-image: repeating-linear-gradient(transparent 0 27px, color-mix(in srgb, var(--s-outlined) 12%, transparent) 27px 28px); background-position: 0 58px; }
.card.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.card-top { display: flex; align-items: center; gap: 6px; font-size: 11.5px; }
.card-num { font-weight: 600; color: var(--muted); }
.pill { font-size: 10.5px; font-weight: 600; color: var(--s); background: color-mix(in srgb, var(--s) 14%, transparent); padding: 1px 7px; border-radius: 99px; }
.card .wc { color: var(--muted); font-variant-numeric: tabular-nums; }
.card input, .card textarea { border: 0; background: transparent; padding: 2px 0; box-shadow: none !important; border-radius: 0; }
.card-title { font: var(--display-w) 16px var(--display); }
.card-syn { font: 14px/28px var(--serif); padding: 0 !important; }
.card-purpose { font: italic 13px/1.4 var(--serif); color: var(--ink-2); }
.card-foot { display: flex; gap: 8px; margin-top: auto; padding-top: 4px; }
.card.add { align-items: center; justify-content: center; flex-direction: row; border: 1px dashed var(--line-strong); box-shadow: none; background: none; color: var(--muted); cursor: pointer; font-weight: 500; }
.card.add:hover { color: var(--ink); border-color: var(--muted); }

/* ---------- outline ---------- */
.outline-head { margin-bottom: 16px; }
.seg-control { display: inline-flex; margin-top: 12px; background: var(--surface-2); padding: 3px; border-radius: var(--radius-sm); }
.seg-control button { border: 0; background: none; padding: 4px 11px; border-radius: calc(var(--radius-sm) - 2px); font-size: 12.5px; color: var(--ink-2); }
.seg-control button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.outline-grid { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.o-row { display: grid; grid-template-columns: minmax(200px, 1.1fr) 1.6fr 1.3fr 110px 70px; align-items: start; border-top: 1px solid var(--line); }
.o-row > * { min-width: 0; }
.o-row.o-head { border-top: 0; background: var(--surface-2); font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.o-row.o-head > div { padding: 8px 10px; }
.o-row.selected { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.o-row input, .o-row textarea, .o-row select { border: 0; background: transparent; border-radius: 0; padding: 9px 10px; box-shadow: none !important; }
.o-row textarea { font-family: var(--serif); font-size: 14px; }
.o-row input:focus, .o-row textarea:focus { background: var(--bg); }
.o-title { display: flex; align-items: center; padding-left: calc(10px + var(--depth) * 16px); }
.o-title .dot { margin-right: 2px; }
.o-row.type-part { background: color-mix(in srgb, var(--t-part) 8%, transparent); }
.o-row.type-part .o-title input { font-weight: var(--display-w); font-family: var(--display); font-size: 15px; }
.o-row.type-chapter .o-title input { font-weight: 600; }
.o-words { padding: 10px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.status-select { color: var(--s) !important; font-weight: 600; font-size: 12.5px; }

/* ---------- notebook ---------- */
.capture-wrap { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; max-width: 760px; margin-bottom: 20px; }
.capture { font: 16px/1.6 var(--serif); padding: 14px 16px !important; background: var(--surface) !important; box-shadow: var(--shadow); border-radius: var(--radius) !important; }
.notes { columns: 260px; column-gap: 14px; }
.nb-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.nb-controls .seg-control { margin-top: 0; }
.nb-controls .note-filter { flex: 0 1 240px; width: 240px; margin: 0; }
.nb-controls .note-filter, .nb-controls .note-scope { height: 32px; padding-top: 0; padding-bottom: 0; }
.note-scope { width: auto; }
.zoom { display: inline-flex; align-items: center; gap: 2px; }
.zoom .link { min-width: 44px; text-align: center; }
.canvas-tips { margin: 10px 0 0; }
.canvas-tips .icon { width: 13px; height: 13px; vertical-align: -2px; }

/* note colours: one hue per swatch, mixed into the skin's surface so they suit every skin and mode */
.c-yellow { --n-hue: #f2cf4a; } .c-peach { --n-hue: #f4a077; } .c-green { --n-hue: #9cc47f; } .c-blue { --n-hue: #82acd9; } .c-lilac { --n-hue: #b89ae0; }
.c-yellow, .c-peach, .c-green, .c-blue, .c-lilac { --n-bg: color-mix(in oklab, var(--n-hue, transparent) var(--note-mix), var(--surface)); --n-line: color-mix(in oklab, var(--n-hue, transparent) calc(var(--note-mix) + 18%), var(--surface)); }
.c-label  { --n-bg: transparent; --n-line: transparent; }

.note { break-inside: avoid; margin-bottom: 14px; background: var(--n-bg); border: 1px solid var(--n-line); border-radius: 4px 4px 12px 4px; padding: 10px 12px 8px; box-shadow: var(--shadow); cursor: grab; }
.note textarea { border: 0; background: transparent; padding: 0; font: 15px/1.55 var(--serif); box-shadow: none !important; }
.note.c-label { box-shadow: none; border: 1px dashed transparent; padding-left: 4px; }
.note.c-label:hover, .note.c-label:focus-within { border-color: var(--line-strong); }
.note.c-label textarea { font: var(--display-w) 24px/1.25 var(--display); color: var(--ink-2); }
.note-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.chip { font-size: 11px; line-height: 1.3; padding: 2px 7px; border-radius: 99px; border: 0; background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--ink-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.chip:hover { background: color-mix(in srgb, var(--ink) 14%, transparent); }
.chip.src { color: var(--muted); }
.note-foot { display: flex; align-items: center; gap: 4px; margin-top: 6px; }
.swatches { display: flex; gap: 3px; }
.sw { width: 14px; height: 14px; border-radius: 50%; padding: 0; border: 1px solid color-mix(in srgb, var(--ink) 25%, transparent); background: var(--n-bg); font: 700 9px/12px var(--serif); color: var(--ink-2); }
.sw.c-label { background: var(--surface); }
.sw.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.note .place { width: 92px; font-size: 11.5px; padding: 2px 4px; background: transparent; border-color: color-mix(in srgb, var(--ink) 15%, transparent); }
.note.static { cursor: default; margin: 0; box-shadow: none; }
.note.static p { margin: 0; font: 15px/1.55 var(--serif); white-space: pre-wrap; }

/* canvas */
.notebook.canvas-mode { height: 100%; display: flex; flex-direction: column; padding-bottom: 16px; }
.notebook.canvas-mode .capture-wrap { flex-direction: row; align-items: flex-start; max-width: none; margin-bottom: 12px; }
.notebook.canvas-mode .capture { font-size: 15px; padding: 9px 12px !important; }
.canvas-wrap { position: relative; flex: 1; min-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background-color: var(--surface);
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 14%, transparent) 1px, transparent 1.2px); background-size: 22px 22px; }
.canvas-wrap.panning { cursor: grabbing; }
.canvas-sizer { position: relative; }
.canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; cursor: grab; }
.canvas-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; font-family: var(--serif); font-style: italic; font-size: 17px; }
svg.links { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
svg.links .line { fill: none; stroke: color-mix(in srgb, var(--accent) 60%, var(--muted)); stroke-width: 1.8; stroke-dasharray: 5 4; }
svg.links .hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
svg.links g.link:hover .line { stroke: var(--danger); stroke-dasharray: none; }
svg.links .rubber { stroke: var(--accent); stroke-width: 2; }
.cnote { position: absolute; width: 240px; margin: 0; cursor: default; padding-top: 14px; }
.cnote.moving { box-shadow: var(--shadow-lg); z-index: 5; opacity: .92; }
.cnote.dim { opacity: .25; }
.cnote-grip { position: absolute; left: 0; right: 0; top: 0; height: 14px; cursor: grab; border-radius: 4px 4px 0 0; }
.cnote-grip::after { content: ''; position: absolute; left: 50%; top: 5px; width: 28px; height: 3px; margin-left: -14px; border-radius: 2px; background: color-mix(in srgb, var(--ink) 18%, transparent); }
.cnote .note-foot { opacity: 0; transition: opacity .12s; }
.cnote:hover .note-foot, .cnote:focus-within .note-foot { opacity: 1; }
.link-handle { cursor: crosshair; }

/* modals */
dialog.modal, dialog.sprint { border: 1px solid var(--line); border-radius: calc(var(--radius) + 4px); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
dialog.modal { padding: 20px 22px; width: min(720px, calc(100vw - 32px)); }
dialog.modal h2 { font: var(--display-w) 22px var(--display); margin: 0; }
.pair { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; margin: 16px 0; }
.pair .plus { font: var(--display-w) 26px var(--display); color: var(--accent); }
.collide textarea { font: 16px/1.55 var(--serif); }
dialog.sprint { width: min(860px, calc(100vw - 32px)); height: min(720px, calc(100vh - 48px)); padding: 0; }
dialog.sprint[open] { display: flex; flex-direction: column; }
.sprint-setup { padding: 28px 32px; display: flex; flex-direction: column; gap: 14px; }
.sprint-setup h2 { font: var(--display-w) 26px var(--display); margin: 0; }
.sprint-setup p { margin: 0; }
.sprint-prompt-input { font: 16px var(--serif) !important; padding: 10px 12px !important; }
.sprint-setup .seg-control { align-self: flex-start; margin: 0; }
.sprint-run { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.sprint-run[hidden], .sprint-setup[hidden] { display: none; }
.sprint-bar { display: flex; align-items: center; gap: 14px; padding: 12px 20px; border-bottom: 1px solid var(--line); font-size: 13px; }
.sprint-prompt { font-family: var(--serif); font-style: italic; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sprint-wc { color: var(--muted); font-variant-numeric: tabular-nums; }
.sprint-clock { font: 600 20px var(--ui); font-variant-numeric: tabular-nums; }
.sprint-clock.done { color: var(--accent); font-size: 14px; }
.sprint-text { flex: 1; border: 0 !important; box-shadow: none !important; padding: 28px 48px !important; background: transparent !important; outline: none; }

/* ---------- inspector ---------- */
.inspector { border-left: 1px solid var(--line); background: var(--surface); overflow: auto; padding: 14px 16px 40px; display: flex; flex-direction: column; gap: 22px; }
.panel-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.panel-title { font: var(--display-w) 16px var(--display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv { display: grid; grid-template-columns: 70px 1fr; gap: 8px 10px; align-items: center; }
.kv label { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.kv select, .kv input { padding: 5px 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.assistant.off { background: var(--bg); border-radius: var(--radius); padding: 12px; }
.ai-actions { display: flex; flex-direction: column; gap: 6px; }
.ai-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; text-align: left; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.ai-btn:hover:not(:disabled) { border-color: var(--accent); }
.ai-btn:disabled { opacity: .5; }
.ai-btn strong { font-weight: 600; font-size: 13px; }
.ai-btn span { font-size: 11.5px; color: var(--muted); }
.ask { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; margin-top: 10px; }
.ai-result { margin-top: 14px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 12px; background: var(--bg); font-size: 13.5px; }
.ai-result.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.ai-result-head { display: flex; justify-content: space-between; align-items: center; margin: -4px -6px 4px 0; }
.ai-body { font-family: var(--serif); line-height: 1.55; }
.ai-body p { margin: 0 0 .6em; }
.ai-body h4 { font: 600 13px var(--ui); margin: .8em 0 .3em; }
.ai-body ul, .ai-body ol { padding-left: 1.2em; margin: 0 0 .6em; }
.ai-body li { margin-bottom: .3em; }
.suggest { margin-bottom: 10px; }
.suggest p { font-family: var(--serif); margin: 3px 0 6px; }
.pieces { padding-left: 0; list-style: none; margin: 8px 0 10px; display: flex; flex-direction: column; gap: 8px; }
.pieces label { display: flex; gap: 8px; align-items: flex-start; font-family: var(--serif); font-size: 13px; }
.pieces input { margin-top: 3px; }
.error-text { color: var(--danger); margin: 0; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.panel-sub { font-size: 12.5px; color: var(--ink-2); font-family: var(--serif); font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-head.row-head { flex-direction: row; justify-content: space-between; align-items: center; }
.scope-select { font-size: 12.5px; padding: 4px 6px; margin-top: 4px; }
.spark-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.spark-btn { padding: 8px 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); font-size: 12.5px; font-weight: 500; text-align: center; }
.spark-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.spark-btn:disabled { opacity: .45; cursor: default; }
.spark .muted.small { margin: 10px 0 0; }
.prompt-text { font: 17px/1.45 var(--serif); margin: 4px 0 4px; }
.spark-result .actions { margin-top: 10px; }
.spark-ideas, .interview { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-direction: column; gap: 10px; }
.spark-ideas li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: start; }
.spark-ideas .kind { grid-column: 1 / -1; font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--accent); font-weight: 600; }
.spark-ideas .idea-text { font: 14px/1.45 var(--serif); }
.interview p { margin: 0 0 4px; font: var(--display-w) 14px/1.4 var(--display); }
.interview textarea { font-family: var(--serif); background: var(--surface); }
.idea-list { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-direction: column; gap: 6px; }
.idea-list li { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px; background: var(--n-bg); border: 1px solid var(--n-line); border-radius: 6px; padding: 6px 4px 6px 9px; }
.idea-list li.c-label { background: var(--bg); border-color: var(--line); }
.idea-list textarea { flex: 1; min-width: 0; border: 0; background: transparent; padding: 0; font: 13.5px/1.45 var(--serif); box-shadow: none !important; }
.idea-list .chip { order: 3; }

/* ---------- dialog & toast ---------- */
dialog.settings { border: 1px solid var(--line); border-radius: calc(var(--radius) + 4px); background: var(--surface); color: var(--ink); padding: 20px 22px; width: min(480px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgb(20 15 10 / .35); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-head h2 { font: var(--display-w) 22px var(--display); margin: 0; }
dialog h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 20px 0 10px; }
dialog .kv { grid-template-columns: 90px 1fr; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0; font-size: 13.5px; }
.check input { margin-top: 3px; }
.conflict p { color: var(--ink-2); margin: 10px 0 16px; }
.conflict-choices { display: flex; flex-direction: column; gap: 8px; }
.conflict-choices .btn { flex-direction: column; align-items: flex-start; gap: 2px; white-space: normal; text-align: left; padding: 10px 14px; }
.conflict-choices .btn span { font-weight: 400; font-size: 12.5px; opacity: .8; }
.conflict-choices .btn.danger-ghost { border-color: transparent; background: none; }
.conflict-choices .btn.danger-ghost:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); }
.type-controls { margin: 18px 0 4px; padding-top: 14px; border-top: 1px solid var(--line); scroll-margin-top: 12px; }
.type-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.type-sample { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 12px; }
.type-sample strong { display: block; font: var(--display-w) 19px/1.25 var(--display); margin-bottom: 4px; }
.type-sample p { margin: 0; font: calc(16px * var(--prose-scale))/var(--prose-leading) var(--serif); color: var(--ink-2); }
.type-controls .kv { gap: 8px 10px; }
.type-controls optgroup { font-style: normal; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input { flex: 1; }
.range-val { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2.6em; text-align: right; }
.look-fonts { align-self: flex-start; }
.dlg-foot { display: flex; justify-content: flex-end; margin-top: 18px; }
dialog.word-styles { width: min(640px, calc(100vw - 32px)); }
dialog.word-styles > p { margin: 8px 0 14px; }
.ws-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.ws-row { display: grid; grid-template-columns: 1fr 1.3fr 104px 28px; gap: 6px; align-items: center; }
.ws-row input, .ws-row select { padding: 6px 8px; min-width: 0; }
.ws-head span { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.ws-empty { margin: 4px 0; }
dialog.word-styles .dlg-foot { align-items: center; gap: 8px; flex-wrap: wrap; }
dialog.word-styles .dlg-foot .spacer { flex: 1; }
@media (max-width: 560px) { .ws-row { grid-template-columns: 1fr 1fr; } .ws-head { display: none; } }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow-lg); z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast.error { background: var(--danger); color: #fff; }
#toast .link { color: var(--accent-soft); font-size: 13px; }

/* ---------- progress & celebrations ---------- */
.progress-ring { display: grid; place-items: center; width: 26px; height: 26px; padding: 0; border: 0; background: none; border-radius: 50%; }
.progress-ring:hover { background: var(--surface-2); }
.progress-ring svg { width: 20px; height: 20px; transform: rotate(-90deg); }
.progress-ring circle { fill: none; stroke-width: 3; }
.progress-ring .track { stroke: var(--surface-3); }
.progress-ring .fill { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .6s cubic-bezier(.2, .8, .2, 1); }
.progress-ring.full .fill { stroke: var(--s-done); }
.session-chip { border: 0; background: color-mix(in srgb, var(--s-done) 14%, transparent); color: var(--s-done); font-weight: 600; font-size: 12px; padding: 2px 9px; border-radius: 99px; font-variant-numeric: tabular-nums; }
.session-chip:hover { background: color-mix(in srgb, var(--s-done) 22%, transparent); }
#toast.cheer { background: var(--surface); color: var(--ink); border: 1px solid var(--accent); box-shadow: var(--shadow-lg), 0 0 0 4px var(--accent-soft); font-weight: 500; }
#toast .cheer-icon { color: var(--accent); display: grid; }
#toast.cheer.show { animation: cheer-pop .45s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes cheer-pop { from { transform: translate(-50%, 14px) scale(.9); } to { transform: translate(-50%, 0) scale(1); } }
canvas.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 60; }
dialog.session { width: min(520px, calc(100vw - 32px)); }
.session-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0 6px; }
.session-stats .stat-num { font-size: 22px; }
.session-list { margin-top: 12px; }
.session-list p { margin: 3px 0 0; font-family: var(--serif); }
@media (max-width: 520px) { .session-stats { grid-template-columns: 1fr 1fr; } }

/* ---------- writing aids ---------- */
.tb-toggles { display: inline-flex; gap: 2px; }
.tb.toggle { color: var(--muted); }
.tb.toggle .icon { width: 15px; height: 15px; }
.tb.toggle.on { color: var(--accent); background: var(--accent-soft); }
.editor.fade-rest > * { transition: opacity .35s ease; }
.editor.fade-rest.fading > * { opacity: .22; }
.write.tw-scroll .editor { padding-bottom: 55vh; }
dialog .kv.indent { margin: -4px 0 8px 26px; grid-template-columns: 60px 1fr; }
dialog .check strong { font-weight: 600; }

/* ---------- help ---------- */
dialog.help { padding: 0; width: min(920px, calc(100vw - 32px)); height: min(680px, calc(100vh - 48px)); border: 1px solid var(--line); border-radius: calc(var(--radius) + 4px); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); overflow: hidden; }
dialog.help[open] { display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.help-side { background: var(--binder-bg, var(--surface-2)); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.help-title { font: var(--display-w) 22px var(--display); padding: 0 6px; }
.help-nav { display: flex; flex-direction: column; gap: 2px; overflow: auto; flex: 1; }
.help-nav button { text-align: left; border: 0; background: none; padding: 7px 9px; border-radius: var(--radius-sm); color: var(--ink-2); font-size: 13px; }
.help-nav button:hover { background: var(--surface-3); color: var(--ink); }
.help-nav button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.help-tour { align-self: flex-start; }
.help-main { position: relative; overflow: auto; min-height: 0; }
.help-close { position: absolute; top: 12px; right: 12px; }
.help-body { padding: 28px 40px 48px; max-width: 680px; line-height: 1.6; }
.help-body h2 { font: var(--display-w) 28px/1.2 var(--display); margin: 0 0 14px; padding-right: 30px; }
.help-body h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 26px 0 8px; }
.help-body p, .help-body li { color: var(--ink-2); }
.help-body strong { color: var(--ink); }
.help-body ul, .help-body ol { padding-left: 1.2em; }
.help-body li { margin-bottom: 8px; }
.help-body .lede-s { font: 17px/1.6 var(--serif); color: var(--ink); }
.help-body ol.steps { counter-reset: step; list-style: none; padding: 0; }
.help-body ol.steps li { counter-increment: step; position: relative; padding-left: 38px; margin-bottom: 12px; }
.help-body ol.steps li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; display: grid; place-items: center; }
.help-body table.keys { border-collapse: collapse; width: 100%; }
.help-body table.keys td { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); color: var(--ink-2); vertical-align: top; }
.help-body table.keys td:first-child { white-space: nowrap; width: 1%; }
kbd.key { display: inline-block; min-width: 22px; padding: 1px 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); font: 600 11.5px/1.5 var(--ui); color: var(--ink); text-align: center; }
.welcome-help { margin: 18px 0 0; color: var(--muted); font-size: 13.5px; }
.welcome-help .link { font-size: 13.5px; }

/* new project */
dialog.newproj { width: min(720px, calc(100vw - 32px)); }
.newproj-title { font: var(--display-w) 20px var(--display) !important; padding: 9px 12px !important; }
.newproj-label { margin: 18px 0 8px; }
.shape-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.shape-opt { display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.shape-opt:hover { border-color: var(--line-strong); }
.shape-opt.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.shape-opt strong { font: var(--display-w) 15px var(--display); }
.shape-blurb { font-size: 12.5px; color: var(--ink-2); line-height: 1.4; }
.shape-preview { font-size: 11px; color: var(--muted); margin-top: auto; padding-top: 4px; }
dialog.newproj .dlg-foot { gap: 8px; }

/* tour */
.tour { position: fixed; inset: 0; z-index: 70; }
.tour-hole { position: fixed; border-radius: var(--radius); box-shadow: 0 0 0 9999px rgb(10 8 5 / .55); outline: 2px solid var(--accent); outline-offset: 2px; transition: all .3s cubic-bezier(.3, .9, .3, 1); pointer-events: none; }
.tour-card { position: fixed; width: min(340px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: calc(var(--radius) + 2px); box-shadow: var(--shadow-lg); padding: 16px 18px 14px; transition: left .3s, top .3s; }
.tour-count { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.tour-card h3 { font: var(--display-w) 19px/1.25 var(--display); margin: 4px 0 6px; }
.tour-card p { margin: 0 0 14px; color: var(--ink-2); line-height: 1.5; }
.tour-foot { display: flex; align-items: center; gap: 6px; }
.tour-back[hidden] { display: none; }
@media (prefers-reduced-motion: reduce) { .tour-hole, .tour-card { transition: none; } }

/* ---------- context menu ---------- */
.ctx { position: fixed; z-index: 80; min-width: 210px; max-width: 300px; max-height: min(70vh, 520px); overflow: auto; padding: 5px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font: 13px/1.3 var(--ui); animation: ctx-in .09s ease-out; }
@keyframes ctx-in { from { opacity: 0; transform: translateY(-3px); } }
.ctx-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 10px 6px 8px; border: 0; background: none; border-radius: calc(var(--radius-sm) - 3px); text-align: left; color: var(--ink); }
.ctx-item:hover:not(:disabled), .ctx-item:focus { background: var(--surface-2); outline: none; }
.ctx-item:disabled { color: var(--muted); cursor: default; }
.ctx-item.danger { color: var(--danger); }
.ctx-item.danger:hover, .ctx-item.danger:focus { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.ctx-icon { width: 16px; display: grid; place-items: center; flex: none; color: var(--ink-2); }
.ctx-item.danger .ctx-icon { color: var(--danger); }
.ctx-icon .icon { width: 14px; height: 14px; }
.ctx-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-item kbd { margin-left: 12px; }
.ctx-arrow { color: var(--muted); display: grid; }
.ctx-arrow .icon { width: 12px; height: 12px; }
.ctx-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.title-more { flex: none; color: var(--muted); }
.title-more .icon, .card-more .icon { stroke-width: 3.2; }
.card-more { width: 22px; height: 22px; margin: -3px -4px -3px 0; color: var(--muted); opacity: 0; }
.card:hover .card-more, .card:focus-within .card-more { opacity: 1; }
.overview-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.panel-btn.on { color: var(--ink); }
.panel-btn:not(.on) { color: var(--muted); }

/* ---------- export ---------- */
dialog.export { padding: 0; width: min(1120px, calc(100vw - 32px)); height: min(820px, calc(100vh - 40px)); border: 1px solid var(--line); border-radius: calc(var(--radius) + 4px); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
dialog.export[open] { display: flex; flex-direction: column; }
dialog.export .dlg-head { padding: 16px 20px 12px; border-bottom: 1px solid var(--line); }
.export-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 340px minmax(0, 1fr); }
.export-side { overflow: auto; padding: 16px 18px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 16px; }
.export-kinds { display: flex; flex-direction: column; gap: 6px; }
.export-kind { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.export-kind:hover { border-color: var(--line-strong); }
.export-kind.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.export-kind strong { font: var(--display-w) 15px var(--display); }
.export-kind span { font-size: 12px; color: var(--ink-2); line-height: 1.4; }
.export-opts { display: flex; flex-direction: column; gap: 8px; }
.export-opts .check { margin: 2px 0; }
.export-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 4px; }
.export-field .seg-control { margin: 0; align-self: flex-start; }
.export-preview { position: relative; overflow: hidden; background: #e9e6e0; }
.export-frame { position: absolute; left: 0; top: 0; width: 860px; border: 0; transform-origin: 0 0; background: #e9e6e0; }
.export-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid var(--line); }
.export-foot .ext { opacity: .6; font-weight: 400; }
@media (max-width: 820px) {
  .export-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(260px, 1fr); overflow: auto; }
  .export-side { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .export-foot { justify-content: flex-start; }
}

/* ---------- drawer (Echoes, Polish, Story check) ---------- */
.drawer { position: fixed; top: 60px; right: 12px; bottom: 12px; width: min(380px, calc(100vw - 24px)); z-index: 40; display: flex; flex-direction: column; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: calc(var(--radius) + 2px); box-shadow: var(--shadow-lg); animation: drawer-in .18s ease-out; }
@keyframes drawer-in { from { opacity: 0; transform: translateX(16px); } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; font: var(--display-w) 17px var(--display); }
.drawer-body { flex: 1; overflow: auto; padding: 12px 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.drawer-body > .btn { align-self: flex-start; }
body:has(.drawer):not(.no-inspector) .main { padding-right: 80px; }
body:has(.drawer).no-inspector .main, body.focus:has(.drawer) .main { padding-right: 392px; }
::highlight(echo) { background-color: color-mix(in srgb, var(--s-drafting) 38%, transparent); }
::highlight(echo-now) { background-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.echo-group .eyebrow { margin-top: 6px; }
.echo-group p { margin: 2px 0 6px; }
.echo-list { display: flex; flex-wrap: wrap; gap: 5px; }
.echo-item { display: inline-flex; align-items: baseline; gap: 5px; border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 3px 10px; font-size: 12.5px; }
.echo-item:hover { border-color: var(--line-strong); }
.echo-item.on { border-color: var(--accent); background: var(--accent-soft); }
.echo-term { font-family: var(--serif); }
.echo-count { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.echo-stepper { position: sticky; top: -12px; z-index: 1; display: flex; align-items: center; gap: 4px; padding: 6px 8px; margin: 0 -8px; border-radius: var(--radius-sm); background: var(--accent-soft); font-size: 12.5px; }
.echo-stepper span { flex: 1; }
.icon-btn.flip .icon { transform: scaleX(-1); }
.polish-orig { margin: 0; padding: 8px 12px; border-left: 3px solid var(--line-strong); font: italic 15px/1.55 var(--serif); color: var(--ink-2); }
.polish-overall { font: 15px/1.55 var(--serif); margin: 0; }
.polish-card { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--bg); display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.polish-card p { margin: 0; }
.polish-card.done { opacity: .55; }
.polish-text { font: 15px/1.55 var(--serif); }
.polish-del { font: 14px/1.5 var(--serif); color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.polish-ins { font: 15px/1.5 var(--serif); color: var(--ink); border-left: 3px solid var(--s-done); padding-left: 8px; }
.polish-actions { display: flex; gap: 6px; }
.story-card { border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--bg); display: flex; flex-direction: column; gap: 5px; }
.story-card p { margin: 0; font-size: 13.5px; line-height: 1.5; }
.story-card strong { font: var(--display-w) 15px/1.3 var(--display); }
.story-card.sev-high { border-left-color: var(--danger); }
.story-card.sev-medium { border-left-color: var(--s-drafting); }
.story-card.sev-low { border-left-color: var(--s-outlined); }
.story-top { display: flex; gap: 6px; align-items: center; }
.sev { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.story-links { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-top: 2px; }
.link-chip { cursor: pointer; }
.link-chip:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- the Desk ---------- */
.desk { max-width: 880px; margin: 0 auto; padding: 36px clamp(16px, 5vw, 56px) 80px; display: flex; flex-direction: column; gap: 26px; }
.desk-head h1 { font: var(--display-w) 40px/1.1 var(--display); margin: 6px 0 8px; letter-spacing: -.01em; }
.desk-premise { font: 17px/1.55 var(--serif); color: var(--ink-2); margin: 0; max-width: 64ch; }
.next-card { position: relative; padding: 22px 24px 22px; border-radius: calc(var(--radius) + 4px); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); overflow: hidden; }
.next-card::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--accent); }
.next-top { display: flex; align-items: center; gap: 10px; }
.next-card h2 { font: var(--display-w) 26px/1.2 var(--display); margin: 10px 0 6px; }
.next-card p { margin: 0 0 16px; color: var(--ink-2); font: 15px/1.55 var(--serif); max-width: 62ch; }
.next-card .btn { padding: 10px 18px; font-size: 14.5px; }
.stage-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.stage-chip .stage-n { width: 18px; height: 18px; font-size: 10px; border-color: var(--accent); color: var(--accent); }
.also { display: flex; flex-direction: column; gap: 8px; }
.also-item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; text-align: left; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.also-item:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.also-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.also-text strong { font-weight: 600; }
.also-go { color: var(--accent); font-weight: 600; font-size: 13px; white-space: nowrap; }
.stage-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 8px; }
.stage-col { display: flex; flex-direction: column; gap: 7px; text-align: left; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stage-col:hover { border-color: var(--accent); }
.stage-col-top { display: flex; align-items: center; gap: 7px; }
.stage-col .stage-n { width: 20px; height: 20px; color: var(--accent); }
.stage-meter { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.stage-meter i { display: block; height: 100%; background: var(--s-done); border-radius: 3px; }
.stage-col .muted.small { line-height: 1.35; }
.recent-list { display: flex; flex-direction: column; margin-top: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.recent-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 0; background: none; text-align: left; }
.recent-item + .recent-item { border-top: 1px solid var(--line); }
.recent-item:hover { background: var(--surface-2); }
.recent-title { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; max-width: 980px; margin-bottom: 18px; }
.share-card { display: flex; flex-direction: column; gap: 8px; text-align: left; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.share-card:hover { border-color: var(--accent); }
.share-card strong { font: var(--display-w) 18px var(--display); }
.share-card span { color: var(--ink-2); font-size: 13px; line-height: 1.45; }
.share-card .share-go { color: var(--accent); font-weight: 600; margin-top: auto; }
.tool-list { display: flex; flex-direction: column; gap: 6px; }
.revise-status { margin-top: 12px; }
.next-up { margin-left: auto; }
@media (max-width: 760px) { .stage-strip { grid-template-columns: 1fr 1fr; } .desk-head h1 { font-size: 30px; } .also-item { grid-template-columns: 1fr; } }

/* ---------- map view ---------- */
.main.view-map { display: flex; flex-direction: column; overflow: hidden; }
.map { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.map-bar-top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 20px; padding: 18px clamp(16px, 4vw, 40px) 12px; border-bottom: 1px solid var(--line); }
.map-bar-top h2 { font: var(--display-w) 26px var(--display); margin: 0 0 2px; }
.map-bar-top p { margin: 0; }
.map-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.map-controls .seg-control { margin: 0; }
.map-controls .check { margin: 0; font-size: 12.5px; }
.map-levels { display: flex; align-items: center; gap: 6px; }
.map-levels .seg-control { margin: 0; }
.map-wrap { flex: 1; min-height: 0; overflow: auto; cursor: grab; background-color: var(--bg);
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 9%, transparent) 1px, transparent 1.2px); background-size: 24px 24px; }
.map-wrap.panning { cursor: grabbing; user-select: none; }
.map-sizer { position: relative; }
.map-canvas { position: absolute; transform-origin: 0 0; }
.map-edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.map-edges .edge { fill: none; stroke: var(--line-strong); stroke-width: 1.6; }
.map-edges .edge.to-part { stroke: color-mix(in srgb, var(--t-part) 55%, var(--line-strong)); stroke-width: 2.2; }
.map-edges .edge.to-chapter { stroke: color-mix(in srgb, var(--t-chapter) 40%, var(--line-strong)); stroke-width: 1.9; }
.map-card { position: absolute; min-height: 58px; display: flex; flex-direction: column; gap: 4px; padding: 8px 10px 7px 12px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--t-section); border-radius: var(--radius-sm); box-shadow: var(--shadow); cursor: pointer; transition: box-shadow .15s, transform .15s; }
.map-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.map-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.map-card.type-book { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface)); }
.map-card.type-part { border-left-color: var(--t-part); }
.map-card.type-chapter { border-left-color: var(--t-chapter); }
.map-card.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.map-card.dragging { opacity: .4; }
.map-card.drop-inside { outline: 2px solid var(--accent); background: var(--accent-soft) !important; }
.map-card.drop-before { box-shadow: 0 -3px 0 var(--accent), var(--shadow) !important; }
.map-card.drop-after { box-shadow: 0 3px 0 var(--accent), var(--shadow) !important; }
.map-wrap.down .map-card.drop-before { box-shadow: -3px 0 0 var(--accent), var(--shadow) !important; }
.map-wrap.down .map-card.drop-after { box-shadow: 3px 0 0 var(--accent), var(--shadow) !important; }
.map-card-top { display: flex; align-items: flex-start; gap: 6px; min-height: 0; }
.map-card-top .dot { margin-top: 5px; }
.map-book { width: 14px; height: 14px; color: var(--accent); margin-top: 2px; }
.map-title { flex: 1; min-width: 0; font-size: 13px; line-height: 1.3; font-weight: 500; overflow-wrap: anywhere; }
.map-card.type-book .map-title, .map-card.type-part .map-title { font: var(--display-w) 14.5px/1.25 var(--display); }
.map-card.type-chapter .map-title { font-weight: 600; }
.map-syn { margin: 0; font: 12px/1.45 var(--serif); color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.map-meta { display: flex; align-items: center; gap: 8px; margin-top: auto; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.map-bar { flex: 1; height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.map-bar i { display: block; height: 100%; background: var(--accent); }
.map-fold { flex: none; min-width: 22px; height: 18px; padding: 0 5px; border: 1px solid var(--line-strong); border-radius: 99px; background: var(--surface); color: var(--ink-2); font: 600 11px/1 var(--ui); }
.map-fold:hover { border-color: var(--accent); color: var(--accent); }
.map-add { position: absolute; z-index: 2; display: none; place-items: center; width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 1px solid var(--accent); background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.map-add .icon { width: 12px; height: 12px; stroke-width: 2.4; }
.map-add:hover { background: var(--accent); color: var(--accent-ink); }
.map-card:hover .map-add, .map-card.selected .map-add, .map-card:focus-within .map-add { display: grid; }
.map-card.dragging .map-add, .map-card.renaming .map-add { display: none !important; }
.map-add-child { right: -12px; top: 50%; margin-top: -11px; }
.map-add-after { left: 50%; bottom: -19px; margin-left: -11px; width: 20px; height: 20px; }
.map-wrap.down .map-add-child { right: auto; top: auto; left: 50%; bottom: -12px; margin: 0 0 0 -11px; }
.map-wrap.down .map-add-after { left: auto; right: -19px; bottom: auto; top: 50%; margin: -10px 0 0; }
.map-drop { position: absolute; pointer-events: none; z-index: 4; }
.map-drop.is-row { height: 3px; margin-top: -1.5px; background: var(--accent); border-radius: 2px; }
.map-drop.is-col { width: 3px; margin-left: -1.5px; background: var(--accent); border-radius: 2px; }
.map-drop.is-row::before, .map-drop.is-col::before { content: ''; position: absolute; width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--accent); background: var(--surface); box-sizing: border-box; }
.map-drop.is-row::before { left: -5px; top: -3px; }
.map-drop.is-col::before { top: -5px; left: -3px; }
.map-drop .drop-label { position: absolute; white-space: nowrap; }
.map-drop.is-row .drop-label { left: 50%; top: -10px; transform: translateX(-50%); right: auto; }
.map-drop.is-col .drop-label { top: -22px; left: 50%; transform: translateX(-50%); right: auto; }
.map-drop.is-inside .drop-label { left: -8px; top: -11px; transform: translateX(-100%); right: auto; }
.map-tools { position: absolute; top: 4px; right: 4px; z-index: 2; display: flex; gap: 1px; padding: 2px; border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line); opacity: 0; pointer-events: none; transition: opacity .12s; }
.map-card:hover .map-tools, .map-card:focus-within .map-tools { opacity: 1; pointer-events: auto; }
.map-card.renaming .map-tools, .map-card.dragging .map-tools { display: none; }
.map-rename-btn { flex: none; display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 5px; background: none; color: var(--muted); }
.map-rename-btn .icon { width: 12px; height: 12px; }
.map-rename-btn:hover { background: var(--surface-2); color: var(--accent); }
.map-del-btn:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.map-title { cursor: text; }
.map-rename { flex: 1; min-width: 0; padding: 3px 6px !important; font: inherit; font-size: 13px; line-height: 1.35; resize: none; overflow: hidden; border-color: var(--accent) !important; box-shadow: 0 0 0 3px var(--accent-soft) !important; }
.map-card.type-book .map-rename, .map-card.type-part .map-rename { font: var(--display-w) 14.5px/1.3 var(--display); }
.map-card.renaming { z-index: 6; box-shadow: var(--shadow-lg); }
.map-card.just-added { animation: just-added 1.2s ease-out; }
.map-fold.folded { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- read view ---------- */
.read { max-width: var(--prose-width); margin: 0 auto; padding: 0 clamp(16px, 5vw, 64px) 120px; }
.read-bar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.read-bar .read-scope { width: auto; max-width: 260px; }
.read-bar .check { margin: 0; font-size: 12.5px; }
.read-title { text-align: center; margin: 56px 0 40px; }
.read-title h1 { font: var(--display-w) 40px/1.15 var(--display); margin: 8px 0 0; }
.read-block { position: relative; }
.read-h { font-family: var(--display); font-weight: var(--display-w); text-align: center; }
.read-h1 { font-size: 30px; margin: 80px 0 36px; letter-spacing: .01em; }
.read-h2 { font-size: 23px; margin: 56px 0 26px; }
.read-h3 { font-size: 15px; margin: 32px 0 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.read-prose { cursor: text; }
.read-break { text-align: center; color: var(--muted); letter-spacing: .4em; margin: 1.4em 0; }
.read-gap { text-align: center; color: var(--muted); font: italic 14px var(--serif); margin: 24px 0; padding: 10px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); }
.read-edit { position: absolute; top: 0; right: -44px; opacity: 0; transition: opacity .15s; }
.read-block:hover > .read-edit { opacity: 1; }
.read-hint { text-align: center; margin-top: 48px; }
@media (max-width: 960px) { .read-edit { right: 0; } }

/* ---------- trash ---------- */
.trash-list { display: flex; flex-direction: column; gap: 10px; max-width: 760px; }
.trash-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.trash-item p { margin: 0; }
.trash-top { display: flex; align-items: center; gap: 8px; }
.trash-top strong { font: var(--display-w) 17px var(--display); }
.trash-syn { font-family: var(--serif); color: var(--ink-2); }
.trash-preview { font: italic 13.5px/1.5 var(--serif); color: var(--muted); }
.trash-actions { display: flex; gap: 8px; margin-top: 4px; }
.board-head .btn.danger-ghost { margin-top: 10px; }

/* ---------- import ---------- */
dialog.import { width: min(620px, calc(100vw - 32px)); }
.import-body { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.import-body > p { margin: 0; color: var(--ink-2); }
.import-drop { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 34px 16px; border: 2px dashed var(--line-strong); border-radius: var(--radius); background: var(--bg); color: var(--ink); }
.import-drop .icon { width: 26px; height: 26px; color: var(--accent); }
.import-drop:hover, .import-drop.over { border-color: var(--accent); background: var(--accent-soft); }
.import-stats { margin: 0; font-weight: 600; }
.import-outline { list-style: none; margin: 0; padding: 8px 10px; max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); font-size: 13px; }
.import-outline li { padding: 2px 0 2px calc(var(--depth) * 16px); display: flex; align-items: center; gap: 6px; }
.import-outline .dot { width: 7px; height: 7px; }
.dot.type-part { background: var(--t-part); } .dot.type-chapter { background: var(--t-chapter); } .dot.type-section { background: var(--t-section); }
.import-ai { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--accent-soft); }
.import-ai .check { margin: 8px 0; }
.import-ai p { margin: 4px 0 0; }
.import-status { min-height: 1.2em; margin: 10px 0 0; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr) 270px; }
  .stage-guide { display: none; }
}

@media (max-width: 960px) {
  .workspace { display: block; overflow: auto; }
  .binder { max-height: 38vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .main { overflow: visible; }
  .inspector { border-left: 0; border-top: 1px solid var(--line); }
  .main.view-map { overflow: visible; }
  .main.view-map .map-wrap { min-height: 70vh; }
}
@media (max-width: 760px) {
  .topbar-row:first-child { flex-wrap: wrap; row-gap: 6px; }
  .topbar-row .book-title { flex: 1; min-width: 120px; max-width: none; }
  .stage-row { overflow-x: auto; scrollbar-width: none; }
  .stage-guide { display: none; }
  .stage-label { display: none; }
  .stage.on .stage-label { display: inline; }
  .direction-grid, .neighbors { grid-template-columns: 1fr; }
  .pair { grid-template-columns: 1fr; }
  .sprint-text { padding: 20px !important; }
  .stats { grid-template-columns: 1fr 1fr; }
  dialog.help[open] { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .help-side { border-right: 0; border-bottom: 1px solid var(--line); padding: 12px; }
  .help-nav { flex-direction: row; overflow-x: auto; flex: none; }
  .help-nav button { white-space: nowrap; }
  .help-tour { display: none; }
  .help-body { padding: 20px 18px 36px; }
  .outline-grid { overflow-x: auto; }
  .o-row { min-width: 720px; }
  .title-input { font-size: 24px !important; }
  .drawer { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; height: 62vh; }
  body:has(.drawer) .main { padding-right: 0 !important; padding-bottom: 64vh; }
  .read-title h1 { font-size: 30px; }
}

/* side panel hidden */
body.no-inspector .inspector { display: none; }
body.no-inspector:not(.focus) .workspace { grid-template-columns: 270px minmax(0, 1fr); }
@media (max-width: 1180px) { body.no-inspector:not(.focus) .workspace { grid-template-columns: 220px minmax(0, 1fr); } }
@media (max-width: 960px) { body.no-inspector .workspace { display: block; } }

/* outline collapsed into a tab */
.binder-tab { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 14px 0; border: 0; border-right: 1px solid var(--line); background: var(--binder-bg); color: var(--ink-2); font: 600 11.5px var(--ui); letter-spacing: .08em; text-transform: uppercase; cursor: pointer; min-height: 0; }
.binder-tab span { writing-mode: vertical-rl; transform: rotate(180deg); }
.binder-tab .icon { width: 16px; height: 16px; }
.binder-tab:hover { color: var(--accent); background: var(--surface-2); }
body.no-binder:not(.focus) .workspace { grid-template-columns: 34px minmax(0, 1fr) 310px; }
body.no-binder.no-inspector:not(.focus) .workspace { grid-template-columns: 34px minmax(0, 1fr); }
@media (max-width: 1180px) { body.no-binder:not(.focus) .workspace { grid-template-columns: 34px minmax(0, 1fr) 270px; } body.no-binder.no-inspector:not(.focus) .workspace { grid-template-columns: 34px minmax(0, 1fr); } }
@media (max-width: 960px) {
  .binder-tab { flex-direction: row; width: 100%; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .binder-tab span { writing-mode: horizontal-tb; transform: none; }
}

/* off-screen box used to measure map cards before laying out the tree */
.map-measure { position: absolute; left: -10000px; top: 0; visibility: hidden; pointer-events: none; }
.map-measure .map-card { position: relative; height: auto !important; }

/* ---------- welcome: everything on one screen ---------- */
.welcome { padding: clamp(16px, 4vh, 40px) 24px; }
.welcome-card { max-width: 1080px; width: 100%; display: grid; gap: clamp(16px, 3vh, 32px); }
.welcome-intro, .welcome-side { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.welcome h1 { margin: clamp(10px, 2vh, 18px) 0 clamp(8px, 1.4vh, 12px); font-size: clamp(34px, 5.4vh, 44px); }
.welcome .lede { margin-bottom: clamp(16px, 2.6vh, 28px); font-size: clamp(16px, 2.1vh, 18px); }
.welcome-help { margin-top: clamp(12px, 2vh, 18px); }
.welcome-foot { border-top: 1px solid var(--line); padding-top: clamp(12px, 2vh, 20px); text-align: center; display: flex; flex-direction: column; align-items: center; }
.welcome-foot .welcome-help { margin: 0; }
.welcome .welcome-foot .fine { margin: 6px auto 0; max-width: 620px; }
.welcome-side .shelf { margin-top: 0; width: 100%; }
.welcome-side .vibe { margin-top: clamp(16px, 3vh, 32px); }
.book-cover { width: 112px; height: clamp(126px, 17.5vh, 158px); }
.book { width: 112px; }
.shelf-empty { width: 100%; padding: 22px 18px; border: 1.5px dashed var(--line-strong); border-radius: var(--radius); color: var(--muted); font: italic 14px/1.5 var(--serif); text-align: center; }
.shelf-empty b { display: block; font: 600 11px var(--ui); letter-spacing: .1em; text-transform: uppercase; font-style: normal; margin-bottom: 4px; }
@media (min-width: 980px) {
  .welcome-card { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: center; gap: clamp(32px, 5vw, 72px); }
  .welcome-intro { align-items: flex-start; text-align: left; }
  .welcome-intro .lede { margin-left: 0; }
  .welcome-intro .welcome-actions { justify-content: flex-start; }
  .welcome-foot { grid-column: 1 / -1; }
  .welcome-side .shelf-head { justify-content: flex-start; }
  .welcome-side .vibe { align-items: flex-start; }
  .welcome-side .skin-picker.compact { justify-content: flex-start; }
  .welcome-side:not(:has(.shelf)) { align-self: center; }
}

/* daily backups (Settings) */
.backup-settings p { margin: 0 0 8px; }
.backup-list { list-style: none; margin: 0 0 8px; padding: 0; font-size: 12.5px; color: var(--ink-2); }
.backup-list li { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.backup-list .icon { width: 13px; height: 13px; color: var(--s-done); }
