/* Chapter Map — Beat Editor. Built on Premise tokens.css.
   Layout A (act columns), drag/drop scaffolded (Phase 2B), flags, Records tab.
   .be-* renamed to .cm-* per RECONCILIATION §3. Layout B dropped §2. Lock removed §7. */

/* ============================================================
   APP SHELL
   ============================================================ */
.cm-main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  height: 100%;
  overflow: hidden;
}

.cm-topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  flex: none;
}
.cm-crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-3); }
.cm-crumbs .sep { color: var(--ink-5); }
.cm-crumbs .here { color: var(--ink); font-weight: 500; }
.cm-savestate {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11.5px; color: var(--ink-4); font-family: var(--mono); letter-spacing: 0.02em;
}
.cm-savestate .dot { width: 7px; height: 7px; border-radius: 999px; background: var(--ok); }
.cm-topbar-right { display: flex; align-items: center; gap: 14px; }
.cm-edited { font-size: 11px; color: var(--ink-5); font-family: var(--mono); letter-spacing: 0.02em; }

/* ── §3 Sub-header: tabs + stats + flags ── */
.cm-subhead {
  display: flex; align-items: center; gap: 18px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--paper);
  flex: none;
}
.cm-tabs { display: inline-flex; gap: 2px; }
.cm-tab {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 16px;
  border: none; background: transparent;
  border-radius: 7px;
  font-family: var(--serif); font-size: 15px; font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink-4); cursor: pointer;
}
.cm-tab:hover { color: var(--ink-2); background: var(--paper-2); }
.cm-tab.active { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.cm-tab .tab-count {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  color: var(--ink-4);
  background: var(--paper-2); border: 1px solid var(--line-soft);
  border-radius: 999px; padding: 1px 7px;
}
.cm-tab.active .tab-count { color: var(--ink-2); }

.cm-subhead .spacer { flex: 1; }

.cm-headstats { display: flex; align-items: center; gap: 18px; }
.cm-headstat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.cm-headstat .v { font-family: var(--serif); font-size: 18px; font-weight: 600; letter-spacing: -0.01em; color: var(--ink); }
.cm-headstat .l { font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-4); font-weight: 600; margin-top: 2px; }

/* §6 Flags badge button */
.cm-flagbtn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 12px 0 11px;
  border-radius: 7px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer;
  font-size: 12.5px; font-weight: 500; color: var(--ink-2);
}
.cm-flagbtn:hover { background: var(--paper-2); }
.cm-flagbtn .fdot { width: 8px; height: 8px; border-radius: 999px; background: #C7873A; }
.cm-flagbtn .fcount {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  background: #F3E3CB; color: #9A5B25; border-radius: 999px; padding: 1px 7px;
}
.cm-flagbtn.none .fdot { background: var(--ok); }
.cm-flagbtn.none .fcount { background: var(--surface); color: var(--ink-4); border: 1px solid var(--line-soft); }

/* ── §3 Legend strip ── */
.cm-legend {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  padding: 10px 24px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--paper);
  flex: none;
}
.cm-legend:empty { display: none; }
/* Desktop: the chips wrap as a GROUP onto as many lines as needed, each thread
   name kept on one line — so long names read as one phrase instead of breaking
   mid-word (the old forced single-row crammed them). */
.cm-legend-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  row-gap: 8px;
  column-gap: 14px;
  overflow: visible;
  min-width: 0;
}
.cm-legend-label { font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-4); font-weight: 600; white-space: nowrap; flex: 0 0 auto; }
.cm-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-2); white-space: nowrap; flex: 0 0 auto; }
.cm-legend-sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.cm-legend-sw.thread { width: 4px; height: 14px; border-radius: 2px; }

/* ============================================================
   BOARD (scroll region)
   ============================================================ */
.cm-board { flex: 1; min-height: 0; overflow-x: auto; overflow-y: hidden; background: var(--paper); }

/* ── §2 Layout A · act columns ── */
.cm-acts-cols {
  display: grid;
  grid-template-columns: repeat(3, minmax(320px, 1fr));
  gap: 18px;
  padding: 22px 24px 0;
  align-items: stretch;
  height: 100%;
  min-height: 0;
}

.cm-actcol {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--rad-lg);
  display: flex;
  flex-direction: column;
  max-height: 100%;
  overflow: hidden;
  min-width: 0;
}

.cm-actcol-head {
  position: sticky; top: 0; z-index: 3;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  border-radius: var(--rad-lg) var(--rad-lg) 0 0;
}
.cm-actcol-roman {
  font-family: var(--serif); font-style: italic; font-size: 26px; font-weight: 500;
  color: var(--violet); line-height: 1; width: 38px; text-align: center;
}
.cm-actcol-meta { min-width: 0; }
.cm-actcol-meta .eyebrow { font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-4); font-weight: 600; }
.cm-actcol-meta .name { font-family: var(--serif); font-size: 18px; font-weight: 600; letter-spacing: -0.012em; color: var(--ink); }
.cm-actcol-meta .sub { font-size: 11px; color: var(--ink-4); margin-top: 2px; display: flex; gap: 7px; align-items: center; }
.cm-actcol-meta .sub .dotsep { color: var(--ink-5); }

