/*
 * Scaffold stylesheet. A handful of CSS variables establish the
 * pattern from THEMES.md §2 (the full variable contract and the six
 * bundled themes arrive with the theme module). For now this only
 * lays out the empty three-column shell from UI_SHAPE.md §1.
 */
:root {
  /* Default = standard-light (THEMES.md §2). The app's theme loader
     overrides these on :root for the editor; the marketing pages keep
     these defaults. */
  --gw-color-bg: #fbfaf6;
  --gw-color-bg-elevated: #ffffff;
  --gw-color-bg-sunken: #f0eee7;
  --gw-color-text: #1a1a1a;
  --gw-color-text-muted: #6b6b6b;
  --gw-color-text-faint: #888881;
  --gw-color-accent: #2c7a7b;
  --gw-color-accent-soft: rgba(44, 122, 123, 0.14);
  --gw-color-on-accent: #ffffff;
  --gw-color-danger: #b3261e;
  --gw-color-border: #e3e0d8;
  --gw-color-border-strong: #cfcbbf;
  --gw-font-body: "Source Serif Pro", Georgia, serif;
  --gw-font-heading: "Source Serif Pro", Georgia, serif;
  --gw-font-ui: "Inter", system-ui, sans-serif;
  --gw-font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --gw-font-size-base: 1.125rem;
  --gw-line-height: 1.65;
  --gw-scene-break-glyph: "✦ ✦ ✦";

  /* Layout constants (not theme-varied). */
  --gw-header-height: 80px;
  --gw-footer-height: 28px;
  --gw-binder-width: 240px;
  --gw-inspector-width: 320px;
}

* {
  box-sizing: border-box;
}

/* Visible keyboard focus throughout (WCAG 2.4.7, AA). Mouse clicks don't
   show it (:focus-visible), so it never clutters pointer interaction. */
:where(a, button, select, input, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--gw-color-accent);
  outline-offset: 2px;
  border-radius: 3px;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--gw-color-bg);
  color: var(--gw-color-text);
  font-family: var(--gw-font-ui);
  line-height: 1.5;
}

/* ── Landing / about ─────────────────────────────────────────────── */
.landing {
  max-width: 42rem;
  margin: 0 auto;
  padding: 4rem 1.5rem;
}

.landing h1 {
  font-family: var(--gw-font-body);
  font-size: 2.5rem;
  margin: 0 0 0.5rem;
}

.tagline {
  color: var(--gw-color-text-muted);
  font-size: 1.125rem;
}

.cta {
  color: var(--gw-color-accent);
  font-weight: 600;
  text-decoration: none;
}

.note {
  color: var(--gw-color-text-muted);
  font-size: 0.875rem;
}

/* ── App shell (UI_SHAPE.md §1) ──────────────────────────────────── */
.gw-shell {
  display: grid;
  grid-template-rows: var(--gw-header-height) 1fr var(--gw-footer-height);
  height: 100vh;
}

.gw-header {
  display: flex;
  flex-direction: column;
  background: var(--gw-color-bg-elevated);
  border-bottom: 1px solid var(--gw-color-border);
}

.gw-menubar-row,
.gw-toolbar-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0 0.75rem;
  height: 40px;
  flex: 0 0 40px;
}

.gw-toolbar-row {
  border-top: 1px solid var(--gw-color-border);
}

.gw-header-spacer {
  margin-left: auto;
}

.gw-footer {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 0.75rem;
  background: var(--gw-color-bg-elevated);
  border-top: 1px solid var(--gw-color-border);
  font-size: 0.75rem;
  color: var(--gw-color-text-muted);
}
.gw-footer-seg {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}
/* A dot separator between footer segments. */
.gw-footer-seg:not(:first-child)::before {
  content: "·";
  color: var(--gw-color-text-faint);
}
/* Live progress bar that fills toward a session/manuscript goal. */
.gw-footer-bar {
  display: inline-block;
  width: 4rem;
  height: 0.45rem;
  border-radius: 999px;
  background: var(--gw-color-bg-sunken);
  overflow: hidden;
}
.gw-footer-bar-fill {
  display: block;
  height: 100%;
  background: var(--gw-color-accent);
  transition: width 0.2s ease;
}
.gw-footer-bar.is-complete .gw-footer-bar-fill {
  background: var(--gw-color-success, var(--gw-color-accent));
}

.gw-brand {
  font-weight: 700;
}

/* Project switcher (UI_SHAPE.md §2). */
.gw-project-switcher {
  margin-left: 0.75rem;
  font: inherit;
  font-size: 0.85rem;
  min-width: 12rem;
  max-width: 24rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--gw-color-border);
  border-radius: 4px;
  background: var(--gw-color-bg-elevated);
  color: var(--gw-color-text);
  cursor: pointer;
}

/* Save-state indicator dot (UI_SHAPE.md §2). */
.gw-save-state {
  width: 9px;
  height: 9px;
  margin-left: 0.6rem;
  border-radius: 50%;
  border: 1.5px solid var(--gw-color-text-muted);
  box-sizing: border-box;
}

.gw-save-state.is-clean {
  background: transparent; /* hollow = no unsaved changes */
}

.gw-save-state.is-dirty {
  background: var(--gw-color-text-muted); /* filled = pending */
  border-color: var(--gw-color-text-muted);
}

.gw-save-state.is-saving {
  border-color: var(--gw-color-accent);
  border-right-color: transparent;
  background: transparent;
  animation: gw-spin 0.7s linear infinite;
}

.gw-save-state.is-error {
  background: var(--gw-color-danger);
  border-color: var(--gw-color-danger);
}

@keyframes gw-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Theme picker. */
.gw-theme-select {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--gw-color-border);
  border-radius: 4px;
  background: var(--gw-color-bg-elevated);
  color: var(--gw-color-text);
  cursor: pointer;
}

/* View tabs (Editor / Corkboard / Outliner). */
.gw-tabs {
  display: flex;
  gap: 0.15rem;
  margin-left: 1rem;
}

.gw-tab {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--gw-color-text-muted);
  cursor: pointer;
}

.gw-tab:hover {
  color: var(--gw-color-text);
}

.gw-tab.is-active {
  color: var(--gw-color-accent);
  border-color: var(--gw-color-border);
  background: var(--gw-color-bg);
}

/* Right-aligned header actions (legacy; kept for compatibility). */
.gw-header-actions {
  margin-left: auto;
  display: flex;
  gap: 0.4rem;
}

/* SVG icons (ui/icons.ts) sit inline, centered, and inherit text colour. */
.gw-icon {
  display: inline-block;
  vertical-align: -0.18em;
  flex: 0 0 auto;
}
.gw-btn,
.gw-tool,
.gw-row-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

/* ── Menu bar (UI_SHAPE.md §1a) ─────────────────────────────────────── */
.gw-menubar {
  display: flex;
  gap: 0.1rem;
  position: relative;
  margin-left: 0.5rem;
}

.gw-menu-trigger {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.25rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--gw-color-text);
  cursor: pointer;
}

