/* Ivy Hook — warm paper, ivy green, ink. */
:root {
  --paper: #f4f0e6;
  --paper-raised: #faf7ef;
  --paper-deep: #ece6d8;
  --ink: #2b2620;
  --ink-soft: #5c544a;
  --ink-faint: #8d8477;
  --line: #ddd5c4;
  --ivy: #3f6b4a;
  --ivy-deep: #2f5238;
  --ivy-wash: #e4ecdf;
  --amber: #a06e1f;
  --amber-wash: #f4e6c6;
  --rose: #a5514a;
  --rose-wash: #f3ded9;
  --violet: #6b5a8e;
  --violet-wash: #e9e2f2;
  --field: #ffffff;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, "Segoe UI", system-ui, Roboto, sans-serif;
  --mono: "Cascadia Code", Consolas, "SF Mono", monospace;
  --shadow: 0 8px 28px rgba(43, 38, 32, .18);
  --radius: 9px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans); color: var(--ink); background: var(--paper);
  display: flex; flex-direction: column; overflow: hidden; font-size: 14px;
}
button {
  font-family: inherit; font-size: 13px; color: var(--ink);
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 10px; cursor: pointer;
}
button:hover { border-color: var(--ivy); color: var(--ivy-deep); }
button.primary { background: var(--ivy); border-color: var(--ivy-deep); color: #fff; }
button.primary:hover { background: var(--ivy-deep); color: #fff; }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { border-color: var(--line); }
button.mini { padding: 1px 7px; font-size: 12px; border-radius: 5px; }
button.danger { color: var(--rose); }
button:disabled { opacity: .45; cursor: default; pointer-events: none; }
textarea, input, select {
  font-family: inherit; font-size: 13px; color: var(--ink);
  background: var(--field); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px;
}
textarea:focus, input:focus, select:focus { outline: 2px solid var(--ivy-wash); border-color: var(--ivy); }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ topbar */
#topbar {
  display: flex; align-items: center; gap: 14px; padding: 6px 14px;
  background: var(--paper-deep); border-bottom: 1px solid var(--line);
  flex: 0 0 auto; z-index: 30;
  flex-wrap: wrap; row-gap: 4px;   /* fits any width/zoom — never clips */
}
.brand { display: flex; align-items: center; gap: 7px; font-weight: 600; }
.brand-leaf { font-size: 17px; }
.brand-name { letter-spacing: .3px; color: var(--ivy-deep); }
#project-name { font-weight: 500; color: var(--ink-soft); max-width: 260px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#project-name::after { content: " ▾"; opacity: .55; font-size: 10px; }

/* manuscript switcher dropdown */
#project-menu { position: fixed; z-index: 60; min-width: 250px; max-width: 340px;
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: 10px; padding: 5px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; }
#project-menu .pm-item { display: flex; align-items: baseline; gap: 8px;
  width: 100%; text-align: left; border: 0; background: transparent;
  border-radius: 7px; padding: 7px 10px; font-size: 13px; color: var(--ink); }
#project-menu .pm-item:hover { background: var(--field); }
#project-menu .pm-item.current .pm-name { font-weight: 600; color: var(--ivy-deep); }
#project-menu .pm-name { flex: 1; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
#project-menu .pm-words { font-size: 11px; color: var(--ink-faint);
  font-variant-numeric: tabular-nums; white-space: nowrap; }
#project-menu .pm-check { color: var(--ivy); font-weight: 700; }
#project-menu .pm-sep { border-top: 1px solid var(--line); margin: 4px 2px; }
#project-menu .pm-action { color: var(--ink-soft); font-size: 12.5px; }

/* right-click menu in the manuscript (+ synonyms panel) */
.ivy-menu { position: fixed; z-index: 65; min-width: 210px; max-width: 320px;
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: 10px; padding: 5px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; }
.ivy-menu .im-item { width: 100%; text-align: left; border: 0;
  background: transparent; border-radius: 7px; padding: 6px 10px;
  font-size: 13px; color: var(--ink); }
.ivy-menu .im-item:hover { background: var(--field); }
.ivy-menu .im-item b, .ivy-menu .im-item i { margin-right: 2px; }
.ivy-menu .im-sep { border-top: 1px solid var(--line); margin: 4px 2px; }
.ivy-menu .im-head { font-size: 12px; font-weight: 600; color: var(--ivy-deep);
  padding: 6px 10px 4px; }
.ivy-menu .im-corr { color: var(--amber); font-weight: 700; }
.ivy-menu .im-chips { display: flex; flex-wrap: wrap; gap: 5px;
  padding: 4px 8px 6px; max-height: 190px; overflow-y: auto; }
