@layer surfaces {

/* ============================================================================
   Editor v2 app frame: the editor page opts out of the global chrome (session
   bar, centered shell) and brings its own — a fixed 54px nav rail, a sticky
   52px top bar (title + type badge + view controls + sync), and a full-width
   workspace. The WINDOW stays the scroll container (the virtualized renderer
   measures window.scrollY); the frame feel comes from fixed/sticky chrome,
   never from an inner-scrolling canvas.
   ========================================================================= */
.app-shell--frame {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

/* Typing at the viewport edges auto-scrolls the caret into view; scroll-padding keeps it
   clear of the sticky top bar and the pinned statusbar instead of hiding beneath them. */
html:has(.app-shell--frame) {
  scroll-padding-top: calc(var(--topbar-h, 3.25rem) + 1.5rem);
  scroll-padding-bottom: 5rem;
}

.editor-page--frame {
  max-width: none;
  margin: 0;
  padding-left: 3.375rem; /* clear the fixed nav rail */
  padding-right: 3.25rem; /* clear the fixed lens rail */
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.editor-page--frame .editor-surface {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* The workspace (or board) absorbs the slack so the statusbar sits at the viewport
   bottom even when the document is short; sticky keeps it pinned once it scrolls. */
.editor-page--frame .editor-workspace,
.editor-surface[data-view-mode="board"] .document-board {
  flex: 1;
}

/* The global rail (left-matter model, 2026-07-23): the same fixed rail serves every
   signed-in page. Outside the editor it renders as a body-level sibling of main, so the
   sibling offsets below clear it; inside the editor it lives in .editor-surface and the
   workspace grid already accounts for it. */
.app-shell--rail {
  margin-left: 3.375rem;
}

.editor-navrail ~ .persist-banner {
  margin-left: 3.375rem;
}

/* The dashboard's fixed drawer would otherwise run over the eviction warning. */
@media (min-width: 1025px) {
  body:has(.project-dashboard[data-drawer="open"]) .persist-banner {
    margin-left: calc(3.375rem + 14.75rem);
  }
}

.editor-navrail {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 3.375rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.875rem 0;
  background: var(--c-gray-25);
  border-right: 1px solid var(--c-gray-200);
  z-index: 40;
}

.editor-navrail-mark {
  display: block;
  width: 15px;
  height: 15px;
  border-radius: 4px;
  background: var(--c-ink);
  margin-bottom: 0.625rem;
}

.editor-navrail-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--c-gray-400);
  cursor: pointer;
}

.editor-navrail-button:hover {
  color: var(--c-gray-700);
  background: var(--c-gray-100);
}

.editor-navrail-spacer {
  flex: 1;
}

.editor-navrail .theme-toggle {
  flex-direction: column;
}

/* Text (not an SVG icon), so it must clear the 4.5:1 AA contrast bar the icon buttons
   are exempt from — hence gray-600, not the rail's usual gray-400. */
.editor-navrail-button--palette {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--c-gray-600);
}

/* ---- Project drawer (editor-v3 workspace shell) ------------------------------------
   The binder promoted out of the outline column: a full-height fixed column beside the
   nav rail on desktop (the page pads left to clear it, same trick as the rail).
   data-drawer="closed" hides it and shows the top-bar reveal button instead. ≤1024px it
   flows statically below the workspace under the existing panels toggle. */
.editor-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 3.375rem;
  width: 14.75rem;
  display: flex;
  flex-direction: column;
  background: var(--c-gray-25);
  border-right: 1px solid var(--c-gray-200);
  z-index: 30;
}

.editor-drawer-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.9rem 0.875rem 0.75rem;
  border-bottom: 1px solid var(--c-gray-200);
}

.editor-drawer-heading {
  flex: 1;
  min-width: 0;
}

/* An <a> since 2026-07-23: the drawer title links to the project dashboard. */
.editor-drawer-title {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--c-gray-900);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}

.editor-drawer-title:hover,
.editor-drawer-title:focus-visible {
  color: var(--c-accent);
}

.editor-drawer-kicker {
  display: block;
  margin-top: 0.125rem;
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--c-accent);
}