.gw-menu-trigger:hover,
.gw-menu-trigger[aria-expanded="true"] {
  background: var(--gw-color-bg);
  border-color: var(--gw-color-border);
}

.gw-menu-dropdown {
  position: absolute;
  top: 100%;
  margin-top: 4px;
  min-width: 13rem;
  z-index: 60;
  padding: 0.3rem;
  background: var(--gw-color-bg-elevated);
  border: 1px solid var(--gw-color-border);
  border-radius: 6px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
}

.gw-menu-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  width: 100%;
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  padding: 0.32rem 0.5rem;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--gw-color-text);
  cursor: pointer;
}

.gw-menu-item:hover:not(:disabled) {
  background: var(--gw-color-accent-soft);
}

.gw-menu-item:disabled {
  color: var(--gw-color-text-muted);
  opacity: 0.5;
  cursor: default;
}

.gw-menu-shortcut {
  font-size: 0.75rem;
  color: var(--gw-color-text-muted);
}

.gw-menu-sep {
  height: 1px;
  margin: 0.3rem 0.2rem;
  background: var(--gw-color-border);
}

/* ── Formatting toolbar (UI_SHAPE.md §1a) ───────────────────────────── */
.gw-toolbar {
  display: flex;
  align-items: center;
  gap: 0.12rem;
  /* Stay one row: scroll horizontally on narrow screens rather than wrapping
     down onto the page. Items don't shrink so icons stay legible. */
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
.gw-toolbar > .gw-tool,
.gw-toolbar > .gw-tool-sep,
.gw-toolbar > .gw-tool-highlight {
  flex: none;
}

.gw-tool {
  font: inherit;
  font-size: 0.85rem;
  min-width: 1.9rem;
  height: 1.8rem;
  padding: 0 0.4rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--gw-color-text);
  cursor: pointer;
}

.gw-tool:hover:not(:disabled) {
  background: var(--gw-color-bg);
  border-color: var(--gw-color-border);
}

.gw-tool.is-active {
  background: var(--gw-color-accent-soft);
  border-color: var(--gw-color-accent);
  color: var(--gw-color-accent);
}

.gw-tool:disabled {
  opacity: 0.4;
  cursor: default;
}

.gw-tool-sep {
  width: 1px;
  align-self: stretch;
  margin: 0.2rem 0.25rem;
  background: var(--gw-color-border);
}

/* Corkboard + outliner views. */
.gw-view-empty {
  color: var(--gw-color-text-muted);
}

.gw-corkboard {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 1rem;
  align-items: start;
}

.gw-corkboard-header {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.gw-card {
  display: flex;
  flex-direction: column;
  text-align: left;
  font: inherit;
  padding: 0.9rem;
  /* The left edge carries the first label's color (transparent if none). */
  border: 1px solid var(--gw-color-border);
  border-left: 4px solid var(--gw-card-accent, var(--gw-color-border));
  border-radius: 8px;
  background: var(--gw-color-bg-elevated);
  aspect-ratio: var(--gw-card-aspect, auto);
  min-height: 8rem;
}

.gw-card:hover {
  border-color: var(--gw-color-accent);
  border-left-color: var(--gw-card-accent, var(--gw-color-accent));
}

.gw-card.is-selected {
  border-color: var(--gw-color-accent);
  box-shadow: 0 0 0 1px var(--gw-color-accent);
}

.gw-card[draggable="true"] {
  cursor: grab;
}

/* Drop target while dragging another card before it. */
.gw-card.is-drop {
  border-color: var(--gw-color-accent);
  box-shadow: -3px 0 0 0 var(--gw-color-accent);
}

.gw-card-head {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0.4rem;
}
/* Delete button appears on card hover/focus so it isn't always cluttering. */
.gw-card-del {
  flex: none;
  opacity: 0;
}
.gw-card:hover .gw-card-del,
.gw-card:focus-within .gw-card-del {
  opacity: 1;
}

.gw-card-title {
  margin: 0;
  padding: 0.15rem 0.2rem;
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--gw-font-body);
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--gw-color-text);
}
.gw-card-title:hover:not(:read-only) {
  border-color: var(--gw-color-border);
}
.gw-card-title:focus {
  outline: none;
  border-color: var(--gw-color-accent);
  background: var(--gw-color-bg);
}

/* Inline-editable synopsis. Reads as text until focused. */
.gw-card-synopsis {
  flex: 1 1 auto;
  margin: 0 0 0.6rem;
  padding: 0.15rem;
  width: 100%;
  resize: none;
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--gw-color-text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
}
.gw-card-synopsis::placeholder {
  color: var(--gw-color-text-faint);
  font-style: italic;
}
.gw-card-synopsis:hover:not(:read-only) {
  border-color: var(--gw-color-border);
}
.gw-card-synopsis:focus {
  outline: none;
  border-color: var(--gw-color-accent);
  background: var(--gw-color-bg);
}

.gw-card-meta {
  font-size: 0.75rem;
  color: var(--gw-color-text-muted);
}

/* Corkboard formatting bar (card size / aspect / spacing). */
.gw-corkboard-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: center;
  margin-top: 1.25rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--gw-color-border);
}
.gw-corkboard-ctl {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--gw-color-text-muted);
}
.gw-corkboard-ctl input[type="range"] {
  width: 8rem;
}

/* Per-folder add buttons (document / subfolder) on the right of a row. */
.gw-outline-actions {
  margin-left: auto;
  display: inline-flex;
  gap: 0.15rem;
  opacity: 0;
}
.gw-outline-row:hover .gw-outline-actions,
.gw-outline-actions:focus-within {
  opacity: 1;
}

.gw-outliner {
  font-size: 0.9rem;
  max-width: 50rem;
}

.gw-outline-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  width: 100%;
  text-align: left;
  font: inherit;
  padding: 0.3rem 0.5rem;
  border: none;
  border-bottom: 1px solid var(--gw-color-border);
  background: transparent;
  color: var(--gw-color-text);
}

.gw-outline-row.is-doc:hover {
  background: rgba(0, 0, 0, 0.04);
}

/* Inline-editable title within a row. */
.gw-outline-name {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  padding: 0.15rem 0.25rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--gw-color-text);
}
.gw-outline-name:hover:not(:read-only) {
  border-color: var(--gw-color-border);
}
.gw-outline-name:focus {
  outline: none;
  border-color: var(--gw-color-accent);
  background: var(--gw-color-bg-elevated);
}

.gw-outline-row.is-folder {
  font-weight: 600;
}

.gw-outline-row.is-selected {
  background: color-mix(in srgb, var(--gw-color-accent) 12%, transparent);
}

.gw-outline-row[draggable="true"] {
  cursor: grab;
}

/* Drop target while dragging a row onto it. */
.gw-outline-row.is-drop {
  box-shadow: inset 3px 0 0 0 var(--gw-color-accent);
  background: var(--gw-color-accent-soft);
}

.gw-outline-title {
  flex: 0 0 14rem;
}

