/* ============================================================================
   writing — component styles. Consumes tokens.css.
   ========================================================================== */

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: #cfc6b4;            /* desktop behind the app window */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: var(--text-base);
}
[data-theme="dark"] body { background: #0e0e0c; }
button { font-family: inherit; color: inherit; cursor: pointer; border: none; background: none; }
::selection { background: var(--selection); }

/* ---- App window ---------------------------------------------------------- */
.win {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--paper);
  overflow: hidden;
}
@media (min-width: 1180px) {
  .win {
    inset: 18px; border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--parchment-edge);
  }
}

/* ---- Title bar (merged: brand · view switch · actions · window controls) -- */
.titlebar {
  height: var(--titlebar-h); flex: none;
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-2) 0 var(--s-4);
  background: var(--titlebar);
  border-bottom: 1px solid var(--parchment-edge);
  user-select: none; position: relative;
}
.titlebar .brand {
  display: flex; align-items: center; gap: var(--s-2); white-space: nowrap;
  font-weight: var(--w-semi); font-size: var(--text-sm); letter-spacing: 0.01em;
  color: var(--ink-2); flex: none;
}
.titlebar .brand .glyph { width: 16px; height: 16px; color: var(--accent); }
.tb-divider { width: 1px; height: 22px; background: var(--parchment-edge); flex: none; }
.tb-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; flex: none; }
.titlebar .doc-name {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-size: var(--text-xs); color: var(--ink-3); font-weight: var(--w-medium);
  display: flex; align-items: center; gap: 6px; white-space: nowrap; pointer-events: none;
}
@media (max-width: 1180px) { .titlebar .doc-name { display: none; } }
.titlebar .saved { color: var(--ink-4); font-size: var(--text-2xs); }
.titlebar .wbtns { display: flex; gap: 2px; flex: none; }
.wbtn {
  width: 30px; height: 24px; border-radius: var(--r-xs);
  display: grid; place-items: center; color: var(--ink-3);
}
.wbtn:hover { background: var(--parchment-deep); color: var(--ink); }
.wbtn.close:hover { background: #d6573e; color: #fff; }

/* ---- Top bar ------------------------------------------------------------- */
.topbar {
  height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: var(--s-2);
  padding: 0 var(--s-3) 0 var(--s-4);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  z-index: 5;
}
.topbar .spacer { flex: 1; }

/* segmented view switch */
.segmented {
  display: inline-flex; background: var(--parchment-deep);
  border-radius: var(--r-md); padding: 3px; gap: 2px;
}
.segmented button {
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: var(--text-sm); font-weight: var(--w-medium); color: var(--ink-2);
  padding: 5px 12px; border-radius: var(--r-sm);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.segmented button.on {
  background: var(--paper); color: var(--ink);
  box-shadow: var(--shadow-xs);
}
.segmented button:not(.on):hover { color: var(--ink); }
.segmented .ic { width: 15px; height: 15px; }

/* generic icon button */
.iconbtn {
  width: 34px; height: 34px; border-radius: var(--r-md);
  display: grid; place-items: center; color: var(--ink-2);
  transition: background var(--dur-fast), color var(--dur-fast);
  position: relative;
}
.iconbtn:hover { background: var(--parchment-deep); color: var(--ink); }
.iconbtn .ic { width: 18px; height: 18px; }
.iconbtn.has-dot::after {
  content: ""; position: absolute; top: 7px; right: 7px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 2px var(--paper);
}

/* pill button (primary action like Export) */
.btn {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  font-size: var(--text-sm); font-weight: var(--w-semi);
  padding: 7px 14px; border-radius: var(--r-md);
  transition: all var(--dur-fast);
}
.btn .ic { width: 15px; height: 15px; }
.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover { background: var(--parchment-deep); color: var(--ink); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--accent-deep); }
.btn-soft { background: var(--accent-tint); color: var(--accent-deep); }
.btn-soft:hover { background: var(--accent-wash); }

/* ---- Body row ------------------------------------------------------------ */
.body { flex: 1; display: flex; min-height: 0; }
.panel-binder {
  width: var(--binder-w); flex: none;
  background: var(--parchment); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.panel-inspector {
  width: var(--inspector-w); flex: none;
  background: var(--parchment); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.center { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

/* collapse animation hooks */
.panel-binder, .panel-inspector { transition: width var(--dur-slow) var(--ease), opacity var(--dur) ease; }
.collapsed-left { width: 0 !important; opacity: 0; overflow: hidden; border: none; }
.collapsed-right { width: 0 !important; opacity: 0; overflow: hidden; border: none; }

/* ---- Binder -------------------------------------------------------------- */
.project-switch {
  padding: var(--s-3) var(--s-3) var(--s-2);
  border-bottom: 1px solid var(--line-soft);
  flex: none;
}
.proj-btn {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-md); text-align: left;
  transition: background var(--dur-fast);
}
.proj-btn:hover { background: var(--parchment-deep); }
.proj-cover {
  width: 30px; height: 38px; flex: none; border-radius: 3px;
  background: linear-gradient(150deg, var(--accent), var(--accent-deep));
  box-shadow: var(--shadow-xs), inset 2px 0 0 rgba(255,255,255,0.18), inset -1px 0 0 rgba(0,0,0,0.12);
  position: relative;
}
.proj-cover::after {
  content: ""; position: absolute; left: 4px; top: 5px; bottom: 5px; width: 1px;
  background: rgba(255,255,255,0.25);
}
.proj-meta { min-width: 0; flex: 1; }
.proj-title { font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj-sub { font-size: var(--text-2xs); color: var(--ink-3); margin-top: 1px; }
.proj-chev { color: var(--ink-3); flex: none; }

.binder-scroll { flex: 1; overflow-y: auto; padding: var(--s-2) var(--s-2) var(--s-6); }
.binder-scroll::-webkit-scrollbar { width: 9px; }
.binder-scroll::-webkit-scrollbar-thumb { background: var(--parchment-edge); border-radius: 9px; border: 2px solid var(--parchment); }
.binder-scroll:hover::-webkit-scrollbar-thumb { background: var(--ink-4); }

.bsection-head {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 8px 4px; font-size: var(--text-2xs); font-weight: var(--w-bold);
  letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-3);
}
.bsection-head .count { color: var(--ink-4); font-weight: var(--w-semi); }
.bsection-head .add {
  margin-left: auto; width: 20px; height: 20px; border-radius: var(--r-xs);
  display: grid; place-items: center; color: var(--ink-3);
}
.bsection-head .add:hover { background: var(--parchment-deep); color: var(--ink); }

.chapter { margin-bottom: 2px; }
.chapter-row {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-radius: var(--r-sm); cursor: pointer;
  transition: background var(--dur-fast);
}
.chapter-row:hover { background: var(--parchment-deep); }
.chapter-row .twist { color: var(--ink-3); transition: transform var(--dur); flex: none; display: grid; place-items: center; }
.chapter-row.closed .twist { transform: rotate(-90deg); }
.chapter-row .ch-title { font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--ink-2);
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-row .ch-count { font-size: var(--text-2xs); color: var(--ink-4); font-variant-numeric: tabular-nums; }

.scene-list { margin: 1px 0 4px; padding-left: 12px; position: relative; }
.scene-list::before {
  content: ""; position: absolute; left: 15px; top: 2px; bottom: 4px; width: 1px;
  background: var(--line);
}
.scene-row {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 9px 6px 16px; border-radius: var(--r-sm); cursor: pointer;
  position: relative; transition: background var(--dur-fast);
}
.scene-row:hover { background: var(--parchment-deep); }
.scene-row.active { background: var(--accent-tint); }
[data-theme="dark"] .scene-row.active { background: var(--accent-tint); }
.scene-row.active::before {
  content: ""; position: absolute; left: 3px; top: 6px; bottom: 6px; width: 3px;
  border-radius: 3px; background: var(--accent);
}
.scene-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.scene-title { font-size: var(--text-sm); color: var(--ink-2); flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scene-row.active .scene-title { color: var(--ink); font-weight: var(--w-medium); }
.scene-words { font-size: 10px; color: var(--ink-4); font-variant-numeric: tabular-nums; opacity: 0; transition: opacity var(--dur-fast); }
.scene-row:hover .scene-words, .scene-row.active .scene-words { opacity: 1; }

.add-chapter {
  width: 100%; display: flex; align-items: center; gap: 6px; justify-content: center;
  margin-top: 6px; padding: 7px; border-radius: var(--r-sm);
  border: 1px dashed var(--parchment-edge); color: var(--ink-3);
  font-size: var(--text-xs); font-weight: var(--w-medium);
  transition: all var(--dur-fast);
}
.add-chapter:hover { border-color: var(--accent-ring); color: var(--accent-deep); background: var(--accent-wash); }

/* quick-notes entry at the bottom of the binder */
.binder-foot { flex: none; border-top: 1px solid var(--line-soft); padding: var(--s-2); }
.foot-btn {
  width: 100%; display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--r-md); color: var(--ink-2);
  font-size: var(--text-sm); font-weight: var(--w-medium);
  transition: background var(--dur-fast);
}
.foot-btn:hover { background: var(--parchment-deep); color: var(--ink); }
.foot-btn .ic { width: 16px; height: 16px; color: var(--ink-3); }
.foot-btn .badge {
  margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill);
  background: var(--accent); color: #fff; font-size: 10px; font-weight: var(--w-bold);
  display: grid; place-items: center;
}

/* ---- Canvas -------------------------------------------------------------- */
.canvas-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; }
.canvas-scroll::-webkit-scrollbar { width: 11px; }
.canvas-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 9px; border: 3px solid var(--paper); }
.canvas-scroll:hover::-webkit-scrollbar-thumb { background: var(--parchment-edge); }
.canvas-wrap { max-width: var(--prose-measure); margin: 0 auto; padding: var(--s-12) var(--s-8) 30vh; }

