/* Script module (sp-): screenplay editor, scene navigator, tool panels, status bar.
   The page is laid out in character cells: every block spans the full paper width and indents its text
   with padding measured in ch (Courier Prime is monospaced, 1ch = 0.1 in at 12 pt), so columns match
   screenplay/elements.js METRICS and the PDF. Colours on the paper are mixed from candy colours so they
   read the same in light and dark themes (the paper stays paper-coloured in both). */

/* ================================================================ layout */

.sp-page { --sp-zoom: 1; }
.sp-layout {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}
.sp-center {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background: var(--canvas);
}
.sp-scroll {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: var(--s-6) var(--s-5) 0;
  background: var(--canvas);
  scroll-padding: 80px 0;
  container: sp-scroll / inline-size;
}
.sp-scroll-end { height: 40vh; }
.sp-page.is-focus .sp-scroll-end { height: 50vh; }

.sp-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
}
.sp-tb-group { display: inline-flex; align-items: center; gap: 2px; }
.sp-type .select { min-width: 178px; font-weight: 700; }
.sp-toolbar > .toolbar-divider { margin: 0 2px; }
.sp-type { --tc: var(--gray); }
.sp-type .select { box-shadow: inset 5px 0 0 var(--tc); padding-left: 14px; }
.sp-type[data-type="scene"] { --tc: var(--blue); }
.sp-type[data-type="character"] { --tc: var(--orange); }
.sp-type[data-type="parenthetical"] { --tc: var(--amber); }
.sp-type[data-type="dialogue"] { --tc: var(--green); }
.sp-type[data-type="transition"] { --tc: var(--violet); }
.sp-type[data-type="shot"] { --tc: var(--pink); }
.sp-type[data-type="centered"] { --tc: var(--teal); }
.sp-type[data-type="note"] { --tc: var(--yellow); }
.sp-type[data-type="section"] { --tc: var(--indigo); }
.sp-type[data-type="synopsis"] { --tc: var(--cyan); }

.sp-zoom { display: inline-flex; align-items: center; gap: 2px; }
.sp-zoom-value {
  min-width: 48px;
  padding: 3px 6px;
  font: 700 var(--fs-sm)/1 var(--font-ui);
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
  background: none;
  border: 0;
  border-radius: var(--r-xs);
  cursor: pointer;
}
.sp-zoom-value:hover { background: var(--hover); color: var(--text); }
.sp-listening { color: var(--red-ink); animation: sp-pulse 1.2s ease-in-out infinite; }
@keyframes sp-pulse { 50% { background: var(--red-soft); } }

/* ================================================================ paper */

.sp-paper {
  --pc: 85;
  --sp-bg: var(--paper);
  --sp-ink: var(--paper-ink);
  position: relative;
  box-sizing: content-box;
  width: calc(var(--pc) * 1ch);
  margin: 0 auto;
  padding: 6em 0 6em;
  /* 12 pt at 100%; shrinks (down to 10 px) when the column is narrower than the page, 85ch = 51em */
  font: 400 max(10px, min(calc(16px * var(--sp-zoom)), calc((100cqi - 8px) / 51.2))) / 1 var(--font-script);
  color: var(--sp-ink);
  background: var(--sp-bg);
  border: var(--bw) solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow-md);
}
.sp-paper.is-a4 { --pc: 82.7; }
.sp-paper.is-revising { box-shadow: 4px 4px 0 0 var(--line), 0 -6px 0 -2px var(--rc, var(--blue)); }
.is-darkpage .sp-paper { --sp-bg: var(--paper-ink); --sp-ink: var(--paper); }

.sp-paper[data-rev="blue"] { --rc: var(--blue); }
.sp-paper[data-rev="pink"] { --rc: var(--pink); }
.sp-paper[data-rev="yellow"] { --rc: var(--yellow); }
.sp-paper[data-rev="green"] { --rc: var(--green); }
.sp-paper[data-rev="amber"] { --rc: var(--amber); }
.sp-paper[data-rev="brown"] { --rc: var(--brown); }
.sp-paper[data-rev="orange"] { --rc: var(--orange); }
.sp-paper[data-rev="red"] { --rc: var(--red); }

.sp-surface {
  min-height: 30em;
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  caret-color: var(--blue);
  -webkit-user-modify: read-write-plaintext-only;
}
.sp-surface:focus-visible { outline: none; }