.gw-outline-synopsis {
  flex: 1;
  color: var(--gw-color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gw-outline-meta {
  flex: 0 0 auto;
  color: var(--gw-color-text-muted);
  font-size: 0.78rem;
}

/* Command palette modal (UI_SHAPE.md §9). */
.gw-modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 12vh;
  background: rgba(0, 0, 0, 0.35);
  z-index: 20;
}

.gw-modal {
  width: min(32rem, 92vw);
  max-height: 70vh;
  overflow: auto;
  background: var(--gw-color-bg-elevated);
  color: var(--gw-color-text);
  border: 1px solid var(--gw-color-border-strong);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  padding: 0.75rem;
}

.gw-modal-search {
  width: 100%;
  font: inherit;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--gw-color-border);
  border-radius: 6px;
  background: var(--gw-color-bg);
  color: var(--gw-color-text);
}

.gw-modal-subhead {
  margin: 0.75rem 0 0.25rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gw-color-text-faint);
}

.gw-cmd-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.gw-cmd {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  font: inherit;
  text-align: left;
  padding: 0.4rem 0.5rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--gw-color-text);
  cursor: pointer;
}

button.gw-cmd:hover:not(:disabled) {
  background: var(--gw-color-accent-soft);
}

.gw-cmd:disabled {
  color: var(--gw-color-text-faint);
  cursor: default;
}

.gw-cmd.is-static {
  cursor: default;
}

.gw-cmd-hint {
  color: var(--gw-color-text-faint);
  font-size: 0.85em;
}

/* Export reminder banner (step 11). */
.gw-reminder {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: 22rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--gw-color-bg-elevated);
  border: 1px solid var(--gw-color-accent);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font-size: 0.85rem;
  z-index: 10;
}

.gw-reminder span {
  flex: 1 1 100%;
}

.gw-columns {
  display: grid;
  grid-template-columns: var(--gw-binder-width) 6px 1fr 6px var(--gw-inspector-width);
  min-height: 0;
}

/* Pin each region to its column so a hidden panel never makes the others
   shift left (which would squeeze the editor to 0 width). */
.gw-binder {
  grid-column: 1;
}
.gw-columns > .gw-splitter[data-splitter="binder"] {
  grid-column: 2;
}
.gw-view {
  grid-column: 3;
  min-width: 0;
}
.gw-columns > .gw-splitter[data-splitter="inspector"] {
  grid-column: 4;
}
.gw-inspector {
  grid-column: 5;
}

/* Drag-to-resize splitters between the panels and the view. */
.gw-splitter {
  cursor: col-resize;
  background: transparent;
  transition: background 0.12s;
  touch-action: none;
}
.gw-splitter:hover,
.gw-splitter:active {
  background: var(--gw-color-accent);
}

/* Collapsible side panels (UI_SHAPE.md §1). */
.gw-shell[data-binder-collapsed] .gw-columns {
  grid-template-columns: 0 0 1fr 6px var(--gw-inspector-width);
}
.gw-shell[data-inspector-collapsed] .gw-columns {
  grid-template-columns: var(--gw-binder-width) 6px 1fr 0 0;
}
.gw-shell[data-binder-collapsed][data-inspector-collapsed] .gw-columns {
  grid-template-columns: 0 0 1fr 0 0;
}
.gw-shell[data-binder-collapsed] .gw-binder,
.gw-shell[data-binder-collapsed] .gw-splitter[data-splitter="binder"],
.gw-shell[data-inspector-collapsed] .gw-inspector,
.gw-shell[data-inspector-collapsed] .gw-splitter[data-splitter="inspector"] {
  display: none;
}

.gw-binder,
.gw-inspector {
  padding: 0.75rem;
  color: var(--gw-color-text-muted);
  overflow: auto;
}

/* ── Binder (UI_SHAPE.md §1, §3) ─────────────────────────────────── */
.gw-search {
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 0.3rem 0.5rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--gw-color-text);
  background: var(--gw-color-bg-elevated);
  border: 1px solid var(--gw-color-border);
  border-radius: 4px;
}

.gw-search:focus {
  outline: none;
  border-color: var(--gw-color-accent);
}

.gw-search-empty {
  margin: 0.5rem 0.35rem;
  font-size: 0.85rem;
  color: var(--gw-color-text-muted);
}

.gw-binder-toolbar {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.gw-btn {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--gw-color-border);
  border-radius: 4px;
  background: var(--gw-color-bg-elevated);
  color: var(--gw-color-text);
  cursor: pointer;
}

.gw-btn:hover {
  border-color: var(--gw-color-accent);
  color: var(--gw-color-accent);
}

.gw-tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

.gw-tree .gw-tree {
  padding-left: 0.9rem; /* nested-level indent */
}

.gw-tree-root {
  min-height: 2rem;
}

.gw-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  color: var(--gw-color-text);
  font-size: 0.9rem;
  cursor: default;
}

.gw-row.is-doc .gw-row-label {
  cursor: pointer;
}

.gw-row:hover {
  background: rgba(0, 0, 0, 0.04);
}

.gw-row.is-selected {
  background: color-mix(in srgb, var(--gw-color-accent) 16%, transparent);
  color: var(--gw-color-text);
}

.gw-row.is-drop {
  outline: 2px solid var(--gw-color-accent);
  outline-offset: -2px;
}

.gw-row-label {
  flex: 1;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  overflow: hidden;
  white-space: nowrap;
}

.gw-row-label > span,
.gw-outline-title > span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.gw-row-label .gw-icon,
.gw-outline-title .gw-icon {
  width: 16px;
  height: 16px;
  color: var(--gw-color-text-muted);
}

.gw-outline-title {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.gw-row-btn {
  font: inherit;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0 0.3rem;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--gw-color-text-muted);
  cursor: pointer;
  opacity: 0;
}

.gw-row:hover .gw-row-btn {
  opacity: 1;
}

.gw-row-btn:hover {
  color: var(--gw-color-accent);
}

.gw-row-del:hover {
  color: var(--gw-color-danger);
}

.gw-binder {
  border-right: 1px solid var(--gw-color-border);
}

.gw-inspector {
  border-left: 1px solid var(--gw-color-border);
}

/* Inspector tab rail (Scrivener-style). */
.gw-inspector-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.7rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--gw-color-border);
}

.gw-inspector-tab {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--gw-color-text-muted);
  cursor: pointer;
}

.gw-inspector-tab:hover {
  background: var(--gw-color-bg-sunken);
  color: var(--gw-color-text);
}

.gw-inspector-tab.is-active {
  background: var(--gw-color-accent-soft);
  color: var(--gw-color-accent);
}

.gw-tab-badge {
  position: absolute;
  top: 0;
  right: 2px;
  font-size: 0.6rem;
  line-height: 1;
  padding: 0.08rem 0.25rem;
  border-radius: 999px;
  background: var(--gw-color-accent);
  color: var(--gw-color-on-accent);
}