.ivy-menu .im-chip { font-size: 12.5px; padding: 3px 10px; border-radius: 12px;
  background: var(--field); border: 1px solid var(--line); color: var(--ink); }
.ivy-menu .im-chip:hover { border-color: var(--ivy); color: var(--ivy-deep); }
.ivy-menu .im-note { font-size: 12px; color: var(--ink-faint); padding: 2px 4px; }
#mode-toggle { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
#mode-toggle button { border: 0; border-radius: 0; background: transparent; padding: 4px 14px; }
#mode-toggle button.active { background: var(--ivy); color: #fff; }
#counts { font-variant-numeric: tabular-nums; color: var(--ink-soft); }
#counts b { color: var(--ink); }
#wc-new { color: var(--ivy-deep); cursor: pointer; }
#wc-new:hover { text-decoration: underline; }
.wc-sep { margin: 0 6px; color: var(--ink-faint); }
#menu { margin-left: auto; display: flex; gap: 6px; }
body[data-mode="draft"] #btn-read { display: none; }  /* R9.3 — revision tool */

/* ------------------------------------------------------------------ layout */
#layout { flex: 1 1 auto; display: flex; min-height: 0; }
#chapnav {
  flex: 0 0 232px; overflow-y: auto; padding: 10px;
  background: var(--paper-deep); border-right: 1px solid var(--line);
}
body.nav-collapsed #chapnav { display: none; }
.side-section { margin-bottom: 18px; }
.side-head {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--ink-faint); margin-bottom: 6px; display: flex; align-items: center; gap: 6px;
}
.side-head .mini { margin-left: auto; }
.count-chip { background: var(--ivy-wash); color: var(--ivy-deep);
  border-radius: 8px; padding: 0 6px; font-size: 10px; }
.chap-item {
  display: flex; justify-content: space-between; gap: 8px; padding: 4px 7px;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
.chap-item:hover { background: var(--paper-raised); }
.chap-item.active { background: var(--ivy-wash); color: var(--ivy-deep); }
.chap-item .cw { color: var(--ink-faint); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chap-item.outlier .cw { color: var(--amber); font-weight: 600; }
.side-list { display: flex; flex-direction: column; gap: 4px; }
.side-item { font-size: 12.5px; padding: 4px 7px; border-radius: 6px;
  background: var(--paper-raised); border: 1px solid var(--line); cursor: pointer; }
.side-item:hover { border-color: var(--ivy); }
.side-item .sub { color: var(--ink-faint); font-size: 11px; display: block; }
.side-item .row-btns { float: right; display: flex; gap: 3px; }
.side-empty { color: var(--ink-faint); font-size: 12px; padding: 2px 7px; }

/* ------------------------------------------------------------------ editor */
#editor-pane { flex: 1 1 50%; min-width: 240px; display: flex; flex-direction: column; min-height: 0; }
body.left-collapsed #editor-pane, body.left-collapsed #divider-main, body.left-collapsed #chapnav { display: none; }
#toolbar {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px;
  border-bottom: 1px solid var(--line); background: var(--paper);
  flex-wrap: wrap; row-gap: 3px;
}
.tb-group { display: flex; gap: 3px; }
#toolbar button { padding: 2px 8px; min-width: 28px; }
.tb-spacer { flex: 1; }
#save-status { font-size: 11.5px; color: var(--ink-faint); }
#save-status.takeover { color: var(--amber); cursor: pointer;
  font-weight: 600; text-decoration: underline dotted; }
#save-status.dirty { color: var(--amber); }
#editor { flex: 1 1 auto; min-height: 0; overflow: hidden; background: var(--paper-raised); }

/* CodeMirror interior */
.cm-editor { height: 100%; background: transparent; }
.cm-editor.cm-focused { outline: none; }
#editor .cm-scroller {
  font-family: var(--serif); font-size: 17px; line-height: 1.75;
  padding: 28px 0 45vh;
}
.cm-content { max-width: 46em; margin: 0 auto; padding: 0 40px; caret-color: var(--ivy-deep); }
.cm-line { padding: 0; }
.cm-activeLine { background: rgba(63, 107, 74, .05); }
.cm-selectionBackground, .cm-content ::selection { background: rgba(63, 107, 74, .22) !important; }
.cm-cursor { border-left-color: var(--ivy-deep); border-left-width: 2px; }
.cm-marker { color: var(--ink-faint); opacity: .55; font-size: .85em; }
.cm-em { font-style: italic; }
.cm-strong { font-weight: 700; }
.cm-inline-code { font-family: var(--mono); font-size: .82em; background: var(--paper-deep); border-radius: 3px; }
.cm-line-h1 { font-size: 1.65em; font-weight: 700; line-height: 1.3;
  padding-top: .9em; padding-bottom: .25em; color: var(--ivy-deep); }