/* ---------------------------------------------------------------- elements */

.sp-el {
  --col: 15;
  --w: 60;
  position: relative;
  min-height: 1em;
  margin-top: 1em;
  padding: 0 calc((var(--pc) - var(--col) - var(--w)) * 1ch) 0 calc(var(--col) * 1ch);
}
.sp-el:first-child { margin-top: 0; }
.sp-el[data-type="scene"] { margin-top: 2em; font-weight: 700; text-transform: uppercase; }
.sp-el[data-type="scene"]:first-child { margin-top: 0; }
.sp-el[data-type="character"] { --col: 37; --w: 38; text-transform: uppercase; }
.sp-el[data-type="parenthetical"] { --col: 32; --w: 24; margin-top: 0; text-indent: -1ch; }
.sp-el[data-type="dialogue"] { --col: 25; --w: 35; margin-top: 0; }
.sp-el[data-type="transition"] { text-align: right; text-transform: uppercase; }
.sp-el[data-type="shot"] { text-transform: uppercase; }
.sp-el[data-type="centered"] { text-align: center; }
.sp-el[data-type="section"] {
  margin-top: 2em;
  font: 700 0.95em/1.1 var(--font-ui);
  letter-spacing: 0.02em;
  color: color-mix(in srgb, var(--indigo) 60%, var(--sp-ink));
}
.sp-el[data-type="synopsis"] {
  margin-top: 0.5em;
  font: italic 500 0.9em/1.15 var(--font-ui);
  color: color-mix(in srgb, var(--sp-ink) 62%, transparent);
}
.sp-el[data-type="note"] {
  padding-top: 0.25em;
  padding-bottom: 0.25em;
  background-color: color-mix(in srgb, var(--yellow) 42%, var(--sp-bg));
  background-clip: content-box;
  box-shadow: inset calc(var(--col) * 1ch - 0.4ch) 0 0 -0.1ch var(--sp-bg), inset calc(var(--col) * 1ch) 0 0 -0.1ch var(--amber);
  font-style: italic;
}
.sp-el[data-type="pagebreak"] {
  height: 1em;
  user-select: none;
  background: repeating-linear-gradient(90deg, color-mix(in srgb, var(--sp-ink) 45%, transparent) 0 1ch, transparent 1ch 2ch) center / 100% 1px no-repeat content-box;
}
.sp-el[data-type="pagebreak"]::after {
  content: "Page break";
  position: absolute;
  top: -0.1em;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 1ch;
  font: 700 0.7em/1.6 var(--font-ui);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--sp-ink) 55%, transparent);
  background: var(--sp-bg);
}

/* dual dialogue: a violet bar beside the cue and its speech */
.sp-el[data-dualblk] {
  background-image: linear-gradient(var(--violet), var(--violet));
  background-repeat: no-repeat;
  background-size: 0.35ch 100%;
  background-position: calc((var(--col) - 2) * 1ch) 0;
}

/* emphasis: the Fountain marks stay in the text, dimmed */
.sp-mark { opacity: 0.38; font-weight: 400; font-style: normal; text-decoration: none; }
.sp-b { font-weight: 700; }
.sp-i { font-style: italic; }
.sp-u { text-decoration: underline; text-underline-offset: 0.15em; }

/* omitted scene */
.sp-el[data-omitted] { text-decoration: line-through; text-decoration-thickness: 2px; opacity: 0.55; }

/* placeholders */
.sp-el.is-ph:not([data-pb])::before,
.sp-surface.is-blank > .sp-el:first-child::before {
  content: attr(data-ph);
  position: absolute;
  top: 0;
  left: calc(var(--col) * 1ch);
  right: calc((var(--pc) - var(--col) - var(--w)) * 1ch);
  font-weight: 400;
  font-style: italic;
  text-transform: none;
  text-indent: 0;
  text-align: inherit;
  color: color-mix(in srgb, var(--sp-ink) 38%, transparent);
  pointer-events: none;
  white-space: nowrap;
}
.sp-surface.is-blank > .sp-el:first-child::before { content: "Start with a scene heading: INT. KITCHEN - DAY"; text-align: left; }