.scene-eyebrow {
  display: flex; align-items: center; gap: 8px; margin-bottom: var(--s-3);
  font-family: var(--font-ui); font-size: var(--text-xs); font-weight: var(--w-semi);
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3);
}
.scene-eyebrow .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--ink-4); }
.scene-h1 {
  font-family: var(--font-prose); font-weight: var(--w-semi);
  font-size: var(--text-3xl); line-height: 1.15; color: var(--ink);
  margin: 0 0 6px; letter-spacing: -0.01em;
}
.scene-byline { font-size: var(--text-xs); color: var(--ink-3); margin-bottom: var(--s-8);
  display: flex; align-items: center; gap: 10px; }
.scene-byline .dotsep { width: 3px; height: 3px; border-radius: 50%; background: var(--ink-4); }

.prose { font-family: var(--font-prose); font-size: var(--prose-size);
  line-height: var(--prose-leading); color: var(--ink); }
.prose p { margin: 0 0 var(--prose-leading)em; }
.prose p { margin-bottom: 1.25em; }
.prose p:first-of-type::first-letter {
  initial-letter: 3; -webkit-initial-letter: 3;
  font-weight: var(--w-bold); color: var(--accent); margin-right: 10px;
}
.prose .entity { color: var(--ink); border-bottom: 1.5px solid var(--accent-ring);
  cursor: pointer; transition: background var(--dur-fast); padding: 0 1px; border-radius: 2px; }
.prose .entity:hover { background: var(--accent-wash); }
.prose .entity.loc { border-bottom-color: var(--location); }

/* ---- Auto-linked Story-Bible names (Direction A · quiet accent underline) --- */
.prose .al-link {
  color: inherit; cursor: pointer; padding: 0 1px; border-radius: 2px;
  border-bottom: 1.5px solid color-mix(in srgb, var(--accent) 55%, transparent);
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.prose .al-link:hover {
  background: var(--accent-wash);
  border-bottom-color: var(--accent);
}
/* "On hover only" appearance: underline hidden until hovered */
.prose.al-hideunder .al-link { border-bottom-color: transparent; }
.prose.al-hideunder .al-link:hover { border-bottom-color: var(--accent); }

/* hover peek card */
.al-peek {
  position: fixed; z-index: 62; width: 264px;
  background: var(--paper); border: 1px solid var(--parchment-edge);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg); padding: 13px;
  animation: cm-in 110ms var(--ease-out);
}
.al-peek-head { display: flex; align-items: center; gap: 10px; }
.al-peek-name { font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--ink); }
.al-peek-type { font-size: var(--text-2xs); color: var(--ink-3); margin-top: 1px; }
.al-peek-note { font-size: var(--text-xs); color: var(--ink-2); line-height: 1.5; margin-top: 10px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.al-peek-acts { display: flex; gap: 6px; margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--line); }
.al-pbtn { display: inline-flex; align-items: center; gap: 5px; font-family: var(--font-ui);
  font-size: var(--text-xs); font-weight: var(--w-medium); color: var(--ink-2); padding: 5px 8px;
  border-radius: var(--r-sm); transition: background var(--dur-fast), color var(--dur-fast); }