.cm-line-h2 { font-size: 1.32em; font-weight: 650; padding-top: .55em; }
.cm-line-h3 { font-size: 1.12em; font-weight: 650; padding-top: .4em; }
.cm-line-quote { border-left: 3px solid var(--ivy); padding-left: 14px !important;
  color: var(--ink-soft); font-style: italic; }
.cm-line-hr { text-align: center; color: var(--ink-faint); letter-spacing: 6px; }
.cm-placeholder {
  background: var(--violet-wash); color: var(--violet); border-radius: 4px;
  padding: 0 2px; font-family: var(--sans); font-size: .8em; font-weight: 600;
}
.cm-entity { border-bottom: 1px dotted rgba(63, 107, 74, .6); }
.cm-lintRange-warning { background-position: left bottom;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="6" height="3"><path d="m0 3 l2 -2 l1 0 l2 2 l1 0" stroke="%23a06e1f" fill="none" stroke-width=".8"/></svg>'); }
/* !important: CodeMirror injects its own theme after ours and would keep a
   light tooltip in dark mode (light-on-light text — unreadable) */
.cm-tooltip { background: var(--paper-raised) !important;
  color: var(--ink) !important; border: 1px solid var(--line) !important;
  border-radius: 7px; box-shadow: var(--shadow); font-family: var(--sans); }
.cm-tooltip-lint { padding: 2px 4px; max-width: 340px; }
.cm-diagnostic { border-left: 3px solid var(--amber); padding: 3px 8px;
  color: var(--ink); }
.cm-diagnostic-warning { border-left-color: var(--amber); }
.cm-diagnosticSource { color: var(--ink-faint) !important; font-size: 11px; }
.cm-flash { background: var(--amber-wash); border-radius: 3px;
  box-shadow: 0 0 0 2px var(--amber-wash); transition: background .3s; }
.cm-diagnosticAction { background: var(--ivy); border-radius: 4px; padding: 1px 7px;
  margin-left: 6px; color: #fff; font-size: 11px; }
/* CM injects z-index:300 on its panels — that floated find/replace above
   the Settings modal (z:70) and blocked its buttons. Keep panels above the
   editor, below every overlay. */
#editor .cm-panels { z-index: 40 !important; }
.cm-panels { background: var(--paper-deep); border-color: var(--line);
  font-family: var(--sans); }
.cm-searchMatch { background: var(--amber-wash); }
.cm-searchMatch-selected { background: var(--amber); color: #fff; }
#editor .cm-gutters { background: transparent !important; border: 0;
  color: var(--ink-faint); }

/* ------------------------------------------------------------ fragment bar */
#fragment-bar {
  display: flex; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line);
  background: var(--paper-deep); align-items: stretch;
}
body[data-mode="revision"] #fragment-bar { display: none; }
#fragment-input { flex: 1; resize: vertical; min-height: 64px; max-height: 45vh;
  font-family: var(--serif); font-size: 14.5px; background: var(--paper-raised); }
.frag-buttons { display: flex; flex-direction: column; gap: 5px; justify-content: center; }

/* ---------------------------------------------------------------- dividers */
.divider-v { flex: 0 0 6px; cursor: col-resize; background: var(--paper-deep);
  border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.divider-v:hover, .divider-h:hover { background: var(--ivy-wash); }
.divider-h { flex: 0 0 6px; cursor: row-resize; background: var(--paper-deep);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
body.right-collapsed #right-col, body.right-collapsed #divider-main { display: none; }

/* ------------------------------------------------------------------- panes */
#right-col { flex: 1 1 50%; min-width: 300px; display: flex; flex-direction: column; min-height: 0; position: relative; }
.pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; flex: 1 1 auto; background: var(--paper); }
#chat-tabs { display: flex; align-items: center; gap: 5px; padding: 6px 10px 0;
  border-bottom: 1px solid var(--line); flex-wrap: wrap; min-width: 0; }
#tab-strip { display: flex; gap: 3px; overflow-x: auto; flex: 1; min-width: 0; }
.chat-tab { border-radius: 8px 8px 0 0; border-bottom: 0; font-size: 12.5px;
  padding: 4px 11px; white-space: nowrap; background: var(--paper-deep); }