/* Inspector: metadata (labels + custom fields). */
.gw-meta-section {
  margin-bottom: 1.25rem;
}
.gw-meta-section-title {
  margin: 0 0 0.5rem;
  font-family: var(--gw-font-ui, var(--gw-font-body));
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gw-color-text-muted);
}
.gw-meta-chips {
  margin: 0 0 0.6rem;
}
.gw-label-list,
.gw-cf-list {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.gw-label-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0.3rem;
  border-radius: 6px;
}
.gw-label-row:hover {
  background: var(--gw-color-bg-sunken);
}
.gw-cf-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Leading check toggle — a rounded box that fills when the label is applied. */
.gw-label-check {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: 1.5px solid var(--gw-color-border-strong);
  border-radius: 5px;
  background: transparent;
  color: var(--gw-color-on-accent);
  cursor: pointer;
}
.gw-label-row.is-assigned .gw-label-check {
  background: var(--gw-color-accent);
  border-color: var(--gw-color-accent);
}
.gw-label-check .gw-icon {
  width: 14px;
  height: 14px;
}

/* Round color swatch (native color input, chrome stripped). */
.gw-label-swatch {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.gw-label-swatch::-webkit-color-swatch-wrapper {
  padding: 0;
}
.gw-label-swatch::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}
.gw-label-swatch::-moz-color-swatch {
  border: none;
  border-radius: 50%;
}

/* Name reads as plain text until focused. */
.gw-label-name {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  padding: 0.2rem 0.3rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--gw-color-text);
}
.gw-label-name:hover {
  border-color: var(--gw-color-border);
}
.gw-label-name:focus {
  outline: none;
  border-color: var(--gw-color-accent);
  background: var(--gw-color-bg-elevated);
}

/* Compact square icon buttons (add / delete). */
.gw-icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--gw-color-text-muted);
  cursor: pointer;
}
.gw-icon-btn:hover {
  background: var(--gw-color-bg-sunken);
  color: var(--gw-color-text);
}
.gw-icon-btn.gw-row-del:hover {
  color: var(--gw-color-danger);
}
.gw-icon-btn .gw-icon {
  width: 15px;
  height: 15px;
}

/* New label / new field rows. */
.gw-meta-add {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
}
.gw-meta-add .gw-input {
  flex: 1 1 auto;
  min-width: 0;
}

.gw-cf-key {
  flex: 0 0 6rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gw-color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gw-cf-key-input {
  flex: 0 0 6rem;
}
.gw-cf-value {
  flex: 1 1 auto;
  min-width: 0;
}

/* Label chips on cards / outliner rows. */
.gw-label-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.5rem;
}
.gw-label-chip {
  font-size: 0.68rem;
  line-height: 1;
  padding: 0.18rem 0.4rem;
  border-radius: 999px;
  white-space: nowrap;
}
.gw-outline-row .gw-label-chips {
  margin-top: 0;
}

/* Inspector: snapshots (Tier 2). */
.gw-inspector-empty {
  font-size: 0.85rem;
  color: var(--gw-color-text-muted);
}

.gw-inspector-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--gw-color-text);
}

.gw-snapshots {
  list-style: none;
  margin: 0;
  padding: 0;
}

.gw-snapshot {
  padding: 0.4rem 0;
  border-top: 1px solid var(--gw-color-border);
  font-size: 0.85rem;
}

.gw-snapshot-label {
  color: var(--gw-color-text);
}

.gw-snapshot-meta {
  margin: 0.1rem 0 0.3rem;
  color: var(--gw-color-text-muted);
  font-size: 0.78rem;
}

.gw-snapshot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

/* ── Inline annotations in the editor (footnotes, margin notes) ──────── */
.gw-footnote-ref {
  color: var(--gw-color-accent);
  cursor: pointer;
  font-weight: 600;
  padding: 0 0.1em;
}

.gw-footnote-def {
  counter-increment: none;
  position: relative;
  margin: 0.4rem 0 0.4rem 1.6rem;
  padding-left: 0.4rem;
  font-size: 0.9em;
  color: var(--gw-color-text-muted);
  border-left: 2px solid var(--gw-color-border);
}

.gw-footnote-def::before {
  content: attr(data-footnote-def);
  position: absolute;
  left: -1.4rem;
  font-weight: 600;
  color: var(--gw-color-accent);
}

/* Set the footnotes apart: a rule above the first definition in a run. */
* + .gw-footnote-def:first-of-type {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--gw-color-border);
}

/* The margin-note pin is just an anchor — the text shows in the gutter. */
.gw-margin-note {
  cursor: pointer;
  font-size: 0.7em;
  vertical-align: super;
  color: var(--gw-color-accent);
  opacity: 0.7;
}

.gw-margin-note:hover {
  opacity: 1;
}

.gw-html-comment {
  cursor: pointer;
  font-size: 0.8em;
  vertical-align: super;
  color: var(--gw-color-accent);
  background: var(--gw-color-accent-soft);
  border-radius: 3px;
  padding: 0 0.2em;
}