.editor-drawer-collapse,
.editor-drawer-reveal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 1.625rem;
  height: 1.625rem;
  border: 1px solid var(--c-gray-300);
  border-radius: 7px;
  background: none;
  color: var(--c-gray-400);
  cursor: pointer;
}

.editor-drawer-collapse:hover,
.editor-drawer-reveal:hover {
  color: var(--c-gray-700);
  background: var(--c-gray-100);
}

.editor-drawer-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.75rem 0.875rem 1rem;
}

/* The reveal button only exists as an affordance for the desktop fixed drawer. */
.editor-drawer-reveal {
  display: none;
}

/* The dashboard hosts the same drawer (left-matter model): same classes, same
   data-drawer mechanics, on the .project-dashboard root instead of .editor-surface.
   Below 1025px the dashboard hero already lists every document, so the drawer and its
   reveal stand down entirely. */
.project-dashboard .editor-drawer-title--static {
  cursor: default;
}

@media (max-width: 1024px) {
  .project-dashboard .editor-drawer,
  .project-dashboard .editor-drawer-reveal {
    display: none;
  }
}

@media (min-width: 1025px) {
  .project-dashboard[data-drawer="closed"] .editor-drawer {
    display: none;
  }

  .project-dashboard[data-drawer="closed"] .editor-drawer-reveal {
    display: block;
    position: fixed;
    left: 3.875rem;
    top: 0.875rem;
    z-index: 25;
    border: 1px solid var(--c-gray-300);
    border-radius: 6px;
    background: var(--c-white);
    color: var(--c-gray-600);
    cursor: pointer;
    padding: 0.3rem 0.4rem;
  }

  .project-dashboard[data-drawer="closed"] .editor-drawer-reveal:hover {
    color: var(--c-gray-900);
    border-color: var(--c-gray-400);
  }

  .project-dashboard[data-drawer="open"] {
    padding-left: 15.75rem;
  }
}

@media (min-width: 1025px) {
  .editor-surface[data-drawer="closed"] .editor-drawer {
    display: none;
  }

  .editor-surface[data-drawer="closed"] .editor-drawer-reveal {
    display: inline-flex;
  }
}

/* Wide desktops: the open drawer pushes the workspace aside (page padding clears rail +
   drawer). Focus mode wins (its padding-left: 0 rule targets the same element), so
   exclude it here — later rules of equal specificity would override it. */
@media (min-width: 1361px) {
  .editor-page--frame:has(.editor-surface[data-drawer="open"]:not([data-focus="true"])) {
    padding-left: calc(3.375rem + 14.75rem);
  }
}

/* Smaller desktops (1025–1360px): all three side surfaces plus the drawer can't share the
   width without starving the prose column, so an open drawer OVERLAYS the workspace
   (temporary-drawer pattern) instead of pushing it — the shadow says "floating". JS
   defaults the drawer closed at these widths; opening it is a deliberate act. */
@media (min-width: 1025px) and (max-width: 1360px) {
  .editor-surface[data-drawer="open"] .editor-drawer {
    box-shadow: 0 0 0 1px var(--c-gray-200), 0 12px 32px var(--c-shadow);
  }
}

.editor-topbar {
  position: sticky;
  top: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-height: var(--topbar-h, 3.25rem);
  padding: 0 1.25rem;
  background: var(--c-white);
  border-bottom: 1px solid var(--c-gray-200);
}

.editor-topbar .document-title {
  margin: 0;
  min-width: 0;
  flex-shrink: 1;
}

.editor-topbar .document-title-display,
.editor-topbar .document-title-input {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.editor-doc-type-badge {
  flex: none;
  font-size: 0.59375rem;
  font-weight: 700;
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--c-gray-500);
  border: 1px solid var(--c-gray-300);
  border-radius: 5px;
  padding: 0.125rem 0.375rem;
}

.editor-topbar-spacer {
  flex: 1;
}

/* The palette's visible affordance: a keycap chip naming the platform chord (the JS
   stamps ⌘K / Ctrl+K into [data-palette-hint]). gray-600, not lighter — small text
   must clear the AA contrast gate (axe). */