.chat-tab.active { background: var(--ivy); color: #fff; }
.chat-tab .tab-x { opacity: .6; margin-left: 3px; }
.chat-tab .tab-x:hover { opacity: 1; }
#chat-tabs .pane-tools { margin-left: 4px; padding-bottom: 5px; }
#chat-bodies { flex: 1 1 auto; min-height: 0; min-width: 0; display: flex; }
.chat-body { display: none; flex-direction: column; min-height: 0; min-width: 0; flex: 1; }
.chat-body.active { display: flex; }
.pane-head {
  display: flex; align-items: center; padding: 6px 12px 4px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap; row-gap: 3px;
}
.pane-title { font-weight: 650; font-size: 13px; color: var(--ivy-deep); }
.pane-sub { font-weight: 400; color: var(--ink-faint); font-size: 11.5px; margin-left: 6px; }
.pane-tools { margin-left: auto; display: flex; gap: 5px; align-items: center;
  flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
#chat-model { max-width: 128px; font-size: 11.5px; padding: 2px 4px;
  color: var(--ink-soft); background: var(--field); border: 1px solid var(--line);
  border-radius: 7px; text-overflow: ellipsis; }
.ivy-menu .im-close { float: right; border: 0; background: transparent;
  font-size: 11px; color: var(--ink-faint); padding: 0 2px; }
.ivy-menu .im-close:hover { color: var(--ink); }
.sel-pin { background: var(--ivy-wash); border-bottom: 1px solid var(--line); padding: 7px 12px; }
.sel-pin-text { font-family: var(--serif); font-size: 13.5px; color: var(--ink);
  max-height: 3.1em; overflow: hidden; }
.sel-pin.expanded .sel-pin-text { max-height: 14em; overflow-y: auto; }
.sel-pin-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.sel-loc { font-size: 11px; color: var(--ivy-deep); font-weight: 600; }
.sel-none { padding: 9px 12px; font-size: 12.5px; color: var(--ink-faint);
  border-bottom: 1px solid var(--line); font-style: italic; }
.pane-actions { display: flex; flex-wrap: wrap; gap: 5px; padding: 7px 12px;
  border-bottom: 1px solid var(--line); }
.pane-actions button { font-size: 12px; padding: 3px 9px; border-radius: 14px; }
.pane-msgs { flex: 1 1 auto; overflow-y: auto; padding: 12px; display: flex;
  flex-direction: column; gap: 10px; }
.pane-msgs > * { flex: 0 0 auto; }
.chat-notice { align-self: center; font-size: 11.5px; color: var(--ink-faint);
  background: var(--field); border: 1px dashed var(--line); border-radius: 10px;
  padding: 3px 12px; margin: 2px 0; }
.pane-input { display: flex; gap: 7px; padding: 9px 12px; border-top: 1px solid var(--line); }
.pane-input textarea { flex: 1; resize: none; }
.pane-input .send { align-self: flex-end; }
#pane-b-toggle {
  position: absolute; bottom: 8px; right: 10px; z-index: 5; font-size: 11.5px;
  border-radius: 14px; box-shadow: var(--shadow); background: var(--paper-raised);
}
#right-col.b-open #pane-b-toggle { display: none; }

/* --------------------------------------------------------------- messages */
.msg { max-width: 100%; }
.msg .bubble {
  border-radius: var(--radius); padding: 8px 12px; font-size: 13.5px; line-height: 1.55;
}
.msg.user .bubble { background: var(--ivy-wash); margin-left: 12%; }
.msg.assistant .bubble { background: var(--paper-raised); border: 1px solid var(--line); margin-right: 6%; }
.msg .who { font-size: 10.5px; color: var(--ink-faint); margin: 0 4px 2px;
  text-transform: uppercase; letter-spacing: .6px; display: flex; gap: 8px; align-items: center; }
.msg .who .capture-btn { margin-left: auto; }
.msg.user .who { text-align: right; justify-content: flex-end; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 20px; }
.bubble code { font-family: var(--mono); font-size: .85em; background: var(--paper-deep);
  padding: 0 3px; border-radius: 3px; }
.bubble blockquote { border-left: 3px solid var(--ivy); margin: 6px 0; padding: 2px 10px;
  color: var(--ink-soft); }
.tool-chip {
  align-self: flex-start; font-size: 11px; color: var(--ink-soft);
  background: var(--paper-deep); border: 1px dashed var(--line);
  border-radius: 12px; padding: 2px 10px;
}
.typing { color: var(--ink-faint); font-size: 12px; padding: 0 4px; }
.typing::after { content: "…"; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------------------------------------------------------- assembly cards */
.assembly-card {
  border: 1px solid var(--ivy); border-radius: var(--radius);
  background: var(--paper-raised); overflow: hidden; margin-right: 4%;
}
.assembly-card .ac-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 11px;
  background: var(--ivy-wash); font-size: 12px; color: var(--ivy-deep); font-weight: 650;
}
.ac-head .legend { margin-left: auto; font-weight: 400; font-size: 10.5px; color: var(--ink-soft); }
.legend .swatch { display: inline-block; width: 9px; height: 9px; border-radius: 2px;
  margin: 0 3px 0 8px; vertical-align: -1px; }