/* ── Tippy.js core CSS (inlined from tippy.js/dist/tippy.css) ─────────── */
.tippy-box[data-animation=fade][data-state=hidden]{opacity:0}
[data-tippy-root]{max-width:calc(100vw - 10px)}
.tippy-box{position:relative;background-color:#333;color:#fff;border-radius:4px;font-size:14px;line-height:1.4;white-space:normal;outline:0;transition-property:transform,visibility,opacity}
.tippy-box[data-placement^=top]>.tippy-arrow{bottom:0}
.tippy-box[data-placement^=top]>.tippy-arrow:before{bottom:-7px;left:0;border-width:8px 8px 0;border-top-color:initial;transform-origin:center top}
.tippy-box[data-placement^=bottom]>.tippy-arrow{top:0}
.tippy-box[data-placement^=bottom]>.tippy-arrow:before{top:-7px;left:0;border-width:0 8px 8px;border-bottom-color:initial;transform-origin:center bottom}
.tippy-box[data-placement^=left]>.tippy-arrow{right:0}
.tippy-box[data-placement^=left]>.tippy-arrow:before{border-width:8px 0 8px 8px;border-left-color:initial;right:-7px;transform-origin:center left}
.tippy-box[data-placement^=right]>.tippy-arrow{left:0}
.tippy-box[data-placement^=right]>.tippy-arrow:before{left:-7px;border-width:8px 8px 8px 0;border-right-color:initial;transform-origin:center right}
.tippy-box[data-inertia][data-state=visible]{transition-timing-function:cubic-bezier(.54,1.5,.38,1.11)}
.tippy-arrow{width:16px;height:16px;color:#333}
.tippy-arrow:before{content:"";position:absolute;border-color:transparent;border-style:solid}
.tippy-content{position:relative;padding:5px 9px;z-index:1}

/* ── Tippy tooltips theme (matches the app palette) ──────────────────── */
.tippy-box[data-theme~="gw"] {
  background: var(--gw-color-text);
  color: var(--gw-color-bg);
  font-size: 0.78rem;
  font-family: var(--gw-font-ui, var(--gw-font-body));
  border-radius: 5px;
}

.tippy-box[data-theme~="gw"] .tippy-arrow {
  color: var(--gw-color-text);
}

/* ── Table controls popover (UI_SHAPE.md §4.1) ───────────────────────── */
.gw-table-popover {
  position: fixed;
  z-index: 70;
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--gw-color-bg-elevated);
  border: 1px solid var(--gw-color-border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.gw-table-popover-btn {
  font: inherit;
  font-size: 0.78rem;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--gw-color-border);
  border-radius: 4px;
  background: transparent;
  color: var(--gw-color-text);
  cursor: pointer;
}

.gw-table-popover-btn:hover {
  background: var(--gw-color-accent-soft);
  color: var(--gw-color-accent);
}

/* ── Link popover (UI_SHAPE.md §4.1) ─────────────────────────────────── */
.gw-link-popover {
  position: fixed;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 28rem;
  padding: 0.3rem 0.5rem;
  background: var(--gw-color-bg-elevated);
  border: 1px solid var(--gw-color-border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  font-size: 0.82rem;
}

.gw-link-popover-label {
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--gw-color-text-muted);
}

.gw-link-popover-btn {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--gw-color-border);
  border-radius: 4px;
  background: transparent;
  color: var(--gw-color-accent);
  cursor: pointer;
}

.gw-link-popover-btn:hover {
  background: var(--gw-color-accent-soft);
}

/* Annotation visibility toggles (View menu). Hide the clutter while
   writing without deleting anything. */
.gw-shell[data-hide-footnotes] .gw-footnote-def {
  display: none;
}
.gw-shell[data-hide-footnotes] .gw-footnote-ref {
  opacity: 0.3; /* keep refs (no reflow) but de-emphasized */
}
.gw-shell[data-hide-margin-notes] .gw-margin-layer,
.gw-shell[data-hide-margin-notes] .gw-margin-note {
  display: none !important;
}
.gw-shell[data-hide-comments] .gw-comment,
.gw-shell[data-hide-open-comments] .gw-comment:not(.is-resolved),
.gw-shell[data-hide-resolved-comments] .gw-comment.is-resolved {
  background: none !important;
  border-bottom: none !important;
  box-shadow: none !important;
}
.gw-shell[data-hide-highlights] mark {
  background: transparent;
}

/* ── Text highlights (MANUSCRIPT_MARKDOWN.md §4a) ─────────────────────── */
/* A `<mark>` is part of the manuscript; the color rides as a semantic class
   so themes and compiled output share these variables. The color classes are
   generic (not `mark`-only) so the toolbar swatches use them too, and each
   carries a literal fallback so colors show even before theme vars resolve.
   Text color is left alone so highlighted prose stays readable on every
   theme. */
mark {
  color: inherit;
  border-radius: 2px;
  padding: 0 0.05em;
  background-color: var(--gw-hl-yellow, #fdf0a3);
}
.gw-hl-yellow {
  background-color: var(--gw-hl-yellow, #fdf0a3);
}
.gw-hl-green {
  background-color: var(--gw-hl-green, #c5edc9);
}
.gw-hl-blue {
  background-color: var(--gw-hl-blue, #bfe0ff);
}
.gw-hl-pink {
  background-color: var(--gw-hl-pink, #ffd2e1);
}
.gw-hl-purple {
  background-color: var(--gw-hl-purple, #e5d6ff);
}

/* Toolbar highlight picker: a button that drops a small palette of swatches. */
.gw-tool-highlight {
  position: relative;
  display: inline-flex;
}
.gw-hl-popover {
  /* Fixed (not absolute) so the scrollable toolbar doesn't clip it; the
     left/top are set from the button's rect when it opens. */
  position: fixed;
  z-index: 200;
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 6px;
  background: var(--gw-color-bg-elevated);
  border: 1px solid var(--gw-color-border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.gw-hl-popover[hidden] {
  display: none;
}
.gw-hl-swatch {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid var(--gw-color-border-strong);
  border-radius: 4px;
  cursor: pointer;
}
.gw-hl-swatch:hover {
  outline: 2px solid var(--gw-color-accent);
  outline-offset: 1px;
}
.gw-hl-none {
  padding: 2px 8px;
  font: inherit;
  font-size: 0.8rem;
  color: var(--gw-color-text-muted);
  background: var(--gw-color-bg-sunken);
  border: 1px solid var(--gw-color-border);
  border-radius: 4px;
  cursor: pointer;
}
.gw-hl-none:hover {
  color: var(--gw-color-text);
}

/* ── Comments (UI_SHAPE.md §5) ───────────────────────────────────────── */
.gw-comment {
  background: var(--gw-color-accent-soft);
  border-bottom: 2px solid var(--gw-color-accent);
  cursor: pointer;
  border-radius: 2px 2px 0 0;
}

.gw-comment.is-active {
  /* Stronger highlight WITHOUT recolouring the text (keeps it readable). */
  background: var(--gw-color-accent-soft);
  box-shadow: 0 0 0 2px var(--gw-color-accent);
  border-radius: 2px;
}

/* Resolved comments read as clearly "done": no fill, a faint dashed
   underline, and dimmed — distinct from an open comment's solid accent rule. */
.gw-comment.is-resolved {
  background: transparent;
  border-bottom: 1px dashed var(--gw-color-text-faint);
  border-radius: 0;
  opacity: 0.6;
}
.gw-comment.is-resolved.is-active {
  /* Keep the active outline visible even when resolved. */
  opacity: 1;
  box-shadow: 0 0 0 2px var(--gw-color-text-faint);
}

.gw-head-icon {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.gw-head-icon .gw-icon {
  width: 16px;
  height: 16px;
  color: var(--gw-color-accent);
}

.gw-comments {
  list-style: none;
  margin: 0;
  padding: 0;
}

.gw-comment-box {
  padding: 0.5rem 0;
  border-top: 1px solid var(--gw-color-border);
  font-size: 0.85rem;
}

.gw-comment-box.is-resolved {
  opacity: 0.6;
}

.gw-comment-box.is-flash,
.gw-flash {
  animation: gw-flash 1.2s ease-out;
  border-radius: 3px;
}

/* Hold a clear accent tint + ring briefly, then fade — visible even on a tiny
   footnote-reference superscript. */
@keyframes gw-flash {
  0% {
    background: var(--gw-color-accent);
    color: var(--gw-color-on-accent);
    box-shadow: 0 0 0 3px var(--gw-color-accent);
  }
  35% {
    background: var(--gw-color-accent-soft);
    color: inherit;
    box-shadow: 0 0 0 3px var(--gw-color-accent-soft);
  }
  100% {
    background: transparent;
    color: inherit;
    box-shadow: 0 0 0 3px transparent;
  }
}

.gw-comment-meta {
  font-size: 0.75rem;
  color: var(--gw-color-text-muted);
}

.gw-comment-quote {
  margin: 0.25rem 0;
  padding-left: 0.5rem;
  border-left: 2px solid var(--gw-color-accent);
  color: var(--gw-color-text-muted);
  font-style: italic;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.gw-comment-text {
  color: var(--gw-color-text);
  white-space: pre-wrap;
}

.gw-comment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.3rem;
}

/* ── Inspector metadata fields (synopsis, notes) ────────────────────── */
.gw-textarea {
  resize: vertical;
  width: 100%;
  font-family: inherit;
  line-height: 1.4;
}

.gw-meta-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.7rem;
}

.gw-meta-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gw-color-text-muted);
}

.gw-meta-input {
  font-size: 0.85rem;
}

.gw-btn-sm {
  font-size: 0.75rem;
  padding: 0.12rem 0.45rem;
}

/* ── Notebook (master-detail) ────────────────────────────────────────── */
.gw-notebook {
  width: min(56rem, 94vw);
  text-align: left;
  display: flex;
  flex-direction: column;
  max-height: 86vh;
}

.gw-nb-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.gw-nb-body {
  display: grid;
  grid-template-columns: 15rem 1fr;
  gap: 1rem;
  min-height: 24rem;
  flex: 1;
  overflow: hidden;
}

.gw-nb-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--gw-color-border);
}

.gw-nb-tagfilter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding-bottom: 0.5rem;
  margin-bottom: 0.3rem;
  border-bottom: 1px solid var(--gw-color-border);
}

.gw-nb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
  /* Cap at roughly ten notes, then scroll, so the modal stops growing. */
  max-height: 32rem;
}

.gw-nb-item.is-drop {
  box-shadow: inset 0 2px 0 var(--gw-color-accent);
}

.gw-nb-item-tags {
  font-size: 0.72rem;
  color: var(--gw-color-accent);
}

/* Tag chips (filter + per-note editor). */
.gw-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.74rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--gw-color-border);
  background: transparent;
  color: var(--gw-color-text-muted);
  cursor: pointer;
}

.gw-tag-chip.is-active {
  background: var(--gw-color-accent-soft);
  border-color: var(--gw-color-accent);
  color: var(--gw-color-accent);
}

.gw-tag-x {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
}

.gw-nb-tags {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.gw-nb-tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}

.gw-nb-tag-input {
  font: inherit;
  font-size: 0.8rem;
  border: none;
  background: transparent;
  color: var(--gw-color-text);
  min-width: 6rem;
  flex: 1;
  outline: none;
}

.gw-nb-item {
  padding: 0.5rem;
  border-radius: 6px;
  cursor: pointer;
}

.gw-nb-item:hover {
  background: var(--gw-color-bg-sunken);
}

.gw-nb-item.is-active {
  background: var(--gw-color-accent-soft);
}

.gw-nb-item-title {
  font-weight: 600;
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gw-nb-item-snippet {
  font-size: 0.78rem;
  color: var(--gw-color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gw-nb-detail {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 0;
  overflow: auto;
}

.gw-nb-title {
  font-size: 1rem;
  font-weight: 600;
}

.gw-nb-content {
  flex: 1;
  min-height: 12rem;
  resize: vertical;
}

.gw-nb-send {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--gw-color-border);
}

.gw-nb-send-row {
  display: flex;
  gap: 0.5rem;
}

.gw-nb-send-row > * {
  flex: 1;
}

.gw-nb-danger {
  display: flex;
  justify-content: flex-end;
}

/* ── Dialogs (insert link, snapshot preview, trash, move, compile) ───── */
.gw-dialog {
  width: min(36rem, 92vw);
  text-align: left;
}

.gw-dialog-title {
  margin: 0 0 0.8rem;
  font-size: 1.1rem;
}

.gw-dialog-body {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.gw-dialog-note {
  margin: 0;
  font-size: 0.82rem;
  color: var(--gw-color-text-muted);
}

.gw-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.82rem;
  color: var(--gw-color-text-muted);
}

.gw-input {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--gw-color-border);
  border-radius: 4px;
  background: var(--gw-color-bg);
  color: var(--gw-color-text);
}

.gw-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.gw-check-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--gw-color-text);
  cursor: pointer;
}

