@layer surfaces {

/* ---- Responsive + touch (beta workstream A) ------------------------------------------- */

/* Mobile-only outline/tools toggle in the editor top bar. */
.editor-panels-toggle {
  display: none;
  border: 1px solid var(--c-gray-300);
  border-radius: 6px;
  background: var(--c-white);
  color: var(--c-gray-700);
  cursor: pointer;
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.3rem 0.85rem;
}

/* Storyboard card ↑/↓ reorder — a touch-operable alternative to drag. Hover-revealed on fine
   pointers; always shown on touch (see @media (hover: none)). */
.document-board-card-title {
  flex: 1;
}

.document-board-card-move {
  display: inline-flex;
  gap: 0.1rem;
  opacity: 0;
  transition: opacity var(--t-fast);
}

.document-board-card:hover .document-board-card-move,
.document-board-card:focus-within .document-board-card-move {
  opacity: 1;
}

.document-board-card-move-button {
  border: 1px solid var(--c-gray-300);
  border-radius: 4px;
  background: var(--c-white);
  color: var(--c-gray-500);
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0.15rem 0.4rem;
}

.document-board-card-move-button:hover {
  border-color: var(--c-accent);
  color: var(--c-accent);
}

/* Touch devices (no hover): reveal the otherwise hover-only controls, drop the drag affordances
   (HTML5 drag can't fire on touch — reorder is via the ↑/↓ buttons), and enlarge tap targets. */
@media (hover: none) {
  .document-export-button,
  .document-delete-button,
  .document-outline-node-actions,
  .document-board-card-move {
    opacity: 1;
  }

  /* No hover to reveal overlays: the outline controls return to the flow — reserved
     space is the honest layout when the controls are permanently visible. */
  .document-outline-node-row {
    display: flex;
    align-items: center;
    gap: 0.25rem;
  }

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

  .document-outline-node-actions,
  .document-outline-node-status {
    position: static;
    transform: none;
    background: transparent;
    pointer-events: auto;
  }

  .document-outline-drag-handle {
    display: none;
  }

  .document-board-card {
    cursor: default;
  }

  .document-board-card-move-button,
  .document-outline-node-actions button,
  .document-export-button,
  .document-delete-button {
    min-height: 40px;
  }
}

/* Tablet + phone: stack the editor, writing canvas first, and collapse the outline + side panels
   behind the "Outline & tools" toggle so the writing surface is primary. */
@media (max-width: 1024px) {
  .editor-workspace {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .editor-canvas {
    order: -1;
  }

  .document-outline {
    position: static;
    order: 1;
    border-right: 0;
    border-bottom: 1px solid var(--c-gray-200);
    padding-right: 0;
    padding-bottom: 1rem;
  }

  .document-notes {
    position: static;
    order: 2;
    border-left: 0;
    border-top: 1px solid var(--c-gray-200);
    padding-left: 0;
    padding-top: 1rem;
  }

  .editor-panels-toggle {
    display: inline-flex;
  }

  .editor-surface[data-view-mode="board"] .editor-panels-toggle {
    display: none;
  }

  .editor-surface[data-panels-collapsed="true"] .document-outline,
  .editor-surface[data-panels-collapsed="true"] .document-notes,
  .editor-surface[data-panels-collapsed="true"] .editor-drawer {
    display: none;
  }
}

/* Phone: one storyboard column per screen (snap), and keep the find bar from overflowing. */
@media (max-width: 640px) {
  .document-board-columns {
    scroll-snap-type: x mandatory;
  }

  .document-board-column {
    flex: 0 0 85vw;
    scroll-snap-align: start;
  }

  .editor-find-bar {
    left: 0;
    right: 0;
    width: auto;
  }

  .editor-find-input {
    flex: 1;
    width: auto;
  }
}

/* ---- Read-only documents (seeded tutorial/terms/privacy) — beta workstream B ----------- */

.editor-surface[data-read-only="true"] {
  /* Pure edit affordances vanish — they carry no information when you can't edit. */
  & .document-notes-add,
  & .document-versions-create,
  & .document-board-card-move,
  & .document-outline-node-actions,
  & .document-outline-drag-handle,
  & .editor-margin-empty,
  & .editor-empty-hint {
    display: none;
  }

  /* Metadata controls stay VISIBLE (they show the scene's status/synopsis/beat/active
     template — the whole point of an explorable read-only tutorial) but become
     non-interactive. The JS guards are the real enforcement; this just removes the
     affordance. */
  & .document-scene-body button,
  & .document-scene-body input,
  & .document-scene-body textarea,
  & .document-scene-body select,
  & .document-board-card-status,
  & .document-board-card-beat,
  & .document-board-template-select {
    pointer-events: none;
  }

  & .editor-blocks {
    cursor: default;
  }
}

.document-title.is-read-only .document-title-display {
  cursor: default;
}

/* ---- Admin (invitations + users) and account pages — beta workstream C ----------------- */
.admin-page {
  max-width: 42rem;
}

.admin-invite-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.admin-invite-input {
  flex: 1;
  border: 1px solid var(--c-gray-300);
  border-radius: 4px;
  padding: 0.5rem 0.7rem;
}

.admin-invite-input:focus {
  border-color: var(--c-gray-900);
  outline: 2px solid transparent;
}

.admin-form-error {
  margin: 0 0 0.75rem;
  color: var(--c-danger-900);
  font-size: 0.875rem;
}

.admin-note {
  margin: 0 0 1.5rem;
  color: var(--c-gray-500);
  font-size: 0.875rem;
}

.admin-section-title {
  margin: 1.5rem 0 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--ls-kicker);
  color: var(--c-gray-500);
}

.admin-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.admin-list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  border: 1px solid var(--c-gray-200);
  border-radius: 6px;
  padding: 0.75rem 1rem;
}