.al-pbtn:hover { background: var(--parchment-deep); color: var(--ink); }
.al-count { font-size: 10.5px; color: var(--ink-4); background: var(--parchment-deep); border-radius: 20px; padding: 1px 6px; }

.caret {
  display: inline-block; width: 2px; height: 1.1em; background: var(--accent);
  vertical-align: -0.18em; margin-left: 1px; animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---- Status bar ---------------------------------------------------------- */
.statusbar {
  height: var(--statusbar-h); flex: none;
  display: flex; align-items: center; gap: var(--s-4);
  padding: 0 var(--s-4); border-top: 1px solid var(--line);
  background: var(--paper); font-size: var(--text-xs); color: var(--ink-3);
}
.statusbar .sb { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.statusbar .sb .ic { width: 13px; height: 13px; color: var(--ink-4); }
.statusbar .sb-right { margin-left: auto; display: flex; align-items: center; gap: var(--s-4); }
.statusbar .sb-right .ic { width: 13px; height: 13px; }
.statusbar .goal-mini { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.statusbar .goal-track { width: 90px; height: 5px; border-radius: 3px; background: var(--parchment-deep); overflow: hidden; }
.statusbar .goal-fill { height: 100%; border-radius: 3px; background: var(--accent); }

/* ---- Inspector ----------------------------------------------------------- */
.insp-scroll { flex: 1; overflow-y: auto; padding: var(--s-5) var(--s-4) var(--s-8); }
.insp-scroll::-webkit-scrollbar { width: 9px; }
.insp-scroll::-webkit-scrollbar-thumb { background: var(--parchment-edge); border-radius: 9px; border: 2px solid var(--parchment); }
.insp-group { margin-bottom: var(--s-6); }
.insp-label {
  display: flex; align-items: center; gap: 6px; margin-bottom: var(--s-3);
  font-size: var(--text-2xs); font-weight: var(--w-bold); letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--ink-3);
}
.insp-label .ic { width: 13px; height: 13px; }
.insp-label--toggle { cursor: pointer; user-select: none; transition: color var(--dur-fast); }
.insp-label--toggle:hover { color: var(--ink-2); }
.insp-caret { color: var(--ink-4); flex: none; transition: transform var(--dur-fast); }
.insp-caret.closed { transform: rotate(-90deg); }
.insp-act { margin-left: auto; display: flex; align-items: center; }
.insp-act .add { margin-left: 0; }
.insp-label .add { margin-left: auto; color: var(--ink-3); width: 18px; height: 18px;
  display: grid; place-items: center; border-radius: var(--r-xs); }
.insp-label .add:hover { background: var(--parchment-deep); color: var(--ink); }

.synopsis {
  font-family: var(--font-prose); font-size: var(--text-md); line-height: 1.55;
  color: var(--ink-2); background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--s-3) var(--s-3); font-style: italic;
}

.entity-card {
  display: flex; align-items: center; gap: 10px; padding: 8px;
  border-radius: var(--r-md); cursor: pointer; transition: background var(--dur-fast);
}
.entity-card:hover { background: var(--parchment-deep); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: var(--text-sm); font-weight: var(--w-bold);
}
.avatar.character { background: var(--character-tint); color: var(--character); }
.avatar.location { background: var(--location-tint); color: var(--location);
  border-radius: var(--r-sm); }
/* palette-token avatars (new entity types) — shape: items/factions/lore squared, themes round */
.avatar.clay, .fe-av-lg.clay { background: color-mix(in srgb, var(--label-clay) 18%, transparent); color: var(--label-clay); }
.avatar.sea, .fe-av-lg.sea { background: color-mix(in srgb, var(--label-sea) 18%, transparent); color: var(--label-sea); }
.avatar.moss, .fe-av-lg.moss { background: color-mix(in srgb, var(--label-moss) 18%, transparent); color: var(--label-moss); }
.avatar.plum, .fe-av-lg.plum { background: color-mix(in srgb, var(--label-plum) 18%, transparent); color: var(--label-plum); }
.avatar.gold, .fe-av-lg.gold { background: color-mix(in srgb, var(--label-gold) 18%, transparent); color: var(--label-gold); }
.avatar.slate, .fe-av-lg.slate { background: color-mix(in srgb, var(--label-slate) 18%, transparent); color: var(--label-slate); }
.avatar.rose, .fe-av-lg.rose { background: color-mix(in srgb, var(--label-rose) 18%, transparent); color: var(--label-rose); }
.avatar.ink, .fe-av-lg.ink { background: color-mix(in srgb, var(--label-ink) 18%, transparent); color: var(--label-ink); }
.avatar.gold, .avatar.plum, .avatar.sea { border-radius: var(--r-sm); }
.entity-meta { min-width: 0; flex: 1; }
.entity-name { font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entity-role { font-size: var(--text-2xs); color: var(--ink-3); }
.entity-card .chev { color: var(--ink-4); flex: none; }

.add-entity {
  width: 100%; display: flex; align-items: center; gap: 7px;
  padding: 7px 9px; margin-top: 2px; border-radius: var(--r-sm);
  color: var(--ink-3); font-size: var(--text-xs); font-weight: var(--w-medium);
  transition: all var(--dur-fast);
}
.add-entity:hover { background: var(--parchment-deep); color: var(--ink-2); }

/* goal ring in inspector */
.goal-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s-4); display: flex; align-items: center; gap: var(--s-4);
}
.goal-ring { width: 64px; height: 64px; flex: none; position: relative; }
.goal-ring .pct { position: absolute; inset: 0; display: grid; place-items: center;
  font-size: var(--text-sm); font-weight: var(--w-bold); color: var(--ink); white-space: nowrap; }
.goal-info { min-width: 0; }
.goal-num { font-size: var(--text-lg); font-weight: var(--w-bold); color: var(--ink);
  font-variant-numeric: tabular-nums; }
.goal-num span { font-size: var(--text-xs); color: var(--ink-3); font-weight: var(--w-medium); }
.goal-desc { font-size: var(--text-2xs); color: var(--ink-3); margin-top: 2px; }

.empty-hint {
  font-size: var(--text-xs); color: var(--ink-4); font-style: italic;
  padding: 4px 8px;
}