.gw-btn-primary {
  background: var(--gw-color-accent);
  border-color: var(--gw-color-accent);
  color: var(--gw-color-on-accent);
}

.gw-btn-danger {
  color: var(--gw-color-danger);
  border-color: var(--gw-color-danger);
}

.gw-snapshot-preview {
  max-height: 50vh;
  overflow: auto;
  padding: 0.7rem;
  border: 1px solid var(--gw-color-border);
  border-radius: 4px;
  background: var(--gw-color-bg);
  font-family: var(--gw-font-mono, ui-monospace, monospace);
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Snapshot compare (line diff). */
.gw-diff-summary {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--gw-color-text-muted);
}
.gw-diff {
  max-height: 55vh;
  overflow: auto;
  margin: 0;
  padding: 0.5rem 0;
  border: 1px solid var(--gw-color-border);
  border-radius: 4px;
  background: var(--gw-color-bg);
  font-family: var(--gw-font-mono, ui-monospace, monospace);
  font-size: 0.82rem;
}
.gw-diff-line {
  padding: 0 0.7rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.gw-diff-line.is-add {
  background: color-mix(in srgb, #2ea043 22%, transparent);
}
.gw-diff-line.is-remove {
  background: color-mix(in srgb, #cf222e 20%, transparent);
}
.gw-diff-line.is-equal {
  color: var(--gw-color-text-muted);
}

/* Collections modal (manual + smart lists). */
/* Give this dialog more room than the default; the grid's right column uses
   minmax(0, …) so long titles wrap instead of forcing a horizontal scroll. */
.gw-dialog:has(.gw-collections) {
  width: min(52rem, 94vw);
}

/* Writing-history modal: wider so the per-day rows (date · bar · count · ✕)
   have room for the bar and don't crowd the percentage label. */
.gw-dialog:has(.gw-history-summary) {
  width: min(46rem, 94vw);
}
.gw-collections {
  display: grid;
  grid-template-columns: 13rem minmax(0, 1fr);
  gap: 1rem;
  width: 100%;
  min-height: 22rem;
}
.gw-coll-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  border-right: 1px solid var(--gw-color-border);
  padding-right: 0.75rem;
}
.gw-coll-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.5rem;
  text-align: left;
  font: inherit;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--gw-color-text);
  cursor: pointer;
}
.gw-coll-item:hover {
  background: var(--gw-color-bg-sunken);
}
.gw-coll-item.is-active {
  background: var(--gw-color-accent-soft);
  border-color: var(--gw-color-accent);
}
.gw-coll-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gw-coll-count {
  flex: none;
  font-size: 0.72rem;
  color: var(--gw-color-text-muted);
}
.gw-coll-list-actions {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.5rem;
}
.gw-coll-detail {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-width: 0;
}
.gw-coll-head {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.gw-coll-head .gw-input {
  flex: 1 1 auto;
  font-weight: 600;
}
.gw-coll-query {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.gw-coll-field {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
  color: var(--gw-color-text-muted);
}
.gw-coll-field > span {
  flex: 0 0 4rem;
}
.gw-coll-field .gw-input,
.gw-coll-field .gw-theme-select {
  flex: 1 1 auto;
}
.gw-coll-docs {
  list-style: none;
  margin: 0;
  padding: 0.5rem 0 0;
  border-top: 1px solid var(--gw-color-border);
  overflow: auto;
}
.gw-coll-doc {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.gw-coll-doc-open {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  font: inherit;
  padding: 0.3rem 0.4rem;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--gw-color-accent);
  cursor: pointer;
}
.gw-coll-doc-open:hover {
  background: var(--gw-color-bg-sunken);
}

/* Transient toasts (e.g. "moved to folder · Undo"). */
.gw-toast-tray {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  pointer-events: none;
}
.gw-toast {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  background: var(--gw-color-text);
  color: var(--gw-color-bg);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
  font-size: 0.85rem;
  pointer-events: auto;
}
.gw-toast-action {
  font: inherit;
  font-weight: 600;
  color: var(--gw-color-bg);
  background: transparent;
  border: none;
  text-decoration: underline;
  cursor: pointer;
}

/* Writing history dialog. */
.gw-history-summary {
  margin-bottom: 0.75rem;
}
.gw-history-total {
  margin: 0 0 0.3rem;
  font-size: 0.85rem;
  color: var(--gw-color-text-muted);
}
.gw-history-goalbar {
  display: block;
  width: 100%;
  height: 0.6rem;
  margin-bottom: 0.5rem;
}
.gw-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 55vh;
  overflow: auto;
}
.gw-history-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.2rem 0;
}
.gw-history-date {
  flex: 0 0 6rem;
  font-size: 0.8rem;
  color: var(--gw-color-text-muted);
  font-variant-numeric: tabular-nums;
}
.gw-history-bar {
  flex: 1 1 auto;
  height: 0.7rem;
  background: var(--gw-color-bg-sunken);
  border-radius: 999px;
  overflow: hidden;
}
.gw-history-fill {
  display: block;
  height: 100%;
  background: var(--gw-color-accent);
}
.gw-history-fill.is-neg {
  background: var(--gw-color-danger);
}
.gw-history-fill.is-complete {
  background: var(--gw-color-success, var(--gw-color-accent));
}
.gw-history-num {
  flex: 0 0 9rem;
  text-align: right;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.gw-trash-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 50vh;
  overflow: auto;
}