.swatch.ins { background: var(--amber-wash); border: 1px solid var(--amber); }
.swatch.del { background: var(--rose-wash); border: 1px solid var(--rose); }
.swatch.edit { background: var(--ivy-wash); border: 1px solid var(--ivy); }
.assembly-card .ac-text {
  font-family: var(--serif); font-size: 15px; line-height: 1.7; padding: 10px 13px;
  white-space: pre-wrap;
}
.ac-text .d-ins { background: var(--amber-wash); border-bottom: 2px solid var(--amber);
  border-radius: 3px; padding: 0 1px; }
.ac-text .d-del { background: var(--rose-wash); color: var(--rose);
  text-decoration: line-through; border-radius: 3px; padding: 0 1px; }
.ac-text .d-edit { background: var(--ivy-wash); border-bottom: 1px dotted var(--ivy);
  border-radius: 3px; padding: 0 1px; cursor: help; }
.ac-text .d-brk { color: var(--ink-faint); font-size: .75em; opacity: .7;
  cursor: help; user-select: none; }
.assembly-card.hide-del .d-del { display: none; }
.assembly-card.struck .d-ins { display: none; }
.ac-notes { font-size: 12px; color: var(--ink-soft); padding: 0 13px 8px; font-style: italic; }
.ac-stats { font-size: 11px; color: var(--ink-faint); padding: 0 13px 8px; }
.ac-buttons { display: flex; gap: 6px; padding: 8px 11px; border-top: 1px solid var(--line);
  flex-wrap: wrap; align-items: center; }
.ac-amend-box { width: 100%; }
.ac-amend-box textarea { width: 100%; font-family: var(--serif); font-size: 14px; min-height: 90px; }
.assembly-card.resolved .ac-buttons { display: none; }
.ac-resolved-note { font-size: 11.5px; padding: 6px 11px; color: var(--ivy-deep);
  border-top: 1px solid var(--line); background: var(--ivy-wash); }

/* ---------------------------------------------------------- pending change */
.pending-card { border: 1px solid var(--violet); border-radius: var(--radius);
  background: var(--violet-wash); padding: 9px 12px; font-size: 12.5px; }
.pending-card .pc-title { font-weight: 650; color: var(--violet); margin-bottom: 4px; }
.pending-card pre { font-size: 11.5px; background: var(--field); padding: 7px; border-radius: 6px;
  overflow-x: auto; margin: 6px 0; }
.pending-card .ac-buttons { border: 0; padding: 4px 0 0; }

/* ------------------------------------------------------------------ panels */
#panel-root { position: fixed; inset: 0; z-index: 60; }
#panel-scrim, #modal-scrim { position: absolute; inset: 0; background: rgba(43,38,32,.35); }
#panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(660px, 92vw);
  background: var(--paper); box-shadow: var(--shadow); display: flex; flex-direction: column;
}
#panel > header { display: flex; align-items: center; padding: 12px 16px;
  border-bottom: 1px solid var(--line); font-weight: 700; color: var(--ivy-deep); }
#panel-title { font-size: 15px; }
#panel-close, #rt-close { margin-left: auto; }
#panel-tabs { display: flex; gap: 4px; padding: 8px 14px 0; border-bottom: 1px solid var(--line);
  flex-wrap: wrap; }
#panel-tabs button { border-radius: 7px 7px 0 0; border-bottom: 0; font-size: 12.5px; }
#panel-tabs button.active { background: var(--ivy); color: #fff; }
#panel-tabs button.locked { opacity: .5; }
#panel-body { flex: 1; overflow-y: auto; padding: 14px 16px; }
.panel-note { font-size: 12px; color: var(--ink-soft); background: var(--amber-wash);
  border: 1px solid var(--amber); border-radius: 7px; padding: 7px 11px; margin-bottom: 12px; }
.list-card { border: 1px solid var(--line); border-radius: 8px; background: var(--paper-raised);
  padding: 9px 12px; margin-bottom: 9px; font-size: 13px; }
