@layer surfaces {

/* The manuscript reads in a book face; measure and rhythm follow the editor-v2
   design (19px/1.72). Chrome around the canvas stays on the UI sans stack. */
.editor-blocks,
.editor-empty-hint {
  font-family: var(--font-prose);
  font-size: 1.1875rem;
  line-height: 1.72;
  font-optical-sizing: auto;
}

.editor-blocks[data-virtualized="true"] {
  display: block;
}

.editor-blocks[data-virtualized="true"] .editor-block {
  margin-bottom: 0.25rem;
}

.editor-virtual-spacer {
  flex: 0 0 auto;
  pointer-events: none;
}

.editor-empty-hint {
  display: none;
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  color: var(--c-gray-500);
  pointer-events: none;
}

.editor-blocks[data-empty-document="true"]:not(:focus) + .editor-empty-hint {
  display: block;
}

.editor-empty-hint-lead {
  margin: 0;
}

/* One marks line per structure vocabulary; the surface's data-doc-type picks which one shows
   (headings covers research/note/worldbuilding — see services/document_types.js). */
.editor-empty-hint-marks {
  display: none;
  margin: 0.4rem 0 0;
  font-size: 0.8125rem;
  color: var(--c-gray-500);
}

.editor-surface[data-doc-type="manuscript"] .editor-empty-hint-marks[data-doc-hint="manuscript"],
.editor-surface[data-doc-type="song"] .editor-empty-hint-marks[data-doc-hint="song"],
.editor-surface:is([data-doc-type="research"], [data-doc-type="note"], [data-doc-type="worldbuilding"]) .editor-empty-hint-marks[data-doc-hint="headings"] {
  display: block;
}

.document-row {
  display: block;
  border-bottom: 1px solid var(--c-gray-200);
  padding: 0.75rem 1rem;
  transition: background-color var(--t-fast);
}

.document-row:hover {
  background: var(--c-gray-50);
}

.document-row-content {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.document-row-main {
  min-width: 0;
  flex: 1;
}

.document-row-title {
  font-weight: 500;
}

/* Project titles read in the book face — the same voice split as the editor: the work is
   serif, the chrome is sans (library redesign, 2026-07-23). */
.project-row .document-row-title a {
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-optical-sizing: auto;
  font-size: 1.0625rem;
}

/* Quiet collaboration hint on projects shared WITH this user. */
.project-row-shared {
  margin-left: 0.5rem;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  background: var(--c-accent-100);
  color: var(--c-accent);
  font-size: 0.6875rem;
  font-weight: 600;
  vertical-align: 2px;
}

.document-row-title a:hover {
  color: var(--c-gray-600);
}

.document-row-meta {
  display: block;
  margin-top: 0.25rem;
  color: var(--c-gray-500);
  font-size: 0.875rem;
}

.document-row-meta:hover {
  color: var(--c-gray-700);
}

.document-row-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 0.75rem;
}

/* The row's secondary actions live behind one quiet ⋯ button; the sync toggle stays
   visible (the trust affordance). Menu items reuse the export/delete button classes so
   their hover language (and the e2e selectors) carry over. */
.document-row-menu-wrap {
  position: relative;
}

.document-row-menu-button {
  border: 0;
  background: transparent;
  color: var(--c-gray-500);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  opacity: 0;
  transition: color var(--t-fast), opacity var(--t-fast);
}

.document-row:hover .document-row-menu-button,
.document-row-menu-button:focus-visible,
.document-row-menu-button[aria-expanded="true"] {
  opacity: 1;
}

.document-row-menu-button:hover,
.document-row-menu-button[aria-expanded="true"] {
  color: var(--c-gray-900);
  background: var(--c-gray-100);
}

.document-row-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  min-width: 8.5rem;
  display: flex;
  flex-direction: column;
  padding: 0.25rem;
  border: 1px solid var(--c-gray-200);
  border-radius: 6px;
  background: var(--c-white);
  box-shadow: var(--shadow-float);
}

.document-row-menu [role="menuitem"] {
  opacity: 1;
  text-align: left;
  padding: 0.375rem 0.625rem;
  border-radius: 4px;
  font-size: 0.875rem;
}