/* ---- Overlays / scrim ---------------------------------------------------- */
.scrim {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(42, 33, 18, 0.34);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  animation: fade var(--dur) ease;
}
[data-theme="dark"] .scrim { background: rgba(0,0,0,0.55); }
@keyframes fade { from { background: rgba(42, 33, 18, 0); backdrop-filter: blur(0); } }
.sheet {
  background: var(--paper); border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg); border: 1px solid var(--parchment-edge);
  animation: pop var(--dur-slow) var(--ease-out);
  display: flex; flex-direction: column; max-height: 86%;
}
@keyframes pop { from { transform: translateY(12px) scale(0.985); } }
.sheet-head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line);
}
.sheet-title { font-size: var(--text-lg); font-weight: var(--w-bold); color: var(--ink); }
.sheet-title .ic { width: 18px; height: 18px; color: var(--accent); vertical-align: -3px; margin-right: 8px; }
.sheet-sub { font-size: var(--text-xs); color: var(--ink-3); margin-top: 1px; }
.sheet-x { margin-left: auto; }
.sheet-body { padding: var(--s-5); overflow-y: auto; flex: 1; min-height: 0; }
.sheet-foot { padding: var(--s-4) var(--s-5); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: var(--s-2); }

/* ---- Quick capture popover ---------------------------------------------- */
.qc-pop {
  position: absolute; top: calc(var(--titlebar-h) + 8px);
  right: 14px; width: 360px; z-index: 45;
  background: var(--paper); border: 1px solid var(--parchment-edge);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  animation: pop var(--dur) var(--ease-out); overflow: hidden;
}
.qc-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; }
.qc-head .ic { width: 16px; height: 16px; color: var(--accent); }
.qc-head .t { font-size: var(--text-sm); font-weight: var(--w-bold); color: var(--ink); white-space: nowrap; }
.qc-head .kbd { margin-left: auto; }
.qc-area {
  width: 100%; border: none; resize: none; outline: none; background: transparent;
  font-family: var(--font-prose); font-size: var(--text-md); line-height: 1.5; color: var(--ink);
  padding: 0 14px 12px; min-height: 84px;
}
.qc-area::placeholder { color: var(--ink-4); }
.qc-foot { display: flex; align-items: center; padding: 10px 12px; border-top: 1px solid var(--line-soft);
  background: var(--parchment); }
.qc-foot .hint { font-size: var(--text-2xs); color: var(--ink-3); }

.kbd {
  font-family: var(--font-ui); font-size: 10px; font-weight: var(--w-semi); white-space: nowrap;
  color: var(--ink-3); background: var(--parchment-deep); border: 1px solid var(--parchment-edge);
  border-radius: var(--r-xs); padding: 2px 6px; line-height: 1;
}

/* ---- Corkboard ----------------------------------------------------------- */
.plan-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.plan-wrap > .otl-top { margin: 0; padding: 13px 24px; border-bottom: 1px solid var(--line);
  background: var(--parchment); flex: none; }
.plan-body { flex: 1; min-height: 0; overflow-y: auto; background: var(--parchment-deep); padding: 22px 28px; }
.plan-body .otl-table { max-width: 1100px; margin: 0 auto; }
.corkboard { flex: 1; overflow-y: auto; background: var(--parchment-deep); }
.corkboard-inner { padding: var(--s-8) var(--s-10); max-width: 1100px; margin: 0 auto; }
.cork-chgroup { margin-bottom: var(--s-10); }
.cork-chtitle {
  font-size: var(--text-xs); font-weight: var(--w-bold); letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-3); margin-bottom: var(--s-4);
  display: flex; align-items: center; gap: 10px;
}
.cork-chtitle::after { content: ""; flex: 1; height: 1px; background: var(--parchment-edge); }
.cork-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s-5); }
.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-card); padding: var(--s-4);
  min-height: 158px; display: flex; flex-direction: column;
  cursor: grab; transition: transform var(--dur-fast), box-shadow var(--dur-fast);
  position: relative;
}
.card:hover { transform: translateY(-3px) rotate(-0.4deg); box-shadow: var(--shadow-md); }
.card .pin { position: absolute; top: -7px; left: 50%; transform: translateX(-50%);
  width: 12px; height: 12px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d98c6a, var(--accent));
  box-shadow: 0 2px 3px rgba(0,0,0,0.25); }
.card .card-status { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.card .card-status .dot { width: 7px; height: 7px; border-radius: 50%; }
.card .card-status .lbl { font-size: 10px; font-weight: var(--w-semi); letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--ink-3); }
.card .card-status .w { margin-left: auto; font-size: 10px; color: var(--ink-4); font-variant-numeric: tabular-nums; }
.card .card-title { font-family: var(--font-prose); font-size: var(--text-lg); font-weight: var(--w-semi);
  color: var(--ink); margin-bottom: 6px; line-height: 1.2; }
.card .card-syn { font-size: var(--text-xs); line-height: 1.5; color: var(--ink-2); flex: 1;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.card .card-foot { display: flex; gap: 5px; margin-top: 10px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: var(--w-semi); padding: 2px 7px; border-radius: var(--r-pill);
}
.chip.character { background: var(--character-tint); color: var(--character); }
.chip.location { background: var(--location-tint); color: var(--location); }

/* ---- Story bible --------------------------------------------------------- */
.bible-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }
.bible-col-title { font-size: var(--text-xs); font-weight: var(--w-bold); letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--ink-3); margin: 0 0 var(--s-3); display: flex; align-items: center; gap: 8px; }
.bible-entry {
  display: flex; gap: 12px; padding: var(--s-3); border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--paper); margin-bottom: var(--s-3);
  box-shadow: var(--shadow-card);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast), transform var(--dur-fast);
}
.bible-entry:hover { border-color: var(--parchment-edge); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.bible-entry .avatar { width: 38px; height: 38px; font-size: var(--text-md); }
.bible-entry .be-body { min-width: 0; flex: 1; }
.bible-entry .be-name { font-size: var(--text-md); font-weight: var(--w-bold); color: var(--ink); }
.bible-entry .be-role { font-size: var(--text-2xs); color: var(--accent-deep); font-weight: var(--w-semi);
  text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 5px; }
.bible-entry .be-notes { font-size: var(--text-xs); line-height: 1.5; color: var(--ink-2); }
.bible-entry .be-foot { margin-top: 7px; font-size: 10px; color: var(--ink-4);
  display: flex; align-items: center; gap: 5px; }

/* ---- Goals setup --------------------------------------------------------- */
.goal-type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.goal-type {
  text-align: left; padding: var(--s-3) var(--s-4); border-radius: var(--r-md);
  border: 1.5px solid var(--line); background: var(--paper); transition: all var(--dur-fast);
}
.goal-type:hover { border-color: var(--accent-ring); }
.goal-type.on { border-color: var(--accent); background: var(--accent-wash); }
.goal-type .gt-ic { width: 20px; height: 20px; color: var(--accent); margin-bottom: 8px; }
.goal-type .gt-name { font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--ink); }
.goal-type .gt-desc { font-size: var(--text-2xs); color: var(--ink-3); margin-top: 2px; line-height: 1.4; }

