/* Screenplay editor layout (Phase 2) */
.fe-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: calc(100vh - 12rem);
}

.fe-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.fe-toolbar .btn {
  font-size: 0.8rem;
}

.fe-warnings {
  margin: 0;
}

/* Two-column layout: Edit | Preview (scene nav is a toolbar popover) */
.fe-main,
.fe-main.fe-main-two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.65rem;
  flex: 1;
  min-height: 28rem;
  height: calc(100vh - 16rem);
}

@media (max-width: 900px) {
  .fe-main,
  .fe-main.fe-main-two-col {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 24rem;
  }
  .fe-editor-col {
    min-height: 22rem;
    height: min(60vh, 32rem);
  }
  .fe-preview-col {
    min-height: 16rem;
  }
}

/* Jump-to-scene popover (replaces left scenes column) */
.fe-scenes-pop,
.fe-advanced-pop {
  position: relative;
  display: inline-block;
}

.fe-scenes-pop > summary,
.fe-advanced-pop > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.fe-scenes-pop > summary::-webkit-details-marker,
.fe-advanced-pop > summary::-webkit-details-marker {
  display: none;
}

.fe-scenes-pop-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 0.25rem);
  left: 0;
  width: min(22rem, 85vw);
  max-height: min(22rem, 50vh);
  overflow: auto;
  padding: 0.35rem;
  background: var(--fs-bg-card);
  border: 1px solid var(--fs-border-color);
  border-radius: 0.375rem;
  box-shadow: var(--fs-shadow-card, 0 8px 24px rgba(0, 0, 0, 0.25));
}

.fe-advanced-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 0.25rem);
  left: 0;
  min-width: 12rem;
  max-width: min(24rem, 90vw);
  padding: 0.5rem;
  background: var(--fs-bg-card);
  border: 1px solid var(--fs-border-color);
  border-radius: 0.375rem;
  box-shadow: var(--fs-shadow-card, 0 8px 24px rgba(0, 0, 0, 0.25));
}

.fe-status-line .badge {
  font-weight: 600;
}

.fe-panel {
  border: 1px solid var(--fs-border-color);
  border-radius: 0.375rem;
  background: var(--fs-bg-card);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.fe-panel-header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--fs-text-muted);
  padding: 0.4rem 0.65rem;
  border-bottom: 1px solid var(--fs-border-color);
  background: var(--fs-overlay-soft);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.fe-editor-col .fe-panel-header {
  display: flex;
}

.fe-scenes-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.fe-scene-row {
  display: flex;
  align-items: flex-start;
  gap: 0.15rem;
  border-radius: 0.25rem;
}

.fe-scene-row.is-active {
  background: var(--fe-row-active-bg);
}

.fe-scene-btn {
  flex: 1;
  min-width: 0;
  display: block;
  text-align: left;
  border: none;
  background: transparent;
  padding: 0.35rem 0.35rem 0.35rem 0.45rem;
  font-size: 0.75rem;
  line-height: 1.25;
  color: var(--fs-text-primary);
  border-radius: 0.25rem;
  cursor: pointer;
  /* Collapsed: single line with ellipsis */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Scene labels in jump popover: wrap so full headings are readable */
.fe-scenes-pop-panel .fe-scene-btn {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  word-break: break-word;
}

.fe-scene-btn:hover {
  background: var(--fs-bg-card-hover);
}

.fe-scene-row.is-active .fe-scene-btn {
  color: var(--fs-link);
  font-weight: 600;
}

.fe-scene-row.is-active .fe-scene-btn:hover {
  background: transparent;
}

.fe-scene-book {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--fs-link);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 0.3rem 0.4rem;
  cursor: pointer;
  border-radius: 0.25rem;
  align-self: flex-start;
  margin-top: 0.2rem;
}

.fe-scene-book:hover {
  background: var(--fe-link-hover-bg);
  text-decoration: underline;
}

