@layer surfaces {

/* The unified note model: an edge note IS a doc — the margin is one radius it's visible
   from, and this link is the doorway to the full-document radius. */
.document-note-open {
  color: var(--c-gray-500);
  font-size: 0.75rem;
  margin-right: auto;
  padding: 0.125rem 0;
  text-decoration: none;
}

.document-note-open:hover,
.document-note-open:focus-visible,
.document-note-promote:hover,
.document-note-promote:focus-visible {
  color: var(--c-accent);
  outline: none;
}

.document-note-delete:hover,
.document-note-delete:focus-visible {
  color: var(--c-danger-700);
  outline: none;
}

.document-note-restore:hover,
.document-note-restore:focus-visible {
  color: var(--c-accent);
  outline: none;
}

/* Near-duplicate entity notice (entity-graph-design §4a.3): quiet, demonstrated, dismissible
   by ignoring — a "may be the same?" question, never a red error. */
.document-topics-duplicates {
  display: grid;
  gap: 0.25rem;
  padding: 0.5rem 0.625rem;
  border-radius: 6px;
  background: var(--c-gray-50);
}
.document-topics-duplicate-line {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--c-gray-600);
}

/* Candidate entities (entity-graph-design §4b): recurring un-entified terms to promote.
   Quiet — a suggestion, dismissible by ignoring. */