/* page breaks: a band of canvas across the paper with the next page number */
.sp-el[data-pb]::before {
  content: attr(data-pb) ".";
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  box-sizing: border-box;
  height: 4.5em;
  margin: 0 calc((var(--pc) - var(--col) - var(--w)) * -1ch) 1.5em calc(var(--col) * -1ch);
  padding-right: calc((var(--pc) - 75) * 1ch);
  font: 400 1em/1 var(--font-script);
  font-style: normal;
  text-transform: none;
  text-indent: 0;
  letter-spacing: 0;
  color: color-mix(in srgb, var(--sp-ink) 60%, transparent);
  background: linear-gradient(to bottom,
    transparent 0 1em,
    var(--line) 1em calc(1em + 2px),
    var(--canvas) calc(1em + 2px) calc(2.6em - 2px),
    var(--line) calc(2.6em - 2px) 2.6em,
    transparent 2.6em);
  user-select: none;
}
.sp-el[data-type="note"][data-pb]::before { margin-left: calc(var(--col) * -1ch); }

/* scene numbers in both margins (one pseudo element, justified edge to edge) */
.sp-el[data-sn]::after {
  content: attr(data-sn) " " attr(data-snr);
  position: absolute;
  top: 0;
  left: 10ch;
  width: 69ch;
  font-weight: 400;
  text-transform: none;
  text-indent: 0;
  text-align: justify;
  text-align-last: justify;
  white-space: normal;
  color: color-mix(in srgb, var(--sp-ink) 80%, transparent);
  pointer-events: none;
}
.sp-el[data-pb][data-sn]::after,
.sp-el[data-pb][data-rev]::after { top: 6em; }

/* revision marks: a tint of the revision colour and an asterisk in the right margin */
.sp-el[data-rev] { --rv: var(--blue); background-color: color-mix(in srgb, var(--rv) 16%, transparent); }
.sp-el[data-rev="pink"] { --rv: var(--pink); }
.sp-el[data-rev="yellow"] { --rv: var(--yellow); }
.sp-el[data-rev="green"] { --rv: var(--green); }
.sp-el[data-rev="amber"] { --rv: var(--amber); }
.sp-el[data-rev="brown"] { --rv: var(--brown); }
.sp-el[data-rev="orange"] { --rv: var(--orange); }
.sp-el[data-rev="red"] { --rv: var(--red); }
.sp-el[data-rev="white"], .sp-el[data-rev="gray"] { --rv: var(--gray); }
.sp-el[data-rev]:not([data-sn])::after {
  content: "*";
  position: absolute;
  top: 0;
  left: 78ch;
  font-weight: 700;
  font-style: normal;
  text-indent: 0;
  color: var(--sp-ink);
  pointer-events: none;
}
.sp-el[data-type="note"][data-rev] { background-color: color-mix(in srgb, var(--yellow) 42%, var(--sp-bg)); }

/* comment dot in the left margin (click it to open the comment) */
.sp-el[data-cm] {
  background-image: radial-gradient(circle at 50% 50%, var(--amber) 0 0.28em, var(--line) 0.3em 0.4em, transparent 0.44em);
  background-repeat: no-repeat;
  background-size: 1em 1em;
  background-position: 6ch 0;
}
.sp-el[data-cm][data-pb] { background-position: 6ch 6em; }

.sp-el.is-flash { animation: sp-flash 1.8s ease-out; }
@keyframes sp-flash {
  0%, 30% { background-color: color-mix(in srgb, var(--blue) 30%, transparent); }
  100% { background-color: transparent; }
}

::highlight(sp-find) { background-color: color-mix(in srgb, var(--yellow) 75%, transparent); color: var(--paper-ink); }
::highlight(sp-find-current) { background-color: var(--orange); color: var(--paper-ink); }

/* ================================================================ empty project */

.sp-starter {
  max-width: 640px;
  margin: 0 auto var(--s-6);
  padding: var(--s-5) var(--s-6);
  text-align: center;
  background: var(--surface);
  border: var(--bw) solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
}
.sp-starter-icon {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: var(--s-2);
  color: var(--on-candy);
  background: var(--blue);
  border: var(--bw) solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  transform: rotate(-6deg);
}
.sp-starter-title { margin: 0 0 var(--s-2); font: 600 var(--fs-xl)/1.2 var(--font-display); }
.sp-starter-text { margin: 0 auto var(--s-4); max-width: 460px; color: var(--text-2); line-height: 1.5; }
.sp-starter-text code { font-family: var(--font-script); font-weight: 700; color: var(--blue-ink); }
.sp-starter-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: var(--s-2); }