.document-row-menu [role="menuitem"]:hover {
  background: var(--c-gray-50);
}

.document-sync-status {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-width: 6.5rem;
  color: var(--c-gray-700);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Each state sets the dot/ring pair; the dot declares the pattern once. A new sync
   state is one selector + two custom properties (--off is the default pair). */
.document-sync-dot {
  display: inline-block;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 999px;
  background: var(--sync-dot, var(--c-gray-400));
  box-shadow: 0 0 0 2px var(--c-white), 0 0 0 3px var(--sync-dot-ring, var(--c-gray-300));
}

.document-sync-status--clean {
  --sync-dot: var(--c-success);
  --sync-dot-ring: var(--c-success-200);
}

.document-sync-status--pending {
  --sync-dot: var(--c-warning);
  --sync-dot-ring: var(--c-warning-200);
}

.document-sync-status--pending .document-sync-dot {
  animation: sync-dot-pulse 2.4s ease-in-out infinite;
}

.document-sync-status--local-saving,
.document-sync-status--syncing,
.document-sync-status--transition {
  --sync-dot: var(--c-accent);
  --sync-dot-ring: var(--c-accent-200);
}

.document-sync-status--local-saving .document-sync-dot,
.document-sync-status--syncing .document-sync-dot,
.document-sync-status--transition .document-sync-dot {
  animation: sync-dot-pulse 1.8s ease-in-out infinite;
}

.document-sync-status--retrying,
.document-sync-status--blocked,
.document-sync-status--local-error,
.document-sync-status--conflict,
.document-sync-status--metadata-conflict {
  --sync-dot: var(--c-danger);
  --sync-dot-ring: var(--c-danger-200);
}

@keyframes sync-dot-pulse {
  0%,
  100% {
    opacity: 0.72;
    transform: scale(0.92);
  }

  50% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Honor reduced motion across the board — every transition here is decorative. (Also keeps the
   axe scans in test/e2e/a11y.spec.js deterministic: they emulate this preference so color
   sampling never lands mid-transition.) Must be `transition: none`, NOT the common
   `transition-duration: 0.01ms` snippet — a universal near-zero duration makes Chromium start
   transitions on every property change, which wedges var()+light-dark() token resolution at the
   from-state (body stayed light in dark mode under this preference). */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }

  .document-sync-dot {
    animation: none !important;
  }
}

.document-conflict-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.document-delete-button,
.document-export-button,
.document-sync-button,
.document-conflict-button {
  border: 0;
  background: transparent;
  color: var(--c-gray-500);
  cursor: pointer;
  font-size: 0.875rem;
  opacity: 0;
  padding: 0.25rem 0.5rem;
  transition: color var(--t-fast), opacity var(--t-fast);
}

.document-sync-button {
  border: 1px solid var(--c-gray-300);
  border-radius: 4px;
  background: var(--c-white);
  color: var(--c-gray-700);
  opacity: 1;
  white-space: nowrap;
}

.document-sync-button.is-enabled {
  border-color: var(--c-success-200);
  color: var(--c-success-800);
}

.document-sync-button:disabled,
.document-sync-button.is-disabled {
  border-color: var(--c-gray-200);
  color: var(--c-gray-400);
  cursor: default;
}

.document-conflict-button {
  border: 1px solid var(--c-gray-300);
  border-radius: 4px;
  background: var(--c-white);
  color: var(--c-gray-700);
  opacity: 1;
  white-space: nowrap;
}

.document-conflict-button--primary {
  border-color: var(--c-danger-200);
  color: var(--c-danger-800);
}

.document-row:hover .document-delete-button,
.document-row:hover .document-export-button,
.document-delete-button:focus-visible,
.document-export-button:focus-visible,
.document-sync-button:focus-visible,
.document-conflict-button:focus-visible {
  opacity: 1;
}

.document-sync-button:not(:disabled):hover,
.document-conflict-button:hover,
.document-export-button:hover {
  border-color: var(--c-accent);
  color: var(--c-accent);
}

.document-delete-button:hover {
  color: var(--c-danger-700);
}