.toggle {
  width: 38px; height: 22px; border-radius: var(--r-pill); background: var(--parchment-edge);
  position: relative; transition: background var(--dur); flex: none;
}
.toggle.on { background: var(--accent); }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-xs); transition: transform var(--dur) var(--ease); }
.toggle.on::after { transform: translateX(16px); }

/* ---- Export -------------------------------------------------------------- */
.exp-row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; }
.exp-seg { display: flex; background: var(--parchment-deep); border-radius: var(--r-md); padding: 3px; gap: 2px; }
.exp-seg button { padding: 7px 14px; border-radius: var(--r-sm); font-size: var(--text-sm);
  font-weight: var(--w-medium); color: var(--ink-2); }
.exp-seg button.on { background: var(--paper); color: var(--ink); box-shadow: var(--shadow-xs); }
.fmt-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-3); margin-top: 6px; }
.fmt {
  display: flex; align-items: center; gap: 12px; padding: var(--s-3) var(--s-4);
  border: 1.5px solid var(--line); border-radius: var(--r-md); background: var(--paper);
  transition: all var(--dur-fast); text-align: left;
}
.fmt:hover { border-color: var(--accent-ring); }
.fmt.on { border-color: var(--accent); background: var(--accent-wash); }
.fmt .fmt-ic { width: 30px; height: 30px; border-radius: var(--r-sm); display: grid; place-items: center;
  background: var(--parchment-deep); color: var(--ink-2); flex: none; }
.fmt.on .fmt-ic { background: var(--accent); color: #fff; }
.fmt .fmt-name { font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--ink); }
.fmt .fmt-desc { font-size: var(--text-2xs); color: var(--ink-3); }

.field-label { font-size: var(--text-xs); font-weight: var(--w-semi); color: var(--ink-2); margin-bottom: 7px; display: block; }

/* ---- Goals: manager list ------------------------------------------------- */
.goal-master { display: flex; align-items: center; gap: 12px; padding: 4px 2px 16px; }
.gm-title { font-size: 14px; font-weight: var(--w-semi); color: var(--ink); }
.gm-sub { font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.goal-list-wrap { transition: opacity var(--dur); }
.goal-list-wrap.dim { opacity: 0.45; pointer-events: none; }
.goal-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.goal-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper);
  transition: border-color var(--dur-fast);
}
.goal-row:hover { border-color: var(--parchment-edge); }
.gr-ic { width: 32px; height: 32px; flex: none; border-radius: var(--r-sm); display: grid;
  place-items: center; background: var(--accent-wash); color: var(--accent); }
.gr-ic .ic { width: 17px; height: 17px; }
.gr-main { flex: 1; min-width: 0; }
.gr-name { font-size: 14px; font-weight: var(--w-semi); color: var(--ink); }
.gr-sum { font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.gr-acts { display: flex; gap: 2px; flex: none; }
.goal-add {
  margin-top: 10px; display: flex; align-items: center; justify-content: center; gap: 7px;
  width: 100%; padding: 9px 12px; border: 1.5px dashed var(--parchment-edge); border-radius: var(--r-md);
  color: var(--ink-2); font-size: 13px; font-weight: var(--w-semi); transition: all var(--dur-fast);
}
.goal-add:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-wash); }
.goal-empty { display: flex; align-items: center; gap: 10px; padding: 16px 18px; margin-top: 8px;
  border-radius: var(--r-md); background: var(--parchment); color: var(--ink-3); font-size: 13px; }

/* row mini-indicators */
.grm-amount { display: flex; align-items: center; gap: 8px; flex: none; }
.grm-bar { width: 54px; height: 6px; border-radius: 3px; background: var(--parchment-deep); overflow: hidden; }
.grm-fill { height: 100%; border-radius: 3px; background: var(--accent); }
.grm-pct { font-size: 11px; font-weight: var(--w-semi); color: var(--ink-2);
  font-variant-numeric: tabular-nums; width: 30px; text-align: right; }
.grm-pill { font-size: 11px; font-weight: var(--w-semi); padding: 3px 9px; border-radius: var(--r-pill); flex: none; }
.grm-pill.ontrack { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.grm-pill.behind { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.grm-streak { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: var(--w-bold);
  color: var(--accent); flex: none; font-variant-numeric: tabular-nums; }

/* ---- Goals: adaptive editor --------------------------------------------- */
.goal-target { margin-top: 18px; }
.gt-row { display: flex; gap: 16px; align-items: flex-start; }
.gt-seg { width: 100%; }
.gt-seg button { flex: 1; text-align: center; }
.gt-datepick { border: 1.5px solid var(--line); border-radius: var(--r-md); background: var(--paper); padding: 10px 12px 12px; }
.gt-date-display { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: var(--w-semi);
  color: var(--ink); padding-bottom: 9px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.gt-pace-hint { margin-top: 14px; display: flex; align-items: center; gap: 9px; padding: 11px 13px;
  border-radius: var(--r-md); background: var(--accent-wash); font-size: 12.5px; color: var(--ink-2); line-height: 1.4; }
.gt-pace-hint b { color: var(--ink); }

/* stepper */
.stepper { display: flex; align-items: center; height: 40px; overflow: hidden;
  border: 1.5px solid var(--line); border-radius: var(--r-md); background: var(--paper); }
.st-btn { width: 38px; align-self: stretch; display: grid; place-items: center; color: var(--ink-3);
  transition: background var(--dur-fast), color var(--dur-fast); }
.st-btn:hover { background: var(--parchment-deep); color: var(--ink); }
.st-input { flex: 1; min-width: 0; width: 100%; text-align: center; font-size: 15px; font-weight: var(--w-semi);
  color: var(--ink); background: transparent; border: none; outline: none; font-variant-numeric: tabular-nums; }
.st-suffix { font-size: 12px; color: var(--ink-3); padding-right: 12px; white-space: nowrap; }

/* calendar */
.cal { user-select: none; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-size: 13px; font-weight: var(--w-semi); color: var(--ink); }
.cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; }
.cal-dow span { text-align: center; font-size: 10px; font-weight: var(--w-semi); color: var(--ink-4); text-transform: uppercase; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-empty { height: 30px; }
.cal-day { height: 30px; display: grid; place-items: center; border-radius: var(--r-sm);
  font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; transition: background var(--dur-fast), color var(--dur-fast); }
.cal-day:hover:not(:disabled) { background: var(--parchment-deep); color: var(--ink); }
.cal-day:disabled { color: var(--ink-4); opacity: 0.4; cursor: default; }
.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--accent-ring); color: var(--ink); }
.cal-day.sel, .cal-day.sel:hover { background: var(--accent); color: #fff; font-weight: var(--w-bold); }

/* streak qualifier options */
.streak-opts { display: flex; flex-direction: column; gap: 8px; }
.streak-opt { display: flex; align-items: flex-start; gap: 11px; padding: 11px 13px; text-align: left;
  border: 1.5px solid var(--line); border-radius: var(--r-md); background: var(--paper); transition: all var(--dur-fast); }
.streak-opt:hover:not(:disabled) { border-color: var(--accent-ring); }
.streak-opt.on { border-color: var(--accent); background: var(--accent-wash); }
.streak-opt:disabled { opacity: 0.5; cursor: default; }
.so-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--parchment-edge);
  flex: none; margin-top: 2px; transition: all var(--dur-fast); }
