/* Book Editor — styles. Palette and layout follow the approved combined mock. */

:root {
  --bg: #f4efe6;
  --bar: #f8f4ec;
  --card: #fffdf8;
  --field: #f6f0e4;
  --sel: #ece1cd;
  --border: #e2d8c7;
  --border-strong: #c9b99f;
  --text: #23201b;
  --muted: #5f584c;
  --accent: #8a4b2a;
  --accent-text: #ffffff;
  --danger: #a3372a;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 12px 32px rgba(60, 40, 20, .10);
  --backdrop: rgba(35, 32, 27, .35);

  --serif: 'Newsreader', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --ui: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --text-size: 20px;
  --line: 1.7;
  --column: 640px;
  --binder-w: 280px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #16171b;
  --bar: #1c1e23;
  --card: #23262d;
  --field: #1b1d22;
  --sel: #3a342b;
  --border: #343842;
  --border-strong: #4c515c;
  --text: #e8e4da;
  --muted: #a8a397;
  --accent: #dea277;
  --accent-text: #16171b;
  --danger: #e38b7a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .35);
  --backdrop: rgba(0, 0, 0, .55);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }

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

.icon { display: inline-flex; line-height: 0; }

/* ------------------------------------------------------------ start screen */

.start {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 28px;
  padding: 40px 20px;
}

.start-actions { display: flex; gap: 24px; flex-wrap: wrap; justify-content: center; }

.start-btn {
  width: 200px;
  height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 16px;
  font-weight: 500;
  transition: border-color .15s, transform .15s;
}
.start-btn .icon { color: var(--accent); }
.start-btn:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }

.start-continue {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 6px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.start-note { max-width: 44ch; text-align: center; color: var(--muted); line-height: 1.6; margin: 0; }

/* ------------------------------------------------------------ shell */

.shell { height: 100%; display: flex; flex-direction: column; }

.topbar {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bar);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 14px; min-width: 0; }

.book-title {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  border: none;
  background: none;
  padding: 2px 6px;
  margin-left: -6px;
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}
.book-title:hover { background: var(--sel); }

.save-status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-status.is-error { color: var(--danger); font-weight: 500; }
.word-counts { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--sel); }
.icon-btn.small { width: 30px; height: 30px; border-color: transparent; color: var(--muted); }

.link-btn {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 500;
}

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

.rail {
  width: 64px;
  flex: none;
  border-right: 1px solid var(--border);
  background: var(--bar);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 6px;
}
.rail-spacer { flex: 1; }
.rail-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rail-btn:hover { background: var(--field); }
.rail-btn[aria-pressed="true"] { background: var(--sel); }

.workspace { flex: 1; min-width: 0; overflow-y: auto; transition: padding-left .2s ease; }

@media (min-width: 1100px) {
  .left-open .workspace { padding-left: calc(var(--left-w, 280px) + 32px); }
}

.page-wrap {
  max-width: calc(var(--column) + 80px);
  margin: 0 auto;
  padding: 0 40px 35vh;
}

/* ------------------------------------------------------------ toolbar */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 0 10px;
  margin-bottom: 36px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.tool {
  height: 32px;
  min-width: 32px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-size: 14px;
}
.tool:hover:not(:disabled) { border-color: var(--border); }
.tool[aria-pressed="true"] { background: var(--sel); }
.tool-b { font-weight: 700; }
.tool-i { font-family: var(--serif); font-style: italic; font-size: 16px; }
.tool-break { font-size: 13px; }
.tool-sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; }
.tool-select {
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  padding: 0 8px;
  font-size: 13px;
}

/* ------------------------------------------------------------ page */

.page { font-family: var(--manuscript, var(--serif)); }