/* ================================================================ autocomplete */

.sp-ac {
  position: fixed;
  z-index: var(--z-popover);
  min-width: 220px;
  max-width: 420px;
  padding: 4px;
  background: var(--surface);
  border: var(--bw) solid var(--line);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-md);
}
.sp-ac-item {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  padding: 6px 10px;
  border-radius: var(--r-xs);
  font: 700 14px/1.25 var(--font-script);
  text-transform: uppercase;
  color: var(--text);
  cursor: pointer;
}
.sp-ac-item:hover { background: var(--hover); }
.sp-ac-item.is-active { background: var(--blue-soft); box-shadow: inset 3px 0 0 var(--blue); }
.sp-ac-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-ac-hint { flex: none; font: 600 var(--fs-xs)/1 var(--font-ui); text-transform: none; color: var(--text-muted); }
.sp-ac-foot { display: flex; align-items: center; gap: 6px; padding: 6px 8px 3px; font-size: var(--fs-xs); color: var(--text-muted); border-top: 1px solid var(--border); margin-top: 4px; }

/* ================================================================ find bar */

.sp-find {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: none;
  padding: 8px var(--s-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: inset 0 -3px 0 var(--yellow-soft);
}
.sp-find-row { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2); min-width: 0; }
.sp-find-input { flex: 0 1 300px; min-width: 160px; }
.sp-find-indent { width: 28px; flex: none; }
.sp-find-count { min-width: 76px; font-size: var(--fs-sm); font-weight: 700; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ================================================================ status bar */

.sp-status {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  flex: none;
  min-width: 0;
  min-height: 34px;
  padding: 4px var(--s-4);
  font-size: var(--fs-sm);
  color: var(--text-2);
  background: var(--surface);
  border-top: 1px solid var(--border);
  overflow: hidden;
  white-space: nowrap;
}
.sp-stat { display: inline-flex; align-items: center; gap: 6px; flex: none; font-variant-numeric: tabular-nums; }
.sp-stat b { color: var(--text); }
.sp-stat .icon { color: var(--text-muted); flex: none; }
.sp-stat-scene { flex: 0 1 260px; min-width: 60px; overflow: hidden; }
.sp-goal-btn { flex: 0 1 auto; min-width: 0; overflow: hidden; }
.sp-status { container: sp-status / inline-size; }
@container sp-status (max-width: 860px) {
  .sp-stat-runtime, .sp-stat-session { display: none; }
}
@container sp-status (max-width: 640px) {
  .sp-stat-words, .sp-stat-type { display: none; }
  .sp-stat-scene { flex-basis: 160px; }
}
.sp-stat-num {
  flex: none;
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 20px;
  padding: 0 5px;
  font: 600 12px/1 var(--font-display);
  color: var(--on-candy);
  background: var(--c);
  border: var(--bw-thin) solid var(--line);
  border-radius: var(--r-xs);
}
.sp-stat-num[data-color="white"] { background: var(--strip-white); color: var(--text); }
.sp-stat-type { font-weight: 700; color: var(--blue-ink); }
.sp-dictating { color: var(--red-ink); font-weight: 600; }
.sp-rev-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); border: var(--bw-thin) solid var(--line); }
.sp-goal-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 8px;
  font: 600 var(--fs-sm)/1.2 var(--font-ui);
  color: var(--text-2);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  cursor: pointer;
}
.sp-goal-btn:hover { background: var(--hover); color: var(--text); }
.sp-goal-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.sp-goal-bar { width: 90px; flex: none; }

/* ================================================================ navigator */