.document-topics-suggestions {
  display: grid;
  gap: 0.25rem;
}
.document-topics-suggestion {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.document-topics-suggestion-label {
  font-size: 0.8125rem;
  color: var(--c-gray-700);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.document-topics-suggestion-add,
.document-outline-drift-action {
  flex: none;
  padding: 0;
  border: 0;
  background: none;
  font-size: 0.75rem;
  color: var(--c-accent);
  cursor: pointer;
  white-space: nowrap;
}
.document-topics-suggestion-add:hover,
.document-topics-suggestion-add:focus-visible,
.document-outline-drift-action:hover,
.document-outline-drift-action:focus-visible {
  text-decoration: underline;
}

.document-topic-trash {
  display: grid;
  gap: 0.125rem;
}

.document-topic-group-title {
  color: var(--c-gray-500);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: var(--ls-kicker);
  text-transform: uppercase;
}

.document-topics {
  border-top: 1px solid var(--c-gray-200);
}

.document-topics.is-active {
  border-top-color: var(--c-gray-900);
}

.document-topic-row-button {
  display: grid;
  gap: 0.125rem;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--c-gray-900);
  cursor: pointer;
  padding: 0.5rem 0;
  text-align: left;
}

.document-topic-row-button:hover,
.document-topic-row-button:focus-visible,
.document-topics.is-active .document-topic-row-button {
  background: var(--c-gray-50);
  outline: none;
}

.document-topic-row-title {
  overflow: hidden;
  color: var(--c-gray-900);
  font-size: 0.875rem;
  font-weight: 650;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-topic-row-anchor {
  overflow: hidden;
  color: var(--c-gray-500);
  font-size: 0.75rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-topic-detail {
  display: grid;
  gap: 0.5rem;
  border-top: 1px solid var(--c-gray-900);
  padding-top: 0.75rem;
}

.document-topic-detail-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.5rem;
}

.document-topics-anchor {
  overflow: hidden;
  border: 0;
  background: transparent;
  color: var(--c-gray-700);
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.25;
  padding: 0;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-topics-anchor:hover,
.document-topics-anchor:focus-visible {
  color: var(--c-gray-900);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  outline: none;
}

.document-topics-kind {
  max-width: 6.25rem;
  border: 1px solid var(--c-gray-300);
  border-radius: 4px;
  background: var(--c-white);
  color: var(--c-gray-700);
  font-size: 0.75rem;
  padding: 0.125rem 0.25rem;
}

.document-topics-title-input,
.document-topics-body {
  width: 100%;
  border: 1px solid var(--c-gray-200);
  border-radius: 4px;
  color: var(--c-gray-900);
  outline: none;
  padding: 0.5rem;
}

.document-topics-title-input {
  min-height: 2rem;
  font-weight: 650;
}

.document-topics-body {
  min-height: 5.5rem;
  resize: vertical;
}

.document-topics-title-input:focus,
.document-topics-body:focus,
.document-topics-kind:focus {
  border-color: var(--c-gray-900);
}

.document-topics-meta {
  color: var(--c-gray-500);
  font-size: 0.75rem;
}

/* Graduation (entity-graph-design §5): the entity's long-form sheet. A quiet ghost offer or
   the linked doc's title — never a nudge, never a status (MANIFESTO §6). */
.document-topic-sheet {
  display: flex;
  gap: 0.75rem;
}

.document-topic-sheet-create,
.document-topic-sheet-link,
.document-topic-sheet-open {
  overflow: hidden;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 0.8125rem;
  line-height: 1.25;
  padding: 0;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-topic-sheet-create,
.document-topic-sheet-link {
  color: var(--c-gray-500);
}

.document-topic-sheet-open {
  color: var(--c-gray-700);
  font-weight: 600;
}

.document-topic-sheet-create:hover,
.document-topic-sheet-create:focus-visible,
.document-topic-sheet-link:hover,
.document-topic-sheet-link:focus-visible,
.document-topic-sheet-open:hover,
.document-topic-sheet-open:focus-visible {
  color: var(--c-gray-900);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  outline: none;
}

.document-topic-sheet-open:disabled {
  color: var(--c-gray-500);
  cursor: default;
  font-style: italic;
  text-decoration: none;
}

/* Tier-0 presence on the entity (entity-graph-design §4a): appears-in / appears-with chips +
   a gentle loose-thread glance. Quiet, demonstrated — never an alarm. */
.document-topic-presence {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.25rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--c-gray-200);
}
.document-topic-presence-summary {
  font-size: 0.75rem;
  color: var(--c-gray-500);
}
.document-topic-presence-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.document-topic-presence-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: var(--ls-kicker);
  text-transform: uppercase;
  color: var(--c-gray-500);
}
.document-topic-presence-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.document-topic-presence-chip {
  border: 1px solid var(--c-gray-200);
  border-radius: 999px;
  background: var(--c-gray-50);
  color: var(--c-gray-700);
  font-size: 0.75rem;
  line-height: 1.2;
  padding: 0.125rem 0.5rem;
}
.document-topic-presence-loose {
  margin: 0;
  font-size: 0.75rem;
  color: var(--c-gray-500);
  font-style: italic;
}

/* Auto-link assist (entity-graph-design §3.1): a quiet, full-width secondary action that
   offers to bulk-link the entity's other exact-title occurrences. */
.document-topics-autolink {
  align-self: flex-start;
  border: 1px solid var(--c-accent-200);
  border-radius: 6px;
  background: var(--c-accent-50);
  color: var(--c-accent);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
}
.document-topics-autolink:hover,
.document-topics-autolink:focus-visible {
  background: var(--c-accent-100);
  outline: none;
}

/* Tier-1 continuity surface (entity-graph-design §4c): author-invoked, cited, dismissible,
   and always marked as AI-derived. Only rendered when the global LLM gate is on. */
/* Tier-1 analysis surfaces (entity-graph-design §4c) — continuity, dropped-thread and
   relationship on the entity panel, "what am I forgetting" in the scene inspector. They share
   one renderer (topic_cards.buildAnalysisElement), which stamps .document-analysis-* beside
   the per-analysis prefixed classes; styles key on the shared class, tests/JS on the prefixes. */
.document-analysis {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.25rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--c-gray-300);
}
.document-analysis-check {
  align-self: flex-start;
  border: 1px solid var(--c-gray-300);
  border-radius: 6px;
  background: var(--c-gray-50);
  color: var(--c-gray-700);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
}
.document-analysis-check:hover,
.document-analysis-check:focus-visible {
  background: var(--c-gray-100);
  outline: none;
}
.document-analysis-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.document-analysis-provenance {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: var(--ls-kicker);
  text-transform: uppercase;
  color: var(--c-gray-500);
}
.document-analysis-dismiss {
  flex: none;
  padding: 0;
  border: 0;
  background: none;
  font-size: 0.75rem;
  color: var(--c-accent);
  cursor: pointer;
}
.document-analysis-dismiss:hover,
.document-analysis-dismiss:focus-visible {
  text-decoration: underline;
}
.document-analysis-none {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--c-gray-500);
}
.document-analysis-finding {
  display: grid;
  gap: 0.25rem;
}
.document-analysis-summary {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--c-gray-800);
}
.document-analysis-cite {
  margin: 0;
  padding: 0.25rem 0.5rem;
  border-left: 2px solid var(--c-gray-300);
  background: var(--c-gray-25);
  color: var(--c-gray-600);
  font-size: 0.75rem;
  line-height: 1.35;
}

.view-setting-hint {
  margin: 0;
  font-size: 0.6875rem;
  line-height: 1.35;
  color: var(--c-gray-500);
}

.document-topics-actions {
  display: flex;
  justify-content: flex-end;
}

.document-topics-delete,
.document-topic-restore {
  border: 0;
  background: transparent;
  color: var(--c-gray-500);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.125rem 0;
}