.page-location {
  margin: 0 0 6px;
  font-family: var(--ui);
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.page-title {
  display: block;
  width: 100%;
  margin: 0 0 32px;
  padding: 0 0 4px;
  border: none;
  border-bottom: 1px solid transparent;
  background: transparent;
  font-family: var(--manuscript, var(--serif));
  font-size: 34px;
  font-weight: 600;
  line-height: 1.2;
}
.page-title:hover { border-bottom-color: var(--border); }
.page-title:focus { outline: none; border-bottom-color: var(--accent); }

.page-empty { text-align: center; padding: 64px 0; color: var(--muted); font-family: var(--ui); }
.page-empty p { margin: 0 0 16px; }
.page-error { font-family: var(--ui); color: var(--danger); }

.chapter-scene + .chapter-scene { margin-top: 12px; }
.scene-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 40px 0 22px;
}
.chapter-scene:first-of-type .scene-divider { margin-top: 0; }
.scene-divider::before, .scene-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.scene-link {
  border: none;
  background: none;
  font-family: var(--ui);
  font-size: 12px;
  color: var(--muted);
  padding: 4px 6px;
  border-radius: 6px;
}
.scene-link:hover { color: var(--accent); background: var(--field); }

/* ------------------------------------------------------------ manuscript text */

.ProseMirror { position: relative; word-wrap: break-word; white-space: pre-wrap; white-space: break-spaces; }
.ProseMirror-hideselection *::selection { background: transparent; }
.ProseMirror-hideselection { caret-color: transparent; }
.ProseMirror [draggable][contenteditable=false] { user-select: text; }

.manuscript {
  outline: none;
  font-family: var(--manuscript, var(--serif));
  font-size: var(--text-size);
  line-height: var(--line);
  min-height: 40vh;
  caret-color: var(--accent);
  hanging-punctuation: first;
}
.chapter-scene .manuscript { min-height: 3em; }
.manuscript p { margin: 0 0 .9em; }
.manuscript h1, .manuscript h2, .manuscript h3 { font-weight: 600; line-height: 1.25; margin: 1.4em 0 .6em; }
.manuscript h1 { font-size: 1.45em; }
.manuscript h2 { font-size: 1.2em; }
.manuscript h3 { font-size: 1em; font-style: italic; font-weight: 500; }
.manuscript > :first-child { margin-top: 0; }
.manuscript strong { font-weight: 700; }

.manuscript hr.scene-break {
  border: none;
  height: auto;
  margin: 1.6em 0;
  text-align: center;
  overflow: visible;
  color: var(--muted);
}
.manuscript hr.scene-break::before {
  content: '*   *   *';
  white-space: pre;
  font-size: .9em;
  letter-spacing: .1em;
}
.manuscript .ProseMirror-selectednode { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }

::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }

/* ------------------------------------------------------------ cards: binder */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.binder {
  position: absolute;
  left: 80px;
  top: 16px;
  width: var(--binder-w);
  max-height: calc(100% - 32px);
  display: none;
  flex-direction: column;
  z-index: 10;
}
.left-binder .binder { display: flex; }

.card-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 4px 16px; }
.card-title { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }

.bn-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.bn-empty { color: var(--muted); font-size: 13px; padding: 8px; margin: 0; }

.bn-row {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 34px;
  padding-left: calc(var(--depth) * 16px);
  border-radius: 6px;
}
.bn-row:hover { background: var(--field); }
.bn-row.is-current { background: var(--sel); }
.bn-row.is-dragging { opacity: .4; }

.bn-caret, .bn-caret-space { flex: none; width: 24px; height: 28px; }
.bn-caret {
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}
.bn-caret .icon { transition: transform .15s; }
.bn-caret.open .icon { transform: rotate(90deg); }

.bn-title {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: none;
  background: none;
  padding: 7px 4px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 4px;
}
.bn-part > .bn-title { font-weight: 600; }
.bn-chapter > .bn-title { font-weight: 500; }