.cm-actcol-body {
  padding: 12px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.cm-actcol-body::-webkit-scrollbar { display: none; }

/* §7 Generate button (replaces lock button — lock concept removed) */
.cm-genbtn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 12px;
  border-radius: 7px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2);
  font-size: 12px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.cm-genbtn:hover:not(:disabled) { background: var(--paper-2); border-color: var(--ink-3); }
.cm-genbtn:disabled { opacity: 0.6; cursor: default; }
.cm-genbtn svg { width: 13px; height: 13px; }

/* §7 Generating shimmer */
.cm-genbar { height: 3px; border-radius: 2px; background: var(--violet-soft); overflow: hidden; }
.cm-genbar > span { display: block; height: 100%; width: 40%; background: var(--violet); border-radius: 2px; animation: cm-slide 1s ease-in-out infinite; }
@keyframes cm-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(280%); } }

/* ============================================================
   §3 CHAPTER CARD
   ============================================================ */
.cm-ch {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  overflow: hidden;
}
.cm-ch.flagged { border-color: #E4C58E; }
.cm-ch.drop-target { border-color: var(--violet); box-shadow: 0 0 0 2px var(--violet-soft); }
.cm-ch.dragging-src { opacity: 0.6; }
.cm-beat.dragging-src {
  opacity: 0;
}

.cm-ch-head {
  display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 10px;
  padding: 11px 13px 9px;
}
.cm-ch-num {
  font-family: var(--mono); font-size: 11px; font-weight: 600; color: var(--ink-4);
  background: var(--paper-2); border: 1px solid var(--line-soft);
  border-radius: 5px; padding: 3px 7px; letter-spacing: 0.02em; white-space: nowrap;
  line-height: 1.3;
}
.cm-ch-titlewrap { min-width: 0; }
.cm-ch-title {
  font-family: var(--serif); font-size: 16px; font-weight: 600; letter-spacing: -0.012em;
  color: var(--ink); line-height: 1.2; outline: none; border-radius: 3px;
  text-wrap: pretty;
}
/* contenteditable=true wired in Phase 2B */
.cm-ch-title:focus { background: var(--violet-soft); box-shadow: 0 0 0 2px var(--violet-soft); }
.cm-ch-sub { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 5px; }
.cm-pov {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 600; color: var(--ink-2);
  background: var(--paper-2); border: 1px solid var(--line-soft);
  border-radius: 999px; padding: 2px 8px 2px 6px;
}
.cm-pov svg { width: 10px; height: 10px; opacity: 0.7; }
.cm-role {
  font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 600;
  color: var(--ink-4);
}
.cm-anchor {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--serif); font-style: italic; font-size: 12px; color: var(--ink-3);
}
.cm-anchor svg { width: 11px; height: 11px; opacity: 0.6; }

.cm-ch-grip { color: var(--ink-5); cursor: grab; padding-top: 2px; }
.cm-ch-grip svg { width: 14px; height: 14px; }