.list-card .lc-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 3px; flex-wrap: wrap; }
.list-card .lc-title { font-weight: 650; }
.list-card .lc-meta { color: var(--ink-faint); font-size: 11.5px; }
.list-card .lc-buttons { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.sev { font-size: 10px; padding: 1px 7px; border-radius: 9px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px; }
.sev.high, .sev.significant { background: var(--rose-wash); color: var(--rose); }
.sev.medium, .sev.minor { background: var(--amber-wash); color: var(--amber); }
.sev.low, .sev.none, .sev.info { background: var(--ivy-wash); color: var(--ivy-deep); }
.panel-toolbar { display: flex; gap: 7px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.panel-toolbar .spacer { flex: 1; }
.job-progress { font-size: 12px; color: var(--ink-soft); }
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th { text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--ink-faint); padding: 4px 8px; border-bottom: 1px solid var(--line); }
table.data td { padding: 5px 8px; border-bottom: 1px solid var(--paper-deep); vertical-align: top; }
.bar { height: 8px; background: var(--ivy-wash); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ivy); }
.bar.outlier > i { background: var(--amber); }

.bulk-diff { font-family: var(--mono); font-size: 11.5px; line-height: 1.5;
  background: var(--field); border: 1px solid var(--line); border-radius: 7px;
  padding: 10px; overflow: auto; max-height: 46vh; white-space: pre; }
.bulk-diff .dl-add { background: var(--ivy-wash); color: var(--ivy-deep); display: inline; }
.bulk-diff .dl-del { background: var(--rose-wash); color: var(--rose); display: inline; }
.bulk-diff .dl-hunk { color: var(--ink-faint); }

/* bible */
.bible-grid { display: grid; grid-template-columns: 150px 1fr; gap: 12px; min-height: 100%; }
.bible-types { display: flex; flex-direction: column; gap: 4px; }
.bible-types button { text-align: left; }
.bible-types button.active { background: var(--ivy); color: #fff; }
.entity-card { cursor: pointer; }
.entity-card:hover { border-color: var(--ivy); }
.field-row { display: grid; grid-template-columns: 150px 1fr; gap: 7px; margin-bottom: 7px; }
.field-row label { font-size: 11.5px; color: var(--ink-soft); padding-top: 7px; }
.field-row textarea { min-height: 34px; }
.form-actions { display: flex; gap: 8px; margin-top: 12px; }
.form-actions .spacer { flex: 1; }

/* ------------------------------------------------------------------- modal */
#modal-root { position: fixed; inset: 0; z-index: 70; display: flex; }
#modal { position: relative; margin: auto; background: var(--paper);
  border-radius: 12px; box-shadow: var(--shadow); width: min(640px, 94vw);
  max-height: 88vh; display: flex; }
#modal-body { padding: 18px 20px; overflow-y: auto; width: 100%; }
#modal-body h3 { margin: 0 0 12px; color: var(--ivy-deep); }
.settings-section { margin-bottom: 18px; }
.settings-section > .sh { font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--ink-faint); border-bottom: 1px solid var(--line); padding-bottom: 3px; margin-bottom: 9px; }
.set-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.set-row label:first-child { flex: 0 0 190px; color: var(--ink-soft); }
.set-row input[type="text"], .set-row input[type="password"], .set-row input[type="number"],
.set-row select { flex: 1; }
.set-row .hint { font-size: 11px; color: var(--ink-faint); }
.persona-box { width: 100%; min-height: 170px; font-family: var(--mono); font-size: 12px; }
.rule-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 12.5px; }
.rule-row .rd { color: var(--ink-faint); font-size: 11.5px; }
.switch { position: relative; width: 34px; height: 19px; flex: 0 0 34px; }
.switch input { display: none; }
.switch i { position: absolute; inset: 0; background: var(--line); border-radius: 10px;
  transition: .15s; cursor: pointer; }
.switch i::after { content: ""; position: absolute; width: 15px; height: 15px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + i { background: var(--ivy); }
.switch input:checked + i::after { left: 17px; }

/* ------------------------------------------------------------- readthrough */
#readthrough { position: fixed; inset: 0; background: var(--paper-raised); z-index: 80;
  overflow-y: auto; }
#rt-close { position: fixed; top: 14px; right: 18px; z-index: 81; }
#rt-body { font-family: var(--serif); font-size: 19px; line-height: 1.85;
  max-width: 42em; margin: 0 auto; padding: 60px 30px 40vh; color: var(--ink); }
#rt-body h1 { text-align: center; margin: 2.2em 0 1.4em; font-size: 1.5em;
  letter-spacing: 1px; }
#rt-body hr { border: 0; text-align: center; margin: 1.6em 0; }
#rt-body hr::after { content: "❦"; color: var(--ink-faint); }
#rt-body p { margin: 0; text-indent: 1.6em; }
#rt-body h1 + p, #rt-body hr + p { text-indent: 0; }