.bn-more {
  flex: none;
  width: 28px;
  height: 28px;
  margin-right: 2px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
}
.bn-row:hover .bn-more, .bn-row:focus-within .bn-more, .bn-more[aria-expanded="true"] { opacity: 1; }
.bn-more:hover { background: var(--sel); }
@media (hover: none) { .bn-more { opacity: 1; } }

.bn-rename {
  flex: 1;
  min-width: 0;
  margin: 3px 6px 3px 0;
  padding: 4px 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--card);
  font-size: 13px;
  outline: none;
}

.bn-row.drop-before::before,
.bn-row.drop-after::after {
  content: '';
  position: absolute;
  left: calc(var(--depth) * 16px + 24px);
  right: 6px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}
.bn-row.drop-before::before { top: -1px; }
.bn-row.drop-after::after { bottom: -1px; }
.bn-row.drop-inside { box-shadow: inset 0 0 0 2px var(--accent); }

.bn-add { display: flex; gap: 6px; padding: 10px 12px 12px; border-top: 1px solid var(--border); }
.btn-dashed {
  flex: 1;
  height: 34px;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  background: transparent;
  font-size: 12px;
}
.btn-dashed:hover { border-style: solid; background: var(--field); }

/* ------------------------------------------------------------ menus, dialogs, toasts */

.menu {
  position: fixed;
  z-index: 50;
  min-width: 190px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: none;
  font-size: 13px;
}
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--field); outline: none; }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }

.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: var(--backdrop); }
.dialog h2 { margin: 0 0 12px; font-family: var(--serif); font-size: 22px; font-weight: 600; }
.dialog p { margin: 0; line-height: 1.55; color: var(--muted); }
.dialog label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.dialog input[type="text"] {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg);
  font-size: 15px;
}
.dialog input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.dialog .dialog-hint { font-size: 13px; margin-top: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

.btn {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
}
.btn:hover { background: var(--field); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}
.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  box-shadow: var(--shadow);
}
.toast-action {
  border: none;
  background: none;
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}

/* ------------------------------------------------------------ small screens */