.document-topics-delete:hover,
.document-topics-delete:focus-visible,
.document-topic-restore:hover,
.document-topic-restore:focus-visible {
  color: var(--c-gray-900);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  outline: none;
}

.document-topic-trash-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  border-top: 1px solid var(--c-gray-200);
  padding: 0.5rem 0;
}

.document-topic-trash-row .document-topic-row-title {
  color: var(--c-gray-500);
  font-weight: 500;
}

.document-outline-children {
  margin-left: 0.75rem;
  padding-left: 0.5rem;
  border-left: 1px solid var(--c-gray-200);
}

.document-outline-node {
  min-width: 0;
}

/* The row is the full-width title button; drag handle, move/delete actions, and the
   status badge float OVER it as hover-revealed overlays. Reserving in-flow space for
   hover-only controls was truncating section titles for nothing (owner, 2026-07-11). */
.document-outline-node-row {
  display: block;
  position: relative;
}

.document-outline-node-row.is-dragging {
  opacity: 0.45;
}

.document-outline-node-row.is-drop-before::before,
.document-outline-node-row.is-drop-after::after {
  position: absolute;
  right: 0;
  left: 0;
  height: 2px;
  border-radius: 999px;
  background: var(--c-accent);
  content: "";
}

.document-outline-node-row.is-drop-before::before {
  top: -2px;
}

.document-outline-node-row.is-drop-after::after {
  bottom: -2px;
}

.document-outline-node-row.is-drop-inside-before,
.document-outline-node-row.is-drop-inside-after {
  background: var(--c-accent-50);
  border-radius: 4px;
  outline: 1px solid var(--c-accent-300);
}

.document-outline-node-row.is-drop-inside-before {
  box-shadow: inset 0 2px 0 var(--c-accent);
}

.document-outline-node-row.is-drop-inside-after {
  box-shadow: inset 0 -2px 0 var(--c-accent);
}

.document-outline-drag-handle {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.75rem;
  border-radius: 4px 0 0 4px;
  color: var(--c-gray-400);
  /* Matches the hovered button's background, so the overlay reads as part of the row. */
  background: var(--c-gray-100);
  cursor: grab;
  font-size: 0.75rem;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  user-select: none;
}

.document-outline-drag-handle:active {
  cursor: grabbing;
}

.document-outline-node-row:hover .document-outline-drag-handle,
.document-outline-node-row:focus-within .document-outline-drag-handle {
  opacity: 1;
  pointer-events: auto;
}

.document-outline-node-button {
  display: flex;
  align-items: baseline;
  width: 100%;
  min-height: 2rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--c-gray-600);
  cursor: pointer;
  padding: 0.375rem 0.5rem;
  text-align: left;
}

.document-outline-node-button:hover,
.document-outline-node-button:focus-visible,
.document-outline-node-button.is-active {
  background: var(--c-gray-100);
  color: var(--c-gray-900);
  outline: none;
}