/* ------------------------------------------------- selection popover, flags */
#sel-popover { position: fixed; z-index: 55; display: flex; gap: 4px;
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: 10px; padding: 4px 6px; box-shadow: var(--shadow); }
#sel-popover button { font-size: 12px; padding: 2px 10px; border-radius: 13px; }
.bible-chip { align-self: flex-start; font-size: 12px; color: var(--ink);
  background: var(--violet-wash); border: 1px solid var(--violet);
  border-radius: 13px; padding: 4px 12px; display: flex; gap: 7px; align-items: center; }
.origin-chip { font-size: 10px; color: var(--violet); background: var(--field);
  border: 1px solid var(--violet); border-radius: 8px; padding: 0 6px;
  white-space: nowrap; }
.field-star { color: var(--violet); cursor: help; }
.cat-text { white-space: pre-wrap; font-size: 13px; margin-top: 4px; }
.cat-text.prose { font-family: var(--serif); font-size: 13.5px; }
.cat-card .lc-head { align-items: center; }
.msg .copy-btn { opacity: 0; transition: opacity .12s; }
.msg:hover .copy-btn { opacity: 1; }

/* ------------------------------------------------------------------ toasts */
#toast-root { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 90; display: flex; flex-direction: column; gap: 7px; align-items: center; }
.toast { background: var(--ink); color: var(--paper-raised); border-radius: 8px;
  padding: 8px 16px; font-size: 13px; box-shadow: var(--shadow);
  animation: rise .18s ease-out; max-width: 70vw; }
.toast.warn { background: var(--amber); }
.toast.error { background: var(--rose); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px;
  border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); background-clip: content-box; }

/* --------------------------------------------------------------- dark theme */
body[data-theme="dark"] {
  --paper: #211e18;
  --paper-raised: #2a261e;
  --paper-deep: #1a1712;
  --ink: #e9e2d2;
  --ink-soft: #b8ae9b;
  --ink-faint: #837a69;
  --line: #3d382c;
  --ivy: #5f9670;
  --ivy-deep: #8ec49d;
  --ivy-wash: #2b3a2f;
  --amber: #d3a352;
  --amber-wash: #3e3322;
  --rose: #d3857c;
  --rose-wash: #443029;
  --violet: #ab9ad1;
  --violet-wash: #332c42;
  --field: #262218;
  --shadow: 0 8px 28px rgba(0, 0, 0, .5);
}
body[data-theme="dark"] .cm-activeLine { background: rgba(120, 170, 132, .07); }
body[data-theme="dark"] .cm-selectionBackground,
body[data-theme="dark"] .cm-content ::selection {
  background: rgba(120, 170, 132, .3) !important; }
body[data-theme="dark"] .cm-entity { border-bottom-color: rgba(142, 196, 157, .55); }
body[data-theme="dark"] .toast { background: var(--paper-deep); color: var(--ink);
  border: 1px solid var(--line); }
body[data-theme="dark"] .toast.warn { background: #4a3a1c; color: #f0d9a8; border-color: var(--amber); }
body[data-theme="dark"] .toast.error { background: #4a2620; color: #f2c4bd; border-color: var(--rose); }
body[data-theme="dark"] #panel-scrim, body[data-theme="dark"] #modal-scrim {
  background: rgba(0, 0, 0, .55); }

/* --------------------------------------------------------------- narration */
#narrator { position: fixed; bottom: 72px; right: 18px; z-index: 58;  /* clear of the chat composer */
  display: flex; gap: 8px; align-items: center; background: var(--paper-raised);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px;
  box-shadow: var(--shadow); }
#narrator select { font-size: 12px; max-width: 190px; }
/* minimized: a small pill — narration keeps playing, screen stays yours */
#narrator.min { padding: 5px 8px; gap: 6px; border-radius: 16px; }
#narrator.min select, #narrator.min label, #narrator.min #nar-stop,
#narrator.min #nar-min { display: none; }
#narrator.min #nar-expand { display: inline-block; }
.chap-side { display: flex; gap: 6px; align-items: center; }
.chap-play { opacity: 0; cursor: pointer; font-size: 11px; transition: opacity .12s; }
.chap-item:hover .chap-play { opacity: .85; }
#rt-listen { position: fixed; top: 14px; right: 64px; z-index: 81; }
#rt-chapter { position: fixed; top: 14px; right: 152px; z-index: 81;
  max-width: 230px; }