.sp-nav {
  display: flex;
  flex-direction: column;
  flex: 0 0 280px;
  width: 280px;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.sp-nav-head { display: flex; align-items: center; gap: var(--s-2); padding: 10px 8px 6px var(--s-4); }
.sp-nav-title { display: flex; align-items: baseline; gap: 6px; flex: 1 1 auto; min-width: 0; font: 600 var(--fs-lg)/1.2 var(--font-display); }
.sp-nav-count { font-size: 20px; color: var(--blue-ink); }
.sp-nav-pages { font: 600 var(--fs-xs)/1 var(--font-ui); color: var(--text-muted); margin-left: auto; }
.sp-nav-search { padding: 0 var(--s-3) var(--s-2); }
.sp-nav-search .search { width: 100%; }
.sp-nav-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 2px var(--s-2) var(--s-4); }
.sp-nav-none { padding: var(--s-3); color: var(--text-muted); font-size: var(--fs-sm); }
.sp-nav-row {
  position: relative;
  display: grid;
  grid-template-columns: 6px 30px minmax(0, 1fr) auto;
  align-items: start;
  gap: 0 8px;
  padding: 7px 6px 7px 0;
  margin-bottom: 2px;
  border-radius: var(--r-sm);
  cursor: pointer;
  outline: none;
}
.sp-nav-row:hover { background: var(--hover); }
.sp-nav-row:focus-visible { box-shadow: 0 0 0 2px var(--focus); }
.sp-nav-row.is-active { background: var(--blue-soft); }
.sp-nav-row.is-active .sp-nav-num { background: var(--blue); color: var(--on-candy); border-color: var(--line); }
.sp-nav-row.is-dragging { opacity: 0.4; }
.sp-nav-row.dnd-before { box-shadow: inset 0 3px 0 var(--blue); }
.sp-nav-row.dnd-after { box-shadow: inset 0 -3px 0 var(--blue); }
.sp-nav-edge {
  align-self: stretch;
  width: 6px;
  border-radius: 0 3px 3px 0;
  background: var(--c);
  border: var(--bw-thin) solid var(--line);
  border-left: 0;
}
.sp-nav-edge[data-color="white"] { background: var(--strip-white); }
.sp-nav-num {
  display: grid;
  place-items: center;
  height: 22px;
  margin-top: 1px;
  font: 600 13px/1 var(--font-display);
  color: var(--text);
  background: var(--surface-2);
  border: var(--bw-thin) solid var(--border);
  border-radius: var(--r-xs);
  font-variant-numeric: tabular-nums;
}
.sp-nav-main { min-width: 0; }
.sp-nav-heading {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 700 12.5px/1.45 var(--font-script);
  text-transform: uppercase;
  color: var(--text);
}
.sp-nav-omit {
  margin-right: 6px;
  padding: 0 5px;
  font: 700 10px/1.5 var(--font-ui);
  text-transform: uppercase;
  color: var(--red-ink);
  background: var(--red-soft);
  border-radius: var(--r-xs);
}
.sp-nav-row.is-omitted .sp-nav-heading { text-decoration: line-through; color: var(--text-muted); }
.sp-nav-syn { margin-top: 1px; font-size: var(--fs-xs); line-height: 1.35; color: var(--text-2); }
.sp-nav-syn .inline-edit { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sp-nav-syn .inline-edit.is-empty { color: var(--text-muted); font-style: italic; opacity: 0; }
.sp-nav-row:hover .sp-nav-syn .inline-edit.is-empty,
.sp-nav-row.is-active .sp-nav-syn .inline-edit.is-empty,
.sp-nav-syn .inline-edit.is-empty:focus { opacity: 1; }
.sp-nav-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.sp-nav-len { font: 700 var(--fs-xs)/1.5 var(--font-ui); color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sp-nav-tag { width: 12px; height: 12px; border-radius: 4px; background: var(--c); border: var(--bw-thin) solid var(--line); }
.sp-nav-more {
  display: grid;
  place-items: center;
  width: 24px;
  height: 22px;
  padding: 0;
  color: var(--text-muted);
  background: none;
  border: 0;
  border-radius: var(--r-xs);
  cursor: pointer;
  opacity: 0;
}
.sp-nav-row:hover .sp-nav-more, .sp-nav-row.is-active .sp-nav-more, .sp-nav-more:focus-visible { opacity: 1; }
.sp-nav-more:hover { background: var(--surface-sunken); color: var(--text); }
.sp-pop { display: flex; flex-direction: column; gap: var(--s-2); padding: var(--s-3); }
.sp-pop-title { font-weight: 700; font-size: var(--fs-sm); }

/* ================================================================ right panel */

.sp-side {
  display: flex;
  flex-direction: column;
  flex: 0 0 360px;
  width: 360px;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
}
.sp-side-head { display: flex; align-items: center; gap: 2px; padding: 6px 4px 0 4px; border-bottom: 1px solid var(--border); }
.sp-side-head .tabs { flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; gap: 2px; padding: 0 2px; }
.sp-side-head .tab { padding: 0 6px; gap: 4px; font-size: 12.5px; }
.sp-side-head .tab .icon { display: none; }
.sp-side-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.sp-panel-body { display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-3); }
.sp-panel-bar { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.sp-panel-loading { display: grid; place-items: center; padding: var(--s-7); }

.sp-comments, .sp-versions { display: flex; flex-direction: column; gap: var(--s-2); }
.sp-comment, .sp-version {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--amber);
  border-radius: var(--r-sm);
}
.sp-version { display: flex; align-items: flex-start; gap: var(--s-2); border-left-color: var(--blue); }
.sp-comment.is-focus { background: var(--amber-soft); border-color: var(--amber); }
.sp-comment.is-resolved { border-left-color: var(--green); opacity: 0.8; }
.sp-comment-where {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
  padding: 0;
  font: 700 12px/1.4 var(--font-script);
  color: var(--text-2);
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}
.sp-comment-where:hover { color: var(--blue-ink); }
.sp-comment-text { margin: 6px 0; white-space: pre-wrap; line-height: 1.45; }
.sp-comment-foot { display: flex; align-items: center; gap: 4px; }
.sp-version-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sp-version-name { font-weight: 700; }
.sp-version-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }

