:root {
  --bg: #faf8f4;
  --panel: #ffffff;
  --ink: #23201b;
  --muted: #6b665d;
  --faint: #98928699;
  --note: #423c32; /* logline — readable secondary, between muted and ink */
  --line: #e6e1d8;
  --hover: #f0ece4;
  --btn: #f4f0e8;
  --energy: #534ab7;
  --tension: #d85a30; --tension-line: #e8cabd;
  --radius: 12px;
  /* Editor-zone accents: Sections = sage (matches loglines), Rhymes = rose, Details = azure. */
  --sage: #5f7d57; --sage-bg: #eef3e7; --sage-line: #cdddbf;
  --rose: #b5446e; --rose-bg: #fbeaf0; --rose-line: #f0ccda;
  --azure: #2f6db0; --azure-bg: #e6f1fb; --azure-line: #c4dcf2;
  --hl: #f4ecd4; --hl-ink: #4a4330; /* editorial highlight — muted, not a bright marker */
}

body.dark {
  --bg: #1a1917;
  --panel: #242220;
  --ink: #e8e3d8;
  --muted: #9a9488;
  --faint: #8a847b;
  --note: #cfc9bd;
  --line: #333028;
  --hover: #2e2c28;
  --btn: #2a2825;
  --energy: #8b82e8;
  --tension: #e07a55; --tension-line: #5a3a2c;
  --sage: #9cc28d; --sage-bg: #16210f; --sage-line: #3a5a2d;
  --rose: #e07898; --rose-bg: #2a0f1c; --rose-line: #5a2540;
  --azure: #82b8ec; --azure-bg: #0d1f35; --azure-line: #2a4a6e;
  --hl: #5c5536; --hl-ink: #ece5d2; /* editorial highlight — muted olive, light ink */
}

/* Prose Plot skin — same substrate, coral accent instead of Song Plot's purple.
   Higher-specificity dark+prose rule wins over plain body.dark regardless of
   source order, so it holds whichever theme (light/dark) is active. */