@media (max-width: 760px) {
  .topbar { padding: 0 12px; }
  .word-counts { display: none; }
  .rail { width: 52px; }
  .binder { left: 60px; width: min(var(--binder-w), calc(100vw - 72px)); }
  .page-wrap { padding: 0 20px 35vh; }
  .page-title { font-size: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ============================================================ stage 2: planner */

.manuscript .name-mark { border-bottom: 1.5px dotted var(--accent); }

.tool-character { font-size: 13px; }

.menu { max-height: min(60vh, 420px); overflow-y: auto; }

.planner {
  position: absolute;
  right: 16px;
  top: 16px;
  bottom: 16px;
  width: var(--planner-w);
  display: none;
  flex-direction: column;
  z-index: 10;
  overflow: hidden;
}
.planner-open .planner { display: flex; }
:root { --planner-w: 380px; }

@media (min-width: 1200px) {
  .planner-open .workspace { padding-right: calc(var(--planner-w) + 24px); }
}
@media (min-width: 1100px) and (max-width: 1499px) {
  .left-open.planner-open .page-wrap { padding: 0 24px 35vh; }
}

.planner-head { display: flex; align-items: center; gap: 4px; padding: 8px; border-bottom: 1px solid var(--border); }
.ptabs { display: flex; gap: 2px; flex: 1; }
.ptab {
  flex: 1;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  padding: 0 4px;
}
.ptab:hover { background: var(--field); }
.ptab[aria-selected="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }

.planner-body { flex: 1; overflow-y: auto; padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 4px; }

.phead { display: flex; flex-direction: column; gap: 6px; padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.phead-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pkicker { margin: 0; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.ptitle { margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 600; line-height: 1.2; min-width: 0; overflow-wrap: anywhere; }
.pmeta { margin: 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.phint { margin: 4px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.pempty { margin: 4px 0 8px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.pgroup { margin: 10px 0 2px; font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .04em; }

.psec { border-bottom: 1px solid var(--border); }
.psec:last-child { border-bottom: none; }
.psec > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text);
  border-radius: 6px;
}
.psec > summary::-webkit-details-marker { display: none; }
.psec > summary::before {
  content: '';
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  margin: 0 4px 0 2px;
  transition: transform .15s;
}
.psec[open] > summary::before { transform: rotate(45deg); }
.psec-title { flex: 1; }
.psec-meta { font-size: 12px; font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--muted); white-space: nowrap; }
.psec-body { display: flex; flex-direction: column; gap: 10px; padding: 0 0 14px 18px; }

.pfield { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.pfield > label { font-size: 11px; font-weight: 600; letter-spacing: .04em; color: var(--muted); }
.pgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.pinput, .pselect {
  width: 100%;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--field);
  padding: 7px 10px;
  font-size: 13px;
  line-height: 1.5;
}
textarea.pinput { resize: vertical; field-sizing: content; min-height: 3.2em; }
.pinput:hover, .pselect:hover { border-color: var(--border); }
.pinput:focus, .pselect:focus { outline: none; border-color: var(--accent); background: var(--card); }
.pselect { width: auto; padding: 5px 8px; font-size: 12px; }
.pinput::placeholder { color: var(--muted); opacity: .8; }
.pinput.is-done { text-decoration: line-through; color: var(--muted); }

.ptarget-row { display: flex; align-items: center; gap: 8px; }
.ptarget { width: 110px; padding: 4px 8px; }
.pbar[hidden] { display: none; }
.pbar { height: 6px; border-radius: 3px; background: var(--sel); overflow: hidden; }
.pbar > div { height: 100%; background: var(--accent); border-radius: 3px; }

.pbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bar);
  font-size: 12px;
  white-space: nowrap;
}
.pbtn:hover { background: var(--sel); }
.pbtn.small { height: 26px; padding: 0 8px; font-size: 11px; }

.padd {
  align-self: flex-start;
  height: 28px;
  padding: 0 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  background: transparent;
  font-size: 12px;
}
.padd:hover { border-style: solid; background: var(--field); }

.pchips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pchip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 28px;
  padding: 0 4px 0 10px;
  border-radius: 999px;
  background: var(--sel);
  font-size: 12px;
  max-width: 100%;
}
.pchip > span:only-child, .pchip:not(:has(.pchip-x)) { padding-right: 10px; }
.pchip { white-space: nowrap; }
.pchip.is-auto { background: transparent; border: 1px solid var(--border-strong); color: var(--muted); }
.pchip .dot { margin-right: 6px; }
.pchip-btn { border: none; background: none; padding: 4px 2px; font-size: 12px; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.pchip-btn:hover { text-decoration: underline; text-underline-offset: 2px; }
.pchip-x { width: 22px; height: 22px; border: none; border-radius: 50%; background: transparent; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.pchip-x:hover { background: var(--field); color: var(--text); }
.scene-chip { background: var(--field); border: 1px solid var(--border); }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

.prows { display: flex; flex-direction: column; gap: 4px; }
.prow {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  border: none;
  border-radius: 8px;
  background: var(--field);
  font-size: 13px;
  text-align: left;
}
button.prow:hover { background: var(--sel); }
.prow.is-current { box-shadow: inset 0 0 0 1.5px var(--accent); }
.prow-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.link-row { padding-right: 4px; color: var(--accent); }
.link-go { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; border: none; background: none; padding: 0; color: var(--text); text-align: left; }
.link-go .prow-meta { max-width: 100%; }
.link-go:hover .prow-title { text-decoration: underline; text-underline-offset: 2px; }

.objectives { display: flex; flex-direction: column; gap: 4px; }
.objective { display: flex; align-items: center; gap: 8px; }
.objective input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); flex: none; margin: 0; }

.thread { border: 1px solid var(--border); border-radius: 10px; padding: 8px 8px 10px; display: flex; flex-direction: column; gap: 8px; }
.thread-head { display: flex; align-items: center; gap: 6px; }
.thread-toggle { width: 24px; height: 28px; border: none; background: none; color: var(--muted); display: flex; align-items: center; justify-content: center; }
.thread-toggle.open .icon { transform: rotate(90deg); }
.thread-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--card); box-shadow: 0 0 0 1px var(--border-strong); flex: none; padding: 0; }
.thread-title { font-weight: 600; background: transparent; padding: 4px 6px; }
.beats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.beat { display: flex; align-items: flex-start; gap: 8px; padding: 8px; border-radius: 8px; background: var(--field); }
.beat.is-current { box-shadow: inset 0 0 0 1.5px var(--accent); }
.beat-num { flex: none; width: 18px; padding-top: 7px; font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.beat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.beat-title { background: var(--card); }
.beat-del { flex: none; }

.char-top { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.char-search { display: flex; gap: 8px; }
.pseg { display: flex; padding: 3px; border-radius: 8px; background: var(--field); flex: none; }
.pseg button { height: 28px; padding: 0 10px; border: none; border-radius: 6px; background: transparent; font-size: 12px; white-space: nowrap; }
.pseg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.roster { display: flex; flex-wrap: wrap; gap: 6px; }
.roster-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px 0 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
}
.roster-item:hover { background: var(--field); }
.roster-item[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); font-weight: 600; }
.initial { width: 24px; height: 24px; border-radius: 50%; background: var(--sel); color: var(--accent); font-family: var(--serif); font-size: 14px; display: flex; align-items: center; justify-content: center; }
.char-name { font-family: var(--serif); font-size: 21px; font-weight: 600; background: transparent; padding: 2px 6px; margin-left: -6px; }