/* Book fidelity — floating window (does not block the editor) */
.fe-book-window {
  position: fixed;
  z-index: 1080;
  top: 5.5rem;
  right: 1.25rem;
  width: min(26rem, calc(100vw - 2rem));
  min-width: 16rem;
  max-width: min(40rem, calc(100vw - 1rem));
  height: min(28rem, calc(100vh - 7rem));
  min-height: 12rem;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  background: var(--fs-bg-card);
  border: 1px solid var(--fs-border-color);
  border-radius: 0.5rem;
  box-shadow: var(--fs-shadow-card);
  overflow: hidden;
  resize: both; /* corner-resize on supporting browsers */
}

.fe-book-window-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--fs-border-color);
  background: var(--fe-note-bg);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.fe-book-window-header.is-dragging {
  cursor: grabbing;
}

.fe-book-window-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
  color: var(--fe-note-fg);
}

.fe-book-window-header .fe-book-sub {
  font-size: 0.75rem;
  color: var(--fs-text-muted);
  margin-top: 0.15rem;
  font-weight: 400;
  max-width: 18rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fe-book-window-drag-hint {
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fs-text-muted);
  margin-top: 0.15rem;
}

.fe-book-window-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.85rem 1rem 1rem;
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--fs-text-primary);
  cursor: text;
  user-select: text;
}

.fe-book-window-body .fe-book-empty {
  color: var(--fs-text-muted);
  font-family: system-ui, sans-serif;
  font-size: 0.88rem;
  user-select: none;
}

.fe-book-window-close {
  border: none;
  background: transparent;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--fs-text-muted);
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 0.25rem;
  flex-shrink: 0;
}

.fe-book-window-close:hover {
  background: var(--fs-bg-card-hover);
  color: var(--fs-text-primary);
}

.fe-scenes-empty {
  font-size: 0.8rem;
  color: var(--fs-text-muted);
  padding: 0.5rem;
}

.fe-editor-col {
  min-height: 0;
}

.fe-editor-host {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  /* Constrain CodeMirror so long scripts scroll inside the pane */
  height: 100%;
}

.fe-editor-host .CodeMirror {
  position: absolute;
  inset: 0;
  height: 100% !important;
  width: 100% !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.88rem;
  line-height: 1.45;
  background: var(--fs-bg-card);
  color: var(--fe-editor-fg);
}

/* Always show a vertical scrollbar so long drafts are obviously scrollable */
.fe-editor-host .CodeMirror-scroll {
  min-height: 100%;
  max-height: 100%;
  overflow-y: scroll !important;
  overflow-x: auto !important;
}

.fe-editor-host .CodeMirror-vscrollbar {
  display: block !important;
  overflow-y: scroll !important;
}

.fe-editor-host .CodeMirror-gutters {
  background: var(--fs-bg-card);
  border-right: 1px solid var(--fs-border-color);
}

.fe-editor-host .CodeMirror-linenumber {
  color: var(--fe-editor-gutter-fg);
}

.fe-editor-host .CodeMirror-cursor {
  border-left-color: var(--fe-editor-cursor);
}

.fe-editor-host .CodeMirror-selected {
  background: var(--fe-editor-selection);
}

.fe-editor-host .CodeMirror-activeline-background {
  background: var(--fs-bg-card-hover);
}

.fe-editor-host .CodeMirror-matchingbracket {
  color: var(--fe-token-header) !important;
}

/* Fountain mode token colors */
.cm-s-default .cm-keyword {
  color: var(--fe-token-keyword);
  font-weight: 600;
  text-transform: none;
}
.cm-s-default .cm-def {
  color: var(--fe-token-def);
  font-weight: 600;
}
.cm-s-default .cm-string {
  color: var(--fe-editor-fg);
}
.cm-s-default .cm-comment {
  color: var(--fs-text-muted);
  font-style: italic;
}
.cm-s-default .cm-atom {
  color: var(--fe-token-atom);
  font-weight: 600;
}
.cm-s-default .cm-variable-2 {
  color: var(--fe-editor-fg);
}
.cm-s-default .cm-header {
  color: var(--fe-token-header);
  font-weight: 600;
}
.cm-s-default .cm-hr {
  color: var(--fs-text-muted);
}