.document-outline-node-title {
  overflow: hidden;
  font-size: 0.875rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Chapter vs scene reads from weight + the children indent/border (below), not a text label.
   Chapters anchor the eye; scenes sit quieter beneath them. */
.document-outline-node[data-kind="chapter"] > .document-outline-node-row .document-outline-node-title {
  font-weight: 500;
  color: var(--c-gray-900);
}

.document-outline-node[data-kind="scene"] > .document-outline-node-row .document-outline-node-title {
  color: var(--c-gray-500);
}

/* Song sections are flat top-level cards (the arrangement, song-doc §4) — read like
   primary items, not nested scenes. */
.document-outline-node[data-kind="section"] > .document-outline-node-row .document-outline-node-title {
  font-weight: 500;
  color: var(--c-gray-800);
}

/* Drift variant coloring (song-doc §6): a quiet dot marks which version-cluster a section
   belongs to. The hues are equal-weight (blue/violet/teal/rose) on purpose — no red "wrong",
   no green "right". Symmetric: a cluster id, never an odd-one-out badge. Only set on nodes
   whose type has >1 variant, so a steady refrain shows no dot at all. */
.document-outline-node[data-variant] > .document-outline-node-row .document-outline-node-title::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.4rem;
  border-radius: 50%;
  background: var(--variant-color, var(--c-gray-400));
  vertical-align: middle;
}
.document-outline-node[data-variant="0"] { --variant-color: light-dark(#2563eb, #5b8def); }
.document-outline-node[data-variant="1"] { --variant-color: light-dark(#7c3aed, #a78bfa); }
.document-outline-node[data-variant="2"] { --variant-color: light-dark(#0d9488, #2dd4bf); }
.document-outline-node[data-variant="3"] { --variant-color: light-dark(#db2777, #f472b6); }

/* The song-level "N versions" caption: reflect, don't flag (song-doc §6). Calm, muted,
   set apart at the top of the arrangement — it names the count, never which section. */
.document-outline-drift {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0.625rem;
  border-radius: 6px;
  background: var(--c-gray-50);
}
.document-outline-drift-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--c-gray-600);
}
.document-outline-drift-line + .document-outline-drift-line {
  margin-top: 0.375rem;
}
.document-outline-drift-line.is-dismissed .document-outline-drift-text {
  color: var(--c-gray-400);
}
.document-outline-drift-text::first-letter {
  text-transform: uppercase;
}
/* "Keep different" / "Undo" is the same quiet link-button as the suggestion add —
   styled with .document-topics-suggestion-add above. */

/* Move/delete: overlay pinned right, leaving the status badge's slot free at the far
   edge so the badge never jumps between hover states. Hidden = untouchable — an
   invisible delete button floating over the title must not catch clicks. */
.document-outline-node-actions {
  position: absolute;
  /* Flush against the status slot (1.5rem wide, pinned at right: 0) — any gap between
     the two overlay slabs lets a sliver of the underlying title peek through. */
  right: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  display: inline-flex;
  gap: 0.125rem;
  padding: 0.125rem 0.125rem 0.125rem 0.625rem;
  /* Fade in from the left so a long title dissolves under the slab instead of being
     cut mid-glyph at a hard edge. */
  background: linear-gradient(to right, transparent, var(--c-gray-100) 0.5rem);
  opacity: 0;
  pointer-events: none;
}

.document-outline-node-row:hover .document-outline-node-actions,
.document-outline-node-row:focus-within .document-outline-node-actions {
  opacity: 1;
  pointer-events: auto;
}

.document-outline-node-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--c-gray-500);
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.document-outline-node-action:hover,
.document-outline-node-action:focus-visible {
  background: var(--c-gray-200);
  color: var(--c-gray-900);
  outline: none;
}

/* Status badge: rightmost overlay slot — always visible once a status is set,
   hover-revealed otherwise. Its slot is what the actions cluster's right offset keeps
   clear, so the badge holds still while the actions fade in beside it. */
.document-outline-node-status {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  opacity: 0;
  pointer-events: none;
}

.document-outline-node-row:hover .document-outline-node-status,
.document-outline-node-row:focus-within .document-outline-node-status {
  opacity: 1;
  pointer-events: auto;
  background: var(--c-gray-100);
  border-radius: 0 4px 4px 0;
  /* Match the actions cluster's padded height so the two slabs read as one. */
  height: 1.75rem;
}

.document-outline-node-status[data-status] {
  opacity: 1;
  pointer-events: auto;
  color: var(--c-accent);
  font-weight: 600;
}

/* "planned" reads quiet — intention, not achievement, so no accent. */
.document-outline-node-status[data-status="planned"] {
  color: var(--c-gray-500);
}

/* A set status badge is the one overlay that persists without hover — reserve its slot
   in the title only then, so long titles don't run underneath it. */
.document-outline-node-row:has(.document-outline-node-status[data-status]) .document-outline-node-button {
  padding-right: 2rem;
}

.editor-find-bar {
  position: absolute;
  top: -0.5rem;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
  border: 1px solid var(--c-gray-300);
  border-radius: 6px;
  background: var(--c-white);
  box-shadow: var(--shadow-pop);
  padding: 0.25rem;
  transform: translateY(-100%);
}

/* The replace row wraps to a second line inside the same bar; flex-basis forces the
   break without restructuring the find row's children. */
.editor-find-replace-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-basis: 100%;
}

.editor-find-replace-row[hidden] {
  display: none;
}

.editor-find-button-word {
  width: auto;
  padding: 0 0.5rem;
  font-size: 0.8125rem;
}

/* Read-only (commenter) editors keep find but never show replace affordances. */
.editor-surface[data-read-only="true"] .editor-find-replace-row,
.editor-surface[data-read-only="true"] [data-document-target="replaceToggle"] {
  display: none;
}

.editor-find-input {
  width: 12rem;
  border: 0;
  outline: none;
  padding: 0.375rem 0.5rem;
}

.editor-find-count {
  min-width: 4rem;
  color: var(--c-gray-500);
  font-size: 0.8125rem;
  text-align: center;
}

.editor-find-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--c-gray-700);
  cursor: pointer;
}

.editor-find-button:hover,
.editor-find-button:focus-visible {
  background: var(--c-gray-100);
}

.editor-blocks[contenteditable="true"] {
  cursor: text;
  outline: none;
}

}