body.app-prose { --energy: #dd6349; }
body.dark.app-prose { --energy: #f0937a; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.control-group { display: flex; flex-direction: column; gap: 5px; }
.control-group label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); }
.seg { display: inline-flex; background: var(--btn); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font-size: 13px;
  padding: 6px 13px; border-radius: 7px; cursor: pointer; font-weight: 500;
  transition: background .12s, color .12s; font-family: inherit;
}
.seg button:hover { color: var(--ink); }
.seg button.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px #0000000f; }
body.dark .seg button.active,
body.dark .lwtoggle.active { background: #4a453e; color: #f3eee3; box-shadow: 0 1px 2px rgba(0,0,0,0.45); }

.pbtn { font-family: inherit; font-size: 12.5px; padding: 7px 11px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; cursor: pointer; }
.pbtn:hover { background: var(--hover); }
.pbtn:disabled { opacity: 0.4; cursor: default; }
.pbtn.danger { color: #a32d2d; }
.pbtn.danger:hover:not(:disabled) { background: #fbeaea; }

.stats { display: flex; gap: 8px; margin-left: auto; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; min-width: 58px; }
.stat.stat-editable { cursor: pointer; }
.stat.stat-editable:hover { border-color: var(--energy); }
.stat .k { font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; }
.stat .v { font-size: 17px; font-weight: 600; margin-top: 1px; }


/* act lanes */
.acts { display: flex; flex-direction: column; gap: 12px; }
.actband { display: flex; gap: 12px; align-items: stretch; }
.actlabel {
  flex: 0 0 32px; border-radius: 9px; background: var(--btn); color: var(--muted);
  display: flex; align-items: center; justify-content: center; padding: 12px 0;
  writing-mode: vertical-rl; transform: rotate(180deg); font-size: 12px; font-weight: 600; letter-spacing: 0.08em;
}
.actcards {
  flex: 1 1 auto; display: flex; flex-wrap: wrap; gap: 10px; align-content: flex-start;
  padding: 10px; border: 1px solid var(--line); border-radius: 11px; background: var(--bg); min-height: 92px;
  transition: background .1s, border-color .1s;
}
.actcards.dragover { border-color: var(--ink); background: var(--panel); }

.bcard {
  width: 218px; background: var(--panel); border: 1px solid var(--line); border-radius: 7px;
  padding: 10px 11px 11px; cursor: grab; display: flex; flex-direction: column; gap: 6px;
  transition: box-shadow .12s, border-color .12s;
}
.bcard:hover { box-shadow: 0 4px 14px #00000012; border-color: #d9d3c8; }
.bcard.beat { background: var(--btn); border-style: dashed; }
.bcard.beat:hover { border-style: solid; }
.bcard.scene { background: #efeefe; border-color: #c7c0f2; width: 50px; min-height: 100px; padding: 10px 0; align-items: center; justify-content: space-between; overflow: hidden; }
/* Cap the vertical label at ~2 columns by constraining its block axis (width,
   since writing-mode is vertical) and clipping the overflow. Deliberately NOT
   using -webkit-line-clamp / -webkit-box here: that combination flips the text
   upside-down on iOS WebKit when paired with vertical writing-mode. */
.bcard.scene .scene-title { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 11px; font-weight: 700; text-transform: uppercase; text-decoration: underline; letter-spacing: 0.07em; line-height: 1.85; color: #3c3489; text-align: center; flex: 1; min-height: 0; max-width: 3.7em; overflow: hidden; }
.scene-read-btn { border: 0; background: transparent; color: #3c3489; cursor: pointer; font-size: 10px; padding: 4px 0 2px; opacity: 0.5; line-height: 1; }
.scene-read-btn:hover { opacity: 1; }
body.dark .bcard.scene { background: #211d33; border-color: #5a5080; border-width: 1.5px; }
body.dark .bcard.scene .scene-title { color: #b8aef0; }
body.dark .scene-read-btn { color: #b8aef0; }
/* Prose Plot recontextualizes scenes as chapters — same thin vertical-text
   rectangle, coral instead of purple. */
body.app-prose .bcard.scene { background: #fdece7; border-color: #f0c4b3; }
body.app-prose .bcard.scene .scene-title { color: #9a4a34; }
body.app-prose .scene-read-btn { color: #9a4a34; }
body.dark.app-prose .bcard.scene { background: #2a1f1c; border-color: #6b4a3c; }
body.dark.app-prose .bcard.scene .scene-title { color: #f0937a; }
body.dark.app-prose .scene-read-btn { color: #f0937a; }
.bcard.dragging { opacity: 0.4; }
.bcard.drop-before { box-shadow: inset 3px 0 0 var(--ink); }
.bcard.drop-after { box-shadow: inset -3px 0 0 var(--ink); }

.bcard .top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.pill { font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 5px; }
.pill.beat-pill { background: var(--btn); color: var(--muted); }
/* Editable beat-function pill — typed straight on the card. */
.pill.beat-fn { cursor: text; outline: none; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill.beat-fn:not(.empty) { background: #e7e4f7; color: #4a4290; }
body.dark .pill.beat-fn:not(.empty) { background: #322c4d; color: #b8aef0; }
.pill.beat-fn:not(.empty):hover { box-shadow: inset 0 0 0 1px var(--line); }
.bcard:hover .pill.beat-fn.empty:hover, .pill.beat-fn.empty:focus { box-shadow: inset 0 0 0 1px var(--line); }
.pill.beat-fn:focus { background: #e7e4f7; color: #3c3489; box-shadow: inset 0 0 0 1px #8b82e8; }
body.dark .pill.beat-fn:focus { background: #322c4d; color: #cdc8ee; }
/* Keep a stable width while empty so focusing (which hides the placeholder)
   doesn't collapse the box out from under the cursor — otherwise the mouseup
   lands on the card behind it and opens the editor instead of placing a caret. */
.pill.beat-fn.empty { min-width: 38px; }
.pill.beat-fn.empty::before { content: ''; }
.bcard:hover .pill.beat-fn.empty:not(:focus)::before { content: '+ Beat'; opacity: 0.7; }
.pill.scene-pill { background: #e4e1fb; color: #3c3489; }
body.dark .pill.scene-pill { background: #14103a; border: 1px solid #6858d8; color: #9e90f0; }

/* Song tag families — light mode */
.pill[data-fam="blue"]   { background: #E6F1FB; color: #0C447C; }
.pill[data-fam="teal"]   { background: #E1F5EE; color: #0F6E56; }
.pill[data-fam="amber"]  { background: #FAEEDA; color: #854F0B; }
.pill[data-fam="pink"]   { background: #FBEAF0; color: #993556; }
.pill[data-fam="coral"]  { background: #FAECE7; color: #993C1D; }
.pill[data-fam="purple"] { background: #EEEDFE; color: #3C3489; }
.pill[data-fam="red"]    { background: #FCEBEB; color: #A32D2D; }
.pill[data-fam="green"]  { background: #EAF3DE; color: #27500A; }
.pill[data-fam="gray"]   { background: #F1EFE8; color: #444441; }

/* Song tag families — dark mode: darker bg + bright border + lighter text */
body.dark .pill[data-fam="blue"]   { background: #0d1f35; border: 1px solid #4a82c0; color: #82b8ec; }
body.dark .pill[data-fam="teal"]   { background: #0a2018; border: 1px solid #2a9060; color: #58c490; }
body.dark .pill[data-fam="amber"]  { background: #2a1806; border: 1px solid #c07820; color: #e8a84a; }
body.dark .pill[data-fam="pink"]   { background: #2a0f1c; border: 1px solid #c04070; color: #e07898; }
body.dark .pill[data-fam="coral"]  { background: #2a0e08; border: 1px solid #c05030; color: #e07858; }
body.dark .pill[data-fam="purple"] { background: #14103a; border: 1px solid #6858d8; color: #9e90f0; }
body.dark .pill[data-fam="red"]    { background: #2a0a0a; border: 1px solid #c03030; color: #e06868; }
body.dark .pill[data-fam="green"]  { background: #0a1e06; border: 1px solid #3a8a20; color: #70c050; }
body.dark .pill[data-fam="gray"]   { background: #1e1c18; border: 1px solid #706858; color: #a09888; }
.pct { font-size: 11px; font-weight: 700; color: var(--ink); background: var(--btn); border-radius: 5px; padding: 2px 6px; font-variant-numeric: tabular-nums; margin-left: auto; }
.pct.pct-hit { color: #fff; background: var(--energy); }
.bcard .title { font-size: 13px; font-weight: 600; line-height: 1.25; outline: none; }
.bcard .sub { font-size: 11px; color: var(--muted); line-height: 1.3; outline: none; }
.bcard .sub.note { color: var(--note); font-size: 11.5px; line-height: 1.4; }
/* editable title/sub sit flush until hovered/focused, so cards stay clean at rest */
.title.cardedit, .sub.cardedit { border-radius: 4px; padding: 0 3px; margin: 0 -3px; }
.title.cardedit:hover, .sub.cardedit:hover { cursor: text; box-shadow: inset 0 0 0 1px var(--line); }
.title.cardedit[contenteditable="true"], .sub.cardedit[contenteditable="true"] { cursor: text; box-shadow: inset 0 0 0 1px var(--line); }
.bcard .foot { display: flex; gap: 8px; align-items: center; margin-top: auto; padding-top: 3px; font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bcard .foot .statusdot { margin-left: auto; flex-shrink: 0; }
.card-lyric-row { display: flex; }
.card-lyric-btn { border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; padding: 3px 9px; border-radius: 6px; font-family: inherit; }
.card-lyric-btn:hover { background: var(--hover); color: var(--ink); border-color: var(--line); }
.change-badge { font-size: 12px; font-weight: 700; line-height: 1; margin-right: 4px; }
.change-badge.pos { color: var(--ink); }
.change-badge.neg { color: var(--ink); }
.change-badge.none { color: var(--faint); }
/* Clickable card-face controls (status dot + scene-change chip) replace the
   former Details dropdowns. */
.change-badge.click { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; margin-right: 0; border: 1px solid var(--line); border-radius: 5px; }
.change-badge.click:hover { background: var(--hover); }
.foot-rt { margin-left: auto; padding-left: 6px; }
.bcard .conflict { font-size: 10.5px; color: var(--muted); outline: none; min-width: 1ch; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: text; }
.bcard .conflict:hover, .bcard .conflict:focus { white-space: normal; overflow: visible; color: var(--ink); }
/* Empty conflict reads as nothing at rest; the "+ Conflict" box only appears
   on card hover (or while focused), so cards stay clean. */
.bcard .conflict[data-ph]:empty::before { content: ''; }
.bcard:hover .conflict[data-ph]:empty::before, .bcard .conflict[data-ph]:empty:focus::before { content: attr(data-ph); }
.bcard:hover .conflict:empty, .bcard .conflict:empty:focus { border: 1px dashed var(--line); border-radius: 5px; padding: 1px 5px; margin: -1px -5px; color: var(--faint); }
.bcard .statusdot.click { cursor: pointer; width: 9px; height: 9px; }
.bcard .statusdot.click:hover { box-shadow: 0 0 0 2px var(--hover), 0 0 0 3px var(--line); }
.minipop { position: fixed; z-index: 4000; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 8px 24px rgba(0,0,0,0.18); padding: 4px; display: flex; flex-direction: column; gap: 1px; min-width: 134px; }
.minipop-item { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; border-radius: 6px; padding: 6px 9px; font-family: inherit; font-size: 12.5px; color: var(--ink); cursor: pointer; text-align: left; }
.minipop-item:hover { background: var(--hover); }
.minipop-item.active { background: var(--btn); font-weight: 600; }
.minipop-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.minipop-sym { width: 14px; text-align: center; font-weight: 700; flex-shrink: 0; }
.minipop-sym.pos { color: var(--ink); }
.minipop-sym.neg { color: var(--ink); }
.minipop-sym.none { color: var(--faint); }

.addtile {
  width: 64px; min-height: 64px; border: 1px dashed #d6cfc1; border-radius: 10px; background: transparent;
  color: var(--muted); display: flex; align-items: center; justify-content: center; position: relative;
  align-self: stretch;
}
.addtile .addbtn { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.addtile .addbtn:hover { background: var(--ink); color: #fff; }
.addtile .addmenu { position: absolute; top: 40px; left: 50%; transform: translateX(-50%); z-index: 6; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 6px 20px #0000001a; padding: 4px; display: none; flex-direction: column; gap: 2px; }
.addtile .addmenu.open { display: flex; }
.addtile .addmenu button { white-space: nowrap; border: 0; background: transparent; padding: 6px 14px; border-radius: 6px; font-size: 12.5px; color: var(--ink); cursor: pointer; text-align: left; font-family: inherit; }
.addtile .addmenu button:hover { background: var(--hover); }

/* intermission / midpoint divider between lanes */
.laneint { display: flex; align-items: center; gap: 12px; margin: 5px 0 5px 44px; }
.laneint::before, .laneint::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.laneint span { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); background: var(--btn); padding: 3px 12px; border-radius: 20px; font-weight: 600; }
.laneint.interm::before, .laneint.interm::after { background: var(--line); }
.laneint.interm span { background: var(--btn); color: var(--muted); }

.bcard .statusdot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

.hint { font-size: 12px; color: var(--muted); margin-top: 16px; line-height: 1.6; }
.hint b { color: var(--ink); font-weight: 600; }

/* detail drawer */
.lyricwin .dclose { border: 0; background: transparent; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.lyricwin .dclose:hover { background: var(--hover); color: var(--ink); }
/* Dark mode: lift the editor windows off the near-identical board behind them. */
body.dark .lyricwin-overlay { background: rgba(0,0,0,0.62); }
body.dark .lyricwin { border-color: #4a443a; box-shadow: 0 28px 80px rgba(0,0,0,0.6); }

.fld { display: flex; flex-direction: column; gap: 5px; }
.fld[hidden] { display: none !important; }
.fld.row2 { flex-direction: row; gap: 12px; }
.fld.row2 > .fld { flex: 1; }
.fl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); font-weight: 600; }
.fi { width: 100%; font-family: inherit; font-size: 13px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); }
.fi:focus { outline: none; border-color: var(--ink); }
select.fi { cursor: pointer; }
textarea.ft { width: 100%; font-family: inherit; font-size: 13px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; min-height: 64px; color: var(--ink); line-height: 1.5; background: var(--bg); }
textarea.ft:focus { outline: none; border-color: var(--ink); }

.sing { background: #efeefe; border: 1px solid #c7c0f2; border-radius: 10px; padding: 12px; }
.sing .fl { color: #3c3489; }
.sing.empty { border-color: #a99de8; background: #efeefe; }
.sing textarea.ft { background: var(--panel); }
body.dark .sing { background: var(--panel); border-color: #8b82e8; }
body.dark .sing .fl { color: #9e90f0; }
body.dark .sing.empty { background: var(--panel); border-color: #8b82e8; }

.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row input[type=range] { flex: 1; accent-color: var(--ink); }
.slider-row .sv { font-size: 13px; font-weight: 600; min-width: 18px; text-align: right; font-variant-numeric: tabular-nums; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--energy); }
.dnote { font-size: 11px; color: var(--faint); margin-top: -2px; }

/* rhyme tools */
.rhymeresults { display: flex; flex-wrap: wrap; gap: 5px; }
.rchip { font-size: 12px; background: var(--panel); color: var(--energy); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; }
.rchip.click { cursor: pointer; }
.rchip.click:hover { background: var(--hover); }
.rhint { font-size: 11px; color: var(--faint); }
.rhyme-tab-wrap { display: flex; gap: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.rhyme-tab { flex: 1; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; padding: 4px 0; border: none; background: var(--panel); color: var(--faint); cursor: pointer; }
.rhyme-tab.active { background: var(--hover); color: var(--energy); }
.rhyme-tab:hover:not(.active) { background: var(--hover); }

/* Edit / Preview toggle in lyric window header */
.lwtoggle-wrap { display: inline-flex; background: var(--btn); border-radius: 8px; padding: 3px; gap: 2px; }
.lwtoggle { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 5px 12px; border-radius: 6px; cursor: pointer; font-weight: 500; font-family: inherit; }
.lwtoggle:hover { color: var(--ink); }
.lwtoggle.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px #0000000f; }


/* Broadway preview pane */
.lwpreview-wrap { flex: 1; overflow-y: auto; background: var(--panel); display: flex; flex-direction: column; }
.lwrich-wrap { flex: 1; min-height: 0; overflow-y: auto; background: var(--panel); display: flex; flex-direction: column; }
.lwrich-wrap .ms-card-rich-editor { flex: 1; min-height: 0; }
.lwrich-wrap .ms-style-bar { position: sticky; top: 0; z-index: 2; }
/* .ms-card-rich-editor is a column flexbox, so ms-line-editor is a flex item —
   auto margins on a flex item's cross axis absorb free space directly and
   override align-items:stretch, which shrank this to its content width (a
   near-empty line) instead of centering a 720px column. An explicit width
   makes it a definite size again, so margin:auto centers it normally. */
.lwrich-wrap .ms-line-editor { width: 100%; padding: 20px 24px 60px; max-width: 720px; margin: 0 auto; }
.lwzoom-bar { display: flex; align-items: center; gap: 6px; justify-content: center; padding: 6px 0; background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0; position: sticky; top: 0; z-index: 2; }
.lw-preview {
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 13px; line-height: 1.25;
  max-width: 620px; margin: 0 auto; padding: 40px 32px 60px;
  color: var(--ink);
}
.lw-preview-hint { font-size: 13px; color: var(--faint); text-align: center; margin-top: 48px; }

/* Act header: ACT ONE — centered bold underlined */
.lw-act-header { text-align: center; font-weight: 700; text-decoration: underline; letter-spacing: 0.06em; }
/* Scene heading: SCENE 1: SUMMER FESTIVAL — centered bold underlined */
.lw-scene-header { text-align: center; font-weight: 700; text-decoration: underline; }
/* Song number: (#01) OPENING — left, bold underlined */
.lw-song-header { font-weight: 700; text-decoration: underline; }
/* Character cue: centered bold — no extra margin; blank lines in text provide spacing */
.lw-char { text-align: center; font-weight: 700; letter-spacing: 0.04em; }
/* Sung line: left flush */
.lw-sung {}
/* Spoken dialogue under a character cue: small left indent */
.lw-dialogue { padding-left: 8%; }
/* Parenthetical: italic, indented more than dialogue */
.lw-paren { font-style: italic; padding-left: 20%; color: var(--muted); }
/* Standalone stage action: deeply right-shifted */
.lw-action { padding-left: 54%; }
/* Blank line = exactly one line height so rhythm stays consistent */
.lw-blank { height: 1.25em; }
.lw-section-row { margin: 0.2em 0; }
.lw-section-tag {
  display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--sage); background: var(--sage-bg); padding: 2px 14px; border-radius: 20px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
/* Section tags live on the always-white print sheets, so keep the sage pill light
   even in dark mode (the dark sage-bg is unreadable on a white sheet). */
.ms-viewport .lw-section-tag,
#pdf-print-root .lw-section-tag { background: #eef3e7; color: #5f7d57; }
/* Prose Plot's scene break — a centered ⁂ divider, not a text line. */
.lw-scenebreak { text-align: center; color: var(--muted); letter-spacing: 0.3em; margin: 0.6em 0; }

/* Manuscript page */
.ms-zoom-wrap { display: flex; align-items: center; gap: 4px; }
.ms-zoom-btn { border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 16px; line-height: 1; width: 32px; height: 32px; border-radius: 7px; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; font-family: inherit; transition: background 0.12s, color 0.12s; }
.ms-zoom-btn:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
.ms-zoom-btn:disabled { opacity: 0.35; cursor: default; }
.ms-zoom-lbl { font-size: 12px; color: var(--muted); min-width: 38px; text-align: center; font-variant-numeric: tabular-nums; }
.ms-body { flex: 1; overflow-y: auto; background: #888; }
body.dark .ms-body { background: var(--bg); }
/* Settings is the icon variant of the shared ribbon button: square, no text,
   a larger glyph. Height/border/hover come from the shared rule below. */
.ms-settings-btn { width: 32px; padding: 0; justify-content: center; }
.ms-print-btn svg { display: block; flex-shrink: 0; }
.ms-settings-btn svg { display: block; flex-shrink: 0; width: 19px; height: 19px; }
/* "Section tags" toggle hides section pills in the Edit/Rich view too. */
.ms-edit-doc.hide-sections .lw-section-row,
.ms-edit-doc.hide-sections .ms-el.lw-section-row { display: none; }
/* Beatlines have their own toggle (independent of Section tags — Song Plot's
   chord/section markup has nothing to do with a beat's outline reference). */
.ms-edit-doc.hide-beatlines .lw-note-ms,
.ms-edit-doc.hide-beatlines .ms-edit-logline { display: none; }
.ms-card-content > .lw-note-ms:first-child { margin-top: 0; }
/* Beatline pinned above the rich editor while editing — keep the sheet column
   padding for wrapping, but hug the editor (no big bottom gap). */
.ms-edit-doc .ms-edit-logline { padding: 12px 120px 0; }
.ms-edit-logline .lw-note-ms { margin-top: 0; }
.ms-opt-toggle { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); cursor: pointer; margin-left: 12px; white-space: nowrap; user-select: none; }
.ms-opt-toggle input { cursor: pointer; accent-color: var(--energy); }

/* Header settings drawer */
.ms-hd-drawer { width: 0; overflow: hidden; background: var(--panel); border-left: 1px solid var(--line); transition: width 0.22s ease; flex-shrink: 0; display: flex; flex-direction: column; }
.ms-hd-drawer.open { width: 288px; }
.ms-hd-inner { width: 288px; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 0 16px 22px; }
/* Sticky title so it stays put while the options scroll */
.ms-hd-titlebar { position: sticky; top: 0; z-index: 2; background: var(--panel); display: flex; align-items: center; justify-content: space-between; padding: 14px 0 10px; border-bottom: 1px solid var(--line); }
.ms-hd-title { font-size: 13px; font-weight: 600; color: var(--ink); }
.ms-hd-close { border: 0; background: transparent; font-size: 15px; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 5px; line-height: 1; }
.ms-hd-close:hover { background: var(--hover); color: var(--ink); }

.ms-hd-section-head { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; margin-top: 4px; }
.ms-hd-divider { border: none; border-top: 1px solid var(--line); margin: 2px 0; }

/* Stacked rows (inputs that need a label above) */
.ms-hd-row { display: flex; flex-direction: column; gap: 6px; }
.ms-hd-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }

/* Compact inline toggle rows — label left, checkbox right */
.ms-hd-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 0; cursor: pointer; user-select: none; }
.ms-hd-toggle-label { font-size: 13px; color: var(--ink); font-weight: 500; }
.ms-hd-toggle input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--energy); flex-shrink: 0; margin: 0; }

/* Subgroup of header options — dims when header is off */
.ms-hd-subgroup { display: flex; flex-direction: column; gap: 12px; }
.ms-hd-subgroup.dimmed { opacity: 0.4; pointer-events: none; }

.ms-hd-fmt-wrap { display: flex; flex-direction: column; gap: 6px; }
.ms-hd-fmt-input { font-size: 12px; }
.ms-hd-tokens { display: flex; gap: 5px; flex-wrap: wrap; }
.ms-hd-token { font-size: 11px; font-family: 'Courier Prime', monospace; background: var(--btn); border: 1px solid var(--line); border-radius: 5px; padding: 3px 8px; cursor: pointer; color: var(--ink); }
.ms-hd-token:hover { background: var(--hover); border-color: var(--energy); }

/* Make the alignment seg fill the drawer width (no stray empty space) */
.ms-hd-row .seg { display: flex; width: 100%; }
.ms-hd-row .seg button { flex: 1; }

.ms-hd-preview-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.ms-hd-preview { font-family: 'Courier Prime', 'Courier New', Courier, monospace; font-size: 11px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; color: var(--ink); min-height: 32px; display: block; width: 100%; box-sizing: border-box; }
.ms-sheet-hdr-text { flex: 1; }

/* Viewport: gray desk, sheets stack vertically */
.ms-viewport {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  padding: 40px 32px 80px;
  transform-origin: top center;
}

/* Each sheet: 8.5×11" page */
.ms-sheet {
  width: 816px;
  min-height: 1056px;
  background: #fff;
  color: #111;
  box-shadow: 0 4px 24px #0005;
  display: flex;
  flex-direction: column;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 12pt;
  line-height: 1.0; /* FD Spacing="1" Leading="Regular" — 6 lines/inch typewriter standard */
  flex-shrink: 0;
}
.ms-sheet-header {
  display: flex;
  justify-content: space-between;
  padding: 48px 48px 0; /* 0.5" from top edge; 0.5" side margins */
  font-size: 12pt; /* FD: Size=12 */
  color: #333;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  min-height: 24px;
}
.ms-sheet-content {
  flex: 1;
  padding: 12px 120px 72px; /* top: hdr(72px)+12px = 84px = 0.875" from top; bottom: 0.75" = 72px */
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 12pt;
  line-height: 1.0;
  color: #111;
}
.lyricwin .ms-sheet-content { color: var(--ink); padding: 40px 32px 60px; }
.lyricwin .ms-sheet-content .lw-paren { color: var(--muted); }
.ms-edit-doc .ms-sheet-content { color: var(--ink); }
.ms-edit-doc .ms-sheet-content .lw-paren { color: var(--muted); }
.ms-sheet-show-title {
  text-align: center;
  font-size: 14pt;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-decoration: underline;
  /* 32px == the act header's 2em top margin (em differs here: the title is 14pt),
     so a titled/untitled page opens content at the same height. */
  margin: 32px 0 1em;
}

/* In-sheet element styles (override lw- defaults for print context) */
.ms-sheet-content .lw-act-header {
  text-align: center;
  font-weight: 700;
  text-decoration: underline;
  letter-spacing: 0.06em;
  margin: 2em 0 1em;
}
.ms-sheet-content .ms-divider {
  text-align: center;
  margin: 1.5em 0;
  font-weight: 700;
  letter-spacing: 0.18em;
}
/* FD SpaceBefore="12" = 12pt = one line before; SpaceBefore="0" = no gap */
.ms-sheet-content .lw-scene-header { margin: 12pt 0 0; font-weight: bold; text-transform: uppercase; }
.ms-sheet-content .lw-song-header  { margin: 12pt 0 0; }
.ms-sheet-content .lw-blank        { height: 12pt; } /* one line of space */
/* FD Character: 3.00" from page left → 3.00-1.25=1.75" extra = 168px; SpaceBefore="12" */
.ms-sheet-content .lw-char         { margin-left: 168px; margin-top: 12pt; font-weight: bold; text-transform: uppercase; text-align: left; }
/* FD Lyrics: 1.25"–7.25" = full content width; SpaceBefore="0" */
.ms-sheet-content .lw-sung         { margin-left: 0; margin-right: 0; text-transform: uppercase; text-align: left; }
/* FD Dialogue: 1.75"–6.38" → left +48px, right +84px; SpaceBefore="0" */
.ms-sheet-content .lw-dialogue     { margin-left: 48px; margin-right: 84px; text-align: left; }
/* FD Parenthetical: 3.00"–7.00" → left 168px, right 24px; SpaceBefore="0" */
.ms-sheet-content .lw-paren        { margin-left: 168px; margin-right: 24px; padding-left: 0; color: #555; text-align: left; }
/* FD Action: LeftIndent="4.00" (4.00-1.25=2.75"=264px), RightIndent to edge, SpaceBefore="12" */
.ms-sheet-content .lw-action       { margin-top: 12pt; margin-left: 264px; margin-right: 0; padding-left: 0; text-align: left; }
/* Beat logline / outline note — a reference annotation, not script. Sage, italic,
   and gated behind the Section-tags toggle (hidden when off, via buildContentTokens). */
.ms-sheet-content .lw-note-ms      { margin-top: 12pt; color: #5f7d57; font-style: italic; text-align: left; }
body.dark .ms-sheet-content .lw-note-ms { color: #9cc28d; }
.ms-viewport .lw-note-ms, #pdf-print-root .lw-note-ms { color: #5f7d57; }
/* Avoid double gaps: when a literal blank-line token already precedes an element
   that carries SpaceBefore, drop the margin so the gap is one line, not two. */
/* Revisions panel in the manuscript settings drawer. */
.ms-rev-section { display: flex; flex-direction: column; gap: 8px; }
.ms-rev-current { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.ms-rev-swatch { width: 13px; height: 13px; border-radius: 3px; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15); }
.ms-rev-name { font-weight: 600; }
.ms-rev-none { font-size: 12px; color: var(--muted); line-height: 1.4; }
.ms-rev-btn {
  align-self: flex-start; font-size: 12px; font-weight: 600; padding: 5px 11px;
  border: 1px solid var(--energy); border-radius: 6px; background: var(--energy); color: #fff;
  cursor: pointer; font-family: inherit;
}
.ms-rev-btn:hover { filter: brightness(1.08); }
.ms-rev-lockbtn { background: transparent; color: var(--energy); }
.ms-rev-locknote { font-size: 12px; color: var(--muted); line-height: 1.4; }
.ms-rev-list { display: flex; flex-direction: column; gap: 4px; margin-top: 2px; }
.ms-rev-item { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.ms-rev-item.active { color: var(--ink); font-weight: 600; }

/* Final Draft-style revision mark: an asterisk in the right margin of any line
   changed under the active revision. Colour = the revision's issue colour. */
.ms-sheet-content .lw-rev { position: relative; }
.ms-sheet-content .lw-rev::after {
  content: '*';
  position: absolute; top: 0; right: -60px;
  color: var(--revc, #2b6cb0);
  font-weight: 700;
}
.ms-sheet-content .lw-blank + .lw-char,
.ms-sheet-content .lw-blank + .lw-action,
.ms-sheet-content .lw-blank + .lw-note-ms,
.ms-sheet-content .lw-blank + .lw-scene-header,
.ms-sheet-content .lw-blank + .lw-song-header { margin-top: 0; }
/* Dual dialogue: two (or more) cues side by side. Columns share the content
   width; inside a column the cue/lyrics indents collapse to fit the narrow box. */
.ms-sheet-content .lw-dual { display: flex; gap: 24px; margin-top: 12pt; align-items: flex-start; }
.ms-sheet-content .lw-dual .lw-col { flex: 1 1 0; min-width: 0; }
.ms-sheet-content .lw-dual .lw-char { margin-left: 0; margin-top: 0; text-align: center; }
.ms-sheet-content .lw-dual .lw-sung,
.ms-sheet-content .lw-dual .lw-dialogue { margin-left: 0; margin-right: 0; }
.ms-sheet-content .lw-dual .lw-paren { margin-left: 0; margin-right: 0; text-align: center; }
.ms-sheet-content .lw-dual .lw-col > .lw-blank:first-child { display: none; }

/* Print export root — built off-screen, revealed only when printing */
#pdf-print-root { display: none; }

@media print {
  @page { size: letter; margin: 0; }

  html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; }

  /* When PDF export root is present, show only that */
  body:has(#pdf-print-root) > *:not(#pdf-print-root) { display: none !important; }
  #pdf-print-root { display: block !important; }
  #pdf-print-root .ms-viewport { zoom: 1 !important; gap: 0 !important; padding: 0 !important; display: block !important; }
  /* Exact letter sizing in inches avoids px→page rounding (blank pages / right-edge clipping) */
  #pdf-print-root .ms-sheet {
    width: 8.5in;
    height: 11in;
    min-height: 0;
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    overflow: hidden;
    break-after: page;
    page-break-after: always;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  #pdf-print-root .ms-sheet:last-child { break-after: avoid; page-break-after: avoid; }
  #pdf-print-root [contenteditable] { outline: none; }
}

/* Title pages */
.tp-title-page { display: flex; flex-direction: column; min-height: 912px; /* 1056 - 144px header/padding */ }
.tp-spacer-large { height: 144pt; }
.tp-spacer { height: 24pt; }
.tp-spacer-push { flex: 1; }
.tp-spacer-push-2 { flex: 2; }
.tp-draft-block { text-align: center; }
.tp-draft-line { text-align: center; }
.tp-show-title { text-align: center; font-weight: bold; letter-spacing: 0.05em; }
.tp-rule { border-top: 1px solid #111; margin: 12pt 48px; }
.tp-subtitle { text-align: center; }
.tp-authors { text-align: center; white-space: pre-wrap; }
.tp-contact-block { margin-bottom: 24pt; }
.tp-contact-label { }
.tp-contact-line { padding-left: 48px; }
.tp-contact-or { padding-left: 48px; margin-top: 12pt; }
.tp-contact-inline { display: inline; }
.tp-section-heading { text-align: center; font-weight: normal; font-size: 12pt; text-decoration: underline; text-transform: uppercase; margin: 24pt 0 0; }
.tp-cast-heading { }
.tp-songs-heading { }
.tp-song-row { text-align: center; line-height: 2; }
.tp-cast-row { text-align: center; line-height: 2; }
.tp-cast-hint { color: #888; font-style: italic; text-align: center; }
.tp-settings-list { padding-left: 96px; white-space: pre-wrap; line-height: 2; }
.tp-freetext { padding-left: 48px; white-space: pre-wrap; }

/* Editable fields on title pages */
[contenteditable="true"] { outline: none; border-radius: 3px; }
[contenteditable="true"]:hover { background: rgba(0,0,0,0.04); }
[contenteditable="true"]:focus { background: rgba(255,220,80,0.15); }
[contenteditable][data-placeholder]:empty::before { content: attr(data-placeholder); color: #aaa; font-style: italic; pointer-events: none; }

/* Title page include-bar */
.tp-checks {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 8px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 2;
}
.tp-checks-group { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.tp-checks-label { flex-shrink: 0; width: 120px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); font-weight: 600; }
.tp-check-item { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--ink); cursor: pointer; user-select: none; }
.tp-check-item input[type="checkbox"] { width: 14px; height: 14px; cursor: pointer; accent-color: var(--energy); }

/* full-screen lyric editor window */
.lyricwin-overlay { position: fixed; inset: 0; background: #2c2c2a55; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 24px; }
.lyricwin { width: 1000px; max-width: 96vw; height: 86vh; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 24px 70px #00000033; display: flex; flex-direction: column; overflow: hidden; }
.lwhead { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.lwhead .lwtitle { font-size: 16px; font-weight: 600; }
.lwhead .lwsummary { font-size: 12px; color: var(--muted); }
.lwbody { flex: 1; display: grid; grid-template-columns: 58px 1fr 264px; min-height: 0; }
.lwgutter { overflow: auto; border-right: 1px solid var(--line); background: var(--bg); padding: 20px 0; scrollbar-width: none; }
.lwgutter::-webkit-scrollbar { display: none; }
.lwg-row { height: 30px; line-height: 30px; display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding-right: 9px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.lwg-row .g-letter { color: var(--energy); font-weight: 700; width: 11px; text-align: center; }
textarea.lweditor { border: 0; resize: none; outline: none; padding: 20px 26px; font-family: 'Iowan Old Style', Palatino, Georgia, serif; font-size: 16px; line-height: 30px; color: var(--ink); white-space: pre; overflow: auto; background: var(--panel); }
textarea.lweditor::placeholder { color: #c5beb0; }
.lwside { border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; background: var(--bg); }
.lwside .fl { color: var(--energy); }
.lwside .fl.muted { color: var(--faint); }
.lwnote { font-size: 11.5px; color: var(--muted); line-height: 1.45; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 9px; }
.lwnote.warn { color: var(--tension); background: var(--btn); border-color: var(--line); }
.lwg-section { background: var(--hover); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.lwsection-btns { display: flex; flex-wrap: wrap; gap: 5px; }

/* Editor sidebar zones — colour the text/accents only, on the plain sidebar
   background (no filled boxes): Sections sage (matches loglines), Rhymes rose. */
.lwzone { display: flex; flex-direction: column; gap: 9px; }
.lwzone-sections .fl { color: var(--sage); }
.lwzone-sections .rchip { color: var(--sage); }
.lwzone-rhymes .fl { color: var(--rose); }
.lwzone-rhymes .rchip { color: var(--rose); }
.lwzone-rhymes .rhyme-tab.active { color: var(--rose); }
.lwzone-rhymes .fi:focus { border-color: var(--rose); }

/* plain editor (scenes): no syllable gutter, prose wraps */
.lwbody-plain { grid-template-columns: 1fr 264px; }
.lwbody-plain .lweditor { white-space: pre-wrap; }

/* Details panel folded into the editor sidebar — azure text on plain background */
.lwdetails { margin-top: 4px; border-top: 1px solid var(--line); padding-top: 10px; }
.lwdetails-head { display: flex; align-items: center; gap: 6px; width: 100%; background: none; border: 0; padding: 4px 0; cursor: pointer; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--azure); font-weight: 600; }
.lwdetails-caret { font-size: 9px; width: 10px; }
.lwdetails-body { display: flex; flex-direction: column; gap: 13px; padding: 10px 0 4px; }
.lwdetails-body .fl { color: var(--azure); }
.lwdetails .fi:focus { border-color: var(--azure); }
.lwdelete { align-self: flex-start; background: none; border: 0; color: #a32d2d; font-size: 13px; padding: 6px 0; cursor: pointer; }

/* inline-editable card fields: placeholder when empty */
.bcard [data-ph]:empty::before { content: attr(data-ph); color: var(--faint); font-weight: 400; font-style: normal; }
.bcard [contenteditable]:focus { background: #fff7e6; box-shadow: 0 0 0 2px #f0d68a; border-radius: 4px; }
body.dark .bcard [contenteditable]:focus { background: #000; color: #fff; box-shadow: 0 0 0 2px #000; }

/* song function pill doubles as a picker (transparent native select overlay) */
.pill-wrap { position: relative; display: inline-flex; }
.pill-wrap .pill { cursor: pointer; }
.pill-select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; -webkit-appearance: none; appearance: none; }

body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }

/* ===== Top navigation ===== */
.topnav {
  --tn-bg: #3a3475; --tn-border: #2e2960; --tn-ink: #f1eefc; --tn-muted: #c2bcee;
  --tn-pill-bg: #4c4592; --tn-pill-ink: #cdc8ee; --tn-active-bg: #ffffff; --tn-active-ink: #3a3475;
  --tn-hover: #4c4592; --tn-brand: #ffffff;
  flex-shrink: 0;
  background: var(--tn-bg);
  border-bottom: 1px solid var(--tn-border);
  padding-top: env(safe-area-inset-top);
  z-index: 20;
}
body.dark .topnav {
  --tn-bg: #201d2b; --tn-border: #2e2a40; --tn-ink: #e8e3d8; --tn-muted: #9a93b0;
  --tn-pill-bg: #2a2640; --tn-pill-ink: #b3abe0; --tn-active-bg: #6a61d0; --tn-active-ink: #ffffff;
  --tn-hover: #2a2738; --tn-brand: #8b82e8;
}
/* Prose Plot skin — the header bar itself goes coral (not just accent chips),
   so the app reads as a different room, not a re-tinted Song Plot. Combined
   dark+prose selector out-specifies plain body.dark so it wins regardless of
   which theme is active. */
body.app-prose .topnav {
  --tn-bg: #9a4a34; --tn-border: #7c3c2a; --tn-ink: #fdf1ec; --tn-muted: #ecc3b3;
  --tn-pill-bg: #b8674a; --tn-pill-ink: #fbe2d8; --tn-active-bg: #ffffff; --tn-active-ink: #9a4a34;
  --tn-hover: #b8674a; --tn-brand: #ffffff;
}
body.dark.app-prose .topnav {
  --tn-bg: #241a17; --tn-border: #3a2620; --tn-ink: #f3e4dc; --tn-muted: #cf9c89;
  --tn-pill-bg: #3a2620; --tn-pill-ink: #edc2ae; --tn-active-bg: #f0937a; --tn-active-ink: #241a17;
  --tn-hover: #33221d; --tn-brand: #f0937a;
}

/* ===== Prose Plot accent overrides =====
   Song Plot's purple leaks in wherever a rule hard-codes a hex instead of
   var(--energy). Rather than refactor every rule to the variable (and risk
   shifting Song Plot), we re-point just the surfaces Prose Plot can actually
   reach — Board beat pills, the manuscript editor toolbar, Characters, the
   save dot, and the snapshots drawer — to a matching coral. Song-only surfaces
   (song function pills, "Why does this sing?", the reference banner) never
   render in Prose Plot, so they're deliberately left alone. */

/* Save-dot pulse (header, both apps) */
body.app-prose .sb-save-dot.saving { background: #f0937a; }

/* Board — editable beat-function pill */
body.app-prose .pill.beat-fn:not(.empty) { background: #fbe3db; color: #8a4230; }
body.dark.app-prose .pill.beat-fn:not(.empty) { background: #3a2620; color: #edc2ae; }
body.app-prose .pill.beat-fn:focus { background: #fbe3db; color: #9a4a34; box-shadow: inset 0 0 0 1px #dd8a72; }
body.dark.app-prose .pill.beat-fn:focus { background: #3a2620; color: #f3d3c5; }

/* Manuscript — nav / settings / title toggle buttons */
body.app-prose .ms-nav-btn.active, body.app-prose .ms-settings-btn.active, body.app-prose .ms-title-btn.active { background: var(--energy); border-color: var(--energy); }
body.dark.app-prose .ms-nav-btn.active, body.dark.app-prose .ms-settings-btn.active, body.dark.app-prose .ms-title-btn.active { background: var(--energy); border-color: var(--energy); }

/* Manuscript — Edit/Print segment container */
body.app-prose .ms-mode-seg, body.app-prose .ribbon .seg { background: #f2ded4; }
body.dark.app-prose .ms-mode-seg, body.dark.app-prose .ribbon .seg { background: #33221d; }

/* Manuscript — style dropdown + Dual + Bold/Italic/Underline toolbar */
body.app-prose .ms-style-sel, body.app-prose .ms-dual-btn, body.app-prose .ms-fmt-btn { border-color: #f0c4b3; color: #9a4a34; }
body.app-prose .ms-style-sel:focus { border-color: #dd8a72; }
body.app-prose .ms-fmt-btn:hover { background: #fbede8; }
body.app-prose .ms-fmt-divider { background: #f0d2c8; }
body.dark.app-prose .ms-style-sel, body.dark.app-prose .ms-dual-btn, body.dark.app-prose .ms-fmt-btn { background: #33221d; border-color: #5a3d33; color: #edc2ae; }
body.dark.app-prose .ms-fmt-divider { background: #5a3d33; }

/* Characters — character/group toggle (dark active) */
body.dark.app-prose .ch-kind-btn.active { background: var(--energy); }

/* Snapshots drawer — reassurance banner */
body.app-prose .snap-reassure { background: #fdece7; color: #9a4a34; }
body.dark.app-prose .snap-reassure { background: #2a1f1c; color: #edc2ae; }

/* Primary buttons (New novel, Create novel, Add character, Sync, etc.) */
body.app-prose .pbtn.primary { background: #cb5237; border-color: #cb5237; color: #fdf1ec; }
body.app-prose .pbtn.primary:hover { background: #b8482f; border-color: #b8482f; }
body.dark.app-prose .pbtn.primary { background: #b04a34; border-color: #b04a34; color: #fce8df; }
body.dark.app-prose .pbtn.primary:hover { background: #c85a40; border-color: #c85a40; }

/* Toolbar / ribbon backgrounds (Board ribbon, Manuscript toolbar, Characters bar) */
body.app-prose .ribbon, body.app-prose .ms-toolbar { background: #fbeee9; }
body.dark.app-prose .ribbon, body.dark.app-prose .ms-toolbar { background: #221a17; }

/* Manuscript format bar (the sticky Element/Bold/Italic strip) */
body.app-prose .ms-style-bar { background: #fbe9e3; border-bottom-color: #f2d5cb; }
body.dark.app-prose .ms-style-bar { background: #1f1613; border-bottom-color: #3a2620; }

/* "Body" (a screenplay Action line, reused as Prose Plot's default paragraph)
   carries a deep script-convention right-indent — wrong for a novel, which
   wants a plain full-width paragraph in both Edit and Print View. */
body.app-prose .lw-action { padding-left: 0; }
/* Paragraph convention (Prose Plot, Page setup drawer). Default: Indent — a
   first-line indent with paragraphs flowing tight, no gap (print-novel
   convention). "Block" swaps to no indent + a visible gap between paragraphs
   (manuscript/web-serial convention). Applies in both Edit and Print View. */
body.app-prose .ms-sheet-content .lw-action { margin-left: 0; margin-top: 0; text-indent: 1.5em; }
body.app-prose .lw-action { margin-top: 0; }
body.app-prose.ms-para-block .ms-sheet-content .lw-action { text-indent: 0; margin-top: 0.5em; }
body.app-prose.ms-para-block .lw-action { margin-top: 0.4em; }
/* Standard manuscript format is double-spaced (Shunn convention) — Song Plot's
   screenplay sheet is single-spaced (line-height: 1, §5), so Prose Plot needs
   its own override. Wraps within a paragraph get the full double gap; a
   first-line indent (not a blank line) is what separates paragraphs, so no
   extra margin is layered on top in the default Indent style. */
body.app-prose .ms-sheet-content .lw-action { line-height: 2; }
body.app-prose .lw-action { line-height: 2; }
/* Scene break — tint the ⁂ divider to match the coral accent instead of the
   neutral --muted grey used elsewhere (Song Plot has no scene-break element). */
body.app-prose .lw-scenebreak { color: #c07a63; }
body.dark.app-prose .lw-scenebreak { color: #cf9c89; }
.tn-bar { position: relative; display: flex; align-items: center; gap: 10px; padding: 8px 14px; min-height: 50px; }
.tn-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tn-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.tn-nav {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: inline-flex; background: var(--tn-pill-bg); border-radius: 11px; padding: 3px; gap: 2px;
}
/* Library is "choose a file," not "a page of the current show" — hide the
   page tabs there so a stray click can't jump into the wrong show's app. */
body.on-library .tn-nav { display: none; }
/* Same reasoning for Find/Export/Snapshots — they act on the open show, and
   there isn't one while you're picking. */
body.on-library #sb-find, body.on-library #sb-export, body.on-library #sb-snapshots { display: none; }
.tn-tab {
  font-family: inherit; font-size: 12.5px; padding: 5px 13px; border-radius: 8px;
  border: none; background: none; color: var(--tn-pill-ink); cursor: pointer; white-space: nowrap;
  transition: background 0.14s, color 0.14s;
}
.tn-tab:hover { background: rgba(255, 255, 255, 0.13); }
.tn-tab.active:hover { background: var(--tn-active-bg); }
.tn-tab.active { background: var(--tn-active-bg); color: var(--tn-active-ink); font-weight: 500; }

.tn-iconbtn {
  width: 32px; height: 30px; border: none; background: none; color: var(--tn-muted);
  border-radius: 7px; cursor: pointer; font-size: 16px; line-height: 1;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-family: inherit;
}
.tn-iconbtn:hover { background: var(--tn-hover); color: var(--tn-ink); }
.tn-library { color: var(--tn-muted); }
.tn-library svg { display: block; flex-shrink: 0; }
.tn-library.active, .tn-library.active:hover { background: var(--tn-active-bg); color: var(--tn-active-ink); }

.tn-show-btn {
  display: flex; align-items: center; gap: 7px; max-width: 240px;
  border: none; background: none; cursor: pointer; padding: 5px 9px; border-radius: 8px;
  font-family: inherit; color: var(--tn-ink); transition: background 0.14s;
}
.tn-show-btn:hover { background: var(--tn-hover); }
.tn-bar .sb-save-dot { display: block; }
.tn-bar .sb-show-name { display: block; font-size: 13px; font-weight: 500; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tn-caret { color: var(--tn-muted); flex-shrink: 0; display: inline-flex; align-items: center; }

/* Plot Suite waffle launcher — occupies the show-title slot, but only while
   browsing the Library (no show open yet to switch between). */
.tn-show-slot { position: relative; display: flex; align-items: center; }
.tn-show-slot [hidden] { display: none !important; }
.tn-waffle-icon { color: var(--tn-muted); display: inline-flex; flex-shrink: 0; }
.waffle-menu {
  position: fixed;
  top: calc(52px + env(safe-area-inset-top));
  left: 12px;
  width: 200px;
  background: #2c2a26;
  border: 1px solid #555;
  border-radius: 10px;
  box-shadow: 0 12px 32px #00000055;
  z-index: 50;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.waffle-item {
  display: flex; align-items: center; gap: 8px;
  border: none; background: none; border-radius: 7px; padding: 8px 10px;
  color: #e0dbd0; font-family: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.waffle-item:hover { background: #3a3830; color: #f8f3e8; }
.waffle-item.active { color: #f5f0e4; font-weight: 600; }
.waffle-item-check { width: 14px; flex-shrink: 0; color: var(--energy); }

@media (max-width: 880px) {
  .tn-nav { position: static; transform: none; left: auto; top: auto; margin: 0 auto; }
}


.app-root {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-right: env(safe-area-inset-right);
  background: var(--bg);
}

.page { flex: 1; min-height: 0; overflow-y: auto; padding: 0; }
#page-board { padding: 0; }
/* Breathing room between the ribbon and the first row of cards. */
.board-header.ribbon + div { margin-top: 12px; }

.sb-save-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #6b6477;
  box-shadow: 0 0 0 0 rgba(0,0,0,0);
  transition: background 0.2s, box-shadow 0.2s;
  display: none;
}
.sb-save-dot.saved { background: #4ecb8b; box-shadow: 0 0 5px 0 rgba(78,203,139,0.6); }
.sb-save-dot.unsaved,
.sb-save-dot.ref { background: #6b6477; }
.sb-save-dot.saving { background: #8b82e8; animation: sb-dot-pulse 1s ease-in-out infinite; }
.sb-save-dot.err { background: #e0564f; box-shadow: 0 0 5px 0 rgba(224,86,79,0.6); }
@keyframes sb-dot-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

/* Show-switcher popover */
.sp-close-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 6px;
  border-bottom: 1px solid #444;
  margin-bottom: 4px;
}
.sp-close-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #706860;
}
.sp-close-btn {
  background: none;
  border: none;
  color: #908880;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 5px;
}
.sp-close-btn:hover { background: #3a3830; color: #f0ebe0; }
/* ---- Reference "teaches" study banner ---- */
.ref-teach { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; padding: 9px 14px; background: #eeedfe; border: 1px solid #d8d3f5; border-radius: 9px; }
body.dark .ref-teach { background: #211d33; border-color: #3a3357; }
.ref-teach-tag { flex-shrink: 0; font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: #fff; background: #6a61d0; padding: 3px 8px; border-radius: 5px; }
.ref-teach-text { font-size: 13px; color: #3c3489; line-height: 1.4; }
body.dark .ref-teach-text { color: #c2bcee; }

/* ---- Snapshots drawer (whole-show version history) ---- */
.snap-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.32); z-index: 59; }
.snap-drawer {
  position: fixed; top: 52px; right: 12px; width: 340px; max-width: calc(100vw - 24px);
  max-height: calc(100vh - 66px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 34px #00000026; z-index: 60;
  display: flex; flex-direction: column; overflow: hidden;
  animation: snapIn 0.14s ease;
}
@keyframes snapIn { from { transform: translateY(-6px); opacity: 0; } to { transform: none; opacity: 1; } }
.snap-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 12px; border-bottom: 1px solid var(--line); }
.snap-title { font-size: 15px; font-weight: 500; color: var(--ink); flex: 1; }
.snap-save-btn { font-family: inherit; font-size: 12.5px; font-weight: 500; padding: 6px 11px; border: none; border-radius: 8px; background: var(--energy); color: #fff; cursor: pointer; white-space: nowrap; }
.snap-save-btn:hover { filter: brightness(1.06); }
.snap-close { border: none; background: transparent; color: var(--muted); font-size: 14px; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.snap-close:hover { background: var(--hover); color: var(--ink); }
.snap-reassure { margin: 12px 12px 4px; padding: 9px 11px; border-radius: 8px; background: #eeedfe; color: #3c3489; font-size: 12px; line-height: 1.4; }
body.dark .snap-reassure { background: #211d33; color: #b8aef0; }
.snap-list { flex: 1; overflow-y: auto; padding: 8px 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.snap-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 8px; line-height: 1.5; }
.snap-row { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; background: var(--bg); }
.snap-row-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.snap-label { font-size: 13.5px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snap-time { font-size: 11.5px; color: var(--muted); flex-shrink: 0; }
.snap-actions { display: flex; align-items: center; gap: 6px; margin-top: 9px; }
.snap-restore { font-family: inherit; font-size: 12px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 7px; background: transparent; color: var(--energy); cursor: pointer; font-weight: 500; }
.snap-restore:hover { background: var(--hover); }
.snap-act { font-family: inherit; font-size: 12px; padding: 4px 8px; border: none; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.snap-act:hover { background: var(--hover); color: var(--ink); }
.snap-act.danger:hover { color: #c0392b; }

.show-popover {
  position: fixed;
  top: calc(52px + env(safe-area-inset-top));
  left: 12px;
  width: 264px;
  background: #2c2a26;
  border: 1px solid #555;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 12px 32px #00000055;
  z-index: 50;
  padding: 6px 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 70vh;
  overflow-y: auto;
}
.sp-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #9a9488;
  padding: 6px 10px 2px;
}
.sp-item-row {
  display: flex;
  align-items: center;
  border-radius: 7px;
}
.sp-item-row:hover { background: #3a3830; }
.sp-item-row:hover .sp-item { color: #f8f3e8; background: none; }
.sp-item-row:hover .sp-dots { opacity: 1; }
.sp-item {
  display: block;
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 7px 10px;
  border-radius: 7px;
  border: none;
  background: none;
  color: #e0dbd0;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sp-item:hover { background: none; }
.sp-item.active { color: #f5f0e4; font-weight: 600; }
.sp-item-row:has(.sp-item.active) { background: #3d3a34; }
.sp-dots {
  flex-shrink: 0;
  opacity: 0;
  background: none;
  border: none;
  color: #c0b8ac;
  cursor: pointer;
  font-size: 15px;
  letter-spacing: -1px;
  padding: 4px 8px;
  border-radius: 5px;
  line-height: 1;
  transition: opacity 0.1s, background 0.1s;
}
.sp-dots:hover { background: #4a4840; color: #f8f3e8; }
.sp-divider { height: 1px; background: #444; margin: 4px 0; }
.sp-footer {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 8px;
  margin-top: 4px;
  border-top: 1px solid #444;
  background: #2c2a26;
  cursor: pointer;
}
.sp-footer:hover { background: #3a3830; }
.sp-footer-icon { font-size: 14px; color: #9a9488; flex-shrink: 0; }
.sp-footer-name { font-size: 13px; font-weight: 600; color: #e0dbd0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-footer-save { font-size: 11px; color: #7a7468; white-space: nowrap; }
.sp-actions { display: flex; flex-direction: column; gap: 3px; }
.sp-actions .pbtn { width: 100%; text-align: left; background: transparent; border-color: transparent; color: #d8d0c4; font-size: 12.5px; padding: 6px 10px; }
.sp-actions .pbtn:hover { background: #3a3830; color: #f8f3e8; border-color: transparent; }
.sp-actions .pbtn:disabled { opacity: 0.3; }
.sp-actions .pbtn.danger { color: #e88080; }
.sp-actions .pbtn.danger:hover:not(:disabled) { background: #3a2020; }


/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: #2c2c2a55; z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 20px 60px #00000028;
  padding: 24px; width: 380px; max-width: 94vw;
  display: flex; flex-direction: column; gap: 18px;
}
.modal-box .seg { display: flex; }
.modal-box .seg button { flex: 1; text-align: center; }
.modal-title { font-size: 17px; font-weight: 600; margin: 0; color: var(--ink); }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; }
.pbtn.primary { background: #7b74c8; color: #f5f3fd; border-color: #7b74c8; }
.pbtn.primary:hover { background: #6e67ba; border-color: #6e67ba; }
body.dark .pbtn.primary { background: #4a3f9e; color: #e6e2fb; border-color: #4a3f9e; }
body.dark .pbtn.primary:hover { background: #564ab0; }

.find-opts { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); }
.find-opts label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.find-status { font-size: 12px; color: var(--muted); min-height: 1em; }
.find-mode-seg { align-self: stretch; }
.find-box [hidden] { display: none !important; }
.modal-btns:has(.find-nav) { justify-content: space-between; }
.find-nav { display: flex; gap: 6px; }
.find-nav .pbtn { padding: 7px 14px; font-size: 15px; line-height: 1; }
.find-nav .pbtn:disabled { opacity: 0.35; }

@keyframes find-flash {
  0%, 100% { box-shadow: none; }
  20%, 60% { box-shadow: 0 0 0 3px var(--energy); }
}
.find-flash { animation: find-flash 1.1s ease; }


/* Manuscript + Title Pages */
#page-manuscript, #page-titlepage { display: flex; flex-direction: column; }

/* ms-wrap contains the scrollable body + the drawer side by side.
   min-height/min-width:0 stops the flex item from growing to its content
   height — otherwise the whole wrap (and the side drawer) balloons to the
   full manuscript height and the drawer scrolls off-screen. */
.ms-wrap { flex: 1; min-height: 0; min-width: 0; display: flex; overflow: hidden; position: relative; }
.ms-wrap .ms-body { flex: 1; min-width: 0; overflow-y: auto; background: #888; }
body.dark .ms-body { background: var(--bg); }

/* Edit-mode outline navigator (jump nav) */
.ms-nav {
  flex: 0 0 212px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
  transition: flex-basis 0.16s ease;
}
.ms-nav-head {
  display: flex; align-items: center; justify-content: space-between;
  height: 37px; box-sizing: border-box;
  padding: 0 8px 0 13px; border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.ms-nav-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); }
.ms-nav-list { flex: 1; overflow-y: auto; padding: 6px; }
.ms-nav-foot { flex-shrink: 0; display: flex; border-top: 1px solid var(--line); }
.ms-nav-foot-stat { flex: 1; padding: 8px 10px; }
.ms-nav-foot-stat:first-child { border-right: 1px solid var(--line); }
.ms-nav-foot-stat .k { font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; }
.ms-nav-foot-stat .v { font-size: 15px; font-weight: 600; margin-top: 1px; font-variant-numeric: tabular-nums; }
.ms-nav-act {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--faint); padding: 11px 8px 4px;
}
.ms-nav-act:first-child { padding-top: 3px; }
.ms-nav-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 5px 8px; border: none; background: transparent; border-radius: 6px;
  cursor: pointer; text-align: left;
  font-family: inherit; color: var(--muted);
}
.ms-nav-row:hover { background: var(--hover); color: var(--ink); }
.ms-nav-row.active { background: var(--hover); color: var(--ink); }
.ms-nav-icon { flex-shrink: 0; width: 13px; text-align: center; font-size: 12px; color: var(--muted); }
.ms-nav-row.active .ms-nav-icon { color: var(--energy); }
.ms-nav-label { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Contextual ribbon — the per-page tool row directly under the top nav.
   Shared so each page's toolbar reads as one consistent system. */
.ribbon, .ms-toolbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
  background: #f3f1fa;
  flex-shrink: 0;
}
body.dark .ribbon, body.dark .ms-toolbar { background: #211e2c; }
.ms-toolbar .ms-zoom-wrap { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.ms-tb-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.ms-wc-lbl { font-size: 12px; color: var(--muted); margin-left: 12px; white-space: nowrap; }
/* Navigation, Print, and Settings share one bare-button language. They sit at
   the same 32px height as the Edit/Print View seg track so the whole ribbon
   reads as one uniform row. */
.ms-nav-btn, .ms-print-btn, .ms-settings-btn, .ms-title-btn {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  height: 32px; padding: 0 11px; border-radius: 7px; border: 1px solid transparent;
  background: transparent; color: var(--muted); font-size: 12px; font-weight: 500;
  font-family: inherit; cursor: pointer; transition: background 0.12s, color 0.12s;
}
.ms-nav-btn:hover, .ms-print-btn:hover, .ms-settings-btn:hover, .ms-title-btn:hover { background: var(--hover); color: var(--ink); }
.ms-nav-btn.active, .ms-settings-btn.active, .ms-title-btn.active { background: #534ab7; color: #fff; border-color: #534ab7; }
body.dark .ms-nav-btn.active, body.dark .ms-settings-btn.active, body.dark .ms-title-btn.active { background: #6a61d0; color: #fff; border-color: #6a61d0; }
.ms-tb-divider { width: 1px; height: 22px; background: var(--line); flex-shrink: 0; }
/* Segmented toggles in a ribbon share the nav-pill language: a tinted track
   container with a purple-filled active chip (matches the top-nav pill and the
   in-drawer Left/Center/Right seg). */
.ms-mode-seg { flex-shrink: 0; }
.ms-mode-seg, .ribbon .seg {
  display: inline-flex; align-items: center; height: 32px; gap: 3px;
  background: #e6e1f6; border: none; border-radius: 9px; padding: 3px;
}
body.dark .ms-mode-seg, body.dark .ribbon .seg { background: #2a2640; }
.ms-mode-seg button, .ribbon .seg button {
  display: flex; align-items: center; height: 26px; padding: 0 12px; border-radius: 6px;
  border: none; background: transparent; font-size: 12px; font-weight: 500; color: var(--muted);
}
.ms-mode-seg button:hover, .ribbon .seg button:hover { color: var(--ink); }
.ms-mode-seg button.active, .ribbon .seg button.active { background: var(--energy); color: #fff; box-shadow: none; }
body.dark .ms-mode-seg button.active, body.dark .ribbon .seg button.active { background: var(--energy); color: #fff; }
/* Outer manuscript container: a non-scrolling flex column so .ms-wrap fills it
   and only the inner sheet body scrolls — keeps the side drawer pinned. */
#ms-body { display: flex; flex-direction: column; overflow: hidden; }

/* Research notes (SPEC §14) — Navigator rail (note index) + freeform pane. */
#page-notes { display: flex; flex-direction: column; }
.notes-wrap { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.notes-rail {
  flex: 0 0 212px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
}
.notes-rail-head {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 44px; box-sizing: border-box;
  padding: 0 8px 0 13px; border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.notes-rail-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); }
.notes-add-btn {
  width: 22px; height: 22px; border-radius: 6px; border: none; background: transparent;
  color: var(--muted); font-size: 15px; line-height: 1; cursor: pointer; font-family: inherit;
}
.notes-add-btn:hover { background: var(--hover); color: var(--ink); }
.notes-rail-list { flex: 1; overflow-y: auto; padding: 6px; }
.notes-rail-row {
  display: flex; align-items: center; gap: 4px; width: 100%;
  padding: 7px 6px 7px 9px; margin-bottom: 1px; border: none; background: transparent; border-radius: 6px;
  border-left: 2px solid transparent; cursor: pointer; text-align: left;
  font-family: inherit; color: var(--muted);
}
.notes-rail-row:hover { background: var(--hover); color: var(--ink); }
.notes-rail-row.active { background: var(--hover); color: var(--ink); border-left-color: var(--energy); font-weight: 600; }
.notes-rail-label { flex: 1; min-width: 0; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notes-rail-dots {
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border: none; border-radius: 5px; background: transparent;
  color: var(--muted); cursor: pointer; opacity: 0; transition: opacity 0.1s, background 0.1s;
}
.notes-rail-row:hover .notes-rail-dots { opacity: 1; }
.notes-rail-dots:hover { background: var(--line); color: var(--ink); }

.notes-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
/* Firm 44px (border-box) so the bar matches the rail head exactly — the zoom
   control is now in normal flow (not absolutely positioned like the Manuscript's)
   and would otherwise push the ribbon past its min-height. */
.notes-toolbar { gap: 6px; height: 44px; min-height: 44px; padding: 0 14px; box-sizing: border-box; }
.notes-toolbar .ms-zoom-wrap { margin-left: auto; flex-shrink: 0; }
.notes-fmt { display: inline-flex; align-items: center; gap: 2px; flex-shrink: 0; }
.notes-fmt-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 28px; min-width: 28px; padding: 0 7px; border-radius: 6px; border: none;
  background: transparent; color: var(--muted); font-size: 12px; font-weight: 600;
  font-family: inherit; cursor: pointer; line-height: 1;
}
.notes-fmt-btn:hover { background: var(--hover); color: var(--ink); }
.notes-fmt-btn.wide { padding: 0 9px; font-size: 12px; font-weight: 500; }
.notes-fmt-btn.strong { font-weight: 800; }
.notes-fmt-btn.em { font-style: italic; font-family: Georgia, 'Times New Roman', serif; font-size: 14px; }
.notes-fmt-divider { width: 1px; height: 18px; background: var(--line); margin: 0 5px; flex-shrink: 0; }
.notes-scroll { flex: 1; overflow-y: auto; background: var(--bg); }
.notes-doc { max-width: 760px; padding: 30px 40px 90px; }
.notes-title-head {
  display: block; width: 100%; border: none; background: transparent; color: var(--ink);
  font-family: inherit; font-size: 26px; font-weight: 800; letter-spacing: -0.02em;
  padding: 0 0 12px; margin: 0; border-bottom: 1px solid var(--line);
}
.notes-title-head:focus { outline: none; }
.notes-title-head::placeholder { color: var(--faint); }
.notes-editor {
  min-height: 55vh; padding-top: 16px;
  font-size: 14.5px; line-height: 1.65; color: var(--ink);
}
.notes-editor:focus { outline: none; background: transparent; }
.notes-editor h2 { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; margin: 0 0 10px; }
.notes-editor p { margin: 0 0 12px; }
.notes-editor blockquote {
  margin: 0 0 12px; padding: 4px 0 4px 14px; border-left: 3px solid var(--line);
  color: var(--muted); font-style: italic;
}
.notes-editor a { color: var(--energy); text-decoration: underline; }
.notes-editor ul, .notes-editor ol { margin: 0 0 12px; padding-left: 24px; }
.notes-editor li { margin-bottom: 4px; }
/* Indenting a list item (Tab) nests a new <ul>/<ol> inside the <li> — give each
   nesting level a different bullet/number shape, as Apple Notes / Word do. */
.notes-editor ul ul { list-style-type: circle; }
.notes-editor ul ul ul { list-style-type: square; }
.notes-editor ol ol { list-style-type: lower-alpha; }
.notes-editor ol ol ol { list-style-type: lower-roman; }
.notes-editor table { border-collapse: collapse; margin: 0 0 14px; }
.notes-editor td, .notes-editor th { border: 1px solid var(--line); padding: 6px 10px; min-width: 60px; }
.notes-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 13px; }

/* Edit mode ─────────────────────────────────── */
.ms-edit-doc {
  padding: 32px 40px 80px;
  min-height: 100%;
  box-sizing: border-box;
}
.ms-card-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 14px auto;
  width: 816px;
  user-select: none;
}
.ms-card-divider::before,
.ms-card-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #b0aca6;
}
.ms-card-divider-label {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 12px;
  color: #f0ede8;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.ms-card-section {
  background: var(--panel);
  width: 816px;
  margin: 0 auto;
  cursor: text;
  box-shadow: 0 2px 12px #0003;
  min-height: 40px;
}
.ms-card-content { }
.ms-card-section-empty { min-height: 56px; display: flex; align-items: center; }
.ms-card-placeholder {
  color: var(--faint);
  font-style: italic;
  font-size: 12pt;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  padding: 0 120px;
  user-select: none;
  width: 100%;
}

/* Rich line editor */
.ms-card-rich-editor { display: flex; flex-direction: column; position: relative; }

/* Character-name autocomplete dropdown (FD-style) */
.rich-ac {
  position: absolute; z-index: 20; min-width: 160px; max-height: 220px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px #0006; padding: 4px;
}
.rich-ac-item {
  padding: 5px 12px; border-radius: 5px; cursor: pointer; font-size: 13px; color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap;
}
.rich-ac-item.active { background: var(--energy); color: #fff; }
.rich-ac-item:hover { background: var(--hover); }
.rich-ac-item.active:hover { background: var(--energy); }
.ms-style-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: #f0eefb;
  border-bottom: 1px solid #dddaf5;
  position: sticky;
  top: 0;
  z-index: 5;
  flex-shrink: 0;
}
.ms-style-sel {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 6px;
  border: 1px solid #c9c5f0;
  border-radius: 5px;
  background: #fff;
  color: #3c3489;
  cursor: pointer;
  outline: none;
}
.ms-style-sel:focus { border-color: #8b7fe8; }
.ms-dual-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border: 1px solid #c9c5f0;
  border-radius: 5px;
  background: #fff;
  color: #3c3489;
  cursor: pointer;
  outline: none;
}
.ms-dual-btn:disabled { opacity: 0.4; cursor: default; }
.ms-dual-btn.active { background: var(--energy); border-color: var(--energy); color: #fff; }
body.dark .ms-dual-btn { background: #2a2540; border-color: #3d3760; color: #b8aef0; }
body.dark .ms-dual-btn.active { background: var(--energy); border-color: var(--energy); color: #fff; }
/* Bold / Italic / Underline buttons */
.ms-fmt-divider { width: 1px; align-self: stretch; background: #d4d0ee; margin: 3px 1px; }
.ms-fmt-btn { width: 26px; height: 24px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; padding: 0; border: 1px solid #c9c5f0; border-radius: 5px; background: #fff; color: #3c3489; cursor: pointer; outline: none; font-family: Georgia, 'Times New Roman', serif; }
.ms-fmt-btn > * { pointer-events: none; }
.ms-fmt-btn:hover { background: #f0eefb; }
.ms-fmt-btn.active { background: var(--energy); border-color: var(--energy); color: #fff; }
.ms-fmt-btn:disabled { opacity: 0.4; cursor: default; }
body.dark .ms-fmt-btn { background: #2a2540; border-color: #3d3760; color: #b8aef0; }
body.dark .ms-fmt-btn.active { background: var(--energy); border-color: var(--energy); color: #fff; }
body.dark .ms-fmt-divider { background: #3d3760; }
/* Highlight button previews its own color; active state keeps the amber. */
.ms-fmt-hl mark { background: var(--hl); color: var(--hl-ink); -webkit-text-fill-color: var(--hl-ink); padding: 0 3px; border-radius: 2px; font: inherit; }
.ms-fmt-hl.active { background: var(--hl); border-color: var(--hl); }
.ms-fmt-hl.active mark { background: transparent; padding: 0; }
/* Editorial highlight in the text — soft amber, dark ink so it stays legible in both themes. */
mark { background: var(--hl); color: var(--hl-ink); -webkit-text-fill-color: var(--hl-ink); border-radius: 2px; padding: 0 1px; }
/* Inline note: underline only (no fill), distinct from the plain editorial highlight above.
   Sage, matching the outline/note family (Section tags, loglines, Story DNA truths). */
mark.note-mark {
  background: transparent; color: inherit; -webkit-text-fill-color: inherit; padding: 0; border-radius: 0;
  text-decoration: underline dotted var(--sage); text-decoration-thickness: 1.5px; text-underline-offset: 3px;
  cursor: pointer;
}
mark.note-mark:hover { text-decoration-style: solid; }

/* Inline chord: an empty, zero-width marker anchored at one exact character —
   the chord name floats above via ::after so the lyric text below never
   shifts. Auto-converted from typed [C] shorthand (see CHORD_TOKEN in app.js).
   A line that contains one gets extra top clearance so the label doesn't sit
   on top of the row above (manuscript body uses line-height: 1). */
.ms-el:has(mark.chord-tag) { padding-top: 1.15em; }
/* Page setup → "Show in document" → Chords toggle: hides the label without
   dropping the underlying [C] markup, matching the Section tags convention.
   Collapse the reserved clearance too, or hidden chords still leave a gap. */
body.ms-hide-chords mark.chord-tag { display: none; }
body.ms-hide-chords .ms-el:has(mark.chord-tag) { padding-top: 0; }
mark.chord-tag {
  position: relative; display: inline-block; width: 0; height: 1em;
  background: transparent; padding: 0; border-radius: 0; vertical-align: baseline;
  overflow: visible; cursor: default;
}
mark.chord-tag::after {
  content: attr(data-chord);
  position: absolute; left: 1px; bottom: 100%;
  font-size: 0.72em; font-weight: 700; line-height: 1; white-space: nowrap;
  color: var(--sage); font-family: inherit;
  /* Lyric lines (.lw-sung) render upper-case for the manuscript look — the
     chord name itself must stay exactly as typed, or Bb and B# both read "BB". */
  text-transform: none;
  pointer-events: none;
}

/* Floating "+ Note" pill near a text selection in the rich editor. */
.note-float-toolbar { position: fixed; z-index: 4000; transform: translate(-50%, calc(-100% - 8px)); }
.note-float-btn {
  display: flex; align-items: center; gap: 5px; font-family: inherit; font-size: 12px; font-weight: 600;
  padding: 6px 10px; border: 1px solid var(--sage-line); border-radius: 8px; background: var(--sage-bg); color: var(--sage);
  box-shadow: 0 4px 14px rgba(0,0,0,0.18); cursor: pointer;
}
.note-float-btn:hover { filter: brightness(0.96); }

/* Note create/edit popup and the read-only viewer popover. */
.note-popup {
  position: fixed; z-index: 4001; width: 240px; background: var(--panel); border: 1px solid var(--sage-line);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.2); padding: 10px;
}
.note-popup-ta {
  width: 100%; min-height: 64px; resize: vertical; font-family: inherit; font-size: 13px; padding: 8px;
  border: 1px solid var(--sage-line); border-radius: 7px; background: var(--panel); color: var(--ink);
}
.note-popup-btns { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; }
.note-popup-delete { margin-right: auto; }
.note-popup-btns .pbtn.primary { background: var(--sage); border-color: var(--sage); color: #fff; }
.note-popup-ro { padding: 12px; border-color: var(--sage-line); }
.note-popup-text { font-size: 13px; color: var(--ink); white-space: pre-wrap; word-break: break-word; max-width: 216px; }
.note-popup-close {
  position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; border: none; background: transparent;
  color: var(--muted); font-size: 15px; line-height: 1; cursor: pointer; border-radius: 5px;
}
.note-popup-close:hover { background: var(--sage-bg); color: var(--sage); }

/* Navigator sub-rows for inline notes, nested under their card's row. */
.ms-nav-note { padding-left: 24px; color: var(--sage); }
.ms-nav-note-icon { color: var(--sage); }
.ms-nav-note:hover { background: var(--sage-bg); color: var(--sage); }
.ms-nav-note.active { background: var(--sage-bg); color: var(--sage); border-left-color: var(--sage); }

/* Mark a dual cue in the editor so the writer sees the pairing. */
.ms-el[data-dual="1"]::after {
  content: ' ⇄ dual';
  font-size: 0.7em;
  font-weight: 600;
  color: var(--sage);
  letter-spacing: 0.04em;
  -webkit-text-fill-color: var(--sage);
}
.ms-style-hint { font-size: 11px; color: #aaa; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
body.dark .ms-style-bar { background: #1e1b2e; border-bottom-color: #2e2a45; }
body.dark .ms-style-sel { background: #2a2540; border-color: #3d3760; color: #b8aef0; }
body.dark .ms-style-sel:focus { border-color: #8b7fe8; }
body.dark .ms-style-hint { color: #8b83a8; }

/* One persistent formatting bar at the top of the manuscript Edit surface. Always
   occupies its slot so opening/closing a card editor never shifts the page; its
   contents swap to the active card's ribbon (or an idle hint). */
.ms-format-bar { position: sticky; top: 0; z-index: 6; display: flex; align-items: stretch; min-height: 35px; }
.ms-format-bar > .ms-style-bar { position: static; flex: 1; }
/* Idle bar: same controls, disabled + dimmed. */
.ms-style-bar-idle .ms-style-sel, .ms-style-bar-idle .ms-style-hint { opacity: 0.55; }
.ms-line-editor { outline: none; padding-bottom: 48px; }
/* Zero-reflow: the static edit-doc body now uses the same .ms-el lines as the
   editor, so match the container padding too (editor lineEd has 48px bottom). */
.ms-edit-doc .ms-card-content.ms-sheet-content { padding-bottom: 48px; }
/* When a logline sits above the editor it already supplies the 12px top pad, so
   the editor's own top pad would double it — drop it in that case. */
.ms-edit-doc .ms-card-section.ms-has-logline .ms-line-editor { padding-top: 0; }
.ms-el {
  outline: none;
  min-height: 1em;
  white-space: pre-wrap;
  word-break: break-word;
}
.ms-el-blank { min-height: 12pt; }
.ms-el:empty::before { content: '\00a0'; } /* non-breaking space keeps empty lines selectable */
/* The line editor is one large contenteditable host, so the global title-page
   editable wash ([contenteditable]:focus → a yellow tint, :hover → a dark wash)
   would colour the whole sheet. Suppress it here — like Final Draft / Word, the
   caret alone marks the active line (no line highlight). */
.ms-line-editor:hover,
.ms-line-editor:focus { background: transparent; }
/* Mirror the read-only render inside the rich editor: show ( ) around
   parentheticals and a pill for section headers. The editable text stays free
   of the ( ) [ ] syntax (added back by serializeLines), so editing stays clean. */
.ms-el.lw-paren::before { content: '('; }
.ms-el.lw-paren::after  { content: ')'; }
.ms-el.lw-section-row {
  display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--sage); background: var(--sage-bg); padding: 2px 14px; border-radius: 20px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; margin: 6px 0;
}

/* Board header as slim toolbar */
/* .board-header composes with .ribbon for the shared bar look. */
.board-header { padding-left: 18px; padding-right: 18px; }

/* Placeholder pages */
.placeholder-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  color: var(--muted);
  text-align: center;
  gap: 12px;
}
.placeholder-icon { font-size: 48px; opacity: 0.3; }
.placeholder-page h2 { font-size: 20px; color: var(--ink); margin: 0; }
.placeholder-page p { font-size: 14px; max-width: 340px; line-height: 1.5; margin: 0; }
.coming-soon { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; background: #e8e3d8; color: #8a8070; padding: 4px 12px; border-radius: 20px; }

.sb-dm-icon { font-size: 16px; }

/* ═══════════════════════════════════════════════
   EXPORT PAGE
═══════════════════════════════════════════════ */
#page-export { display: flex; flex-direction: column; overflow-y: auto; }
.exp-wrap { max-width: 520px; padding: 40px 32px; display: flex; flex-direction: column; gap: 0; }
.exp-drawer-body { overflow-y: auto; padding: 4px 16px 20px; }
.exp-drawer-body .exp-section { padding: 18px 0; }
.exp-drawer-body .exp-heading { font-size: 15px; }
.exp-drawer-body .exp-desc { font-size: 13px; margin-bottom: 14px; }
.exp-drawer-body .exp-btn { width: 100%; justify-content: center; }
.exp-section { padding: 28px 0; }
.exp-heading { font-size: 18px; font-weight: 700; margin: 0 0 8px; color: var(--ink); }
.exp-desc { font-size: 14px; color: var(--muted); line-height: 1.6; margin: 0 0 18px; }
.exp-note { font-size: 12px; color: var(--faint); margin: 0 0 10px; }
.exp-btn { font-size: 14px; padding: 10px 18px; display: inline-flex; align-items: center; gap: 8px; }
.exp-divider { height: 1px; background: var(--line); }
.exp-file-input { display: none; }
.exp-toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); cursor: pointer; margin-bottom: 14px; user-select: none; }
.exp-toggle input { cursor: pointer; accent-color: var(--energy); }

/* ═══════════════════════════════════════════════
   CHARACTERS PAGE
═══════════════════════════════════════════════ */
#page-characters { display: flex; flex-direction: column; overflow-y: auto; }

/* .ch-toolbar composes with .ribbon for the shared bar look; only extras here. */
.ch-toolbar { padding-left: 18px; padding-right: 18px; }
.ch-toolbar-title { font-size: 15px; font-weight: 600; color: var(--ink); }

.ch-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 12px;
  color: var(--muted);
  padding: 60px 24px;
  text-align: center;
}
.ch-empty-icon { font-size: 48px; opacity: 0.25; }
.ch-empty p { font-size: 14px; max-width: 360px; line-height: 1.6; margin: 0; }

.ch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 24px;
  align-content: start;
}

.ch-card {
  --ch-accent: hsl(var(--ch-hue, 250), 55%, 55%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.14s, box-shadow 0.14s, transform 0.14s;
}
.ch-card:hover {
  border-color: var(--ch-accent);
  box-shadow: 0 6px 20px #00000014;
  transform: translateY(-1px);
}
.ch-card.ch-manual::before { opacity: 0.45; }

.ch-card-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 16px 26px 0 0;
}
.ch-avatar { display: none; }
.ch-head-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.ch-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ch-count {
  align-self: flex-start;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ch-accent);
  background: hsl(var(--ch-hue, 250), 55%, 55%, 0.12);
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}
.ch-tag { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 20px; align-self: flex-start; }
.ch-tag-manual { background: var(--btn); color: var(--muted); }

.ch-field { display: flex; flex-direction: column; gap: 4px; }
.ch-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--faint); font-weight: 600; }
.ch-select { font-size: 13px; padding: 5px 8px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-family: inherit; }
.ch-note { font-size: 12.5px; line-height: 1.5; padding: 7px 9px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-family: inherit; resize: vertical; min-height: 58px; }
.ch-note:focus, .ch-select:focus { outline: none; border-color: var(--energy); }

.ch-apps { display: flex; flex-direction: column; gap: 4px; }
.ch-app-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 9px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--bg);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
}
.ch-app-chip:hover { background: var(--hover); border-color: var(--muted); }
.ch-app-act { font-size: 10px; font-weight: 700; letter-spacing: 0.06em; color: var(--muted); min-width: 46px; }
.ch-app-title { font-size: 12px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ch-remove {
  position: absolute;
  top: 12px;
  right: 11px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--faint);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.14s, background 0.14s, color 0.14s;
}
.ch-card:hover .ch-remove { opacity: 1; }
.ch-remove:hover { background: var(--tension); color: #fff; }

/* Character vs. group toggle */
.ch-kind { display: inline-flex; align-self: flex-start; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin: -2px 0 2px; }
.ch-kind-btn { font-family: inherit; font-size: 10.5px; font-weight: 600; letter-spacing: 0.02em; padding: 3px 10px; border: none; background: transparent; color: var(--muted); cursor: pointer; transition: background 0.12s, color 0.12s; }
.ch-kind-btn + .ch-kind-btn { border-left: 1px solid var(--line); }
.ch-kind-btn.active { background: var(--energy); color: #fff; }
body.dark .ch-kind-btn.active { background: #6a61d0; }
.ch-kind-btn:not(.active):hover { background: var(--hover); color: var(--ink); }
.ch-kind-btn:disabled { cursor: default; }
.ch-card.ch-group { opacity: 0.82; }
.ch-card.ch-group .ch-avatar { filter: grayscale(0.55); }
.ch-empty-note { font-size: 13px; color: var(--muted); margin: 4px 2px; }
.ch-groupsec { margin-top: 26px; }
.ch-section-head { border-top: 1px solid var(--line); padding: 18px 2px 12px; display: flex; flex-direction: column; gap: 3px; }
.ch-section-title { font-size: 14px; font-weight: 600; color: var(--ink); }
.ch-section-sub { font-size: 12px; color: var(--muted); line-height: 1.5; max-width: 620px; }

/* ---- Story DNA ----
   One deliberately small type system: section titles (15/700 ink), field
   labels (12/600 muted, sentence case), and typed content (13.5 ink). The
   typed-in text is the most prominent voice on the page — labels recede. */
.dna-wrap { max-width: 720px; margin: 16px auto 60px; padding: 0 16px; }

.dna-ledger { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }

.dna-field { display: flex; flex-direction: column; gap: 5px; margin: 4px 0 24px; }
.dna-field-lbl { font-size: 12px; font-weight: 600; color: var(--muted); }
.dna-field-in { width: 100%; font-size: 15px; font-weight: 500; color: var(--ink); font-family: inherit; line-height: 1.4; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); padding: 10px 12px; resize: none; overflow: hidden; }
.dna-field-in:focus { outline: none; border-color: var(--energy); }

.dna-in { width: 100%; border: none; background: transparent; resize: none; overflow: hidden; padding: 0; color: var(--ink); font-family: inherit; font-size: 13.5px; line-height: 1.5; min-height: 21px; }
.dna-in:focus, .dna-field-in:focus, .dna-pole:focus, .dna-tray-sel:focus { outline: none; }
.dna-in::placeholder, .dna-field-in::placeholder, .dna-pole::placeholder { color: var(--faint); }

/* The 7 beats, chronological. Mirrored pairs share an indent level, stepping
   in toward the Midpoint hinge and back out — the shape shows the chiasmus. */
.dna-chiasmus { display: flex; flex-direction: column; gap: 7px; }
.dna-beat { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 10px 14px; }
.dna-depth-1 { margin: 0 30px; }
.dna-depth-2 { margin: 0 60px; }
.dna-depth-3 { margin: 0 90px; }
.dna-beat-name { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
.dna-catch { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }

.dna-divider { border-top: 1px solid var(--line); margin: 28px 0 18px; }
.dna-sec-head { margin-bottom: 12px; }
.dna-sec-title { font-size: 15px; font-weight: 700; color: var(--ink); margin: 0; }
.dna-sec-sub { font-size: 12px; color: var(--muted); margin: 0; line-height: 1.5; }

.dna-stakes { display: block; }
.dna-stake-row { display: grid; grid-template-columns: 140px minmax(0,1fr) 22px minmax(0,1fr); align-items: center; }
.dna-stake-row:not(:last-child) { border-bottom: 1px solid var(--line); }
.dna-stake-lbl { display: flex; flex-direction: column; padding: 10px 12px; border-right: 1px solid var(--line); align-self: stretch; justify-content: center; }
.dna-stake-name { font-size: 12px; font-weight: 600; color: var(--muted); }
.dna-pole { font-size: 13.5px; padding: 10px 12px; border: none; border-radius: 0; background: transparent; color: var(--ink); width: 100%; }
.dna-pole-truth { border-right: 1px solid var(--line); }
.dna-vs { text-align: center; color: var(--muted); font-size: 13px; }

.dna-web { display: grid; grid-template-columns: 132px minmax(0,1fr) minmax(0,1fr); align-items: stretch; }
.dna-web > *:not(:nth-child(3n)) { border-right: 1px solid var(--line); }
.dna-web > *:nth-child(-n+6) { border-bottom: 1px solid var(--line); }
.dna-web-corner { padding: 8px 10px; }
.dna-web-colhead { text-align: center; font-size: 12px; font-weight: 600; padding: 8px 10px; }
.dna-web-rowhead { display: flex; align-items: center; font-size: 12px; font-weight: 600; padding: 8px 10px; }
.dna-truth-ink { color: var(--sage); }
.dna-flaw-ink { color: var(--tension); }
.dna-web-ph { color: var(--muted); }
.dna-web-cell { padding: 9px 10px; min-height: 54px; display: flex; flex-wrap: wrap; gap: 5px; align-content: flex-start; }
.dna-web-chip { font-size: 12.5px; padding: 3px 10px; border-radius: 999px; background: var(--btn); border: 1px solid var(--line); color: var(--ink); }
.dna-web-hole { font-size: 13px; color: var(--muted); }

.dna-tray { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.dna-tray-lbl { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.dna-tray-row { display: flex; align-items: center; gap: 12px; padding: 5px 0; flex-wrap: wrap; }
.dna-tray-name { flex: 1 1 120px; font-size: 13.5px; color: var(--ink); font-weight: 500; min-width: 0; }
.dna-tray-field { display: flex; align-items: center; gap: 5px; }
.dna-tray-field-lbl { font-size: 12px; color: var(--muted); }
.dna-tray-sel { font-size: 12.5px; padding: 5px 8px; border-radius: 4px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }

@media (max-width: 640px) {
  .dna-depth-1, .dna-depth-2, .dna-depth-3 { margin: 0; }
  .dna-stake-row { grid-template-columns: 1fr; }
  .dna-stake-lbl { border-right: none; border-bottom: 1px solid var(--line); }
  .dna-pole-truth { border-right: none; border-bottom: 1px solid var(--line); }
  .dna-vs { display: none; }
}

/* ---- Library / file management ---- */
.lib-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 28px 40px 16px; gap: 16px; flex-wrap: wrap;
}
.lib-title { font-size: 22px; font-weight: 700; color: var(--ink); margin: 0; }
.lib-actions { display: flex; align-items: center; gap: 16px; }
.lib-archtoggle { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.lib-grid { display: flex; flex-direction: column; gap: 26px; padding: 4px 40px 48px; }
.lib-grid-inner {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px;
}
.lib-section { display: flex; flex-direction: column; gap: 12px; }
.lib-section-head { display: flex; align-items: center; gap: 8px; }
.lib-folder-ico { color: var(--muted); font-size: 11px; }
.lib-section-name { font-size: 13px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.lib-section-count {
  font-size: 11px; font-weight: 600; color: var(--muted); background: var(--btn);
  border: 1px solid var(--line); border-radius: 20px; padding: 1px 8px;
}
.lib-empty { color: var(--muted); font-size: 14px; padding: 24px 0; }
.lib-card-ref { opacity: 0.92; }
.lib-card-ref:hover { opacity: 1; }
.lib-ref-badge { color: var(--muted); }
.lib-card {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 16px 14px; cursor: pointer; transition: border-color 0.12s, box-shadow 0.12s, transform 0.06s;
  display: flex; flex-direction: column; gap: 10px; min-height: 96px;
}
.lib-card:hover { border-color: var(--energy); box-shadow: 0 4px 18px #0001; }
.lib-card.current { border-color: var(--energy); }
.lib-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.lib-card-title { font-size: 15px; font-weight: 650; color: var(--ink); line-height: 1.3; }
.lib-card-dots {
  border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1;
  cursor: pointer; padding: 0 4px; border-radius: 6px; flex-shrink: 0;
}
.lib-card-dots:hover { background: var(--hover); color: var(--ink); }
.lib-card-meta { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--muted); }
.lib-dot { opacity: 0.6; }
.lib-teaches { font-size: 12px; line-height: 1.4; color: var(--muted); margin-top: 7px; }
.lib-card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.lib-badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
  padding: 2px 9px; border-radius: 20px; border: 1px solid var(--line); color: var(--muted); background: var(--btn);
}
.lib-status-active { color: #2f7d4f; border-color: #2f7d4f55; background: #2f7d4f14; }
.lib-status-draft { color: #9a7a1e; border-color: #9a7a1e55; background: #9a7a1e14; }
.lib-status-archived { color: var(--muted); }
.lib-shared { color: var(--energy); border-color: color-mix(in srgb, var(--energy) 40%, transparent); background: color-mix(in srgb, var(--energy) 9%, transparent); }

.lib-menu {
  position: fixed; z-index: 1200; min-width: 150px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px #0003;
  padding: 5px; display: flex; flex-direction: column;
}
.lib-menu-item {
  text-align: left; border: 0; background: transparent; color: var(--ink); font-size: 13px;
  padding: 7px 10px; border-radius: 6px; cursor: pointer; font-family: inherit;
}
.lib-menu-item:hover { background: var(--hover); }
.lib-menu-item.danger { color: #a32d2d; }
.lib-menu-item.danger:hover { background: #fbeaea; }
body.dark .lib-menu-item.danger:hover { background: #3a1f1f; }

/* ---- Share modal ---- */
.share-sub { font-size: 12.5px; color: var(--muted); margin: -4px 0 14px; }
.share-list { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; margin-bottom: 16px; }
.share-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.share-row:hover { background: var(--hover); }
.share-name { font-size: 14px; color: var(--ink); }
.share-empty { font-size: 13px; color: var(--muted); line-height: 1.5; padding: 8px 2px; }

/* ---- Folder picker modal ---- */
.folder-list { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow-y: auto; margin-bottom: 14px; }
.folder-opt {
  text-align: left; border: 1px solid transparent; background: transparent; color: var(--ink);
  font-size: 14px; font-family: inherit; padding: 9px 11px; border-radius: 8px; cursor: pointer;
}
.folder-opt:hover { background: var(--hover); }
.folder-opt.active { border-color: var(--energy); color: var(--energy); font-weight: 600; }