.pfields { display: flex; flex-direction: column; gap: 6px; }
.pfield-edit { display: grid; grid-template-columns: 110px minmax(0, 1fr) 30px; gap: 6px; align-items: center; }
.field-label { font-size: 12px; font-weight: 600; color: var(--muted); background: transparent; padding: 6px; }

.mention-row { display: flex; align-items: center; gap: 8px; }
.mention-row.is-dropped .mention-text { text-decoration: line-through; opacity: .6; }
.mention-snip {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 10px;
  border: none;
  border-radius: 8px;
  background: var(--field);
  text-align: left;
  font-size: 13px;
  line-height: 1.45;
}
.mention-snip:hover { background: var(--sel); }
.mention-scene { font-size: 11px; color: var(--muted); }
.mention-text b { color: var(--accent); }

.pfoot { padding-top: 14px; }
.btn-text { border: none; background: none; padding: 6px 0; font-size: 13px; text-decoration: underline; text-underline-offset: 2px; }
.btn-text.danger { color: var(--danger); }

/* ---------------------------------------------------------- binder links */

.bn-links {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 24px;
  padding: 0 5px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  font-size: 11px;
}
.bn-links:hover { background: var(--sel); }

/* ---------------------------------------------------------- scene picker */

.dialog-wide { width: min(520px, calc(100vw - 32px)); }
.picker-search {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg);
  font-size: 14px;
}
.picker-list { margin: 10px 0 14px; max-height: 46vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 6px; }
.picker-group { padding: 8px 8px 4px; font-size: 11px; font-weight: 600; letter-spacing: .04em; color: var(--muted); }
.picker-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px 8px 18px;
  border: none;
  border-radius: 6px;
  background: none;
  font-size: 14px;
}
.picker-option:hover { background: var(--field); }
.picker-option[aria-selected="true"] { background: var(--sel); box-shadow: inset 3px 0 0 var(--accent); font-weight: 500; }
.picker-empty { padding: 12px; }
.picker-label { margin-top: 4px; }
.dialog input[type="text"]#pick-label { margin-top: 2px; }