.streak-opt.on .so-dot { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px var(--paper); }
.so-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.so-title { font-size: 13.5px; font-weight: var(--w-semi); color: var(--ink); }
.so-desc { font-size: 12px; color: var(--ink-3); }

/* ---- Goals: inspector visualizations ------------------------------------ */
.goal-card + .goal-card { margin-top: 8px; }
.goal-card--deadline { display: block; }
.gd-label { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: var(--w-semi);
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-3); margin-bottom: 11px; }

/* pace bar */
.pace { width: 100%; }
.pace-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.pace-days { font-size: 12px; color: var(--ink-2); }
.pace-days b { font-size: 18px; font-weight: var(--w-bold); color: var(--ink); font-variant-numeric: tabular-nums; margin-right: 3px; }
.pace-status { font-size: 11px; font-weight: var(--w-semi); padding: 3px 9px; border-radius: var(--r-pill); }
.pace-status.ontrack { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.pace-status.behind { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pace-track { position: relative; height: 8px; border-radius: 4px; background: var(--parchment-deep); }
.pace-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--accent); }
.pace-notch { position: absolute; top: -3px; bottom: -3px; width: 2px; border-radius: 1px;
  background: var(--ink-2); transform: translateX(-1px); }
.pace-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 9px;
  font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.pace-rate b { color: var(--ink-2); }

/* streak viz */
.streak-flame { position: relative; width: 56px; height: 56px; flex: none; display: grid; place-items: center; }
.streak-flame .ic { width: 50px; height: 50px; color: var(--accent); fill: color-mix(in srgb, var(--accent) 18%, transparent); }
.sf-num { position: absolute; top: 58%; left: 50%; transform: translate(-50%, -50%);
  font-size: 16px; font-weight: var(--w-bold); color: var(--accent-deep); font-variant-numeric: tabular-nums; }
.streak-dots { display: flex; gap: 5px; margin-bottom: 6px; }
.streak-dots .sd { width: 11px; height: 11px; border-radius: 50%; background: var(--parchment-deep);
  box-shadow: inset 0 0 0 1px var(--parchment-edge); }
.streak-dots .sd.on { background: var(--accent); box-shadow: none; }

/* ---- Focus mode hint ----------------------------------------------------- */
.focus-exit {
  position: absolute; top: 14px; right: 16px; z-index: 30;
  display: flex; align-items: center; gap: 8px; opacity: 0; transition: opacity var(--dur);
}
.center:hover .focus-exit { opacity: 1; }

/* ---- Misc ---------------------------------------------------------------- */
.divider { height: 1px; background: var(--line); margin: var(--s-4) 0; }

/* ---- Context menu -------------------------------------------------------- */
.cm-backdrop { position: fixed; inset: 0; z-index: 60; }
.cm {
  position: fixed; z-index: 61; min-width: 184px;
  background: var(--paper); border: 1px solid var(--parchment-edge);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  padding: 5px; animation: cm-in 110ms var(--ease-out);
}
@keyframes cm-in { from { transform: scale(0.97) translateY(-3px); } }
.cm-item {
  display: flex; align-items: center; gap: 10px; width: 100%; white-space: nowrap;
  padding: 7px 10px; border-radius: var(--r-sm); text-align: left;
  font-size: var(--text-sm); color: var(--ink-2); font-weight: var(--w-medium);
  position: relative; transition: background var(--dur-fast), color var(--dur-fast);
}
.cm-item:hover { background: var(--parchment-deep); color: var(--ink); }
.cm-item .ic { width: 15px; height: 15px; color: var(--ink-3); flex: none; }
.cm-item:hover .ic { color: var(--ink-2); }
.cm-item.danger { color: var(--danger); }
.cm-item.danger .ic { color: var(--danger); }
.cm-item.danger:hover { background: rgba(168, 68, 47, 0.10); color: var(--danger); }
.cm-item .chev { margin-left: auto; color: var(--ink-4); }
.cm-item .right { margin-left: auto; font-size: var(--text-2xs); color: var(--ink-4); }
.cm-item .swatch { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.cm-item .tick { margin-left: auto; color: var(--accent); }
.cm-sep { height: 1px; background: var(--line); margin: 5px 6px; }
.cm-label { padding: 6px 10px 4px; font-size: var(--text-2xs); font-weight: var(--w-bold);
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-4); }
.cm-sub { position: absolute; top: -5px; left: 100%; }

/* ---- Inline rename input ------------------------------------------------- */
.rename-input {
  font-family: inherit; font-size: var(--text-sm); font-weight: var(--w-semi);
  color: var(--ink); background: var(--paper); border: 1.5px solid var(--accent);
  border-radius: var(--r-xs); padding: 2px 6px; outline: none; width: 100%;
  box-shadow: 0 0 0 3px var(--accent-wash);
}

/* ---- Toast --------------------------------------------------------------- */
.toast-wrap { position: absolute; bottom: calc(var(--statusbar-h) + 14px); left: 50%;
  transform: translateX(-50%); z-index: 55; }
.toast {
  display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: var(--paper);
  border-radius: var(--r-md); padding: 10px 12px 10px 16px;
  box-shadow: var(--shadow-lg); font-size: var(--text-sm); font-weight: var(--w-medium);
  animation: toast-in var(--dur) var(--ease-out);
}
[data-theme="dark"] .toast { background: var(--parchment-deep); color: var(--ink); border: 1px solid var(--parchment-edge); }
@keyframes toast-in { from { transform: translateY(10px); } }
.toast .undo {
  font-weight: var(--w-bold); color: var(--accent); padding: 4px 8px; border-radius: var(--r-xs);
}
[data-theme="dark"] .toast .undo { color: var(--accent-deep); }
.toast .undo:hover { background: rgba(255,255,255,0.12); }
[data-theme="dark"] .toast .undo:hover { background: var(--parchment); }
.toast .tx { background: rgba(255,255,255,0.10); width: 24px; height: 24px; border-radius: var(--r-xs);
  display: grid; place-items: center; color: rgba(255,255,255,0.7); }