/* ================================================================ suggestions (Claude) */

.sp-ghost {
  position: absolute;
  left: 50%;
  bottom: 48px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  width: min(660px, calc(100% - 48px));
  max-height: 58%;
  transform: translateX(-50%);
  background: var(--surface);
  border: var(--bw) solid var(--line);
  border-top: 6px solid var(--violet);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
}
.sp-ghost-head, .sp-ghost-foot { display: flex; align-items: center; gap: var(--s-2); padding: 8px 12px; }
.sp-ghost-head .icon { color: var(--violet-ink); }
.sp-ghost-foot { justify-content: flex-end; border-top: 1px solid var(--border); }
.sp-ghost-body { flex: 1 1 auto; min-height: 60px; overflow: auto; padding: 4px 12px 10px; }
.sp-ghost-wait { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-3) 0; color: var(--text-2); }
.sp-ghost-error { margin: var(--s-2) 0; color: var(--danger-text); font-weight: 600; }
.sp-ghost-lines {
  padding: 12px 0;
  font: 13px/1.25 var(--font-script);
  color: var(--paper-ink);
  background: color-mix(in srgb, var(--violet) 10%, var(--paper));
  border: 1px dashed var(--violet);
  border-radius: var(--r-sm);
}

/* read-only screenplay lines (version preview, suggestions) */
.sp-ro { margin: 1em 2ch 0; white-space: pre-wrap; overflow-wrap: break-word; }
.sp-ro:first-child { margin-top: 0; }
.sp-ro[data-type="scene"] { margin-top: 1.6em; font-weight: 700; text-transform: uppercase; }
.sp-ro[data-type="character"] { margin-left: 24ch; text-transform: uppercase; }
.sp-ro[data-type="parenthetical"] { margin-top: 0; margin-left: 18ch; max-width: 25ch; }
.sp-ro[data-type="dialogue"] { margin-top: 0; margin-left: 12ch; max-width: 35ch; }
.sp-ro[data-type="transition"] { text-align: right; text-transform: uppercase; }
.sp-ro[data-type="shot"] { text-transform: uppercase; }
.sp-ro[data-type="centered"] { text-align: center; }
.sp-ro[data-type="note"] { background: color-mix(in srgb, var(--yellow) 40%, var(--paper)); font-style: italic; }
.sp-ro[data-type="section"], .sp-ro[data-type="synopsis"] { font-family: var(--font-ui); font-style: italic; opacity: 0.75; }
.sp-ro[data-type="pagebreak"] { border-top: 1px dashed currentColor; opacity: 0.4; }