/* Preview — page layout only (not an editor). Click jumps left; no edit affordances. */
.fe-preview-col .fe-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.fe-preview-col .fe-preview-hint {
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fs-text-muted);
}

.fe-preview-body {
  flex: 1;
  overflow: auto;
  background: var(--fe-chrome-bg); /* flat viewer chrome, not page paper */
  padding: 0.75rem;
  cursor: default;
  /* No text caret / I-beam — this is a view, not a field */
  caret-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  outline: none;
}

.fe-preview-body:focus,
.fe-preview-body:focus-visible {
  outline: none;
  box-shadow: none;
}

/* Lines are not inputs — no hover “focus ring” that looks editable */
.fe-preview-body .fp-page [data-line] {
  cursor: default;
  border-radius: 0;
  transition: none;
}

.fe-preview-body .fp-page [data-line]:hover {
  background: transparent;
  outline: none;
  box-shadow: none;
}

.fp-page {
  max-width: 42rem;
  margin: 0 auto;
  background: var(--fe-page-bg);
  padding: 1.75rem 2rem 2.5rem;
  border: 1px solid var(--fs-border-color);
  box-shadow: none; /* less “document you type in” */
  font-family: "Courier New", Courier, monospace;
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--fe-page-fg); /* slightly muted vs pure edit-pane text */
  pointer-events: none; /* clicks don’t look like field focus; scroll still works on parent */
}

.fp-empty {
  color: var(--fs-text-muted);
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  text-align: center;
  margin: 2rem 0;
}

.fp-title {
  text-align: center;
  margin: 0.15rem 0;
}

.fp-scene {
  text-transform: uppercase;
  font-weight: 700;
  margin: 1.1rem 0 0.55rem;
}

.fp-action {
  margin: 0.35rem 0;
  white-space: pre-wrap;
}

.fp-character {
  margin: 0.85rem auto 0;
  width: 58%;
  text-align: center;
  text-transform: uppercase;
  font-weight: 600;
}

.fp-character.fp-dual {
  color: var(--fs-text-muted);
}

.fp-dual-mark {
  font-size: 0.7rem;
  font-weight: 400;
  text-transform: none;
  color: var(--fs-text-muted);
}

.fp-paren {
  margin: 0 auto;
  width: 42%;
  text-align: center;
  font-style: italic;
  color: var(--fs-text-muted);
}

.fp-dialogue {
  margin: 0 auto;
  width: 62%;
  white-space: pre-wrap;
}

.fp-dialogue-gap {
  height: 0.75rem;
}

.fp-transition {
  margin: 0.75rem 0 0.75rem auto;
  width: 45%;
  text-align: right;
  text-transform: uppercase;
}

.fp-centered {
  text-align: center;
  margin: 0.75rem 0;
  font-weight: 600;
}

.fp-lyric {
  margin: 0.35rem auto;
  width: 62%;
  font-style: italic;
}

.fp-section {
  margin: 1rem 0 0.35rem;
  font-weight: 700;
  color: var(--fe-token-header);
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
}

.fp-synopsis {
  margin: 0.25rem 0 0.75rem;
  color: var(--fs-text-muted);
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  font-style: italic;
}

.fp-note {
  margin: 0.5rem 0;
  padding: 0.35rem 0.5rem;
  background: var(--fe-note-bg);
  border-left: 3px solid var(--fe-note-border);
  font-family: system-ui, sans-serif;
  font-size: 0.78rem;
  color: var(--fe-note-fg);
  font-style: italic;
}

.fp-pagebreak {
  border: none;
  border-top: 2px dashed var(--fs-border-color);
  margin: 1.25rem 0;
}

.fp-blank {
  height: 0.55rem;
}

/* Locate-in-view only (not a selection/caret) */
.fp-flash {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--fs-border-hover);
  background: var(--fs-bg-card-hover);
  transition: background 0.4s ease;
}