/* §6 Flag marker on chapter card */
.cm-ch-flag {
  display: flex; align-items: center; gap: 8px;
  margin: 0 13px 10px;
  padding: 7px 10px;
  background: #FBF3E3; border: 1px solid #EBD7AE; border-radius: 6px;
  cursor: pointer;
}
.cm-ch-flag:hover { background: #F8EDD6; }
.cm-ch-flag .ic { width: 14px; height: 14px; color: #C7873A; flex: none; }
.cm-ch-flag .ftext { font-size: 11.5px; color: #8A5E22; font-weight: 500; flex: 1; min-width: 0; }
.cm-ch-flag .gate { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.06em; color: #A9712C; text-transform: uppercase; }
.cm-ch-flag .chev { width: 13px; height: 13px; color: #C7873A; transition: transform 0.12s; }
.cm-ch-flag.open .chev { transform: rotate(180deg); }

.cm-flag-detail { margin: -4px 13px 10px; padding: 11px 13px; background: #FCF7EC; border: 1px solid #EBD7AE; border-radius: 6px; }
.cm-flag-detail .reason { font-family: var(--serif); font-size: 13px; line-height: 1.5; color: var(--ink-2); text-wrap: pretty; }
.cm-flag-detail .suggestion { font-size: 12px; color: #8A5E22; margin-top: 7px; display: flex; gap: 6px; }
.cm-flag-detail .suggestion .lbl { font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700; padding-top: 2px; }
.cm-flag-detail .note { font-style: italic; font-family: var(--serif); font-size: 12px; color: var(--ink-4); margin-top: 6px; }
.cm-flag-actions { display: flex; gap: 8px; margin-top: 11px; flex-wrap: wrap; }
.cm-flag-actions button {
  height: 28px; padding: 0 11px; border-radius: 6px; font-size: 12px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
}
.cm-flag-actions button:disabled { opacity: 0.5; cursor: default; }
.cm-flag-actions button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.cm-flag-dismiss-row { margin-top: 10px; display: none; gap: 8px; }
.cm-flag-dismiss-row.show { display: flex; }
.cm-flag-dismiss-row input {
  flex: 1; height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 0 10px;
  font-family: var(--sans); font-size: 12.5px; color: var(--ink); background: var(--surface);
}
.cm-flag-dismiss-row input:focus { outline: none; border-color: var(--violet); }
.cm-flag-resolved { display: flex; align-items: center; gap: 7px; margin: 0 13px 11px; font-size: 12px; color: var(--ok); }
.cm-flag-resolved svg { width: 13px; height: 13px; }

/* ============================================================
   §3 BEAT LIST + BEAT CHIP
   ============================================================ */
.cm-beats {
  display: flex; flex-direction: column; gap: 7px;
  padding: 4px 11px 12px;
  min-height: 44px;
}
.cm-beats.dropzone-active { background: var(--violet-soft); border-radius: 6px; outline: 1px dashed var(--violet); }
.cm-beats-empty {
  font-family: var(--serif); font-style: italic; font-size: 12.5px; color: var(--ink-4);
  text-align: center; padding: 12px 0; border: 1px dashed var(--line); border-radius: 6px;
}

.cm-beat {
  position: relative;
  display: grid; grid-template-columns: 4px 1fr auto; gap: 9px; align-items: start;
  padding: 9px 10px 9px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  /* draggable cursor wired in Phase 2B */
  transition: box-shadow 0.1s, border-color 0.1s;
}
.cm-beat:hover { border-color: var(--line-2); box-shadow: 0 1px 4px rgba(0,0,0,0.04); }
.cm-beat .thread-rail { width: 4px; align-self: stretch; border-radius: 6px 0 0 6px; background: var(--ink-4); }
.cm-beat-body { min-width: 0; }
.cm-beat-summary { font-family: var(--serif); font-size: 13px; line-height: 1.42; color: var(--ink); text-wrap: pretty; }
.cm-beat-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.cm-event {
  font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700;
  border-radius: 4px; padding: 2px 6px;
  background: var(--paper-2); color: var(--ink-3); border: 1px solid var(--line-soft);
}
.cm-thread-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--ink-3); font-weight: 500; }
.cm-thread-tag .sw { width: 7px; height: 7px; border-radius: 999px; }
.cm-beat-chars { font-size: 10px; color: var(--ink-4); font-family: var(--mono); letter-spacing: 0.02em; }
.cm-beat-pos { font-family: var(--mono); font-size: 9.5px; color: var(--ink-5); padding: 2px 4px; }

/* §3 cross-act marker (renders when beat.homeAct ≠ chapter act — §9) */
.cm-crossact {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 700;
  color: var(--violet-deep); background: var(--violet-soft); border: 1px solid #D8CEF4;
  border-radius: 4px; padding: 2px 6px;
}
.cm-crossact svg { width: 9px; height: 9px; }

/* §3 drop placeholder line (drag/drop Phase 2B) */
.cm-drop-line { height: 2px; background: var(--violet); border-radius: 2px; margin: 0 2px; box-shadow: 0 0 0 2px var(--violet-soft); }

/* ============================================================
   §6 FLAGS QUEUE (slide-over)
   ============================================================ */
.cm-queue-scrim { position: fixed; inset: 0; background: rgba(27,27,26,0.18); z-index: 40; display: none; }
.cm-queue-scrim.show { display: block; }
.cm-queue {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px; z-index: 41;
  background: var(--paper); border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px -16px rgba(0,0,0,0.25);
  display: flex; flex-direction: column; transform: translateX(100%); transition: transform 0.22s ease;
}
.cm-queue.show { transform: translateX(0); }
.cm-queue-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.cm-queue-head h3 { font-family: var(--serif); font-size: 18px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.cm-queue-head .x { width: 30px; height: 30px; display: grid; place-items: center; border: none; background: transparent; border-radius: 6px; cursor: pointer; color: var(--ink-3); }
.cm-queue-head .x:hover { background: var(--paper-2); }
.cm-queue-body { flex: 1; overflow: auto; padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.cm-queue-item { border: 1px solid #EBD7AE; background: #FCF7EC; border-radius: var(--rad); padding: 13px 14px; cursor: default; }
.cm-queue-item.info { opacity: 0.58; }
.cm-queue-item.resolved { border-color: var(--line); background: var(--surface); opacity: 0.7; }
.cm-queue-item .qhead { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.cm-queue-item .qnum { font-family: var(--mono); font-size: 10px; color: var(--ink-4); }
.cm-queue-item .qgate { font-family: var(--mono); font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700; color: #A9712C; margin-left: auto; }
.cm-queue-item.resolved .qgate { color: var(--ok); }
.cm-queue-item .qtitle { font-family: var(--serif); font-size: 15px; font-weight: 600; color: var(--ink); letter-spacing: -0.01em; }
.cm-queue-item .qreason { font-family: var(--serif); font-size: 12.5px; line-height: 1.45; color: var(--ink-3); margin-top: 5px; text-wrap: pretty; }
.cm-queue-item .qaction { font-family: var(--serif); font-size: 12.5px; line-height: 1.4; font-weight: 600; color: var(--ink); margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); text-wrap: pretty; }
.cm-queue-item .qrefs { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.cm-queue-item .qref { font-size: 12px; line-height: 1.4; }
.cm-queue-item .qref-loc { font-family: var(--mono); font-weight: 700; color: var(--ink); }
.cm-queue-item .qref-sep { color: var(--ink-4); }
.cm-queue-item .qref-snip { font-family: var(--serif); color: var(--ink-3); }
.cm-queue-item .qref-snip::before { content: "\201C"; }
.cm-queue-item .qref-snip::after  { content: "\201D"; }
.cm-queue-item .qref-id { font-family: var(--mono); font-size: 9px; color: var(--ink-4); margin-left: 4px; }
.cm-queue-empty { text-align: center; font-family: var(--serif); font-style: italic; color: var(--ink-4); padding: 40px 20px; }
.cm-queue-empty-sub { display: block; margin-top: 8px; font-size: 12px; font-style: normal; color: var(--ink-4); }

/* ============================================================
   §8 RECORDS TAB
   ============================================================ */
.cm-records { max-width: 1000px; margin: 0 auto; padding: 28px 28px 80px; }
.cm-rec-acthead { display: flex; align-items: baseline; gap: 14px; margin: 34px 0 14px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.cm-rec-acthead:first-child { margin-top: 0; }
.cm-rec-acthead .roman { font-family: var(--serif); font-style: italic; font-size: 30px; color: var(--violet); }
.cm-rec-acthead .name { font-family: var(--serif); font-size: 22px; font-weight: 600; letter-spacing: -0.015em; color: var(--ink); }
.cm-rec-acthead .meta { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.04em; color: var(--ink-4); margin-left: auto; }

.cm-rec { display: grid; grid-template-columns: 60px 1fr; gap: 18px; padding: 16px 0; border-bottom: 1px dotted var(--line); }
.cm-rec-num { font-family: var(--serif); font-size: 28px; font-weight: 500; color: var(--ink-4); letter-spacing: -0.02em; line-height: 1; text-align: right; }
.cm-rec-body { min-width: 0; }
.cm-rec-titlerow { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.cm-rec-title { font-family: var(--serif); font-size: 19px; font-weight: 600; letter-spacing: -0.015em; color: var(--ink); }
.cm-rec-role { font-size: 9.5px; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 600; color: var(--ink-4); }
.cm-rec-fields { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.cm-rec-field { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-2); }
.cm-rec-field .k { font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-4); font-weight: 700; }
.cm-rec-flag { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: #9A5B25; background: #FBF3E3; border: 1px solid #EBD7AE; border-radius: 999px; padding: 2px 9px; }
.cm-rec-flag svg { width: 11px; height: 11px; }
.cm-rec-beats { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.cm-rec-beat { display: grid; grid-template-columns: 24px 1fr; gap: 10px; align-items: baseline; }
.cm-rec-beat .pos { font-family: var(--mono); font-size: 10px; color: var(--ink-5); }
.cm-rec-beat .txt { font-family: var(--serif); font-size: 13.5px; line-height: 1.45; color: var(--ink-2); text-wrap: pretty; }
.cm-rec-beat .btmeta { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin-top: 4px; }

/* Outline: chapter summary line */
.cm-rec-summary {
  font-family: var(--serif); font-size: 13px; line-height: 1.5;
  color: var(--ink-3); margin-top: 6px; margin-bottom: 4px; text-wrap: pretty;
}
/* Outline: structure fields (want/obstacle/turn/outcome/stake) */
.cm-rec-struct { margin-top: 8px; flex-direction: column; gap: 4px; }
.cm-rec-struct .cm-rec-field { align-items: baseline; }
.cm-rec-struct .cm-rec-field .k { min-width: 60px; }

/* utility */
.cm-hidden { display: none !important; }

/* ============================================================
   §9 CHAPTER DETAIL PANEL (slide-in from right)
   ============================================================ */
.cm-chdetail-scrim {
  position: fixed; inset: 0; background: rgba(27,27,26,0.18); z-index: 40; display: none;
}
.cm-chdetail-scrim.show { display: block; }

.cm-chdetail-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 440px; z-index: 41;
  background: var(--paper); border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px -16px rgba(0,0,0,0.25);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.22s ease;
  overflow: hidden;
}
.cm-chdetail-panel.show { transform: translateX(0); }

.cm-chdetail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line); flex: none;
}
.cm-chdetail-head .x {
  width: 30px; height: 30px; display: grid; place-items: center;
  border: none; background: transparent; border-radius: 6px; cursor: pointer; color: var(--ink-3);
}
.cm-chdetail-head .x:hover { background: var(--paper-2); }

.cm-chdetail-body { flex: 1; overflow-y: auto; }

.cm-chdetail-chinfo {
  padding: 18px 20px 14px; border-bottom: 1px solid var(--line-soft);
}
.cm-chdetail-num {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; font-weight: 600;
  color: var(--ink-4); text-transform: uppercase; margin-bottom: 5px;
}
.cm-chdetail-title {
  font-family: var(--serif); font-size: 20px; font-weight: 600; letter-spacing: -0.015em;
  color: var(--ink); line-height: 1.2;
}
.cm-chdetail-role {
  font-size: 9.5px; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 600;
  color: var(--ink-4); margin-top: 6px;
}

/* ── Q/A rows ── */
.cm-qa-section { padding: 16px 20px 40px; }
.cm-qa-label {
  font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase; font-weight: 600;
  color: var(--ink-4); margin-bottom: 12px;
}
.cm-qa-why {
  background: var(--paper-2); border: 1px solid var(--line-soft);
  border-radius: 7px; padding: 10px 13px; margin-bottom: 14px;
  font-family: var(--serif); font-size: 13px; line-height: 1.5; color: var(--ink-2); text-wrap: pretty;
}
.cm-qa-why-label {
  display: block; font-family: var(--mono); font-size: 9px; letter-spacing: 0.12em;
  text-transform: uppercase; font-weight: 700; color: var(--ink-4); margin-bottom: 5px;
}
.cm-qa-row {
  padding: 10px 0; border-bottom: 1px dotted var(--line-soft);
}
.cm-qa-row:last-child { border-bottom: none; }
.cm-qa-row.cannot {
  background: #FFF9F5; border-radius: 5px;
  padding: 9px 10px; margin: 2px -10px;
}
.cm-qa-q {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.04em; font-weight: 600;
  color: var(--ink-4); margin-bottom: 5px;
}
.cm-qa-a {
  font-family: var(--serif); font-size: 13px; line-height: 1.5; color: var(--ink-2); text-wrap: pretty;
}
.cm-qa-cannot {
  color: #C45C1A; font-weight: 700; font-family: var(--mono); font-size: 10.5px;
}
.cm-qa-empty {
  font-family: var(--serif); font-style: italic; color: var(--ink-4); font-size: 13px; padding: 20px 0;
}

/* ============================================================
   §10 OUTLINE TAB (v1 chapter accordion)
   ============================================================ */
.cm-board:has(.cm-ol-wrap) { padding: 28px 36px; overflow-y: auto; }
.cm-ol-wrap { max-width: 1500px; margin: 0 auto; padding: 48px 64px 80px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 2px 0 rgba(0,0,0,0.04), 0 14px 40px rgba(20,18,12,0.15); }

/* Act group */
.cm-act { margin-bottom: 40px; }
.cm-act-head {
  display: grid; grid-template-columns: 56px 1fr auto;
  align-items: baseline; padding-bottom: 10px;
  border-bottom: 1.5px solid var(--ink); gap: 18px;
}
.cm-act-head .roman { font-family: var(--serif); font-weight: 500; font-size: 56px; line-height: 0.95; letter-spacing: -0.02em; color: var(--ink); font-variant: small-caps; font-style: italic; }
.cm-act-head .label { display: flex; flex-direction: column; gap: 2px; }
.cm-act-head .eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-2); }
.cm-act-head .name { font-family: var(--serif); font-size: 28px; font-weight: 600; letter-spacing: -0.02em; color: var(--ink); line-height: 1.05; }
.cm-act-head .stats { display: flex; gap: 14px; align-items: baseline; font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em; color: var(--ink-2); }
.cm-act-head .stats .v { color: var(--ink-2); font-weight: 500; }
.cm-act-head .ctl { display: flex; align-items: center; gap: 8px; align-self: center; }

/* Chapter row list */
.cm-list { display: flex; flex-direction: column; }
.cm-row {
  display: grid; grid-template-columns: 64px 1fr;
  gap: 24px; padding: 18px 0;
  border-bottom: 1px solid var(--line-soft);
  position: relative; cursor: pointer;
}
.cm-row:last-child { border-bottom: 0; }
.cm-row.expanded .num .big { color: var(--violet); }
.cm-row-collapsed .body > *:not(.cm-row-head),
.cm-row-collapsed .cm-handoff { display: none; }
.cm-row-collapsed .cm-row-head > *:not(.cm-row-title) { display: none; }

.cm-row .num {
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.18em; color: var(--ink-2); padding-top: 4px;
}
.cm-row .num .big {
  display: block; font-family: var(--serif); font-weight: 500;
  font-size: 32px; line-height: 1; letter-spacing: -0.02em; color: var(--ink);
  font-variant-numeric: tabular-nums; margin-bottom: 4px;
}
.cm-row .body { min-width: 0; }
.cm-row-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; flex-wrap: wrap; }
.cm-row-title { font-family: var(--serif); font-weight: 600; font-size: 19px; letter-spacing: -0.012em; color: var(--ink); line-height: 1.2; }
.cm-row-role { font-family: var(--mono); font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-2); }
.cm-row-summary { font-family: var(--serif); font-size: 15px; line-height: 1.55; color: var(--ink-2); text-wrap: pretty; margin: 4px 0 10px; }
.cm-row-goal { font-family: var(--serif); font-style: italic; font-size: 13.5px; color: var(--ink-2); margin-bottom: 8px; }
.cm-row-goal .lbl { font-family: var(--mono); font-style: normal; font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; margin-right: 8px; color: var(--ink-2); }

/* Validation badge */
.cm-validation {
  display: inline-flex; align-items: center; gap: 4px;
  height: 18px; padding: 0 6px; border-radius: 3px;
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase; flex-shrink: 0;
}
.cm-validation::before { content: ""; width: 5px; height: 5px; border-radius: 50%; }
.cm-validation.pass      { background: rgba(58,135,90,0.10);   color: var(--ok); }
.cm-validation.pass::before    { background: var(--ok); }
.cm-validation.warning   { background: rgba(199,135,58,0.10);  color: #C7873A; }
.cm-validation.warning::before { background: #C7873A; }
.cm-validation.error     { background: rgba(186,71,58,0.10);   color: #BA473A; }
.cm-validation.error::before   { background: #BA473A; }
.cm-validation.unchecked { background: var(--paper-2); color: var(--ink-2); }
.cm-validation.unchecked::before { background: var(--ink-5); }

/* Emotional intensity bar */
.cm-emo { display: inline-flex; align-items: center; gap: 4px; font-family: var(--mono); font-size: 12px; letter-spacing: 0.1em; color: var(--ink-2); text-transform: uppercase; }
.cm-emo-bar { display: inline-flex; gap: 2px; }
.cm-emo-bar .tick { width: 4px; height: 10px; background: var(--paper-3); border-radius: 1px; }
.cm-emo-bar .tick.on { background: var(--violet); }

/* Expanded stat strip */
.cm-row-divider { height: 1px; background: var(--line); margin: 16px 0 14px; }
.cm-row-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 24px 16px; margin: 0 0 16px; }
.cm-row-stats .attr-label { font-family: var(--mono); font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-4); margin-bottom: 4px; }
.cm-row-stats .attr-value { font-family: var(--serif); font-size: 14px; color: var(--ink-2); }

/* Expanded full-width section (structure + beats) */
.cm-expanded {
  grid-column: 1 / -1; margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--line-soft);
  display: grid; grid-template-columns: 1fr 1fr; gap: 22px 32px;
}
.cm-expanded h5 {
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--ink-2); font-weight: 600; margin: 0 0 8px;
  display: flex; align-items: center; gap: 6px;
}
.cm-expanded h5 .count { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }

/* Craft / structure key-value grid. Label column left, value right on desktop;
   row-gap gives breathing room between categories (was an inline style on the
   element, moved here so the <=1100 single-column stack can actually win). */
.cm-craft {
  width: 100%; display: grid; grid-template-columns: 120px 1fr; gap: 8px 14px;
  font-family: var(--mono); font-size: 12px; color: var(--ink-2); letter-spacing: 0.04em;
}
.cm-craft .k { color: var(--ink); font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; }
.cm-craft .v { font-family: var(--serif); color: var(--ink-2); font-size: 13px; }

/* Beat reference cards in expanded */
.cm-ref { border: 1px solid var(--line-soft); border-radius: 5px; padding: 9px 10px; background: var(--surface); margin-bottom: 6px; }
.cm-ref:last-child { margin-bottom: 0; }
.cm-ref-head { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.cm-ref-kind { font-family: var(--mono); font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--violet); font-weight: 600; }
.cm-ref-element { font-family: var(--serif); font-weight: 500; font-size: 13px; color: var(--ink); margin-bottom: 2px; }
.cm-ref-instruction { font-family: var(--serif); font-style: italic; font-size: 12.5px; color: var(--ink-2); line-height: 1.4; text-wrap: pretty; }

/* Empty act generate button */
.cm-actgen { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 24px 0 32px; }
.cm-actgen .est { font-family: var(--mono); font-size: 12px; color: var(--ink-2); letter-spacing: 0.08em; }
.cm-actgen button {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 18px;
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.06em; font-weight: 500;
  background: var(--ink); color: var(--paper); border: none; border-radius: 7px; cursor: pointer;
}
.cm-actgen button svg { width: 12px; height: 12px; }
.cm-actgen button:hover { opacity: 0.85; }
.cm-ol-genbtn {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; display: inline-flex; align-items: center;
  gap: 6px; padding: 6px 14px; border-radius: 20px;
  background: var(--violet-soft); color: #6150C0;   /* --violet 4.41:1 on --violet-soft; deepen text to 5.25:1 */
  border: 1px solid var(--violet); cursor: pointer;
  white-space: nowrap; transition: opacity 0.15s;
}
.cm-ol-genbtn:hover { opacity: 0.8; }
.cm-ol-genbtn:disabled { opacity: 0.5; cursor: default; }
.cm-ol-genbtn svg { width: 11px; height: 11px; }

/* Foreshadowing cue — Outline tab only, once all three acts are generated.
   Calm inline callout at the top of the outline; the action button lives here
   (works on phones too). Not a modal. */
.cm-foreshadow-cue {
  display: flex; align-items: center; gap: clamp(10px, 2.5vw, 16px);
  margin: 0 0 22px;
  padding: clamp(12px, 3.2vw, 14px) clamp(13px, 4vw, 18px);
  background: var(--violet-soft);
  border: 1px solid var(--violet);
  border-radius: var(--rad);
}
/* clamp so the copy scales down on narrow phones instead of staying fixed */
.cm-foreshadow-cue .msg { font-size: clamp(0.8rem, 3vw, 0.875rem); line-height: 1.5; color: var(--ink-2); min-width: 0; }
.cm-foreshadow-cue .msg strong { color: var(--ink); font-weight: 600; }
.cm-foreshadow-cue .cm-ol-genbtn { flex: 0 0 auto; margin-left: auto; }
.cm-foreshadow-cue.is-running { color: var(--violet); }

/* Build-job status line in the subhead (assign + chained act content) */
.cm-assign-status { display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; }
.cm-assign-msg { font-size: 13px; color: var(--ink-2); }
.cm-assign-stage {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--violet); white-space: nowrap;
}
.cm-assign-elapsed { font-family: var(--mono); font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* === Chapter Map responsive === */
.cm-main { min-width:0; }
.cm-legend { min-width:0; }

/* Mobile (<=640): the wrapped legend sprawled to ~8 lines and pushed the
   chapter cards off-screen. Collapse it back to a single swipeable row that
   reclaims the vertical space; the "Threads" label stays pinned at the left
   edge so the strip is always identifiable while you swipe through chips. */
@media (max-width: 640px) {
  .cm-legend-group {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 4px;
    column-gap: 12px;
  }
  .cm-legend-label {
    position: sticky;
    left: 0;
    background: var(--paper);
    padding-right: 6px;
    z-index: 1;
  }
}

@media (max-width:1100px){
  /* stack the acts into one readable column; board scrolls vertically */
  .cm-board { overflow-x:hidden; overflow-y:auto; }
  .cm-acts-cols { grid-template-columns:minmax(0,1fr); overflow-y:auto; }
  .cm-actcol { max-height:none; }
  .cm-row-stats { grid-template-columns:repeat(auto-fit,minmax(90px,1fr)); }
  /* Stack the craft key-values: category name above its text in one column,
     a touch of space between the label and its text, and a clear gap before
     each new category. */
  .cm-expanded { grid-template-columns:1fr; }
  .cm-craft { grid-template-columns:1fr; row-gap:4px; }
  .cm-craft .k:not(:first-of-type) { margin-top:10px; }
  /* topbar + subhead wrap cleanly */
  .cm-topbar { flex-wrap:wrap; gap:8px; height:auto; row-gap:6px; min-width:0; }
  .cm-topbar-right { flex-wrap:wrap; gap:8px; justify-content:flex-start; }
  .cm-ol-genbtn { white-space:normal; max-width:100%; }
  .cm-subhead { flex-wrap:wrap; gap:10px; height:auto; row-gap:8px; min-width:0; }
}
@media (min-width:769px) and (max-width:899px){
  /* collapse the shared sidebar to the 60px icon-rail. Lower bound matters:
     at <=768px premise.css turns the sidebar into an off-canvas drawer and
     forces every shell single-column — an unbounded !important here loads
     later and wins, dropping the MAIN content into the 60px track. */
  .app { grid-template-columns:60px minmax(0,1fr) !important; }
}
@media (max-width:768px){
  /* Outline view at phone width: scale the act typography down and keep
     everything inside the column (Beat Editor already stacks cleanly). */
  .cm-ol-wrap { padding: 20px 14px 48px; }
  .cm-act { margin-bottom: 28px; }
  .cm-act-head { grid-template-columns: 36px minmax(0,1fr); row-gap: 8px; }
  .cm-act-head .roman { font-size: 30px; }
  .cm-act-head .name { font-size: 20px; }
  .cm-act-head .ctl { grid-column: 1 / -1; justify-self: start; }
  .cm-row { grid-template-columns: 44px minmax(0,1fr); gap: 14px; }
  .cm-row .num .big { font-size: 24px; }
  .cm-row-title { font-size: 17px; }

  /* Coherence flags queue: full-screen sheet. Lifted above the fixed
     hamburger/drawer layers (z 70/80) so its own header — title + close —
     is the only chrome; the topbar avatar and hamburger sit underneath. */
  .cm-queue { width: 100vw; left: 0; border-left: none; z-index: 90; }
  .cm-queue-head { padding: 16px 16px 12px; }

  /* Foreshadowing cue stacks: message above, full-width action button below */
  .cm-foreshadow-cue { flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
  .cm-foreshadow-cue .cm-ol-genbtn { margin-left: 0; flex: 1 1 100%; justify-content: center; }
}
@media (max-width:560px){
  .cm-legend { gap:12px; }
}

/* === Independent invisible scroll for ACT columns (Beat Editor) === */
.app { height:100vh !important; max-height:100vh; overflow:hidden; }
.cm-main { height:100vh; min-height:0; overflow:hidden; }
.cm-board { min-height:0; }
.cm-acts-cols { min-height:0; height:100%; }
.cm-actcol { max-height:100%; min-height:0; }
.cm-actcol-body {
  overflow-y:auto; min-height:0; display:flex; flex-direction:column;
  scrollbar-width:none; -ms-overflow-style:none;   /* invisible scrollbar */
}
.cm-actcol-body > .cm-ch { flex:0 0 auto; }          /* cards keep natural height -> column scrolls */
.cm-actcol-body::-webkit-scrollbar { width:0; height:0; display:none; }

/* Narrow: stack acts at natural height and let the board scroll as one */
@media (max-width:1100px){
  .cm-board { overflow-y:auto; }
  .cm-acts-cols { height:auto; min-height:0; }
  .cm-actcol { max-height:none; }
  .cm-actcol-body { overflow-y:visible; }
}

/* Stronger card outlines */
.cm-ch{ border:1.5px solid #d9d4c7; box-shadow:0 1px 2px rgba(40,30,20,.06); }
.cm-ch:hover{ border-color:#bdb6a3; }
.cm-beat{ border:1.5px solid #d9d4c7; box-shadow:0 1px 2px rgba(40,30,20,.06); }
.cm-beat:hover{ border-color:#bdb6a3; }

/* Source card stays fully solid (overrides the older opacity:.6 / opacity:0
   .dragging-src rules above) */
.cm-ch.dragging-src,
.cm-beat.dragging-src{ opacity:1 !important; filter:none !important; }

/* The solid clone that follows the cursor during drag */
.__drag-follow{
  position:fixed !important; margin:0 !important;
  opacity:1 !important; filter:none !important;
  pointer-events:none; z-index:2147483647;
  background:#fff !important; border:1.5px solid #8b7fd6 !important;
  border-radius:10px; list-style:none;
  box-shadow:0 16px 34px rgba(40,30,90,.34);
  transform:rotate(-1.5deg);
}

/* ── Beat Editor drawer ─────────────────────────────────────────────────── */
.cm-beat { cursor: pointer; }
.cm-be-heading {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-3); font-weight: 600;
}
.cm-be-loading {
  padding: 28px 20px; font-family: var(--serif); font-style: italic;
  font-size: 13px; color: var(--ink-3); line-height: 1.6;
}
.cm-be-ctxhead { padding: 16px 20px 14px; border-bottom: 1px solid var(--line-soft); }
.cm-be-title {
  font-family: var(--serif); font-size: 17px; font-weight: 600;
  letter-spacing: -0.01em; color: var(--ink-1); margin-bottom: 4px;
}
.cm-be-meta {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.04em;
  color: var(--ink-4); text-transform: uppercase; margin-bottom: 8px;
}
.cm-be-summary {
  font-family: var(--serif); font-size: 13px; line-height: 1.55; color: var(--ink-2);
}
.cm-be-fields { padding: 16px 20px 4px; display: flex; flex-direction: column; gap: 14px; }
.cm-be-field { display: block; position: relative; }
.cm-be-label {
  display: block; font-family: var(--mono); font-size: 10px; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--ink-4); font-weight: 600; margin-bottom: 5px;
}
.cm-be-input {
  width: 100%; box-sizing: border-box; font-family: var(--serif); font-size: 13.5px;
  line-height: 1.5; color: var(--ink-1); background: var(--paper);
  border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px;
  resize: vertical; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.cm-be-input:focus {
  outline: none; border-color: var(--accent, #5B6FA6);
  box-shadow: 0 0 0 3px rgba(91,111,166,0.12);
}
.cm-be-status {
  position: absolute; top: 0; right: 0; font-family: var(--mono);
  font-size: 9.5px; letter-spacing: 0.05em; text-transform: uppercase;
}
.cm-be-status.saving { color: var(--ink-4); }
.cm-be-status.saved  { color: #4b7a52; }
.cm-be-note {
  padding: 8px 20px 0; font-family: var(--serif); font-style: italic;
  font-size: 11.5px; color: var(--ink-4);
}
.cm-be-danger {
  margin-top: 18px; padding: 16px 20px 22px; border-top: 1px solid var(--line-soft);
}
.cm-be-delete {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; font-weight: 600;
  color: #9A4B4B; background: transparent; border: 1px solid #d8b3b3;
  border-radius: 7px; padding: 8px 14px; cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.cm-be-delete:hover { background: #f7ecec; }
.cm-be-delete.armed { color: #fff; background: #9A4B4B; border-color: #9A4B4B; }
.cm-be-delete:disabled { opacity: 0.6; cursor: default; }
.cm-be-delwarn {
  margin-top: 10px; font-family: var(--serif); font-size: 12px; line-height: 1.5;
  color: var(--ink-2);
}

/* ── Per-tile pipeline flag chips (replaces the retired coherence-gate card) ── */
.cm-tile-flags {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 10px 2px;
}
.cm-tile-chip {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.02em;
  font-weight: 600; line-height: 1.2; padding: 3px 7px; border-radius: 5px;
  cursor: pointer; border: 1px solid; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: filter 0.12s ease;
}
.cm-tile-chip.action { color: #9A4B4B; background: #f7ecec; border-color: #e2c4c4; }
.cm-tile-chip.info   { color: var(--ink-3); background: var(--paper-2); border-color: var(--line); }
.cm-tile-chip:hover  { filter: brightness(0.97); }