.sp-suggest { display: flex; flex-direction: column; gap: var(--s-3); }
.sp-suggest-block { display: flex; flex-direction: column; gap: 6px; }
.sp-suggest-label { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.sp-suggest-block[data-color] .sp-suggest-label { color: var(--c-ink); }
.sp-suggest-text {
  margin: 0;
  max-height: 260px;
  overflow: auto;
  padding: 10px 12px;
  font: 13px/1.45 var(--font-script);
  white-space: pre-wrap;
  color: var(--paper-ink);
  background: var(--paper);
  border: 1px solid var(--border);
  border-left: 4px solid var(--c, var(--gray));
  border-radius: var(--r-sm);
}
.sp-suggest-text.is-old { opacity: 0.7; border-left-color: var(--gray); }

/* ================================================================ versions, title page, PDF */

.sp-ver-loading, .sp-pdf-loading { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-5); color: var(--text-2); }
.sp-ver-preview { display: flex; flex-direction: column; gap: var(--s-3); }
.sp-ver-summary { display: flex; flex-direction: column; gap: var(--s-2); }
.sp-ver-stats { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.sp-ver-diff { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; font-size: var(--fs-sm); }
.sp-ver-diff li { padding: 3px 8px; border-left: 4px solid var(--c); background: var(--c-soft); border-radius: 0 var(--r-xs) var(--r-xs) 0; }
.sp-ro-paper {
  max-height: 46vh;
  overflow: auto;
  padding: 18px 10px;
  font: 13px/1.25 var(--font-script);
  color: var(--paper-ink);
  background: var(--paper);
  border: var(--bw) solid var(--line);
  border-radius: 4px;
}

.sp-tp { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: var(--s-5); }
.sp-tp-form { display: flex; flex-direction: column; gap: var(--s-3); }
.sp-tp-buttons { grid-column: 1 / -1; }
.sp-tp-preview { position: sticky; top: 0; align-self: start; }
.sp-tp-paper {
  position: relative;
  display: flex;
  flex-direction: column;
  aspect-ratio: 8.5 / 11;
  padding: 14% 12% 9%;
  font: 9px/1.35 var(--font-script);
  color: var(--paper-ink);
  background: var(--paper);
  border: var(--bw) solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.sp-tp-center { flex: 1 1 auto; padding-top: 30%; text-align: center; }
.sp-tp-title { font-weight: 700; text-decoration: underline; margin-bottom: 2.4em; overflow-wrap: anywhere; }
.sp-tp-gap { margin-bottom: 1.2em; }
.sp-tp-bottom { display: flex; justify-content: space-between; gap: 8px; }
.sp-tp-right { text-align: right; }
.sp-tp-copy { margin-top: 1em; text-align: center; font-size: 7.5px; opacity: 0.7; }

.sp-pdf { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: var(--s-4); height: min(78vh, 900px); min-height: 420px; }
.sp-pdf-options { display: flex; flex-direction: column; gap: var(--s-3); overflow-y: auto; padding-right: 4px; }
.sp-pdf-view { display: flex; min-width: 0; min-height: 0; }
.sp-pdf-view > .pdfv-viewer { flex: 1 1 auto; min-width: 0; min-height: 0; }

.sp-goal { min-width: 0; }
.sp-keys td:first-child { white-space: nowrap; width: 1%; padding-right: var(--s-4); }

/* ================================================================ focus mode */

.sp-page.is-focus .page-head { display: none; }
.sp-page.is-focus .sp-status { opacity: 0.55; transition: opacity 160ms; }
.sp-page.is-focus .sp-status:hover { opacity: 1; }
.sp-page.is-focus .sp-scroll { padding-top: 15vh; }
.sp-focus-exit { position: absolute; top: 12px; right: 18px; z-index: 4; opacity: 0.6; transition: opacity 160ms; }
.sp-focus-exit:hover, .sp-focus-exit:focus-within { opacity: 1; }

/* ================================================================ narrow screens */

@media (max-width: 1180px) {
  .sp-side { flex-basis: 320px; width: 320px; }
  .sp-nav { flex-basis: 240px; width: 240px; }
}
@media (max-width: 600px) {
  .sp-nav, .sp-side { width: 100% !important; flex-basis: 100% !important; }
}
@media (max-width: 980px) {
  .sp-layout { position: relative; }
  .sp-nav { position: absolute; left: 0; top: 0; bottom: 0; z-index: 6; box-shadow: var(--shadow-md); }
  .sp-side { position: absolute; right: 0; top: 0; bottom: 0; z-index: 6; box-shadow: var(--shadow-md); }
  .sp-scroll { padding-left: var(--s-2); padding-right: var(--s-2); }
  .sp-tp { grid-template-columns: 1fr; }
  .sp-tp-preview { display: none; }
  .sp-pdf { grid-template-columns: 1fr; height: auto; }
}