[data-theme="dark"] .toast .tx { background: var(--parchment); color: var(--ink-3); }

/* ---- Project dropdown ---------------------------------------------------- */
.proj-menu {
  position: absolute; top: 100%; left: var(--s-3); right: var(--s-3); z-index: 50;
  margin-top: 4px; background: var(--paper); border: 1px solid var(--parchment-edge);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg); padding: 5px;
  animation: cm-in 110ms var(--ease-out);
}
.proj-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px;
  border-radius: var(--r-sm); text-align: left; transition: background var(--dur-fast);
}
.proj-item:hover { background: var(--parchment-deep); }
.proj-item.on { background: var(--accent-wash); }
.proj-item .pc { width: 24px; height: 30px; border-radius: 3px; flex: none;
  background: linear-gradient(150deg, var(--accent), var(--accent-deep));
  box-shadow: inset 2px 0 0 rgba(255,255,255,0.18); }
.proj-item .pm { flex: 1; min-width: 0; }
.proj-item .pt { font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--ink); }
.proj-item .ps { font-size: var(--text-2xs); color: var(--ink-3); }
.proj-item .tick { color: var(--accent); flex: none; }
.proj-new { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px;
  border-radius: var(--r-sm); color: var(--ink-2); font-size: var(--text-sm); font-weight: var(--w-medium); }
.proj-new:hover { background: var(--parchment-deep); color: var(--ink); }
.proj-new .ic { width: 15px; height: 15px; color: var(--ink-3); }

/* ---- Final / done status accent ------------------------------------------ */
.scene-check { width: 13px; height: 13px; color: var(--good); flex: none; }

/* ---- Status glyphs (small symbols standing in for status, replacing dots) -- */
.status-glyph { display: inline-flex; align-items: center; justify-content: center; flex: none; }
.status-glyph.clickable { cursor: pointer; }

/* status dot is clickable to change status */
.scene-dot, .card .card-status .dot { cursor: pointer; }

/* ============================================================================
   Page-flip leaf — a turning paper page on scene switch (JS-mounted in .center).
   "fwd" turns right-to-left (hinge left); "back" turns left-to-right (hinge right).
   ========================================================================== */
.page-turn-layer {
  position: absolute; inset: 0; z-index: 9; pointer-events: none;
  perspective: 1700px; perspective-origin: 50% 50%; overflow: hidden;
}

.page-leaf {
  position: absolute; inset: 0; transform-origin: left center;
  transform-style: preserve-3d; will-change: transform;
  animation: leaf-fwd 1170ms cubic-bezier(.4, 0, .2, 1) forwards;
  box-shadow: 0 14px 44px rgba(40, 30, 15, 0.22);
}
.page-turn-layer.back .page-leaf { transform-origin: right center; animation-name: leaf-back; }

.page-leaf .face { position: absolute; inset: 0; backface-visibility: hidden; overflow: hidden; }
.page-leaf .front { background: var(--paper); }
.page-leaf .back { transform: rotateY(180deg); background: var(--parchment); }

.leaf-page { max-width: var(--prose-measure); margin: 0 auto; padding: var(--s-12) var(--s-8); height: 100%; box-sizing: border-box; }
/* curl shading: shadow at the hinge, a sheen and a darkening fold toward the free edge */
.leaf-shade { position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(to right, rgba(40, 30, 15, 0.20) 0%, rgba(40, 30, 15, 0) 20%),
    linear-gradient(to right, rgba(255,255,255,0) 60%, rgba(255,255,255,0.22) 84%, rgba(40, 30, 15, 0.16) 100%); }
.page-turn-layer.back .leaf-shade {
  background:
    linear-gradient(to left, rgba(40, 30, 15, 0.20) 0%, rgba(40, 30, 15, 0) 20%),
    linear-gradient(to left, rgba(255,255,255,0) 60%, rgba(255,255,255,0.22) 84%, rgba(40, 30, 15, 0.16) 100%); }

@keyframes leaf-fwd {
  0%   { transform: translateX(0) rotateY(0deg); }
  100% { transform: translateX(-104%) rotateY(-26deg); }
}
@keyframes leaf-back {
  0%   { transform: translateX(0) rotateY(0deg); }
  100% { transform: translateX(104%) rotateY(26deg); }
}

/* soft cast shadow on the page beneath, fading as the leaf lifts away */
.page-turn-cast {
  position: absolute; inset: 0;
  background: linear-gradient(to right, rgba(40, 30, 15, 0.18), rgba(40, 30, 15, 0) 52%);
  animation: cast-fade 1170ms ease-out forwards;
}
.page-turn-layer.back .page-turn-cast { background: linear-gradient(to left, rgba(40, 30, 15, 0.18), rgba(40, 30, 15, 0) 52%); }
@keyframes cast-fade { 0% { opacity: 0.85; } 100% { opacity: 0; } }

/* ============================================================================
   Motion — "paper settling". Elegant + restrained. Enabled only when the app
   carries .anim AND the user hasn't asked for reduced motion. "from" states are
   only partly transparent so content can never get stuck invisible.
   ========================================================================== */
.view-stage { flex: 1; min-height: 0; display: flex; flex-direction: column; }

@keyframes page-in {
  from { opacity: 0.4; transform: translateY(6px); }
  to   { opacity: 1;   transform: none; }
}
@keyframes view-in {
  from { opacity: 0.4; transform: translateY(8px) scale(0.992); }
  to   { opacity: 1;   transform: none; }
}
@keyframes rise {
  from { opacity: 0.3; transform: translateY(12px); }
  to   { opacity: 1;   transform: none; }
}
@keyframes settle {
  from { opacity: 0.3; transform: translateY(6px); }
  to   { opacity: 1;   transform: none; }
}