@media (max-width: 760px) { #rt-chapter { max-width: 140px; } }

/* ------------------------------------------------ responsive / any scaling
   The window can be any logical size (small laptops, 125–200% Windows
   scaling, browser zoom). Everything above wraps instead of clipping; below,
   the fixed side rail and pane minimums give way so the composer and send
   controls stay reachable at ANY viewport. */
@media (max-width: 1100px) {
  #chapnav { flex-basis: 176px; }
  #topbar { gap: 8px; }
  #project-name { max-width: 150px; }
}
@media (max-width: 900px) {
  #chapnav { flex-basis: 140px; padding: 8px 6px; }
  /* the divider stores a fixed % on the editor pane; at squeezed widths it
     must become flexible again or the row overflows */
  #editor-pane { min-width: 180px; flex: 1 1 45% !important; }
  #right-col { min-width: 200px; }
  .pane-actions { padding: 5px 8px; }
  .pane-input { padding: 7px 8px; }
  #toolbar .tb-group { gap: 2px; }
}
@media (max-width: 700px) {
  /* extreme squeeze / phones: pane minimums give way (the phone-layout
     block below owns everything else at this width) */
  #editor-pane { min-width: 150px; }
  #right-col { min-width: 190px; }
}

/* ------------------------------------------------------------ phone layout */
/* A phone is for prose: one quiet top row, the manuscript, and two thumb
   targets. Everything else lives behind the leaf. */
#chat-fab, #ws-fab, #m-sheet, #m-pen { display: none; }
@media (max-width: 700px) {
  #layout { height: 100dvh; }

  /* quiet top row: leaf + counts, nothing else */
  #topbar { gap: 8px; padding: 7px 12px; flex-wrap: nowrap; }
  #mode-toggle, #menu, #project-name, .brand-name, #wc-chapter { display: none; }
  .brand-leaf { font-size: 22px; }
  #counts { margin-left: auto; }

  /* the page is the prose */
  #toolbar, #fragment-bar, #divider-main { display: none; }
  #editor-pane { min-width: 0; }
  #chapnav { display: block; position: fixed; top: 0; left: 0; bottom: 0;
    width: 78%; max-width: 320px; z-index: 72; box-shadow: var(--shadow); }

  /* chat as a full-screen sheet behind the floating button */
  #right-col { position: fixed; inset: 0; z-index: 66;
    background: var(--paper); display: none; }
  body.chat-open #right-col { display: flex; flex-direction: column; }
  body.chat-open #right-col .pane { height: 100%; }
  .pane-tools #chat-model, #btn-summary { display: none; }
  .pane-actions { flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch; }
  .pane-actions button { flex: 0 0 auto; }

  #chat-fab { display: flex; position: fixed; right: 14px; bottom: 18px;
    z-index: 80; width: 52px; height: 52px; border-radius: 50%;
    align-items: center; justify-content: center; font-size: 22px;
    background: var(--ivy); color: #fff; border: 1px solid var(--ivy-deep);
    box-shadow: var(--shadow); }
  body.chat-open #chat-fab { background: var(--paper-raised); color: var(--ink); }

  /* the write -> workshop loop, thumb-native: appears only with unread prose */
  #ws-fab:not([hidden]) { display: flex; position: fixed; right: 14px;
    bottom: 82px; z-index: 80; height: 44px; padding: 0 16px;
    border-radius: 22px; align-items: center; font-size: 14.5px;
    font-weight: 600; background: var(--amber-wash); color: var(--amber);
    border: 1px solid var(--amber); box-shadow: var(--shadow); }

  /* everything else: the leaf opens a big-buttoned sheet */
  #m-sheet:not([hidden]) { display: flex; flex-direction: column;
    position: fixed; inset: 0; z-index: 90; background: var(--paper); }
  .m-sheet-head { display: flex; align-items: center; justify-content:
    space-between; padding: 14px 18px; font-size: 19px; font-weight: 600;
    color: var(--ivy-deep); border-bottom: 1px solid var(--line); }
  .m-sheet-head button { font-size: 16px; padding: 6px 12px; }
  .m-sheet-rows { display: flex; flex-direction: column; gap: 10px;
    padding: 16px; overflow-y: auto; }
  .m-sheet-rows button { font-size: 16.5px; padding: 14px 16px;
    text-align: left; border-radius: 10px; }

  /* the take-over affordance (the toolbar pill is hidden here) */
  #m-pen:not([hidden]) { display: block; position: fixed; left: 14px;
    right: 84px; bottom: 18px; z-index: 79; padding: 12px 14px;
    border-radius: 10px; background: var(--amber-wash);
    border: 1px solid var(--amber); color: var(--amber);
    font-size: 13.5px; box-shadow: var(--shadow); }
}