.empty-state {
  color: var(--c-gray-400);
  padding: 4rem 0;
  text-align: center;
}

.empty-state p {
  margin: 0 0 0.5rem;
}

.empty-state-hint {
  font-size: 0.875rem;
}

.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--c-gray-500);
  font-size: 0.875rem;
}

.back-link:hover {
  color: var(--c-gray-900);
}

.document-title-display {
  cursor: pointer;
}

.document-title-display:hover {
  color: var(--c-gray-600);
}

.document-title-input {
  width: 100%;
  border: 0;
  border-bottom: 2px solid var(--c-gray-300);
  background: transparent;
  color: var(--c-gray-900);
  font-size: 1.875rem;
  font-weight: 300;
  line-height: 1.2;
  outline: none;
}

.document-title-input:focus {
  border-bottom-color: var(--c-gray-900);
}

.editor-block {
  min-height: 2.75rem;
  padding: 0.75rem;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.editor-block-heading {
  color: var(--c-gray-900);
  font-weight: 650;
}

.editor-block-heading-1 {
  font-size: 1.875rem;
  line-height: 1.25;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
}

.editor-block-heading-1:first-child {
  margin-top: 0;
}

.editor-block-heading-2 {
  font-size: 1.4375rem;
  line-height: 1.35;
  padding-top: 1rem;
}

/* Inline emphasis (core/inline_markup.js): markdown-as-source, so the asterisk markers
   stay in the DOM as real text — dimmed by color only. display:none or zero-width would
   desync caret geometry from the model-offset math (the selection mapper assumes
   rendered text == document text), the same reason heading marks render as ordinary
   styled characters. */
.editor-inline-em {
  font-style: italic;
}

.editor-inline-strong {
  font-weight: 650;
}

.editor-inline-strong-em {
  font-weight: 650;
  font-style: italic;
}

.editor-inline-marker {
  color: var(--c-gray-400);
}

.editor-decoration {
  border-radius: 2px;
}

.editor-decoration-search {
  background: var(--c-warning-150);
}

.editor-decoration-search-active {
  background: var(--c-warning-400);
}

.editor-decoration-note {
  background: var(--c-accent-100);
  box-shadow: inset 0 -2px 0 var(--c-accent-400);
}

.editor-decoration-note-active {
  background: var(--c-accent-200);
  box-shadow: inset 0 -2px 0 var(--c-accent);
}

.editor-decoration-topic {
  background: var(--c-gray-100);
  box-shadow: inset 0 -2px 0 var(--c-gray-400);
}

.editor-decoration-topic-active {
  background: var(--c-gray-200);
  box-shadow: inset 0 -2px 0 var(--c-gray-900);
}

/* Mentions tint by their topic's kind so a character reads amber and a thread
   purple in the prose, matching the margin cards (data-topics-kind is stamped
   by EditorTopics#decorations). Kinds without a dedicated hue keep the gray. */
.editor-decoration-topic[data-topics-kind="character"] {
  background: var(--c-ann-character-bg);
  box-shadow: inset 0 -2px 0 var(--c-ann-character-edge);
}

.editor-decoration-topic-active[data-topics-kind="character"] {
  background: var(--c-warning-200);
  box-shadow: inset 0 -2px 0 var(--c-ann-character);
}

.editor-decoration-topic[data-topics-kind="thread"] {
  background: var(--c-ann-thread-bg);
  box-shadow: inset 0 -2px 0 var(--c-ann-thread-edge);
}

.editor-decoration-topic-active[data-topics-kind="thread"] {
  background: var(--c-thread-200);
  box-shadow: inset 0 -2px 0 var(--c-ann-thread);
}

@media (max-width: 760px) {
  .document-row-content {
    flex-direction: column;
    gap: 0.75rem;
  }

  .document-row-actions {
    justify-content: space-between;
    width: 100%;
  }

  .editor-statusbar-sync {
    width: 100%;
  }

  .document-sync-controls {
    justify-content: space-between;
    width: 100%;
  }

  .document-sync-conflict-banner {
    max-width: none;
    width: 100%;
  }

  .document-sync-status {
    min-width: 0;
  }

}

}