@media (prefers-reduced-motion: no-preference) {
  /* the new page is rendered solid beneath the turning leaf — no entrance fade (avoids the "pop") */
  .anim .canvas-wrap { will-change: transform; }
  /* quiet cross-fade between Write / Corkboard / Story bible */
  .anim .view-stage { animation: view-in 440ms var(--ease-out); }

  /* staggered rise for corkboard cards & bible entries (delay set inline by index) */
  .anim .cork-grid .card { animation: rise 440ms var(--ease-out) both; }
  .anim .bible-entry { animation: rise 440ms var(--ease-out) both; }

  /* inspector groups settle in */
  .anim .insp-group { animation: settle 420ms var(--ease-out) both; }
  .anim .insp-group:nth-child(2) { animation-delay: 50ms; }
  .anim .insp-group:nth-child(3) { animation-delay: 100ms; }
  .anim .insp-group:nth-child(4) { animation-delay: 150ms; }

  /* binder row hover drift + active accent bar growing in */
  .anim .scene-row { transition: background var(--dur-fast), transform var(--dur-fast); }
  .anim .scene-row:hover { transform: translateX(2px); }
  .anim .scene-row.active::before { animation: bar-in 260ms var(--ease-out); }
  @keyframes bar-in { from { transform: scaleY(0.2); opacity: 0; } to { transform: scaleY(1); opacity: 1; } }

  /* chapter twist + dialog/menu already animate; add gentle card hover easing */
  .anim .card { transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out); }
}

/* ---- Settings modal ------------------------------------------------------ */
.set-sheet { width: 760px; max-width: 92%; height: 560px; max-height: 86%; flex-direction: row; overflow: hidden; }
.set-nav { width: 208px; flex: none; background: var(--parchment); border-right: 1px solid var(--line);
  padding: var(--s-3); display: flex; flex-direction: column; gap: 2px; }
.set-nav-title { display: flex; align-items: center; gap: 8px; font-size: var(--text-sm); font-weight: var(--w-bold);
  color: var(--ink); padding: 8px 10px 12px; }
.set-nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: var(--r-md);
  font-size: var(--text-sm); font-weight: var(--w-medium); color: var(--ink-2); text-align: left;
  transition: background var(--dur-fast), color var(--dur-fast); }
.set-nav-item .ic { width: 16px; height: 16px; color: var(--ink-3); }
.set-nav-item:hover { background: var(--parchment-deep); color: var(--ink); }
.set-nav-item.on { background: var(--accent-tint); color: var(--accent-deep); }
.set-nav-item.on .ic { color: var(--accent); }

.set-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.set-main-head { display: flex; align-items: center; justify-content: space-between; white-space: nowrap;
  padding: var(--s-4) var(--s-4) var(--s-4) var(--s-5); border-bottom: 1px solid var(--line);
  font-size: var(--text-lg); font-weight: var(--w-bold); color: var(--ink); }
.set-main-body { flex: 1; overflow-y: auto; padding: var(--s-2) var(--s-5) var(--s-5); }
.set-main-body::-webkit-scrollbar { width: 9px; }
.set-main-body::-webkit-scrollbar-thumb { background: var(--parchment-edge); border-radius: 9px; border: 2px solid var(--paper); }

.set-row { display: flex; align-items: center; gap: var(--s-4); padding: 15px 0; border-bottom: 1px solid var(--line-soft); }
.set-row-l { flex: 1; min-width: 0; }
.set-row-label { font-size: var(--text-sm); font-weight: var(--w-semi); color: var(--ink); }
.set-row-desc { font-size: var(--text-2xs); color: var(--ink-3); margin-top: 2px; line-height: 1.4; }
.set-row-c { flex: none; display: flex; align-items: center; }

.set-seg { display: inline-flex; background: var(--parchment-deep); border-radius: var(--r-md); padding: 3px; gap: 2px; }
.set-seg button { padding: 6px 12px; border-radius: var(--r-sm); font-size: var(--text-xs); font-weight: var(--w-medium);
  color: var(--ink-2); white-space: nowrap; transition: background var(--dur-fast), color var(--dur-fast); }
.set-seg button.on { background: var(--paper); color: var(--ink); box-shadow: var(--shadow-xs); }

.set-select { font-family: inherit; font-size: var(--text-sm); font-weight: var(--w-medium); color: var(--ink);
  background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--r-md); padding: 7px 30px 7px 11px;
  cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8071' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.set-select:hover { border-color: var(--parchment-edge); }

.set-range { width: 150px; accent-color: var(--accent); }

.set-swatches { display: flex; gap: 8px; }.set-swatch { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  box-shadow: var(--shadow-xs); border: 2px solid transparent; transition: transform var(--dur-fast); }
.set-swatch:hover { transform: scale(1.08); }
.set-swatch.on { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--accent-ring); }

.set-typechips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 280px; }
.set-typechip { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-2xs);
  font-weight: var(--w-semi); padding: 5px 10px; border-radius: var(--r-pill);
  border: 1px solid var(--parchment-edge); color: var(--ink-3); background: var(--paper);
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast); }
.set-typechip.on { color: var(--accent-deep); border-color: var(--accent-ring); background: var(--accent-wash); }
.set-typechip.dis { color: var(--ink-4); border-style: dashed; cursor: default; opacity: 0.7; }

.set-bordered { border: 1.5px solid var(--line); }
.set-bordered:hover { border-color: var(--accent-ring); background: var(--accent-wash); }

.set-backup-status { display: flex; align-items: center; gap: 12px; padding: 14px; margin: 14px 0 4px;
  background: var(--parchment); border: 1px solid var(--line); border-radius: var(--r-lg); }

.set-path { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: var(--text-xs);
  color: var(--ink-2); background: var(--parchment-deep); border-radius: var(--r-sm); padding: 6px 6px 6px 10px; }
.set-path button { font-family: var(--font-ui); font-size: var(--text-2xs); font-weight: var(--w-semi);
  color: var(--accent-deep); background: var(--paper); border-radius: var(--r-xs); padding: 4px 9px; }
.set-path button:hover { background: var(--accent-wash); }

.set-about { padding-top: 8px; }
.set-about-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.set-app-mark { width: 52px; height: 52px; border-radius: var(--r-lg); display: grid; place-items: center;
  background: linear-gradient(150deg, var(--accent), var(--accent-deep)); color: #fff; box-shadow: var(--shadow-sm); }
.set-app-name { font-family: var(--font-prose); font-size: var(--text-2xl); font-weight: var(--w-semi); color: var(--ink); }
.set-app-ver { font-size: var(--text-xs); color: var(--ink-3); margin-top: 2px; }
.set-about-blurb { font-family: var(--font-prose); font-size: var(--text-md); line-height: 1.6; color: var(--ink-2);
  margin: 0 0 22px; max-width: 46ch; }
.set-sub { font-size: var(--text-2xs); font-weight: var(--w-bold); letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 10px; }
.set-keys { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; }
.set-key-row { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: var(--text-sm); color: var(--ink-2); }

@media (max-width: 640px) {
  .set-sheet { flex-direction: column; height: 88%; }
  .set-nav { width: auto; flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .set-nav-title { display: none; }
}