.gw-trash-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-top: 1px solid var(--gw-color-border);
}

.gw-trash-meta {
  flex: 1;
  min-width: 0;
}

.gw-trash-title {
  font-size: 0.9rem;
  color: var(--gw-color-text);
}

.gw-trash-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  background: var(--gw-color-accent-soft);
  color: var(--gw-color-accent);
  vertical-align: middle;
}

.gw-trash-sub {
  font-size: 0.76rem;
  color: var(--gw-color-text-muted);
}

.gw-view {
  padding: 2rem;
  overflow: auto;
  font-family: var(--gw-font-body);
  position: relative; /* anchors the block handle + margin-note gutter */
}

/* A comfortable writing measure, left-aligned with a roomy left margin so
   there's no large empty band on the left; the right holds the margin-note
   gutter / whitespace. */
.gw-view .ProseMirror {
  max-width: 40rem;
  margin: 0 0 0 1rem;
}

/* ── Margin-note gutter (UI_SHAPE.md §4.1) ───────────────────────────── */
.gw-margin-layer {
  position: absolute;
  top: 0;
  width: 15rem;
  pointer-events: none;
}

.gw-margin-card {
  position: absolute;
  width: 15rem;
  pointer-events: auto;
  padding: 0.4rem 1.4rem 0.4rem 0.55rem;
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--gw-color-text-muted);
  background: var(--gw-color-accent-soft);
  border: 1px solid var(--gw-color-border);
  border-left: 3px solid var(--gw-color-accent);
  border-radius: 4px;
  cursor: pointer;
  transition: box-shadow 0.1s, transform 0.1s;
}

.gw-margin-card:hover {
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

.gw-margin-card.is-active {
  border-left-color: var(--gw-color-accent);
  box-shadow: 0 0 0 2px var(--gw-color-accent);
}

.gw-margin-card-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.gw-margin-card-del {
  position: absolute;
  top: 0.2rem;
  right: 0.3rem;
  border: none;
  background: transparent;
  color: var(--gw-color-text-muted);
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.1s;
}

.gw-margin-card:hover .gw-margin-card-del {
  opacity: 0.7;
}

.gw-margin-card-del:hover {
  opacity: 1;
}

/* When there's no room for the gutter, `ui/marginNotes.ts` hides it (based
   on the editor pane width, not the viewport) and the pin + popover
   click-to-edit remain the fallback. */

/* Block drag handle (UI_SHAPE.md §4.1) — appears in the gutter on hover. */
.gw-view.gw-has-block-handle {
  position: relative;
}

.gw-block-handle {
  position: absolute;
  width: 18px;
  height: 1.6em;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--gw-color-text-muted);
  cursor: grab;
  border-radius: 4px;
  user-select: none;
  opacity: 0.5;
  transition: opacity 0.1s, background 0.1s;
}

.gw-block-handle:hover {
  opacity: 1;
  background: var(--gw-color-bg-elevated);
}

.gw-block-handle:active {
  cursor: grabbing;
}

/* Distraction-free mode (THEMES.md §8): hide all chrome, editor fills. */
.gw-shell[data-distraction-free] {
  grid-template-rows: 1fr;
}

.gw-shell[data-distraction-free] .gw-header,
.gw-shell[data-distraction-free] .gw-footer,
.gw-shell[data-distraction-free] .gw-binder,
.gw-shell[data-distraction-free] .gw-inspector,
.gw-shell[data-distraction-free] .gw-splitter {
  display: none;
}

/* Flex layout so the lone editor (or the split panes) fill the width *and*
   the height — block layout left percentage-height children (the split view)
   with no height to resolve against. */
.gw-shell[data-distraction-free] .gw-columns {
  display: flex;
}
.gw-shell[data-distraction-free] .gw-view {
  flex: 1 1 auto;
  min-width: 0;
}

/* Print / Save-as-PDF: show only the editor content (THEMES.md §11 PDF). */
@media print {
  .gw-header,
  .gw-footer,
  .gw-binder,
  .gw-inspector,
  .gw-splitter,
  .gw-reminder {
    display: none !important;
  }
  .gw-shell {
    display: block;
    height: auto;
  }
  .gw-columns {
    display: block;
    min-height: 0;
  }
  .gw-view {
    overflow: visible;
    padding: 0;
  }
  .gw-view .ProseMirror {
    max-width: none;
  }
  .gw-scene-break,
  .gw-focus > * {
    opacity: 1 !important; /* never carry focus dimming into print */
  }
}

/* ── Combined view (Scrivenings) ─────────────────────────────────── */
.gw-combined {
  display: flex;
  flex-direction: column;
}

.gw-combined-section + .gw-combined-section {
  margin-top: 1.5rem;
  border-top: 1px solid var(--gw-color-border);
}

.gw-combined-title {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.6rem 0 0.3rem 1rem;
  font-family: var(--gw-font-ui);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gw-color-text-faint);
  background: transparent;
  border: none;
  cursor: pointer;
}

