/* Story Loom · "Quiet studio" */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --text: #16181d;
  --muted: #545a66;
  --line: #e3e6eb;
  --line-strong: #cdd2da;
  --control: #868d9a;
  --chip: #eef0f3;
  --chip-text: #3a404c;
  --accent: #4338ca;
  --accent-strong: #3730a3;
  --accent-soft: #eef0fd;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --ok: #067647;
  --ok-soft: #ecfdf3;
  --warn: #93370d;
  --warn-soft: #fffaeb;
  --ai: #6b21a8;
  --ai-line: #8b5cf6;
  --ai-soft: #f5f0ff;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.07);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, 0.2);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Literata", "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

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

html, body, #root { height: 100%; }

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

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; }
h1 { font-size: 22px; letter-spacing: -0.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 8px; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }
code { font-family: var(--mono); font-size: 0.92em; background: var(--chip); padding: 1px 5px; border-radius: 4px; }
ul, ol { margin: 0; padding: 0; }
[hidden] { display: none !important; }

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

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
.block { display: block; }
.error-text { color: var(--danger); }
.field-error { color: var(--danger); font-size: 12.5px; margin: 4px 0 0; }
.field-hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 0; }

/* ------------------------------------------------------------------ controls */

button, input, select, textarea { font: inherit; color: inherit; }

input[type="text"], input[type="search"], input[type="number"], select, textarea {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--control);
  border-radius: var(--radius-sm);
}
textarea { resize: vertical; line-height: 1.5; }
select { padding-right: 28px; cursor: pointer; }
input:disabled, select:disabled, textarea:disabled { background: var(--chip); color: var(--muted); cursor: not-allowed; }
input::placeholder, textarea::placeholder { color: #6b7280; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 6px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--control); border-radius: var(--radius-sm);
  font-weight: 550; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--chip); color: var(--text); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #912018; color: #fff; }
.btn-small { min-height: 28px; padding: 3px 10px; font-size: 13px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; min-height: 32px; padding: 4px;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--chip); color: var(--text); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; background: transparent; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field > label, .field-label label, .field-label .label-text, .label-text { font-weight: 550; font-size: 13px; }
.field-label { display: flex; align-items: center; gap: 4px; }
.field-wide { grid-column: 1 / -1; }

.box-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0 16px; }
.box-grid-2 { grid-template-columns: 1fr 1fr; }

.fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; margin: 0 0 14px; }
.fieldset legend { padding: 0 6px; font-weight: 600; font-size: 13px; }

.radio-list, .check-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.radio, .check { display: flex; align-items: center; gap: 8px; min-height: 28px; cursor: pointer; }
.radio input, .check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

.inline-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-form label { font-weight: 550; }
.inline-form input { width: auto; flex: 1; min-width: 200px; }
.inline-pair { display: flex; gap: 6px; }

.search { max-width: 320px; }

/* segmented control */
.seg-wrap { display: inline-flex; align-items: center; gap: 6px; }
.seg-label { font-weight: 550; font-size: 13px; }
.segmented { display: inline-flex; border: 1px solid var(--control); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg { position: relative; display: inline-flex; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: inline-flex; align-items: center; min-height: 30px; padding: 3px 12px; font-size: 13px; font-weight: 550; color: var(--text); }
.seg + .seg span { border-left: 1px solid var(--line-strong); }
.seg.on span { background: var(--accent); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -4px; box-shadow: inset 0 0 0 4px #fff; }
.segmented.is-disabled { opacity: 0.55; }
.segmented.is-disabled .seg { cursor: not-allowed; }

/* chips */
.chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  padding: 1px 8px; border-radius: 999px; background: var(--chip); color: var(--chip-text); font-size: 12.5px;
}
.chip-x {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; min-height: 24px; margin: -3px -6px -3px -2px; padding: 0;
  border: 0; background: transparent; color: var(--muted); border-radius: 999px; cursor: pointer;
}
.chip-x:hover { background: var(--line-strong); color: var(--text); }
.chip-btn {
  min-height: 28px; padding: 2px 12px; border-radius: 999px;
  border: 1px solid var(--control); background: var(--surface); color: var(--text); font-size: 13px; cursor: pointer;
}
.chip-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips-input {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  min-height: 34px; padding: 4px 6px; border: 1px solid var(--control); border-radius: var(--radius-sm); background: var(--surface);
}
.chips-input input, .chips-input select { border: 0; min-height: 26px; padding: 2px 4px; flex: 1; min-width: 120px; width: auto; }
.chips-input:focus-within { outline: 2px solid var(--accent); border-color: var(--accent); }
.chips-input input:focus-visible, .chips-input select:focus-visible { outline: none; }

.badge {
  display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; font-weight: 600;
}
.badge-soft { background: var(--warn-soft); color: var(--warn); margin-left: 6px; }

/* info tip */
.tip { position: relative; display: inline-flex; }
.tip-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; padding: 0; border: 0; background: transparent; cursor: help;
  font: italic 600 12px/1 Georgia, serif; color: var(--muted);
}
.tip-btn::before {
  content: ""; position: absolute; width: 16px; height: 16px; border: 1.5px solid var(--control); border-radius: 50%;
}
.tip-btn:hover { color: var(--accent); }
.tip-bubble {
  position: fixed; left: 0; top: 0; z-index: 200;
  width: max-content; max-width: min(340px, calc(100vw - 16px)); padding: 8px 10px; border-radius: var(--radius-sm);
  background: #1f2330; color: #fff; font: 400 12.5px/1.45 var(--font); text-align: left; white-space: normal;
  box-shadow: var(--shadow-lg); visibility: hidden; opacity: 0; transition: opacity 0.12s;
  pointer-events: none;
}
/* Shown once placed inside the window (see InfoTip). */
.tip:hover .tip-bubble[data-placed], .tip-btn:focus-visible + .tip-bubble[data-placed] { visibility: visible; opacity: 1; }