.editor-topbar-palette {
  flex: none;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--c-gray-300);
  border-radius: 7px;
  background: none;
  padding: 0.25rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--c-gray-600);
  cursor: pointer;
}

.editor-topbar-palette:hover {
  color: var(--c-gray-900);
  border-color: var(--c-gray-400);
}

.editor-page--frame .editor-workspace {
  padding: 1.5rem 1.5rem 0;
}

/* Desktop only — the ≤1024px stacked layout (grid: 1fr) must keep winning.
   The prose column gets a hard floor (30rem) and the outline column absorbs the squeeze:
   with the project drawer open on a 1280px window all three side surfaces don't fit at
   full width, and a starved prose column wraps mid-word (garbling End-key caret placement,
   caught by the live-collab e2e). Writing space wins over nav chrome.

   The workspace itself is capped at the triad's natural width (tracks + gaps + padding,
   tracking the margin's collapsed state via --margin-col) and centered, so on wide screens
   the outline hugs the prose's left edge instead of stranding itself beside the drawer —
   outline and margin belong to the content, not the viewport edges (editor-v3). Capping
   the workspace (not the middle track) leaves narrow-width distribution untouched: at
   1280 the outline keeps its full 13rem, where a narrower column pushed the hover actions
   over the node titles and swallowed outline clicks (caught by the outline e2e). */
@media (min-width: 1025px) {
  .editor-page--frame .editor-workspace {
    --outline-col: 13rem;
    grid-template-columns: minmax(0, var(--outline-col)) minmax(30rem, 1fr) var(--margin-col, 19.25rem);
    gap: 1.75rem;
    max-width: calc(var(--outline-col) + var(--prose-w) + var(--margin-col, 19.25rem) + 3.5rem + 3rem);
    margin-inline: auto;
  }

  /* Lens drawer open: a fourth track joins and the cap widens with it. The outline
     column absorbs the squeeze on tight viewports (writing space keeps its 30rem floor). */
  .editor-page--frame .editor-surface:is([data-side-panel="scene"], [data-side-panel="versions"], [data-side-panel="cues"]) .editor-workspace {
    grid-template-columns: minmax(0, var(--outline-col)) minmax(30rem, 1fr) var(--margin-col, 19.25rem) 19.25rem;
    max-width: calc(var(--outline-col) + var(--prose-w) + var(--margin-col, 19.25rem) + 19.25rem + 5.25rem + 3rem);
  }

  /* Comfortable workspace (ultrawide preference): spend the wings on content — a wider
     outline and a roomier margin-card column — instead of empty paper. Only wings that
     EXIST get spent: at 1800–2199px the expansion yields while a lens drawer holds the
     fourth column (the grid would over-budget and squeeze prose to its floor); from
     2200px there is room for everything. Pins mode keeps winning at any width — a
     collapsed margin is a deliberate act. */
  @media (min-width: 1800px) {
    .editor-surface[data-workspace="comfortable"]:not([data-margin-collapsed="true"]):not([data-side-panel="scene"]):not([data-side-panel="versions"]):not([data-side-panel="cues"]) .editor-workspace {
      --outline-col: 16rem;
      --margin-col: 24rem;
      gap: 2.25rem;
    }
  }

  @media (min-width: 2200px) {
    .editor-surface[data-workspace="comfortable"]:not([data-margin-collapsed="true"]) .editor-workspace {
      --outline-col: 16rem;
      --margin-col: 24rem;
      gap: 2.25rem;
    }
  }

  /* The storyboard replaces the triad with a single full-bleed track — no cap. */
  .editor-surface[data-view-mode="board"] .editor-workspace {
    max-width: none;
  }
}

/* The writing column centers itself inside the flexible middle track. */
.editor-page--frame .editor-canvas {
  max-width: var(--prose-w);
  width: 100%;
  margin-inline: auto;
}

.editor-page--frame .editor-statusbar,
.editor-page--frame .document-board {
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

/* The sticky song dock rides below the sticky top bar. */
.editor-page--frame .editor-track-dock {
  top: var(--topbar-h, 3.25rem);
}

}