.admin-list-main {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
  flex: 1;
}

.admin-list-email {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
}

.admin-list-meta {
  color: var(--c-gray-500);
  font-size: 0.8125rem;
  font-weight: 400;
}

.admin-badge {
  border: 1px solid var(--c-gray-300);
  border-radius: 999px;
  background: var(--c-gray-100);
  color: var(--c-gray-500);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.05rem 0.4rem;
}

.admin-empty {
  margin: 0;
  color: var(--c-gray-400);
  font-size: 0.875rem;
}

.admin-copy {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.admin-copy-input {
  width: 16rem;
  max-width: 50vw;
  border: 1px solid var(--c-gray-300);
  border-radius: 4px;
  background: var(--c-gray-50);
  color: var(--c-gray-700);
  font-size: 0.8125rem;
  padding: 0.35rem 0.5rem;
}

.admin-revoke {
  border: 1px solid var(--c-danger-200);
  border-radius: 4px;
  background: var(--c-white);
  color: var(--c-danger-700);
  cursor: pointer;
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.35rem 0.75rem;
}

.admin-revoke:hover,
.admin-revoke:focus-visible {
  border-color: var(--c-danger-700);
  background: var(--c-danger-50);
  outline: none;
}

.account-section {
  border-top: 1px solid var(--c-gray-200);
  padding-top: 1.5rem;
}

/* ---- Persistent-storage-denied banner (RISKS R3) — beta workstream D ------------------- */
.persist-banner {
  border-bottom: 1px solid var(--c-warning-300);
  background: var(--c-warning-50);
}

.persist-banner-inner {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  width: min(100%, 72rem);
  margin: 0 auto;
  padding: 0.6rem 1.5rem;
}

.persist-banner-text {
  flex: 1;
  color: var(--c-warning-900);
  font-size: 0.85rem;
  line-height: 1.4;
}

.persist-banner-link {
  color: var(--c-warning-900);
  text-decoration: underline;
}

.persist-banner-dismiss {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--c-warning-800);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0 0.25rem;
}

.persist-banner-dismiss:hover,
.persist-banner-dismiss:focus-visible {
  color: var(--c-warning-900);
  outline: none;
}

/* Color-theme toggle (session bar) — light / dark / system segmented control. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  padding: 0.1875rem;
  border: 1px solid var(--c-gray-200);
  border-radius: 8px;
  background: var(--c-white);
}

.theme-toggle-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.5rem;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--c-gray-500);
  font-size: 0.8125rem;
  line-height: 1;
  cursor: pointer;
}

.theme-toggle-option:hover,
.theme-toggle-option:focus-visible {
  color: var(--c-gray-900);
  background: var(--c-gray-100);
  outline: none;
}

.theme-toggle-option.is-active {
  color: var(--c-gray-900);
  background: var(--c-gray-200);
}

}