/* notices */
.notice { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 12px; border-radius: var(--radius); margin: 0 0 12px; border: 1px solid; }
.notice-ok { background: var(--ok-soft); border-color: #abefc6; color: #054f31; }
.notice-warn { background: var(--warn-soft); border-color: #fedf89; color: var(--warn); }
.notice-error { background: var(--danger-soft); border-color: #fecdca; color: var(--danger); }
.notice:focus { outline: 2px solid var(--accent); }

.empty { color: var(--muted); padding: 12px 0; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 16px; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  * { transition: none !important; }
}

/* tables */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table th, .table td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table thead th { font-size: 12.5px; font-weight: 600; color: var(--muted); background: var(--surface-2); }
.table tbody tr:last-child th, .table tbody tr:last-child td { border-bottom: 0; }
.table tbody th { font-weight: 550; }
.cell-actions { text-align: right; white-space: nowrap; }
/* A table wider than the room it has (beside the Craft Guide, say) scrolls on its own, not the page. */
.table-scroll { max-width: 100%; overflow-x: auto; margin-bottom: 12px; }
.table-scroll > .table { margin-bottom: 0; }
.table tr.is-future td { color: var(--muted); }

.plain-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }

/* thumbs */
.thumb { flex: none; display: inline-block; border-radius: var(--radius-sm); object-fit: cover; background: var(--chip); }
.thumb-icon { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }

/* toasts */
.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px;
  max-width: min(320px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 14px;
  background: #1f2330; color: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.toast-error { background: #7a271a; }
.toast-text { flex: 1; }
.toast .icon-btn { color: #d0d5dd; }
.toast .icon-btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.toast .btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.5); }
.toast .btn:hover { background: rgba(255, 255, 255, 0.12); }
.toast :focus-visible { outline-color: #a5b4fc; }
/* While a dialog is open, the page's messages wait; the dialog's own show in its bottom bar, beside its buttons. */
.toasts[hidden] { display: none; }
/* In a project, the page's message shows in the top bar, beside the save status: it covers nothing. */
.topbar-messages { flex: 1 1 0; min-width: 0; display: flex; justify-content: flex-end; align-items: center; }
/* The message takes only the room left: the rest of the bar keeps its size, and the project's name gives way. */
.topbar > * { flex: none; }
.topbar > .project-name { flex: 0 1 auto; min-width: 48px; }
.topbar > .topbar-messages { flex: 1 1 0; }
.brand, .save-status { white-space: nowrap; }
.topbar:has(.topbar-messages .toast-wait:not([hidden]) .toast) .project-name { max-width: 14vw; }
.topbar-messages .toast-wait { display: flex; min-width: 0; max-width: 100%; }
.topbar-messages .toast-wait[hidden] { display: none; }
.modal-foot .modal-toasts { flex: 1 1 auto; min-width: 0; display: flex; margin-right: auto; }
.modal-foot .modal-toasts:empty { flex: 0 0 0; margin: 0; }
.modal-foot:has(.modal-toasts .toast) .modal-foot-note { display: none; }
.modal { position: relative; }
.modal-toasts-float { position: absolute; left: 20px; right: 20px; bottom: 12px; display: flex; justify-content: flex-end; pointer-events: none; }
.modal-toasts-float .toast { pointer-events: auto; }
/* A message in a bar keeps to the bar's height: two lines at most, the whole text on hover and for screen readers. */
.topbar-messages .toast, .modal-foot .toast, .modal-toasts-float .toast {
  box-shadow: none; min-width: 0; max-width: 100%; min-height: 32px; padding: 2px 4px 2px 12px; gap: 8px;
  font-size: 12.5px; line-height: 16px;
}
.topbar-messages .toast-text, .modal-foot .toast-text, .modal-toasts-float .toast-text {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-width: 0;
}
.topbar-messages .toast .btn, .modal-foot .toast .btn { min-height: 26px; padding: 2px 10px; flex: none; }
/* The newest message shows; the others still alive, and the whole of a long one, are behind a button. */
.messages { position: relative; display: flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
.messages-more {
  flex: none; min-height: 28px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.messages-more:hover { background: var(--chip); }
.messages-more[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.messages-list {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 210; width: min(440px, calc(100vw - 32px));
  max-height: min(60vh, 360px); overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.messages-list[hidden] { display: none; }
.messages-list-up { top: auto; bottom: calc(100% + 8px); right: auto; left: 0; }
.messages-list .toast, .topbar-messages .messages-list .toast, .modal-foot .messages-list .toast { padding: 6px 6px 6px 12px; }
.topbar-messages .toast-full .toast-text, .modal-foot .toast-full .toast-text, .toast-full .toast-text {
  display: block; -webkit-line-clamp: unset; overflow: visible;
}
.topbar-messages .toast .icon-btn, .modal-foot .toast .icon-btn { min-width: 26px; min-height: 26px; padding: 2px; flex: none; }
.tip-more { white-space: nowrap; opacity: 0.8; }
.tip-more svg { vertical-align: -2px; }

/* menu */
.menu-wrap { position: relative; display: inline-flex; }
.menu {
  position: absolute; top: calc(100% + 4px); z-index: 60; min-width: 220px; padding: 4px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.menu-end { right: 0; }
.menu-start { left: 0; }
.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 32px; padding: 6px 10px;
  border: 0; background: transparent; border-radius: var(--radius-sm); text-align: left; cursor: pointer; color: var(--text);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--accent-soft); color: var(--accent-strong); outline: none; }
.menu-item:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover, .menu-item.danger:focus-visible { background: var(--danger-soft); color: var(--danger); }
.menu-item[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 16px; background: rgba(16, 20, 30, 0.45); overflow-y: auto;
}
.modal {
  width: 100%; max-width: 520px; display: flex; flex-direction: column; max-height: 88vh;
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.modal:focus { outline: none; }
.modal-wide { max-width: 920px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 10px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 12px 12px; }
.modal-foot-note { margin-right: auto; }

/* ------------------------------------------------------------------ start pages */

.center-page { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.center-card { max-width: 560px; background: var(--surface); padding: 32px; border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.center-card h1 { margin-bottom: 12px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
  border-radius: 8px; background: var(--accent); color: #fff; margin-bottom: 8px;
}
.center-card .brand-mark { width: 44px; height: 44px; border-radius: 10px; margin-bottom: 16px; }

.home { max-width: 960px; margin: 0 auto; padding: 32px 24px 64px; }
.home-head { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.home-head .brand-mark { width: 44px; height: 44px; margin: 0; border-radius: 10px; }
.home-app { font-size: 18px; font-weight: 700; margin: 0; }
.home-main:focus { outline: none; }
.home-main h1 { margin-bottom: 16px; }
.home-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.home-actions .inline-form { flex: 1; }
.project-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.project-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.project-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.project-title { font-size: 15px; font-weight: 600; color: var(--text); text-decoration: none; }
.project-title:hover { color: var(--accent); text-decoration: underline; }

/* ------------------------------------------------------------------ app frame */

.app { display: grid; grid-template-columns: 76px minmax(0, 1fr); grid-template-rows: 48px minmax(0, 1fr); height: 100vh; }

.skip-link {
  position: fixed; left: 8px; top: 8px; z-index: 300; padding: 8px 14px; border-radius: var(--radius-sm);
  border: 0; background: var(--accent); color: #fff; font-weight: 600; transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

.topbar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 0 12px 0 14px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 700; }
.brand .brand-mark { width: 28px; height: 28px; margin: 0; border-radius: 7px; }
.brand:hover { color: var(--accent); }
.crumb-sep { color: var(--line-strong); font-size: 18px; }
.project-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: min(24vw, 360px); }
.save-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-right: 6px; }
.save-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.save-busy .save-dot { background: var(--accent); }
.save-error { color: var(--danger); }
.save-error .save-dot { background: var(--danger); }

.rail { grid-row: 2; display: flex; flex-direction: column; gap: 4px; padding: 10px 8px; background: var(--surface); border-right: 1px solid var(--line); }
.rail-link {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 2px;
  border-radius: var(--radius); color: var(--muted); text-decoration: none; font-size: 11.5px; font-weight: 600;
}
.rail-link:hover { background: var(--chip); color: var(--text); }
.rail-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); }

.workspace { grid-row: 2; grid-column: 2; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.page { flex: 1; min-height: 0; overflow: auto; }
.page:focus { outline: none; }
.page-write, .page-wiki, .page-inspiration { overflow: hidden; }

/* context bar */
.context-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 8px 14px;
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.ctx-group { display: flex; align-items: center; gap: 6px; }
.ctx-label { font-weight: 550; font-size: 13px; color: var(--muted); }
.ctx-select { width: auto; max-width: 260px; min-height: 32px; padding-top: 4px; padding-bottom: 4px; }
.ctx-point .ctx-select { min-width: 200px; }
.ctx-summary { margin: 0; font-size: 12.5px; flex-basis: 100%; }
@media (min-width: 1680px) { .ctx-summary { flex-basis: auto; margin-left: auto; } }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-tools { display: flex; gap: 8px; align-items: center; }
.view-line { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; margin: 4px 0 12px; }

/* ------------------------------------------------------------------ inspiration */

.inspiration { display: grid; grid-template-columns: minmax(0, 1fr) 280px; height: 100%; }
.board { overflow-y: auto; padding: 20px 24px 40px; }
.hint { margin: 0 0 10px; }
.tag-filter { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.asset-grid { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; border-radius: var(--radius); }
.asset-grid.is-over { outline: 2px dashed var(--accent); outline-offset: 6px; }
.asset-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: visible; box-shadow: var(--shadow); cursor: grab; }
.asset-card:active { cursor: grabbing; }
.asset-img { aspect-ratio: 4 / 3; background: var(--chip); border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
.asset-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.asset-meta { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.asset-name { margin: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-credit { margin: 0; overflow-wrap: anywhere; }
.tag-list, .link-list { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; }
.chip-link { background: var(--accent-soft); color: var(--accent-strong); }
.chip-link a { color: inherit; text-decoration: none; font-weight: 550; }
.chip-link a:hover { text-decoration: underline; }

.drop-panel { overflow-y: auto; padding: 20px 16px; background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.drop-panel h3 { margin-top: 10px; font-size: 13px; color: var(--muted); }
.drop-target {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px 12px;
  border: 1.5px dashed var(--control); border-radius: var(--radius); color: var(--text); font-weight: 550; background: var(--surface);
}
.drop-new { min-height: 54px; font-size: 14.5px; }
.drop-target.is-over { border-style: solid; border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
.drop-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.drop-list .drop-target { min-height: 36px; padding: 4px 10px; border-width: 1px; font-weight: 500; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 24px; margin-bottom: 14px;
  border: 2px dashed var(--control); border-radius: 12px; text-align: center; color: var(--muted); background: var(--surface);
}
.dropzone p { margin: 0; }
.dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
.dropzone-big { padding: 56px 24px; }
.import-list { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; max-height: 240px; overflow-y: auto; }
.import-list li { display: flex; align-items: center; gap: 10px; padding: 4px 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.import-list img, .import-bad { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; background: var(--chip); display: inline-flex; align-items: center; justify-content: center; color: var(--danger); }
.import-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-list .has-problem { border-color: #fecdca; background: var(--danger-soft); }

/* ------------------------------------------------------------------ wiki */

.wiki { display: grid; grid-template-columns: 264px minmax(0, 1fr); height: 100%; }
.wiki-list { overflow-y: auto; padding: 14px 10px 28px; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.wiki-list .search { max-width: none; }
.wiki-list-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.wiki-home { display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-weight: 600; }
.wiki-home:hover { background: var(--chip); }
.wiki-home.is-current { background: var(--accent-soft); color: var(--accent-strong); }
.wiki-group-title { display: flex; align-items: center; gap: 6px; padding: 0 6px; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 4px; }
.count { display: inline-flex; min-width: 20px; justify-content: center; padding: 0 6px; border-radius: 999px; background: var(--chip); color: var(--chip-text); font-size: 11.5px; font-weight: 600; letter-spacing: 0; text-transform: none; margin-left: 4px; }
.wiki-group ul { list-style: none; }
.wiki-none { padding: 0 6px; }
.wiki-item { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; min-height: 36px; }
.wiki-item:hover { background: var(--chip); }
.wiki-item.is-current { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.wiki-item-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.wiki-content { overflow-y: auto; }
.wiki-page { padding: 20px 28px 48px; max-width: 1400px; }
.entity-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.entity-portrait { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.entity-head .thumb-icon { width: 72px !important; height: 72px !important; border-radius: 10px; }
.entity-title { flex: 1; min-width: 0; }
.entity-title h1 { overflow-wrap: anywhere; }
.eyebrow { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 2px; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.entity-actions { display: flex; align-items: center; gap: 8px; }
.entity-body { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.entity-body-capture { grid-template-columns: minmax(0, 640px); }
.entity-main { min-width: 0; }
.card-section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px 6px; margin-bottom: 16px; }
.card-section > h2, .card-section > h3 { display: flex; align-items: center; gap: 4px; margin-bottom: 12px; }
.card-section .table { margin-bottom: 12px; }
.capture-form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 6px; }

.artwork { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.artwork li { position: relative; }
.artwork img { width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--line); display: block; }
.artwork-x { position: absolute; top: 2px; right: 2px; min-width: 24px; min-height: 24px; background: rgba(255, 255, 255, 0.92); color: var(--text); }

.at-point { position: sticky; top: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 16px 18px; }
.at-point h2 { margin-bottom: 2px; }
.at-point h3 { margin: 16px 0 6px; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.at-point .btn { margin-top: 8px; }
.states { margin: 0; display: flex; flex-direction: column; }
.state-row { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.state-row:last-child { border-bottom: 0; }
.state-row dt { color: var(--muted); font-size: 13px; }
.state-row dd { margin: 0; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.state-value { font-weight: 600; overflow-wrap: anywhere; }
.prov { font-size: 12px; color: var(--muted); }
.evidence { display: block; font-style: italic; color: var(--muted); font-size: 12px; }
.rels li { display: flex; flex-direction: column; }
.statements li { line-height: 1.45; }
.life { font-weight: 600; text-transform: capitalize; }
.life-dead { color: var(--danger); }
.life-missing, .life-unknown { color: var(--warn); }
.life-alive { color: var(--ok); }
.empty-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.empty-panel .button-row { margin-top: 12px; }
.entity-chip { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }

/* ------------------------------------------------------------------ write */

.write { display: grid; grid-template-columns: 268px minmax(0, 1fr) 344px; height: 100%; }
@media (min-width: 1600px) { .write { grid-template-columns: 300px minmax(0, 1fr) 400px; } }

.tree-panel { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.tree-head { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 14px 6px; }
.tree-tools { display: flex; gap: 6px; padding: 0 12px 10px; border-bottom: 1px solid var(--line); }
.tree-tools .btn { flex: 1; padding: 3px 6px; gap: 3px; }
.tree { list-style: none; flex: 1; overflow-y: auto; padding: 8px 6px; }
.tree ul { list-style: none; }
.tree-item { outline: none; }
.tree-item:focus-visible > .tree-row { outline: 2px solid var(--accent); outline-offset: -2px; }
.tree-row {
  position: relative; display: flex; align-items: center; gap: 6px; min-height: 30px; padding: 3px 8px 3px 4px;
  border-radius: var(--radius-sm); cursor: pointer; user-select: none;
}
.tree-row:hover { background: var(--chip); }
.tree-row.is-current { background: var(--chip); }
.tree-row.is-selected { background: var(--accent-soft); color: var(--accent-strong); }
.tree ul .tree-row { padding-left: 20px; }
.tree ul ul .tree-row { padding-left: 36px; }
.tree ul ul ul .tree-row { padding-left: 52px; }
.kind-part .tree-label { font-weight: 700; text-transform: uppercase; font-size: 12px; letter-spacing: 0.04em; }
.kind-chapter .tree-label { font-weight: 650; }
.twisty { display: inline-flex; width: 16px; justify-content: center; color: var(--muted); }
/* Every dot keeps at least 3:1 contrast against white, hover and selected rows. */
.status-dot { flex: none; width: 8px; height: 8px; margin: 0 4px; border-radius: 50%; background: #727885; }
.status-outline { background: #7a5af8; }
.status-draft { background: #c4540a; }
.status-revised { background: #3e63dd; }
.status-final { background: var(--ok); }
.tree-label { flex: 1; min-width: 0; display: flex; gap: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tree-label > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.tree-num { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.tree-row.is-selected .tree-num { color: var(--accent); }
.untitled { color: var(--muted); font-style: italic; }
.tree-flag { color: var(--accent); display: inline-flex; }
.tree-words { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.tree-row.drop-before::before, .tree-row.drop-after::after {
  content: ""; position: absolute; left: 8px; right: 8px; height: 2px; background: var(--accent); border-radius: 2px;
}
.tree-row.drop-before::before { top: -1px; }
.tree-row.drop-after::after { bottom: -1px; }
.tree-row.drop-inside { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.rename-input { min-height: 26px; padding: 2px 6px; }
.tree-empty { padding: 20px 14px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.tree-actions { display: flex; align-items: center; gap: 2px; padding: 6px 8px; border-top: 1px solid var(--line); background: var(--surface-2); }
.tree-current { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; }

.editor { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.editor-head { display: flex; align-items: center; gap: 12px; padding: 14px 24px 8px; max-width: 820px; width: 100%; margin: 0 auto; }
.editor-label { color: var(--muted); font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
input.title-input { border-color: transparent; border-bottom-color: var(--control); border-radius: 0; background: transparent; font-size: 20px; font-weight: 650; padding: 4px 8px; min-height: 38px; }
input.title-input:hover { border-color: var(--line-strong); }
input.title-input:focus-visible { border-color: var(--accent); }
.editor-notice { margin: 0 24px 8px; }
.editor-paper { flex: 1; min-height: 0; display: flex; justify-content: center; padding: 0 24px; }
.prose {
  width: 100%; max-width: 820px; height: 100%; resize: none;
  padding: 36px 56px 48px; border: 1px solid var(--line); border-bottom: 0; border-radius: 10px 10px 0 0;
  background: var(--surface); box-shadow: var(--shadow);
  font: 18px/1.75 var(--serif); color: #1d1f24;
}
.prose:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.editor-foot { display: flex; align-items: center; gap: 14px; padding: 8px 24px; border-top: 1px solid var(--line); background: var(--surface); font-size: 13px; }
.save-text { color: var(--muted); }
.save-dirty { color: var(--warn); }
.save-error, .save-conflict { color: var(--danger); font-weight: 600; }

.write-empty { grid-column: 2 / 4; padding: 48px; }
.write-empty h1 { margin-bottom: 8px; }

.scene-panel { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; padding: 8px 10px 0; border-bottom: 1px solid var(--line); }
.tab {
  display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 6px 12px;
  background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--accent-strong); border-bottom-color: var(--accent); }
.tab-panel { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 14px 32px; }

.cast-list { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.cast-list li { display: grid; grid-template-columns: minmax(0, 1fr) 128px 32px; gap: 6px; align-items: center; }
.cast-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.cast-list select { min-height: 30px; padding: 3px 24px 3px 8px; }
.add-row { display: grid; grid-template-columns: minmax(0, 1fr) 112px auto; gap: 6px; align-items: center; }
.add-row select { min-height: 30px; padding: 3px 24px 3px 8px; }

.route-list { list-style: none; display: flex; flex-direction: column; gap: 8px; margin: 12px 0 16px; }
.route-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; }

.events-head { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-bottom: 10px; }
.event-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.event-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--surface); }
.event-card.is-target { box-shadow: 0 0 0 3px var(--accent); transition: box-shadow 0.3s; }
.event-card:focus { outline: none; }
.event-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.event-head { display: flex; align-items: flex-start; gap: 6px; }
.event-title { flex: 1; font-size: 14px; padding-top: 6px; overflow-wrap: anywhere; }
.event-tools { display: flex; flex: none; }
.event-tools .icon-btn { min-width: 28px; min-height: 28px; }
.event-desc { color: var(--muted); font-size: 13px; margin: 4px 0 6px; }
.event-facts { display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 4px 8px; margin: 6px 0 0; font-size: 13px; }
.event-facts dt { color: var(--muted); }
.event-facts dd { margin: 0; overflow-wrap: anywhere; }

.revision-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.revision-list li { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.revision-list li.is-current { border-color: var(--accent); background: var(--accent-soft); }
.revision-preview { color: var(--muted); font-family: var(--serif); margin: 6px 0 8px; overflow-wrap: anywhere; }
.revision-text { white-space: pre-wrap; font: 16px/1.7 var(--serif); padding: 16px 20px; border: 1px solid var(--line); border-radius: var(--radius); max-height: 55vh; overflow-y: auto; background: var(--surface-2); }

/* event editor */
.event-editor section { padding: 4px 0 14px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.event-editor section:last-child { border-bottom: 0; margin-bottom: 0; }
.event-editor h3 { font-size: 15px; margin-bottom: 8px; }
.section-head { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.section-head h3 { margin: 0; }
.rows { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.row { display: grid; gap: 0 10px; align-items: end; padding: 10px 10px 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.row .field { margin-bottom: 10px; }
.row-x { margin-bottom: 10px; }
.row-2 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) 32px; }
.row-4 { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 1.4fr) 32px; }
.row-3 { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1.4fr) 32px; }
.row-interaction { grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) minmax(0, 1fr) 128px 32px; }
.row-interaction .field-wide { grid-column: 1 / 5; }
.row-knowledge { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)) 32px; }

@media (max-width: 1400px) {
  .write { grid-template-columns: 248px minmax(0, 1fr) 320px; }
  .prose { padding: 28px 36px 40px; }
  .entity-body { grid-template-columns: minmax(0, 1fr) 300px; }
}

/* ================================================================== the living wiki (AI) */

/* Anything the AI proposed that still waits for review: dotted underline plus the "AI proposal" mark. */
.provisional { text-decoration: underline dotted var(--ai-line); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.ai-mark {
  display: inline-flex; align-items: center; gap: 3px; padding: 0 6px; border-radius: 999px; vertical-align: 1px;
  background: var(--ai-soft); color: var(--ai); border: 1px dashed var(--ai-line); font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.ai-mark-compact { padding: 0 3px; }
.badge-ai-ok { background: var(--chip); color: var(--chip-text); margin-left: 6px; }
.table tr.is-proposal td { background: var(--ai-soft); }
.item-reason { display: block; color: var(--muted); font-size: 12px; }
.notice-info { background: #eff4ff; border-color: #c7d7fe; color: #1d2b6b; }
.ok-text { color: var(--ok); }
.nowrap { white-space: nowrap; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; text-align: left; }

/* top bar chip and rail badge */
.ai-chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 550;
  text-decoration: none; background: var(--chip); color: var(--chip-text); white-space: nowrap;
}
.ai-chip:hover { text-decoration: underline; color: var(--text); }
.ai-chip-busy { background: var(--accent-soft); color: var(--accent-strong); }
.ai-chip-waiting { background: var(--ai-soft); color: var(--ai); }
.ai-chip-warn { background: var(--warn-soft); color: var(--warn); }
.ai-chip-off { color: var(--muted); }
.rail-link { position: relative; }
.rail-badge {
  position: absolute; top: 4px; right: 8px; min-width: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--ai); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* the editor: names highlighted behind a transparent textarea */
.prose-wrap { position: relative; width: 100%; max-width: 820px; height: 100%; }
.prose-wrap .prose {
  position: absolute; inset: 0; max-width: none; height: auto; overflow-y: scroll; overflow-x: hidden;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; tab-size: 4; letter-spacing: normal;
}
.prose-backdrop { color: transparent; pointer-events: none; user-select: none; margin: 0; }
/* A highlight takes no room of its own: no padding, margin or border, or the backdrop would wrap differently. */
.prose-backdrop mark { padding: 0; margin: 0; border: 0; font: inherit; letter-spacing: inherit; }
.prose-input { background: transparent; box-shadow: none; z-index: 1; caret-color: #1d1f24; }
.prose-input:focus-visible { box-shadow: 0 0 0 1px var(--accent); }
/* The underline marks a name: drawn at full strength so it stands out at 3:1 or more against the page. */
.name-mark { color: transparent; background: rgba(67, 56, 202, 0.08); border-radius: 3px; box-shadow: inset 0 -2px 0 #4338ca; }
.name-place { background: rgba(6, 118, 71, 0.08); box-shadow: inset 0 -2px 0 #067647; }
.name-object { background: rgba(181, 71, 8, 0.08); box-shadow: inset 0 -2px 0 #b54708; }
.name-linked { box-shadow: inset 0 -2px 0 var(--ai-line); }
.names-line { max-width: 820px; width: calc(100% - 48px); margin: 6px auto 0; color: var(--text); overflow-wrap: anywhere; }

.hover-card {
  position: fixed; z-index: 220; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 10px 12px; font-size: 13px; max-height: 60vh; overflow-y: auto;
}
.hover-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.hover-title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.hover-values { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 10px; margin: 0 0 6px; }
.hover-values > div { display: contents; }
.hover-values dt { color: var(--muted); }
.hover-values dd { margin: 0; overflow-wrap: anywhere; }
.hover-sub { font-weight: 600; font-size: 12px; margin: 8px 0 2px; color: var(--muted); }
.hover-foot { margin: 8px 0 0; }

.link-strip { max-width: 820px; width: calc(100% - 48px); margin: 8px auto 0; padding: 8px 10px; border: 1px dashed var(--ai-line); border-radius: var(--radius); background: var(--ai-soft); }
.link-strip-title { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; color: var(--ai); font-size: 13px; }
.link-strip ul { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.link-strip li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; }
.link-strip li > span { flex: 1; min-width: 180px; }

.ai-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.ai-status-busy { color: var(--accent-strong); }
.ai-status-warn { color: var(--warn); }
.ai-waiting { font-weight: 600; color: var(--ai); }

/* scene card and events */
.suggest-box, .digest-box { border: 1px dashed var(--ai-line); background: var(--ai-soft); border-radius: var(--radius); padding: 8px 10px; margin: 0 0 12px; }
.suggest-title { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--ai); margin: 0 0 6px; }
.suggest-list { list-style: none; display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; }
.suggest-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto 30px 30px; gap: 4px; align-items: center; }
.digest { font-family: var(--serif); font-size: 14px; margin: 0 0 6px; }
.digest-box details { margin-top: 4px; }
.tree-ai { display: inline-flex; align-items: center; gap: 1px; padding: 0 5px; border-radius: 999px; background: var(--ai-soft); color: var(--ai); font-size: 11px; font-weight: 600; }
.tree-recheck { color: var(--warn); display: inline-flex; }
.tree-timecheck { color: var(--warn); display: inline-flex; }
.time-check { align-items: flex-start; }
.time-check > div { flex: 1 1 260px; min-width: 0; }
.time-check p { margin: 0 0 8px; }
.event-card.event-waiting { border-style: dashed; border-color: var(--ai-line); }
.event-card li.is-proposal { padding-left: 2px; }
.verdict-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }

/* the AI page */
.page-ai { overflow: auto; }
.ai-page { max-width: 1080px; margin: 0 auto; padding: 20px 24px 48px; }
.ai-head { flex-direction: column; align-items: stretch; gap: 8px; }
.ai-head h1 { margin: 0; }
.ai-head p { margin: 0; }
.ai-head .notice { margin: 0; }
.ai-tabs { padding: 0; margin-bottom: 16px; }
.ai-tabs .tab { text-decoration: none; }
.meter-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.meter-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-bottom: 8px; }
.meter { position: relative; height: 10px; border-radius: 999px; background: var(--chip); overflow: visible; }
.meter-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--accent); }
.meter-fill.meter-ok { background: var(--ok); }
.meter-fill.meter-warn { background: var(--danger); }
.meter-target { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); }
.meter-card .notice { margin: 10px 0 0; }
.bulk-row { justify-content: space-between; margin-bottom: 12px; }
.proposal-scene-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.proposal-scene-head h2 { margin: 0; font-size: 16px; }
.proposal-event { border-top: 1px solid var(--line); padding: 10px 0 8px; }
.proposal-event h3 { font-size: 14px; margin: 0 0 2px; }
.proposal-items { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.proposal-items li { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; justify-content: space-between; }
.proposal-text { flex: 1; min-width: 240px; }
.proposal-actions { display: flex; gap: 6px; flex: none; }
.checks { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.checks li { display: inline-flex; align-items: center; gap: 3px; padding: 0 6px; border-radius: 999px; font-size: 11.5px; }
.check-ok { background: var(--ok-soft); color: #054f31; }
.check-doubt { background: var(--warn-soft); color: var(--warn); }
.candidate-list { list-style: none; display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.candidate { display: flex; flex-wrap: wrap; gap: 10px 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.candidate:last-child { border-bottom: 0; }
.candidate-main { flex: 1; min-width: 240px; }
.candidate-name { margin: 0 0 2px; }
.candidate-actions { display: flex; flex-direction: column; gap: 6px; flex: 0 1 430px; }
.candidate-create, .candidate-merge { display: flex; gap: 6px; align-items: center; }
.candidate-create input { flex: 1; min-height: 30px; }
.candidate-create select, .candidate-merge select { min-height: 30px; padding-top: 3px; padding-bottom: 3px; width: auto; flex: 1; }
.alert-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.alert-item { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--warn); border-radius: var(--radius); }
.alert-kind { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; color: var(--warn); font-size: 13px; }
.run { font-weight: 600; }
.run-failed, .run-capped { color: var(--danger); }
.run-done { color: var(--ok); }
.call-list { list-style: none; display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.call summary { display: flex; flex-wrap: wrap; gap: 4px 12px; cursor: pointer; padding: 6px 8px; border-radius: var(--radius-sm); font-size: 13px; }
.call summary:hover { background: var(--chip); }
.call-body { padding: 4px 8px 10px; }
.call-body pre { white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.5 var(--mono); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px; max-height: 240px; overflow-y: auto; margin: 2px 0 8px; }
.provider-list { list-style: none; display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.provider p { margin: 4px 0 0 46px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 36px; height: 20px; margin: 0; cursor: pointer; }
.switch-track { position: relative; width: 36px; height: 20px; border-radius: 999px; background: var(--control); flex: none; transition: background 0.15s; pointer-events: none; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.auto-list { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.auto-list li { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; }
.auto-list .check { min-width: 300px; }
.inline-field { max-width: 320px; }
.table.golden td, .table.golden th { white-space: nowrap; }

.ai-settings input[type="number"] { max-width: 200px; }
.notice-text { flex: 1 1 300px; min-width: 0; }
.editor-ai { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; max-width: 820px; width: calc(100% - 48px); margin: 6px auto 0; }
.candidate-row-label { font-size: 12px; color: var(--muted); min-width: 64px; }
.row-proposal { border-color: var(--ai-line); border-style: dashed; background: var(--ai-soft); }
.row-proposal-label { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 4px; }
.suggest-quote { grid-column: 1 / -1; margin: -2px 0 4px; }

/* A quoted sentence of the scene, shown as evidence. */
.evidence-quote { font-style: italic; }
.notice-actions { display: flex; gap: 8px; }

kbd {
  font-family: var(--mono);
  font-size: 0.85em;
  padding: 0 0.3em;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--chip);
  color: var(--text);
}

/* ================================================================== build 3: the story layer */

/* The signed-out dialog uses the same backdrop as every modal. */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300; display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 16px; background: rgba(16, 20, 30, 0.45); overflow-y: auto;
}

.strong { font-weight: 600; }

/* search in the top bar */
.search-btn { gap: 6px; color: var(--muted); }
.search-btn kbd { font-size: 10.5px; }
@media (max-width: 960px) { .search-btn kbd { display: none; } }

/* ------------------------------------------------------------------ meters and box status */

.meter-wrap { display: flex; flex-direction: column; gap: 4px; min-width: min(180px, 100%); }
.meter-wrap .meter { height: 8px; }
.meter-text { color: var(--muted); }
.meter-text strong { color: var(--warn); font-weight: 600; }
.card-meter { padding: 10px 12px; margin: 0 0 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.card-meter-head { display: flex; align-items: center; gap: 2px; margin-bottom: 4px; }
.open-fold { margin-top: 6px; }
.open-fold > summary { cursor: pointer; font-size: 12.5px; font-weight: 550; color: var(--accent); width: max-content; }
.open-fold > summary:hover { text-decoration: underline; }
.open-boxes { list-style: none; display: flex; flex-direction: column; gap: 3px; margin: 6px 0 2px; font-size: 13px; }
.card-meter .open-boxes { max-height: 220px; overflow-y: auto; padding-right: 4px; }
.open-boxes li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.weight-dots { flex: none; color: var(--accent); font-size: 9px; letter-spacing: 1px; }
.open-boxes .weight-1 .weight-dots { color: var(--muted); }
.mini-meter { flex: none; width: 34px; height: 4px; margin-left: auto; border-radius: 999px; background: var(--chip); overflow: hidden; }
.mini-meter > span { display: block; height: 100%; background: var(--accent); }
.status-badge {
  display: inline-flex; align-items: center; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--chip); color: var(--chip-text); white-space: nowrap;
}
.status-badge.status-na { background: #f2f4f7; color: #475467; }
.status-badge.status-empty { background: var(--ok-soft); color: #054f31; }
.field-label .menu-wrap .icon-btn { width: 24px; height: 24px; min-width: 24px; min-height: 24px; }

/* ------------------------------------------------------------------ the scene card */

.scene-card .fieldset > legend { display: inline-flex; align-items: center; gap: 2px; }
.fold { padding: 0; }
.fold > summary {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; padding: 9px 12px; cursor: pointer;
  border-radius: var(--radius); list-style-position: inside;
}
.fold > summary:hover { background: var(--chip); }
.fold-title { font-weight: 600; font-size: 13px; }
.fold[open] > summary { border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; margin-bottom: 10px; }
.fold > .box-grid { padding: 0 12px 2px; }
.box-slot { min-width: 0; }
.scene-card .box-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.lens-block { padding: 8px 0; border-top: 1px solid var(--line); }
.lens-block:first-of-type { border-top: 0; padding-top: 2px; }
.lens-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.chip-list { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.beat-chip { background: var(--accent-soft); color: var(--accent-strong); font-weight: 550; padding-right: 2px; }
.beat-chip .icon-btn { width: 24px; height: 24px; min-width: 24px; min-height: 24px; margin: -3px 0; color: var(--accent-strong); }
.beat-near { margin: 2px 0 6px; }
.lens-block select { max-width: 280px; }
.marker-list { list-style: none; display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.marker-list .marker { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 4px 4px 4px 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.marker-kind {
  display: inline-flex; align-items: center; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 650;
  background: var(--chip); color: var(--chip-text);
}
.marker-promise .marker-kind { background: #eff8ff; color: #175cd3; }
.marker-progress .marker-kind { background: var(--warn-soft); color: var(--warn); }
.marker-payoff .marker-kind { background: var(--ok-soft); color: #054f31; }
.marker-thread { font-weight: 600; }
.marker-note { flex: 1 1 100%; color: var(--muted); }
.marker-list .menu-wrap { margin-left: auto; }
.marker-add { margin-bottom: 4px; }

/* beats in the manuscript tree */
.tree-beats { display: inline-flex; align-items: center; gap: 1px; flex: none; color: var(--accent); font-size: 11px; font-weight: 600; }

/* ------------------------------------------------------------------ overview */

.overview, .foundation, .story { max-width: 1120px; margin: 0 auto; padding: 20px 24px 48px; }
.overview .page-head { flex-direction: column; align-items: flex-start; gap: 2px; }
.overview .page-head h1, .story .page-head h1 { display: inline-flex; align-items: center; gap: 4px; }
.logline { margin: 0 0 12px; padding: 10px 16px; border-left: 3px solid var(--accent); background: var(--accent-soft); font: 16px/1.5 var(--serif); border-radius: 0 var(--radius) var(--radius) 0; }
.premise-parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px 16px; margin: 0 0 12px; }
.premise-parts dt { font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.premise-parts dd { margin: 0; }
.overview-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 16px; align-items: start; }
.next-steps { margin: 0 0 12px 20px; display: flex; flex-direction: column; gap: 6px; }
.next-steps li { padding-left: 2px; }
.questions, .recent { margin-bottom: 12px; }

/* ------------------------------------------------------------------ the story foundation */

.foundation .page-head { align-items: flex-end; }
.page-head-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.foundation-mode { max-width: 880px; }
.foundation-mode > h1 { margin-bottom: 8px; }

.lens-board-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; }
.propose-list li { padding: 4px 0; }
.lens-offer { margin-left: auto; }

.tracked-note { margin: -4px 0 12px; }
.tracked-note p { margin: 0 0 4px; }
.tracked-note .is-here { font-weight: 600; }

/* Capture, Develop and Review (F05) */
.mode-switch { display: flex; align-items: center; gap: 2px; margin: 0 0 12px; }
.entity-actions .mode-switch, .page-head-row .mode-switch { margin: 0; }
.scene-review .card-section, .event-review .card-section { margin-bottom: 14px; }
.scene-review h3 { font-size: 14px; margin-bottom: 6px; }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 0 0 14px; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; }
.event-review h3 { margin-top: 12px; }
.foundation .page-head .meter-wrap { min-width: 260px; }
.wizard { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.stepper ol { list-style: none; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; }
.stepper a {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-size: 13.5px;
}
.stepper a:hover { background: var(--chip); }
.stepper a.is-current { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.step-num {
  flex: none; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  border-radius: 50%; border: 1.5px solid var(--control); color: var(--muted); font-size: 11.5px; font-weight: 650;
}
.stepper a.is-current .step-num { border-color: var(--accent); color: var(--accent-strong); }
.stepper a.is-done .step-num { background: var(--ok); border-color: var(--ok); color: #fff; }
.wizard-step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 22px 16px; min-width: 0; }
.wizard-step > h1 { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 19px; margin-bottom: 6px; }
.wizard-step > h1:focus { outline: none; }
.wizard-step > p.muted { max-width: 70ch; margin-bottom: 16px; }
.foundation-boxes { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.foundation-boxes > div > .btn { margin: -4px 0 12px; }
.wizard-nav { display: flex; justify-content: space-between; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.wizard-step .card-section { margin-top: 8px; background: var(--surface-2); }
.genre-list { list-style: none; display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.genre-list > li { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.genre-list > li.is-done { border-color: #abefc6; }
.genre-text { font-weight: 550; margin-bottom: 6px; }
.genre-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 6px; }
.genre-controls select { width: auto; min-width: 220px; max-width: 100%; }
.lens-switches { list-style: none; display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.lens-switches p { margin: 4px 0 0 46px; }
.lens-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.lens-row .menu-wrap { margin-left: auto; }
.lens-switches p.lens-note { color: var(--accent-strong); font-weight: 500; }
.lens-switches p.lens-note:empty { margin: 0; }

@media (max-width: 860px) {
  .wizard { grid-template-columns: minmax(0, 1fr); }
  .stepper ol { position: static; flex-direction: row; flex-wrap: wrap; }
}

/* ------------------------------------------------------------------ the story page: beats and threads */

.story-head h1 { margin-right: 8px; }
.story-head { justify-content: flex-start; }
.profile-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.lenses-tab .inline-form { margin-bottom: 12px; }
.beat-editor input { min-height: 30px; }
.beat-editor td:nth-child(2) input, .beat-editor td:nth-child(3) input { width: 80px; }
.beat-editor caption { caption-side: top; text-align: left; padding: 0 0 6px; font-size: 12.5px; color: var(--muted); }
.beat-bar { position: relative; height: 34px; margin: 4px 0 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.beat-bar-scene { position: absolute; top: 0; bottom: 0; border-right: 1px solid var(--line-strong); }
.beat-band { position: absolute; top: 6px; height: 10px; border-radius: 3px; background: #d0d5dd; }
.beat-pin { position: absolute; bottom: 4px; width: 3px; height: 12px; margin-left: -1px; border-radius: 2px; background: var(--accent); }
.beat-band.beat-on_target, .beat-pin.beat-on_target { background: var(--ok); }
.beat-band.beat-early, .beat-pin.beat-early, .beat-band.beat-late, .beat-pin.beat-late { background: #dc6803; }
.beat-band.beat-unlinked { background: #d0d5dd; }
.beat-status { display: inline-flex; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--chip); color: var(--chip-text); }
.beat-status.beat-on_target { background: var(--ok-soft); color: #054f31; }
.beat-status.beat-early, .beat-status.beat-late { background: var(--warn-soft); color: var(--warn); }
.table.beats th[scope="row"] { white-space: nowrap; }
.table.beats td:nth-child(2) { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.chips .chip a { color: inherit; }
.in-range { margin: 2px 0 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.btn-tiny { min-height: 24px; padding: 0 8px; font-size: 12px; }
.select-small { width: auto; max-width: 240px; min-height: 30px; padding-top: 3px; padding-bottom: 3px; font-size: 13px; }

.threads { list-style: none; display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.thread-card { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.thread-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 4px; }
.lane-badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 24px; padding: 0 6px; border-radius: 6px;
  font-size: 11.5px; font-weight: 700; background: var(--chip); color: var(--chip-text);
}
.lane-A { background: #eef4ff; color: #3538cd; }
.lane-B { background: #fdf2fa; color: #c11574; }
.lane-C { background: #f0fdf9; color: #107569; }
.markers { list-style: none; display: flex; flex-direction: column; gap: 2px; margin: 6px 0; }
.markers .marker { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 13px; }
.checks-list { list-style: none; display: flex; flex-direction: column; gap: 2px; margin: 6px 0; color: var(--warn); font-size: 13px; }
.checks-list li { display: flex; align-items: center; gap: 6px; }
.add-marker { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.lanes-scroll { overflow-x: auto; margin-bottom: 12px; border-radius: var(--radius); }
.lanes-scroll:focus-visible { outline: 2px solid var(--accent); }
.table.lanes { width: auto; min-width: 100%; }
.table.lanes th, .table.lanes td { padding: 6px 8px; text-align: center; white-space: nowrap; }
.table.lanes th[scope="row"] { text-align: left; position: sticky; left: 0; background: var(--surface); }
.table.lanes thead th { font-weight: 550; }
.lane-main { color: var(--accent-strong); font-weight: 700; }
.lane-marked { color: var(--muted); }

/* ------------------------------------------------------------------ search */

.search-box { display: flex; align-items: center; gap: 8px; padding: 0 2px 0 10px; border: 1px solid var(--control); border-radius: var(--radius); color: var(--muted); }
.search-box:focus-within { outline: 2px solid var(--accent); border-color: var(--accent); }
.search-box input { border: 0; min-height: 40px; font-size: 15px; padding-left: 0; }
.search-box input:focus-visible { outline: none; }
.search-box + p { margin: 6px 0 10px; }
.search-group { margin-bottom: 14px; }
.search-group h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 4px; }
.search-group ul { list-style: none; display: flex; flex-direction: column; }
.search-group li { padding: 6px 8px; border-radius: var(--radius-sm); }
.search-group li:hover { background: var(--surface-2); }
.search-group li > a { display: inline-flex; align-items: center; gap: 4px; color: var(--text); text-decoration: none; }
.search-group li > a:hover strong { color: var(--accent); text-decoration: underline; }
.snippet { margin: 2px 0 0 20px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
/* Search results: a matched word. Not the editor's names, whose backdrop must lay out exactly like the text. */
mark:not(.name-mark) { background: #fef0c7; color: inherit; border-radius: 2px; padding: 0 1px; }

/* ------------------------------------------------------------------ import, export and your own boxes */

.import-preview { max-height: 320px; overflow: auto; border-radius: var(--radius); margin-bottom: 8px; }
.import-preview:focus-visible { outline: 2px solid var(--accent); }
.import-preview .table { margin: 0; }
.import-part td:first-child, .import-part td:nth-child(2) { font-weight: 700; }
.import-chapter td:nth-child(2) { font-weight: 600; }
.import-scene td:nth-child(2) { padding-left: 24px; }
.custom-boxes td, .custom-boxes th { vertical-align: middle; }

/* ------------------------------------------------------------------ the Craft Guide */

.app-guide { grid-template-columns: minmax(0, 1fr); }
.app-guide .page { grid-column: 1; }
.page-learn { overflow: hidden; }
.learn-page { display: grid; grid-template-columns: 300px minmax(0, 1fr); height: 100%; min-height: 0; }
.learn-index { overflow-y: auto; padding: 16px 10px 32px; border-right: 1px solid var(--line); background: var(--surface); }
.learn-index-title { display: flex; align-items: center; gap: 6px; font-size: 16px; margin: 0 6px 10px; }
.learn-index .search { margin-bottom: 10px; }
.learn-index details { margin-bottom: 4px; }
.learn-index summary { display: flex; align-items: center; gap: 4px; cursor: pointer; padding: 5px 6px; border-radius: var(--radius-sm); font-weight: 600; font-size: 13px; }
.learn-index summary::before { content: "▸"; color: var(--muted); font-size: 11px; width: 12px; }
.learn-index details[open] > summary::before { content: "▾"; }
.learn-index summary::-webkit-details-marker { display: none; }
.learn-index summary:hover { background: var(--chip); }
.learn-index ul { list-style: none; margin: 2px 0 6px; }
.learn-index li a {
  display: flex; align-items: baseline; gap: 6px; padding: 4px 8px 4px 22px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-size: 13px;
}
.learn-index li a:hover { background: var(--chip); }
.learn-index li a.is-current { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.learn-index li a .icon-labelled { margin-left: auto; color: var(--muted); flex: none; display: inline-flex; }
.article-id { flex: none; min-width: 22px; font-weight: 650; color: var(--muted); font-variant-numeric: tabular-nums; }
.learn-main { overflow-y: auto; padding: 24px 32px 48px; }
.article { max-width: 720px; }
.article > h1, .article > h2 { margin: 2px 0 8px; }
.article > h1:focus, .article > h2:focus { outline: none; }
.article-tip { font-size: 15px; color: var(--muted); margin-bottom: 14px; }
.markdown { line-height: 1.6; }
.markdown h2, .markdown h3 { margin: 18px 0 6px; }
.markdown p { margin: 0 0 10px; }
.markdown ul { margin: 0 0 10px 20px; list-style: disc; }
.markdown li { margin: 2px 0; }
.article > section { margin-top: 18px; }
.article > section > h3 { margin-bottom: 6px; }
.plain-list.columns { display: block; columns: 2 220px; column-gap: 24px; }
.plain-list.columns li { break-inside: avoid; margin-bottom: 4px; }
.article-notes { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line); }
.article-notes .field-label { justify-content: space-between; }
.article-notes textarea { min-height: 96px; }
.tip-btn-static { position: relative; display: inline-flex; vertical-align: middle; cursor: default; }

/* The guide's width: narrower on a smaller screen, so the page beside it keeps room. */
:root { --guide-w: clamp(360px, 28vw, 440px); }
.learn-drawer {
  position: fixed; top: 48px; right: 0; bottom: 0; z-index: 150; width: min(var(--guide-w), 100vw);
  display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg);
}
.learn-drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 48px; padding: 6px 10px 6px 16px; border-bottom: 1px solid var(--line); }
.learn-drawer-head .eyebrow { margin: 0; }
.learn-drawer-body { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 18px 32px; }
.learn-drawer .article > h2 { font-size: 18px; }
/* Beside the guide, a dialog moves left so both stay readable. */
@media (min-width: 1200px) { .learn-open .modal-backdrop { padding-right: calc(var(--guide-w) + 16px); } }
/* On a screen narrower than the app is made for, the guide lies over the page: opened from the scene card, beside
   the card. */
.learn-drawer-beside { box-shadow: var(--shadow-lg); border-right: 1px solid var(--line); }
@media (min-width: 900px) { .learn-open:not(.learn-beside) .toasts { right: calc(var(--guide-w) + 16px); } }
/* From 1280 px the page makes room for the guide, so nothing is covered. On Write the manuscript list folds away
   below 1600 px, so the text and the scene card keep their room; it comes back when the guide closes. */
@media (min-width: 1280px) {
  .learn-open .workspace { margin-right: var(--guide-w); }
  .learn-open .write { grid-template-columns: minmax(0, 1fr) 344px; }
  .learn-open .write > .tree-panel { display: none; }
  .learn-open .entity-body { grid-template-columns: minmax(0, 1fr); }
}
@media (min-width: 1600px) {
  .learn-open .write { grid-template-columns: 268px minmax(0, 1fr) 344px; }
  .learn-open .write > .tree-panel { display: flex; }
  .learn-open .entity-body { grid-template-columns: minmax(0, 1fr) 300px; }
}

@media (max-width: 860px) {
  .learn-page { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .learn-index { max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .learn-main { padding: 18px 16px 40px; }
}

/* ------------------------------------------------------------------ recently deleted */
.deleted-list { list-style: none; display: flex; flex-direction: column; gap: 2px; margin: 8px 0 0; padding: 0; }
.deleted-list li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.deleted-list li:last-child { border-bottom: 0; }
.deleted-what { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.deleted-name { overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ research tab (Phase 3) */

.page-research { overflow: hidden; }
.research { display: grid; grid-template-columns: 196px minmax(0, 1fr); height: 100%; min-height: 0; }
.rs-nav { border-right: 1px solid var(--line); background: var(--surface); overflow-y: auto; padding: 10px 8px; }
.rs-nav ul { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.rs-nav a {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: var(--radius-sm); color: var(--muted);
  text-decoration: none; font-weight: 550; font-size: 13px;
}
.rs-nav a:hover { background: var(--chip); color: var(--text); }
.rs-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); }
.rs-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.rs-scroll { flex: 1; min-height: 0; overflow: auto; padding: 14px 20px 48px; }
.rs-bar .ctx-select { max-width: 300px; }
.rs-play { gap: 4px; }
.rs-play.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }

.rs-view { margin-top: 6px; }
.rs-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin: 4px 0 10px; }
.rs-title { font-size: 19px; display: flex; align-items: center; gap: 6px; }
.rs-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.rs-tools .inline-field, .rs-toolbar .inline-field { display: flex; align-items: center; gap: 6px; max-width: none; }
.rs-tools .inline-field label, .rs-toolbar .inline-field label { font-size: 13px; color: var(--muted); font-weight: 550; white-space: nowrap; }
.rs-tools select, .rs-toolbar select { width: auto; max-width: 240px; min-height: 30px; padding-top: 3px; padding-bottom: 3px; }
.rs-busy { font-size: 12px; color: var(--muted); min-width: 64px; }
.rs-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 8px; }
.rs-check { min-height: 30px; font-size: 13px; }
.rs-count { margin: 4px 0 8px; }
.rs-notice { margin: 6px 0 12px; }
input.rs-num { width: 64px; min-height: 30px; padding: 3px 8px; }
.rs-caption { caption-side: top; text-align: left; font-weight: 600; padding: 0 0 6px; }

/* questions in plain words */
.rs-ask { margin-bottom: 10px; }
.rs-ask-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); }
.rs-ask-row > svg { color: var(--muted); flex: 0 0 auto; }
.rs-ask-row input[type="text"] { flex: 1 1 320px; min-width: 200px; border: 0; padding: 4px 2px; background: transparent; }
.rs-ask-row input[type="text"]:focus { outline: none; }
.rs-ask-row:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.rs-ask-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.rs-answer { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--ai-line); border-radius: var(--radius); background: var(--ai-soft); }
.rs-answer-read { margin-bottom: 6px; }
.rs-answer-grid { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 8px; }
.rs-answer-grid .inline-field { display: flex; align-items: center; gap: 6px; max-width: none; }
.rs-answer-grid select { width: auto; max-width: 240px; min-height: 30px; padding-top: 3px; padding-bottom: 3px; }
.rs-answer-point { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.rs-saved { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.rs-saved-list { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.rs-saved-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.rs-saved-name { font-weight: 600; }
.rs-saved-tools { display: inline-flex; gap: 4px; margin-left: auto; }

/* filters */
.rs-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 10px; }
.rs-filters-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.rs-filter-list { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.rs-filter { display: inline-flex; align-items: center; gap: 2px; padding: 3px 4px 3px 8px; border: 1px solid var(--line-strong);
  border-radius: var(--radius); background: var(--surface); }
.rs-filter-row { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 13px; }
.rs-filter-row select { width: auto; max-width: 200px; min-height: 28px; padding: 2px 22px 2px 6px; font-size: 13px; }
.rs-filters > select { width: auto; min-height: 28px; padding: 2px 22px 2px 6px; font-size: 13px; }
.rs-filter-text { width: 140px; min-height: 28px; padding: 2px 6px; font-size: 13px; }

/* group-by board */
.rs-columns { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 8px; }
.rs-column { flex: 0 0 236px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.rs-column-unknown { background: #f3f4f6; border-style: dashed; }
.rs-column-head, .rs-subplace-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin: 0 0 6px; }
.rs-column-head { font-size: 14px; }
.rs-subplace { margin-top: 8px; padding-left: 8px; border-left: 2px solid var(--line-strong); }
.rs-subplace-head { font-size: 13px; color: var(--chip-text); font-weight: 600; }
.rs-cards { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.rs-card { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; padding: 6px 8px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.rs-card.is-proposal { border-style: dashed; border-color: var(--ai-line); }
.rs-card.is-moved { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.rs-card-name { font-weight: 600; text-decoration: none; color: var(--text); }
.rs-card-name:hover { color: var(--accent); text-decoration: underline; }
.rs-card-sub { flex-basis: 100%; font-size: 12px; }
.rs-card-why { flex-basis: 100%; font-size: 12px; }
.rs-moved { background: var(--accent-soft); color: var(--accent-strong); font-size: 11px; }
.rs-compare-boards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.rs-board-title { font-size: 14px; margin-bottom: 4px; }
.rs-grid td { min-width: 180px; }
.rs-why { display: inline; }
.rs-evidence { display: block; color: var(--muted); font-style: italic; font-size: 12px; margin-top: 2px; }

/* compare two points */
.rs-compare-points { margin-bottom: 10px; }
.rs-compare { display: flex; flex-direction: column; gap: 10px; }
.rs-compare-entity { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.rs-compare-name { font-size: 15px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
.rs-kind { font-size: 11.5px; background: var(--chip); color: var(--chip-text); }
.rs-kind-death { background: #fef3f2; color: #912018; }
.rs-kind-move { background: #eff8ff; color: #175cd3; }
.rs-kind-handoff { background: #fffaeb; color: #93370d; }
.rs-kind-relationship { background: #fdf2fa; color: #9e165f; }
.rs-compare-fields { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.rs-compare-field { font-weight: 600; }
.rs-before { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.rs-change-list { margin: 4px 0 0 18px; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.rs-change-list li.is-proposal { background: var(--ai-soft); }

/* presence matrix */
.rs-matrix-wrap { max-height: 70vh; overflow: auto; }
.rs-matrix { width: auto; }
.rs-matrix th, .rs-matrix td { padding: 4px 6px; text-align: center; vertical-align: middle; white-space: nowrap; }
.rs-matrix thead th { position: sticky; top: 0; z-index: 1; }
.rs-matrix-chapters th { font-size: 11.5px; color: var(--muted); border-left: 1px solid var(--line); }
.rs-matrix-scene { font-size: 12px; min-width: 34px; }
.rs-matrix-scene a { text-decoration: none; }
.rs-matrix-name { text-align: left !important; position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 150px; }
.rs-away-note { display: block; font-size: 11.5px; color: var(--warn); font-weight: 600; }
.rs-cell { min-width: 34px; }
.rs-away { background: var(--warn-soft); }
.rs-glyph { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; }
.rs-glyph.is-proposal { outline: 1.5px dashed var(--ai-line); border-radius: 50%; }
.g-pov { fill: #0f4a96; }
.g-active { fill: #2370cd; }
.g-present { fill: #fff; stroke: #2370cd; stroke-width: 2; }
.g-mentioned { fill: #fff; stroke: #6b7280; stroke-width: 1.5; }
.g-change { fill: #f47230; stroke: #fff; stroke-width: 1; }
.g-change-wrap { position: absolute; right: -4px; top: -3px; }
.rs-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 8px 0; font-size: 12.5px; color: var(--muted); }
.rs-legend li { display: inline-flex; align-items: center; gap: 6px; }
.rs-legend-away { display: inline-block; width: 16px; height: 12px; background: var(--warn-soft); border: 1px solid #fedf89; }
.rs-line-key { display: inline-block; width: 16px; height: 3px; border-radius: 2px; }

/* charts */
.rs-chart-box { position: relative; }
.rs-chart-frame { position: relative; }
.rs-chart-scroll { overflow-x: auto; max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.rs-svg { display: block; font-family: var(--font); }
.rs-svg text { font-size: 11.5px; fill: var(--muted); }
.rs-axis-label { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.rs-gridline { stroke: #e5e7eb; stroke-width: 1; }
.rs-gridline.zero { stroke: #c4c9d1; }
.rs-col-line { stroke: #eef0f3; stroke-width: 1; }
.rs-lane { fill: #fff; }
.rs-lane.alt { fill: #fafbfc; }
.rs-svg .rs-lane-label { font-size: 11.5px; fill: var(--chip-text); font-weight: 600; }
.rs-svg .rs-lane-label.unknown { fill: var(--muted); font-style: italic; }
.rs-svg .rs-line-label { font-size: 11.5px; fill: var(--text); font-weight: 550; }
.rs-line.faded { opacity: 0.25; }
.rs-line.hot path { stroke-width: 3.5; }
.rs-point { stroke-width: 2; cursor: default; }
.rs-point.unknown { stroke-dasharray: 2 2; }
.rs-point.is-proposal, .rs-mark.is-proposal { stroke-dasharray: 2 2; }
.rs-point:focus-visible, .rs-mark:focus-visible, .rs-edge:focus-visible, .rs-node:focus-visible, .rs-pin:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rs-conflict { fill: #fbb315; stroke: #93370d; stroke-width: 1; }
.rs-chart-note { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 6px 0 0; }
.rs-key { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 3px; vertical-align: -1px; }
.rs-key-scene { background: #6b7280; }
.rs-key-state { border: 2px solid #6b7280; background: #fff; }
.rs-key-unknown { width: 18px; height: 0; border-radius: 0; border-top: 2px dashed #9ca3af; }
.rs-tip { position: absolute; z-index: 20; max-width: 260px; padding: 8px 10px; background: #111827; color: #f9fafb; border-radius: var(--radius-sm);
  font-size: 12.5px; line-height: 1.4; pointer-events: none; box-shadow: var(--shadow-lg); }
.rs-tip-list { margin: 4px 0 0 16px; }
.rs-highlight { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.rs-hl { display: inline-flex; align-items: center; gap: 6px; }
.rs-hl.on { background: var(--surface); color: var(--text); border-color: var(--line-strong); font-weight: 600; }
.rs-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.rs-table-compact th, .rs-table-compact td { padding: 5px 8px; white-space: nowrap; font-size: 12.5px; }
.rs-changed { font-weight: 700; }
.rs-panel { margin-bottom: 14px; }
.rs-panel-title { font-size: 14px; margin: 6px 0 4px; }
.rs-svg .rs-beat-label { font-size: 10.5px; fill: #6a4ce2; font-weight: 600; }
.rs-beat-tick { stroke: #6a4ce2; stroke-width: 1; }
.rs-missing { fill: #fff; stroke: #9ca3af; stroke-width: 1.5; stroke-dasharray: 2 2; }
.rs-changes { margin: 4px 0 10px; font-size: 13px; }
.rs-changes summary { cursor: pointer; color: var(--accent); }
.rs-changes ul { margin: 6px 0 0 18px; display: flex; flex-direction: column; gap: 2px; }
.rs-band { fill: #e8ecf2; }
.rs-band.alt { fill: #dde3eb; }
.rs-band.unknown { fill: #f5f5f5; stroke: #c4c9d1; stroke-dasharray: 3 3; }
.rs-band.is-proposal { stroke: var(--ai-line); stroke-dasharray: 3 2; }
.rs-svg .rs-band-label { font-size: 11.5px; fill: var(--text); }
.rs-band-mark { fill: #f47230; }

/* network and similarity */
.rs-network { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.rs-network .rs-chart-frame { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.rs-edge { cursor: default; }
.rs-edge.faded, .rs-node.faded { opacity: 0.18; }
.rs-node { cursor: pointer; }
.rs-node-dot { stroke: #fff; stroke-width: 2; }
.rs-svg .rs-node-label { font-size: 12px; fill: var(--text); font-weight: 550; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.rs-network-side { flex: 1 1 240px; max-width: 320px; }
.rs-side-title { font-size: 13.5px; margin: 10px 0 6px; }
.rs-rank { margin: 0 0 0 18px; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.rs-clusters, .rs-tone-legend { list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.rs-clusters li, .rs-tone-legend li { display: flex; align-items: center; gap: 6px; }
.rs-tone-line { display: inline-block; width: 22px; height: 3px; border-radius: 2px; }
.rs-plot-bg { fill: var(--surface); }
.rs-close-line { stroke: #f47230; stroke-width: 2; }
.rs-meaning-off { padding: 10px 12px; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface-2); margin: 8px 0; }
.rs-meaning-off.compact { font-size: 13px; }

/* map */
.rs-map-wrap { margin-bottom: 12px; }
.rs-map-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 8px; }
.rs-map-tools .inline-field { display: flex; align-items: center; gap: 6px; max-width: none; }
.rs-map-tools select { width: auto; max-width: 240px; min-height: 30px; padding-top: 3px; padding-bottom: 3px; }
.rs-placing { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; color: var(--accent-strong); font-weight: 600; }
.rs-map { position: relative; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--chip); max-width: 100%; }
.rs-map img { display: block; user-select: none; }
.rs-map-svg { position: absolute; inset: 0; }
.rs-map.is-placing .rs-map-svg { cursor: crosshair; }
.rs-pin { cursor: grab; }
.rs-pin-dot { fill: #c4302f; stroke: #fff; stroke-width: 2; }
.rs-svg .rs-pin-label, .rs-map-svg .rs-pin-label { font-size: 12px; font-weight: 700; fill: #111827; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.rs-map-svg .rs-pin-who { font-size: 11.5px; fill: #1f2937; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.rs-map-svg .rs-pin-who.object { font-style: italic; }
.rs-map-svg .rs-pin-who.is-proposal { fill: var(--ai); }
.rs-map-lists { list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 13px; margin: 6px 0; }
.rs-checks { margin: 12px 0; }
.rs-check-list { list-style: none; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.rs-check-flag { padding: 6px 8px; background: var(--warn-soft); border: 1px solid #fedf89; border-radius: var(--radius-sm); color: #7a2e0e; }
.rs-two { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 0 10px; }
.rs-three { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 10px; }

/* knowledge, objects */
.rs-only { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 13px; }
.rs-know th[scope="row"] { min-width: 200px; }
.rs-know td { min-width: 130px; }
.rs-know-cell { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.rs-know-cell.is-proposal { background: var(--ai-soft); border-radius: 4px; padding: 2px 4px; }
.rs-truth { margin-left: 6px; font-size: 11px; }
.rs-truth-true { background: var(--ok-soft); color: var(--ok); }
.rs-truth-false { background: var(--danger-soft); color: var(--danger); }
.rs-truth-unknown { background: var(--chip); color: var(--chip-text); }
.rs-wrong { color: var(--warn); font-weight: 600; font-size: 12px; display: inline-flex; align-items: center; gap: 3px; }
.rs-history summary { cursor: pointer; font-size: 12px; color: var(--accent); }
.rs-history ol { margin: 4px 0 0 16px; font-size: 12px; }
.rs-chains { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.rs-chain { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.rs-chain-name { font-size: 14px; margin-bottom: 4px; }

/* scene card: story-time stamp and pinned views */
.story-stamp { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
.pinned-views li { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

@media (max-width: 1400px) {
  .research { grid-template-columns: 168px minmax(0, 1fr); }
  .rs-compare-boards { grid-template-columns: minmax(0, 1fr); }
}

.rs-answer-time { margin: 2px 0 6px; display: flex; align-items: center; gap: 4px; }
.rs-hl-more { max-width: 16rem; }
.rs-viewer-note { margin: 4px 0 8px; }

/* ================================================================== Review and the Master Editor (Phase 4) */

.page-review { overflow: auto; }
.review-page { max-width: 1320px; margin: 0 auto; padding: 20px 24px 48px; }
.review-head { align-items: flex-start; margin-bottom: 8px; }
.review-head h1 { display: flex; align-items: center; gap: 4px; margin-bottom: 4px; }
.review-head p { margin: 0; max-width: 720px; }
.review-tabs { padding: 0; margin-bottom: 16px; }
.review-tabs .tab { text-decoration: none; }
.review-active { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--ai-line);
  border-radius: var(--radius); background: var(--ai-soft); color: var(--ai); font-size: 13px; font-weight: 550; }
.review-meter { width: 120px; }
.bullets { list-style: disc; padding-left: 20px; margin: 0 0 10px; display: flex; flex-direction: column; gap: 3px; }

/* labels */
.sev, .cert, .status-chip, .verdict, .rank-badge {
  display: inline-flex; align-items: center; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 650;
  line-height: 18px; white-space: nowrap; text-transform: none;
}
.sev-high { background: var(--danger-soft); color: var(--danger); }
.sev-medium { background: var(--warn-soft); color: var(--warn); }
.sev-low { background: var(--chip); color: var(--chip-text); }
.cert { background: var(--surface); border: 1px solid var(--line-strong); color: var(--chip-text); font-weight: 550; }
.cert-insufficient { border-style: dashed; color: var(--muted); }
.status-chip { background: var(--chip); color: var(--chip-text); }
.status-accepted { background: var(--accent-soft); color: var(--accent-strong); }
.status-addressed { background: var(--ok-soft); color: var(--ok); }
.status-intentional { background: #f0f9ff; color: #075985; }
.status-dismissed { background: #f3f4f6; color: var(--muted); }
.status-withdrawn { background: #f3f4f6; color: var(--muted); text-decoration: line-through; }
.status-measured { background: var(--warn-soft); color: var(--warn); }
.status-changed { background: var(--warn-soft); color: var(--warn); }
.rank-badge { background: var(--accent); color: #fff; }
.lens-chip { background: var(--accent-soft); color: var(--accent-strong); }

/* findings: filters, list and detail */
.review-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 10px; }
.review-filters .inline-field { display: flex; align-items: center; gap: 6px; max-width: none; }
.review-filters .inline-field label { font-size: 13px; color: var(--muted); font-weight: 550; white-space: nowrap; }
.review-filters select { width: auto; max-width: 260px; min-height: 30px; padding-top: 3px; padding-bottom: 3px; }
.review-hidden-note { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.review-split { display: grid; grid-template-columns: minmax(280px, 400px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 980px) { .review-split { grid-template-columns: minmax(0, 1fr); } }
.review-list { position: sticky; top: 0; max-height: calc(100vh - 220px); overflow-y: auto; padding-right: 2px; }
@media (max-width: 980px) { .review-list { position: static; max-height: none; } }
.review-count { margin: 0 0 6px; }
.finding-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.finding-row a { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); color: var(--text); text-decoration: none; }
.finding-row a:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.finding-row.on a { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--accent-soft); }
.finding-row.is-merged a { opacity: 0.72; }
.finding-row-top { display: flex; align-items: flex-start; gap: 6px; }
.finding-q { font-weight: 600; line-height: 1.35; }
.finding-row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 12px; color: var(--muted); }
.review-detail { min-width: 0; }
.finding-detail, .editor-read { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.finding-detail .eyebrow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.finding-detail h2 { display: flex; align-items: flex-start; gap: 8px; font-size: 18px; margin: 4px 0 8px; }
.finding-detail h2:focus { outline: none; }
.finding-labels { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; margin-bottom: 10px; }
.finding-part { margin: 14px 0 0; }
.finding-part > h3 { display: flex; align-items: center; gap: 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted); margin-bottom: 4px; }
.finding-suggestion { padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.finding-suggestion > h3 { color: var(--accent-strong); }
.finding-metrics { margin-top: 12px; font-size: 13px; }
.finding-metrics summary { cursor: pointer; color: var(--muted); font-weight: 550; }
.metric-list { display: grid; grid-template-columns: minmax(120px, max-content) minmax(0, 1fr); gap: 4px 12px; margin: 8px 0; }
.metric-list > div { display: contents; }
.metric-list dt { color: var(--muted); }
.metric-list dd { margin: 0; overflow-wrap: anywhere; }
.finding-actions .button-row { flex-wrap: wrap; }
.passage { margin: 6px 0 10px; }
.passage blockquote { margin: 0; padding: 6px 12px; border-left: 3px solid var(--line-strong); font-family: var(--serif); font-size: 14.5px; background: var(--surface-2); }
.passage figcaption { margin-top: 3px; }
.passage-changed blockquote { border-left-color: var(--warn); }
.passage-gone blockquote { border-left-color: var(--danger); text-decoration: line-through; color: var(--muted); }

/* Discuss */
.thread { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.msg { padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); }
.msg-you { background: var(--accent-soft); border-color: #d6d9fb; margin-left: 32px; }
.msg-editor { border-color: var(--ai-line); background: var(--ai-soft); margin-right: 32px; }
.msg-specialist { margin-right: 32px; }
.msg-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 2px; }
.msg-text { margin: 0; white-space: pre-wrap; }
.discuss-form textarea { margin-bottom: 6px; }
.discuss-form .button-row { flex-wrap: wrap; gap: 6px; }

/* fix proposals and change sets */
.proposal { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); margin: 6px 0 10px; }
.proposal-applied { border-color: #abefc6; }
.proposal-label { font-weight: 650; color: var(--muted); margin: 8px 0 2px; }
blockquote.added { margin: 4px 0; padding: 4px 10px; border-left: 3px solid var(--ok); background: var(--ok-soft); font-family: var(--serif); }
.dep-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 12px; margin: 0 0 6px; font-size: 13px; }
.dep-list > div { display: contents; }
.dep-list dt { color: var(--muted); }
.dep-list dd { margin: 0; }
.change-set { margin-top: 10px; padding: 10px 12px; border: 1px dashed var(--accent); border-radius: var(--radius); background: var(--surface-2); }
.change-set-applied { border-style: solid; border-color: #abefc6; background: var(--ok-soft); }
.change-set h4 { margin: 0 0 8px; font-size: 13.5px; }
.change-item { margin-bottom: 10px; }
.change-item.is-skipped { opacity: 0.6; }
.before-after { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 760px) { .before-after { grid-template-columns: minmax(0, 1fr); } }
.ba-text { font-family: var(--serif); font-size: 13.5px; white-space: pre-wrap; padding: 6px 10px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); margin: 0; max-height: 220px; overflow: auto; }
.ba-text ins { background: #d1fadf; text-decoration: none; }

/* the Master Editor */
.editor-read h2 { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.editor-read h3 { margin: 14px 0 6px; font-size: 14px; }
.editor-story { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.editor-aspect { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); }
.editor-aspect-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.verdict-strength { background: var(--ok-soft); color: var(--ok); }
.verdict-weakness { background: var(--danger-soft); color: var(--danger); }
.verdict-missing { background: var(--warn-soft); color: var(--warn); }
.verdict-unclear { background: var(--chip); color: var(--chip-text); }
.verdict-brief { background: var(--accent-soft); color: var(--accent-strong); }
.verdict-not_judged { background: var(--chip); color: var(--chip-text); }
.editor-top { padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.editor-rec { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--ai-line); border-radius: var(--radius); background: var(--ai-soft); }
.editor-rec h3 { margin-top: 0; }
.editor-not-read { display: flex; gap: 6px; align-items: flex-start; margin-top: 10px; }

/* run a review */
.review-run { max-width: 900px; }
.review-run fieldset.card-section { border: 1px solid var(--line); }
.review-run legend { padding: 0 4px; display: inline-flex; align-items: center; gap: 4px; }
.mode-list .radio { align-items: flex-start; }
.mode-list .radio input { margin-top: 3px; }
.spec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 6px 14px; margin-bottom: 10px; }
.spec-check { align-items: flex-start; }
.spec-check input { margin-top: 3px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 10px; }
.review-cost h3 { margin-bottom: 6px; }
.started-run.is-done { border-color: #abefc6; }

/* the dashboard */
.dash-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.m4-value { font-size: 22px; }
.m4-card .meter, .started-run .meter { display: block; margin: 6px 0 8px; }
.review-meter { display: inline-block; }
.status-counts { list-style: none; display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 6px 0; }
.heatmap td.heat { text-align: center; padding: 0; min-width: 64px; }
.heatmap th { white-space: nowrap; }
.heat-btn { width: 100%; min-height: 34px; border: 0; background: transparent; font: inherit; font-weight: 650; cursor: pointer; color: inherit; }
.heat-btn:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.heat-0 { background: var(--surface); }
.heat-1 { background: #eef0fd; }
.heat-2 { background: #c7cbf7; }
/* Level 3 takes the page's own ink: white on this step measured 2.68:1, dark ink measures 6.6:1 (C05). */
.heat-3 { background: #8f97ee; color: var(--text); }
.heat-4 { background: #4338ca; color: #fff; }
.heat-high { margin-left: 3px; font-size: 11px; }
.measure-block h4 { margin: 10px 0 4px; font-size: 13.5px; }

/* the charter */
.review-charter { max-width: 900px; }
.review-charter .card-section > h2 { display: flex; align-items: center; gap: 4px; }
.goal-list { margin-bottom: 8px; }
.label-line { display: inline-flex; align-items: center; gap: 4px; }
.goal-list .inline-pair { display: flex; gap: 6px; align-items: center; }
.threshold-field .inline-pair { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.threshold-field input { width: 80px; }
.intent-list { gap: 10px; margin-bottom: 10px; }
.intent-row { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(140px, 1fr) minmax(180px, 1fr) 36px; gap: 8px; align-items: end;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.intent-row .field { margin-bottom: 0; }
/* About, aspect, where it holds and remove on the first line; what you intend under them; then the chapter or scene. */
.intent-row .intent-x { margin-bottom: 2px; }
.intent-row .intent-text { grid-column: 1 / 4; }
.intent-row .intent-which { grid-column: 1 / 3; }
.intent-hint { grid-column: 1 / -1; margin: 0; }
@media (max-width: 760px) {
  .intent-row { grid-template-columns: minmax(0, 1fr); }
  .intent-row > .intent-text, .intent-row > .intent-which { grid-column: auto; }
}
.sticky-save { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 0; margin-bottom: 16px;
}
.sticky-save.is-dirty { position: sticky; bottom: 0; background: linear-gradient(to bottom, rgba(246, 247, 249, 0), var(--bg) 30%); }
.decision-list li { padding: 4px 0; border-bottom: 1px solid var(--line); }
.decision-list li:last-child { border-bottom: 0; }

/* Write's Review mode */
.scene-review-panel .card-section { padding: 12px 14px 4px; margin-bottom: 12px; }
.scene-review-panel h3 { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.scene-notes { gap: 10px; }
.scene-note { padding: 6px 0 8px 10px; border-left: 3px solid var(--line-strong); }
.sev-line-high { border-left-color: var(--danger); }
.sev-line-medium { border-left-color: #f79009; }
.scene-note-q { margin: 0 0 2px; font-weight: 600; }
.scene-note p { margin-bottom: 4px; }
.quote-btn { display: flex; align-items: flex-start; gap: 4px; width: 100%; text-align: left; padding: 4px 6px; margin: 2px 0;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); font: italic 12.5px/1.4 var(--serif); cursor: pointer; color: var(--text); }
.quote-btn:hover { border-color: var(--accent); }
.signal-people li { font-size: 13px; }

/* "With my story" in the Craft Guide */
.with-my-story { margin: 16px 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.with-my-story summary { cursor: pointer; padding: 8px 12px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.with-my-story .wms-body, .with-my-story .loading, .with-my-story > details > p { padding: 0 12px 8px; }

/* ------------------------------------------------------------------ Avatar Studio (Phase 5) */

.avatars-page { padding: 20px 24px 40px; max-width: 1180px; }
.avatars-tabs { padding-left: 0; margin-bottom: 14px; }
.avatars-body { display: flex; flex-direction: column; gap: 14px; }
.av-grid { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.av-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow); }
.av-card-link { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--text); }
.av-card-img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: var(--radius-sm); background: var(--chip); }
.av-card-empty { display: flex; align-items: center; justify-content: center; aspect-ratio: 3 / 4; background: var(--chip); border-radius: var(--radius-sm); }
.av-card-name { font-weight: 650; }
.av-card-meta { display: flex; flex-wrap: wrap; gap: 4px; }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.av-check { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; padding: 2px 8px; border-radius: 999px; }
.av-check-ok { background: var(--ok-soft); color: var(--ok); }
.av-check-bad { background: var(--danger-soft); color: var(--danger); }
.av-check-none { background: var(--chip); color: var(--chip-text); }
.av-refs { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.av-ref { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 104px; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; background: var(--surface); }
.av-ref.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.av-ref img { width: 88px; height: 88px; object-fit: cover; border-radius: 4px; }
.av-ref-off { cursor: not-allowed; }
.av-ref-off img { opacity: .55; }
.av-ref .small { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.av-dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 6px 0; }
.av-dl dt { color: var(--muted); font-weight: 600; }
.av-dl dd { margin: 0; overflow-wrap: anywhere; }
.av-dl-row { display: contents; }
.av-mini { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; margin-right: 4px; vertical-align: middle; }
.av-version { margin-top: 10px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.av-images { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin: 12px 0; }
.av-image { display: flex; flex-direction: column; gap: 6px; margin: 0; }
.av-image img { width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--chip); }
.av-image-anchor { max-width: 240px; }
.av-anchor { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; margin-top: 12px; }
.av-sheet { flex: 1 1 420px; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.av-sheet-img { width: 100%; max-width: 720px; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.av-crops { list-style: none; display: flex; gap: 8px; flex-wrap: wrap; }
.av-crops li { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.av-crops img { width: 72px; border-radius: 4px; border: 1px solid var(--line); }
.av-details summary { cursor: pointer; color: var(--accent); font-size: 12.5px; }
.av-sources { list-style: none; display: flex; flex-direction: column; gap: 10px; margin: 10px 0; }
.av-source { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.av-source img { width: 96px; height: 96px; object-fit: cover; border-radius: 4px; }
.av-inspiration { margin: 10px 0 14px; display: flex; flex-direction: column; gap: 8px; }
.av-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 14px; }
.av-fields textarea { width: 100%; }
.av-adapt textarea { border-color: var(--warn); background: var(--warn-soft); }
.av-marks { grid-column: 1 / -1; }
.av-mark { align-items: end; }
.av-timeline { list-style: none; display: flex; flex-direction: column; gap: 12px; margin-top: 10px; border-left: 2px solid var(--line); padding-left: 14px; }
.av-tl-item { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 300px); gap: 14px; align-items: start; }
.av-tl-changes { list-style: none; margin: 4px 0; color: var(--muted); }
.av-tl-img { width: 150px; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.av-tl-variant { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.av-tl-proposed { padding: 10px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); }
.av-history { list-style: none; display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.av-history-item { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 12px; }
.av-history-item img { width: 120px; border-radius: 4px; border: 1px solid var(--line); }
.av-lineup-img { max-width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--line); margin-top: 10px; }
.av-pick-list { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 8px 0 12px; }
.av-wiki { display: flex; gap: 12px; align-items: flex-start; }
.av-wiki img { width: 96px; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.crumbs { color: var(--muted); margin-bottom: 6px; }
.av-style .row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.av-mark { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 170px auto; gap: 8px; align-items: end; }
.av-lineup .card-section { display: block; }
.av-lineup .av-lineup-img { display: block; }

/* ------------------------------------------------------------------ games pack (Phase 6) */
.game-setup { display: flex; flex-direction: column; gap: 16px; }
.game-off { max-width: 640px; }
.game-mech-row { display: grid; grid-template-columns: 160px 1fr; gap: 8px; align-items: start; margin-bottom: 8px; }
.game-role { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--chip, var(--accent-soft)); }
.game-role-hub { background: var(--accent-soft); color: var(--accent-strong); }
.game-role-storylet { background: var(--ok-soft); color: var(--ok); }
.game-role-ending { background: var(--warn-soft); color: var(--warn); }
.game-expr { font-family: var(--mono); font-size: 13px; width: 100%; }
.game-code { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.game-options { display: flex; flex-direction: column; gap: 12px; margin: 12px 0; }
.game-option { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.game-option-head { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.game-option-head input { flex: 1; min-width: 0; }
.game-choice-list li { padding: 4px 0; }
.rs-nav-game:first-of-type, .rs-nav li:not(.rs-nav-game) + .rs-nav-game { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }

.game-play-grid { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(260px, 1.4fr) minmax(200px, 1fr); gap: 12px; align-items: start; }
.game-steps ol li { padding: 3px 0; }
.game-steps .is-current { font-weight: 600; }
.game-offers { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.game-offer { width: 100%; justify-content: flex-start; text-align: left; white-space: normal; }
.game-offer-storylet { border-left: 3px solid var(--ok); }
.game-offer-option { border-left: 3px solid var(--accent); }
.game-changes h3 { font-size: 13px; margin: 12px 0 4px; }
.game-saved { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 4px 0; }
.game-path summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.game-path ol { margin: 4px 0 0 18px; font-size: 12px; }

.game-graph-scroll { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 8px; }
.game-graph { display: block; }
.game-node { cursor: pointer; }
.game-node rect { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1.2; }
.game-node:hover rect, .game-node:focus rect { stroke: var(--accent); stroke-width: 2; }
.game-node:focus { outline: none; }
.game-node:focus-visible rect { stroke: var(--accent); stroke-width: 3; }
.game-node-hub rect { fill: var(--accent-soft); }
.game-node-storylet rect { fill: var(--ok-soft); }
.game-node-ending rect { fill: var(--warn-soft); }
.game-node.is-merge rect { stroke-width: 3; }
.game-node.is-unreached rect { stroke: var(--danger); stroke-dasharray: 5 3; }
.game-node-role { font-size: 11px; fill: var(--muted); }
.game-node-label { font-size: 13px; font-weight: 600; fill: var(--text); }
.game-node-sub { font-size: 10.5px; fill: var(--muted); }
.game-arrow { fill: var(--muted); }
.game-edge, .game-medge { fill: none; stroke: var(--line-strong); stroke-width: 1.6; }
.game-edge-option { stroke: var(--accent); }
.game-edge-unlocks { stroke: var(--ok); stroke-dasharray: 6 3; }
.game-edge-returns { stroke: var(--muted); stroke-dasharray: 2 3; }
.game-edge.is-unreached { stroke: var(--danger); stroke-dasharray: 4 3; }
.game-edge.is-hot, .game-medge.is-hot { stroke-width: 3; }
.game-medge-sets { stroke: var(--accent); }
.game-medge-unlocks { stroke: var(--ok); }
.game-medge-locks { stroke: var(--danger); stroke-dasharray: 5 3; }
.game-medge-leads { stroke: var(--muted); }
.game-medge.is-faded { opacity: .18; }
.game-key { display: inline-block; width: 22px; height: 0; border-top: 2px solid var(--line-strong); vertical-align: middle; margin: 0 2px; }
.game-key-option, .game-key-sets { border-top-color: var(--accent); }
.game-key-unlocks { border-top: 2px dashed var(--ok); }
.game-key-locks { border-top: 2px dashed var(--danger); }
.game-key-returns { border-top: 2px dotted var(--muted); }
.game-key-leads, .game-key-next { border-top-color: var(--muted); }

.game-map { position: relative; }
.game-map-edges { position: absolute; inset: 0; pointer-events: none; }
.game-map-col-title { position: absolute; top: 0; margin: 0; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.game-mnode { position: absolute; display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 6px 10px; text-align: left;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); cursor: pointer; overflow: hidden; }
.game-mnode:hover, .game-mnode:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.game-mnode-variable { background: var(--accent-soft); }
.game-mnode-scene { background: var(--ok-soft); }
.game-mnode.is-unreached { opacity: .55; border-style: dashed; }
.game-mnode.is-warn { border-color: #f79009; }
.game-mnode-kind { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-mnode-label { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-route-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.game-route-list .chip { margin-left: 6px; }
.game-ms-form { flex-wrap: wrap; }
.game-lanes td { vertical-align: top; }
.game-lane li { display: flex; gap: 4px; align-items: baseline; padding: 2px 0; }

@media (max-width: 900px) {
  .game-play-grid { grid-template-columns: 1fr; }
  .game-mech-row { grid-template-columns: 1fr; }
}
.ai-suggest { margin: -4px 0 8px; }
.ai-draft { margin: -2px 0 12px; padding: 8px 10px; border: 1px dashed var(--accent); border-radius: var(--radius-sm); background: var(--accent-soft); }
.ai-draft-label { margin: 0 0 4px; font-size: 12px; font-weight: 600; color: var(--accent-strong); display: flex; gap: 4px; align-items: center; }
.ai-draft-text { margin: 0 0 6px; white-space: pre-wrap; font-size: 14px; }

/* ------------------------------------------------------------------ hosted mode (Phase 6) */
.signin-form { display: flex; flex-direction: column; gap: 4px; text-align: left; }
.signin-form h1 { font-size: 22px; margin: 8px 0; }
.signin-form .btn-primary { margin-top: 8px; align-self: flex-start; }
.account-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.account-bar > span:first-child { margin-right: auto; }
.member-row { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.member-row > span:first-child { margin-right: auto; }
tr.is-muted td { color: var(--muted); }

/* ------------------------------------------------------------------ phones (Phase 6, G6: phone access) */
@media (max-width: 700px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; height: 100dvh; }
  .topbar { flex-wrap: wrap; gap: 6px; padding: 6px 8px; min-height: 48px; }
  .topbar .brand-name, .topbar .crumb-sep, .search-btn kbd, .save-status span:not(.save-dot) { display: none; }
  .project-name { max-width: 40vw; }
  .topbar-messages { order: 10; flex-basis: 100%; justify-content: flex-start; }
  .rail { grid-row: 3; grid-column: 1; flex-direction: row; gap: 2px; padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line); overflow-x: auto; }
  .rail-link { flex: 0 0 auto; min-width: 58px; padding: 6px 4px; font-size: 10.5px; }
  .workspace { grid-row: 2; grid-column: 1; }
  .wiki, .write, .research { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: auto; min-height: 100%; }
  .wiki-list { max-height: 34vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .wiki-page { padding: 14px 12px 40px; }
  .entity-head { flex-wrap: wrap; }
  .tree-panel { max-height: 34vh; overflow: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .tree-head { flex-wrap: wrap; gap: 4px; }
  .write > :nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .rs-nav { border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; }
  .rs-nav ul { flex-direction: row; overflow-x: auto; gap: 4px; }
  .rs-nav li { flex: 0 0 auto; }
  .rs-nav a { white-space: nowrap; }
  .page-research { overflow: auto; }
  .page { -webkit-overflow-scrolling: touch; }
  .page-head, .story-head { flex-wrap: wrap; gap: 8px; }
  .home-main { padding: 16px 12px; }
  .home-head { flex-wrap: wrap; padding: 12px; }
  .home-actions { flex-direction: column; align-items: stretch; }
  .center-page { padding: 12px; }
  .center-card { padding: 20px 16px; }
  .modal-backdrop { padding: 8px; }
  .modal { max-height: 96dvh; }
  .modal-body, .modal-foot { padding-left: 14px; padding-right: 14px; }
  .row-2, .row-3 { grid-template-columns: minmax(0, 1fr); }
  .account-bar { flex-direction: column; align-items: stretch; }
  .table-scroll, .rs-chart-scroll { overflow-x: auto; }
  .seg, .segmented { flex-wrap: wrap; }
}

/* ---------------------------------------------------------------- version history (Phase 7) */
.history-page { max-width: 1200px; }
.history-save { margin: 12px 0 16px; }
.history-save .row { display: flex; gap: 8px; flex-wrap: wrap; }
.history-save input { flex: 1 1 260px; min-width: 0; }
.pv-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pv-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--surface); }
.pv-main { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.pv-name { font-weight: 600; }
.pv-kind { font-size: 12px; padding: 1px 6px; border-radius: 999px; background: var(--chip, #eef1f6); color: var(--text); }
.pv-kind-named { background: var(--accent-soft, #e6efff); }
.pv-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.btn-danger-quiet { color: var(--danger); }
.readonly-banner { display: inline-flex; gap: 6px; align-items: center; padding: 4px 10px; border-radius: 6px;
  background: var(--warn-soft, #fff6e0); color: var(--text); }
.pv-columns { display: grid; grid-template-columns: minmax(220px, 320px) 1fr; gap: 16px; margin-top: 12px; }
@media (max-width: 760px) { .pv-columns { grid-template-columns: 1fr; } }
.pv-tree h2, .pv-detail h2 { font-size: 15px; margin: 12px 0 6px; }
.pv-tree-list, .pv-tree-list ul { list-style: none; margin: 0; padding-left: 14px; }
.pv-tree-list { padding-left: 0; }
.pv-node { display: inline-flex; gap: 4px; align-items: center; padding: 2px 0; text-decoration: none; }
.pv-node[aria-pressed="true"] { font-weight: 700; }
.hist-rows { display: grid; gap: 6px; margin: 8px 0; }
.hist-rows div { display: grid; grid-template-columns: minmax(110px, 180px) 1fr; gap: 8px; }
.hist-rows dt { color: var(--muted); }
.hist-rows dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.hist-text { white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: 6px; padding: 10px;
  background: var(--surface); font-family: var(--serif, Georgia, serif); line-height: 1.6; max-height: 60vh; overflow: auto; }
.hist-text del { background: #fde2e1; color: #7a1712; }
.hist-text ins { background: #dcf5e3; color: #0f5328; text-decoration: none; border-bottom: 2px solid #2f8f4e; }
.sbs-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.sbs-table th, .sbs-table td { border-bottom: 1px solid var(--line); padding: 6px; vertical-align: top; text-align: left;
  white-space: pre-wrap; overflow-wrap: anywhere; }
.sbs-table thead th { font-size: 13px; }
.sbs-table tbody th { width: 22%; color: var(--muted); font-weight: 500; }
.sbs-changed td { background: #fff4d6; }
.sbs-text { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
@media (max-width: 760px) { .sbs-text { grid-template-columns: 1fr; } }
.sbs-text h3 { font-size: 14px; margin: 0 0 4px; }
.sbs-pick { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.ov-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ov-list li { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.ov-list li.ov-picked { border-color: var(--accent); }
.ov-actions { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.hist-result { border: 1px solid var(--accent); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.hist-result .h-small { font-size: 14px; margin: 8px 0 4px; }
.cmp-group ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.page-head.hist-head { display: block; }
.page-head.hist-head h1 { margin: 2px 0 4px; }
.page-head.hist-head .eyebrow a { text-transform: none; letter-spacing: 0; }

/* AI settings: live switches and API keys */
.ai-mode { margin: 8px 0; }
.ai-mode .check { display: flex; gap: 6px; align-items: center; margin: 2px 0; }
.key-row { margin: 0 0 14px; }
.key-input { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.key-input input { flex: 1 1 240px; min-width: 0; font-family: var(--mono, monospace); }