/* ---------------------------------------------------------- plot board */

.board {
  position: absolute;
  inset: 16px 16px 16px 80px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.board[hidden] { display: none; }
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.board-titles { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.board-actions { display: flex; gap: 8px; }
.board-actions .btn { display: inline-flex; align-items: center; gap: 4px; }
.board-cols { flex: 1; display: flex; gap: 14px; padding: 16px 18px; overflow: auto; align-items: flex-start; }
.board-col {
  width: 300px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  background: var(--field);
  border: 1px solid var(--border);
}
.board-col.drop-col { box-shadow: inset 0 0 0 2px var(--accent); }
.board-col-head { display: flex; align-items: center; gap: 8px; padding: 2px 2px 4px; font-size: 14px; font-weight: 600; }
.board-col-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-beats { display: flex; flex-direction: column; gap: 8px; }
.board-beat {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  cursor: grab;
}
.board-beat.is-current { box-shadow: inset 0 0 0 1.5px var(--accent); }
.board-beat.is-dragging { opacity: .4; }
.board-beat.drop-before::before, .board-beat.drop-after::after {
  content: '';
  position: absolute;
  left: 6px;
  right: 6px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.board-beat.drop-before::before { top: -6px; }
.board-beat.drop-after::after { bottom: -6px; }
.board-beat-top { display: flex; align-items: flex-start; gap: 6px; }
.board-beat-top .beat-num { padding-top: 4px; }
.board-beat-title {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  resize: none;
  field-sizing: content;
  font-size: 13px;
  line-height: 1.45;
  padding: 3px 4px;
  border-radius: 6px;
  cursor: text;
}
.board-beat-title:focus { outline: 1.5px solid var(--accent); background: var(--field); }
.board-add { align-self: stretch; border-radius: 8px; height: 34px; }
.board-new {
  width: 220px;
  flex: none;
  height: 120px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 12px;
  background: transparent;
  font-size: 13px;
}
.board-new:hover { background: var(--field); }

@media (max-width: 760px) {
  .planner { left: 60px; right: 8px; width: auto; }
  .board { inset: 8px 8px 8px 60px; }
}


/* ============================================================ stages 3 and 4 */

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.spacer { flex: 1; }
.tool-spacer { flex: 1; }
.tool-history { font-size: 13px; }
.menu-anchor { position: fixed; width: 1px; height: 1px; }

.left-card {
  position: absolute;
  left: 80px;
  top: 16px;
  width: var(--left-w, 320px);
  max-height: calc(100% - 32px);
  display: none;
  flex-direction: column;
  z-index: 10;
  overflow: hidden;
}
.left-search .search-panel, .left-appearance .appearance-panel { display: flex; }

/* spelling */
.manuscript .misspelled {
  text-decoration: underline wavy var(--danger);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  text-decoration-skip-ink: none;
}

/* appearance */
.ap-body { overflow-y: auto; padding: 4px 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.ap-h { margin: 12px 0 2px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .03em; }
.ap-fonts { display: flex; flex-direction: column; gap: 2px; }
.ap-font-row { display: flex; align-items: center; gap: 4px; }
.ap-font {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}
.ap-font:hover { background: var(--field); }
.ap-font[aria-checked="true"] { background: var(--sel); border-color: var(--accent); }
.ap-font-name { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-font-tag { font-size: 11px; color: var(--muted); white-space: nowrap; }
.ap-add { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.ap-add .btn-dashed { flex: none; }
.ap-slider { display: flex; flex-direction: column; gap: 4px; }
.ap-slider-head { display: flex; justify-content: space-between; font-size: 13px; }
.ap-value { color: var(--muted); font-variant-numeric: tabular-nums; }
.ap-slider input[type="range"] { width: 100%; accent-color: var(--accent); }
.ap-seg { align-self: flex-start; }
.ap-check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.ap-check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.ap-lang-add { align-self: flex-start; padding: 0 12px; flex: none; }
.ap-note { margin: 10px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.lang-files { display: grid; grid-template-columns: auto 1fr; gap: 10px 12px; align-items: center; margin: 14px 0 4px; font-size: 13px; }
.dialog .lang-files label { margin: 0; }
.dialog input[type="file"] { font-size: 13px; }

/* find and replace */
.find-form { display: flex; flex-direction: column; gap: 8px; padding: 4px 14px 10px; }
.find-options { display: flex; gap: 16px; flex-wrap: wrap; }
.find-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.find-row .btn { height: 32px; }
.find-summary { margin: 0; padding: 6px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.find-summary:empty { display: none; }
.find-results { flex: 1; overflow-y: auto; padding: 0 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.find-item { display: flex; align-items: center; gap: 6px; }
.find-item mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }

/* goals */
.goals-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
}
.goals-btn:hover { background: var(--sel); }
.goal-ring {
  --p: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 360deg), var(--border) 0);
  -webkit-mask: radial-gradient(circle, transparent 4px, #000 4.5px);
  mask: radial-gradient(circle, transparent 4px, #000 4.5px);
}
.goal-ring.done { -webkit-mask: none; mask: none; background: var(--accent); }
.goal-ring[hidden] { display: none; }
.goals-pop { position: fixed; z-index: 40; width: 300px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.pop-title { margin: 0; font-family: var(--serif); font-size: 18px; font-weight: 600; }
.goal-block { display: flex; flex-direction: column; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.goal-line { display: flex; justify-content: space-between; font-size: 13px; }
.goal-line b { font-variant-numeric: tabular-nums; }
.goal-set { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); }
.goal-set .pinput { width: 120px; }

/* history */
.dialog.history { width: min(900px, calc(100vw - 32px)); }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.history-head h2 { margin: 0; }
.history-main { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; height: min(60vh, 560px); }
.history-list { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding-right: 4px; }
.history-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--field);
  text-align: left;
  font-size: 13px;
}
.history-item span { font-size: 12px; color: var(--muted); }
.history-item[aria-selected="true"] { border-color: var(--accent); background: var(--sel); }
.history-right { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.history-preview { flex: 1; overflow-y: auto; min-height: 0 !important; padding: 16px 20px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); font-size: 17px; }
.dialog.history .dialog-actions { align-items: center; }

/* backups */
.backup-body { display: flex; flex-direction: column; gap: 8px; }
.backup-body > p:first-child { color: var(--muted); line-height: 1.55; margin: 0 0 4px; }
.backup-list { list-style: none; margin: 0; padding: 0; max-height: 180px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.backup-list li { display: flex; justify-content: space-between; padding: 7px 12px; font-size: 13px; border-bottom: 1px solid var(--border); }
.backup-list li:last-child { border-bottom: none; }
.backup-second { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.backup-second > span:first-child { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }

/* export */
.dialog.export { width: min(780px, calc(100vw - 32px)); }
.export-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 24px; }
.export-left { display: flex; flex-direction: column; gap: 10px; }
.export-formats { align-self: flex-start; }
.export-formats button { padding: 0 16px; }
.export-tree-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.export-tree-head h3 { margin: 0; flex: 1; }
.export-tree { max-height: 46vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 6px; margin-top: 8px; }
.export-row { display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px calc(6px + var(--depth) * 18px); font-size: 13px; border-radius: 6px; }
.export-row:hover { background: var(--field); }
.export-row input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.dialog .export-row label { margin: 0; font-weight: 400; font-size: 13px; }
.export-part label, .export-chapter label { font-weight: 600 !important; }
.dialog .pinput { background: var(--bg); border-color: var(--border-strong); }

@media (max-width: 760px) {
  .left-card { left: 60px; width: min(var(--left-w, 320px), calc(100vw - 72px)); }
  .export-grid, .history-main { grid-template-columns: 1fr; }
}