.gw-combined-title:hover {
  color: var(--gw-color-accent);
}

.gw-combined-section.is-focused .gw-combined-title {
  color: var(--gw-color-accent);
}

/* ── Split / side-by-side editing ────────────────────────────────── */
.gw-split-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0 0.5rem;
}
.gw-split {
  display: flex;
  gap: 0;
  height: 100%;
  align-items: stretch;
}
.gw-split.is-vertical {
  flex-direction: column;
}
/* Grid: a mix of rows and columns (2 across, e.g. 2×2 for four panes). The
   1px gap over a border-colored background draws the dividing lines. */
.gw-split.is-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: 1fr;
  gap: 1px;
  background: var(--gw-color-border);
}
.gw-split.is-grid .gw-split-pane {
  border: none;
  min-height: 0;
}
/* Asymmetric: one full-height "feature" pane beside a vertical stack of the
   rest. JS sets each pane's grid-row/column; here we just establish the grid
   surface (the 1px gap over the border color draws the dividers). */
.gw-split.is-asymmetric {
  display: grid;
  gap: 1px;
  background: var(--gw-color-border);
}
.gw-split.is-asymmetric .gw-split-pane {
  border: none;
  min-width: 0;
  min-height: 0;
}
.gw-split-toolbar + .gw-split {
  height: calc(100% - 2.4rem); /* leave room for the toolbar */
}
.gw-split-pane {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--gw-color-border);
  /* Solid background so the grid layout's divider color can't bleed through
     the editor area. */
  background: var(--gw-color-bg);
}
.gw-split-pane:first-child {
  border-left: none;
}
/* Stacked layout: divide with top borders instead of left borders. */
.gw-split.is-vertical .gw-split-pane {
  border-left: none;
  border-top: 1px solid var(--gw-color-border);
}
.gw-split.is-vertical .gw-split-pane:first-child {
  border-top: none;
}
.gw-split-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--gw-color-border);
  background: var(--gw-color-bg-sunken);
}
.gw-split-pane.is-focused .gw-split-head {
  background: var(--gw-color-accent-soft);
}
.gw-split-head.is-drop {
  box-shadow: inset 3px 0 0 0 var(--gw-color-accent);
}
.gw-split-grip {
  flex: none;
  display: inline-flex;
  padding: 0.1rem;
  border: none;
  background: transparent;
  color: var(--gw-color-text-faint);
  cursor: grab;
}
.gw-split-grip:hover {
  color: var(--gw-color-text);
}
.gw-split-picker {
  flex: 1 1 auto;
  min-width: 0;
}
.gw-split-editor {
  flex: 1 1 auto;
  overflow: auto;
  padding: 0.5rem 0;
  position: relative; /* anchors this pane's margin-note gutter */
}
/* Panes are narrower, so don't reserve the single-editor left margin. */
.gw-split-editor .ProseMirror {
  margin: 0 0.75rem;
  max-width: none;
}
/* "Add pane" lives in the split toolbar (a normal inline button now). */
.gw-split-add {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

/* ── Editor surface (TipTap / ProseMirror) ───────────────────────── */
.gw-view .ProseMirror {
  outline: none;
  max-width: 40rem;
  margin: 0 0 0 1rem;
  min-height: 100%;
  /* `--gw-editor-font` / `--gw-user-font-scale` are optional per-user
     overrides (Typography dialog) scoped to the writing surface, so they
     don't restyle the chrome; the scale multiplies each theme's tuned base. */
  font-family: var(--gw-editor-font, var(--gw-font-body));
  font-size: calc(var(--gw-font-size-base) * var(--gw-user-font-scale, 1));
  line-height: var(--gw-line-height);
}

.gw-view .ProseMirror h1,
.gw-view .ProseMirror h2,
.gw-view .ProseMirror h3 {
  font-weight: 600;
  line-height: 1.25;
  margin: 1.5em 0 0.5em;
}

.gw-view .ProseMirror blockquote {
  margin: 1em 0;
  padding-left: 1em;
  border-left: 3px solid var(--gw-color-border);
  color: var(--gw-color-text-muted);
}

.gw-view .ProseMirror p {
  margin: 0 0 1em;
}

/* Research-mode constructs (MANUSCRIPT_MARKDOWN.md §4). */
.gw-view .ProseMirror ul,
.gw-view .ProseMirror ol {
  margin: 0 0 1em;
  padding-left: 1.6em;
}

.gw-view .ProseMirror li > p {
  margin: 0 0 0.3em;
}

.gw-view .ProseMirror pre {
  margin: 0 0 1em;
  padding: 0.75em 1em;
  background: var(--gw-color-bg-sunken);
  border-radius: 6px;
  overflow-x: auto;
  font-family: var(--gw-font-mono);
  font-size: 0.9em;
  line-height: 1.5;
}

.gw-view .ProseMirror code {
  font-family: var(--gw-font-mono);
  font-size: 0.9em;
}

.gw-view .ProseMirror :not(pre) > code {
  background: var(--gw-color-bg-sunken);
  border-radius: 3px;
  padding: 0.1em 0.3em;
}

.gw-view .ProseMirror hr {
  border: none;
  border-top: 1px solid var(--gw-color-border-strong);
  margin: 2rem 0;
}

/* Research-mode tables — visible borders so empty cells aren't invisible. */
.gw-view .ProseMirror table {
  border-collapse: collapse;
  margin: 0 0 1em;
  width: 100%;
  table-layout: fixed;
  overflow: hidden;
}

.gw-view .ProseMirror th,
.gw-view .ProseMirror td {
  border: 1px solid var(--gw-color-border-strong);
  padding: 0.4em 0.6em;
  vertical-align: top;
  min-width: 3em;
}

.gw-view .ProseMirror th {
  background: var(--gw-color-bg-sunken);
  font-weight: 600;
  text-align: left;
}

/* The active table cell (caret inside) — a subtle accent ring. */
.gw-view .ProseMirror .selectedCell::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--gw-color-accent-soft);
  pointer-events: none;
}

.gw-view .ProseMirror td,
.gw-view .ProseMirror th {
  position: relative;
}

.gw-view .ProseMirror img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

/* Scene break flourish; the glyph comes from the active theme (THEMES.md). */
.gw-scene-break {
  margin: 2rem 0;
  text-align: center;
  letter-spacing: 0.5em;
  color: var(--gw-color-text-muted);
  user-select: none;
}

.gw-scene-break::before {
  content: var(--gw-scene-break-glyph, "✦ ✦ ✦");
}

/* Focus mode (THEMES.md §6): dim every block but the caret's; hover or
   selecting restores. Opacity only, so the theme palette is preserved. */
.gw-view .ProseMirror.gw-focus > * {
  opacity: 0.3;
  transition: opacity 140ms ease;
}

.gw-view .ProseMirror.gw-focus > .gw-focus-active,
.gw-view .ProseMirror.gw-focus > *:hover {
  opacity: 1;
}

/* Typewriter mode (THEMES.md §7): room to scroll the caret to center. */
.gw-view.gw-typewriter {
  padding-bottom: 50vh;
}
