/* Lune: colors, type, plate, and motion live in :root.
   Copy lives in CONFIG at the top of screenplay-v20.js.
   Pencil draw + ink-bounds auto-erase message (.sp-ink-not / .sp-ink-eraser).
   Letter pages keep --sp-letter-* (white 12pt Courier).
   Printed worksheet copy uses the same stack as site/style.css (.be / .trace / .name-label).
   House writing is Caveat 700 with font-display:block, same as .house-line.
   Scene scraps (.sp-note) inherit the page's 12pt Courier size (1em) and sit
   as a narrow scrap on the letter, not a full-width action column.
   Gate submit is a pencil checkbox + printed "I checked my work." (no swipe).
   Phone (< 700px): the script reflows at reading size (16px Courier, notes
   match) instead of shrinking the 8.5in letter; desktop/tablet unchanged.
   .sp-gate[hidden] must win over .sp-gate { display:flex } so unlock removes
   the worksheet from layout (not only pointer-events).
   Version picker (.sp-versions) shows after unlock; defaults to newest.
   Version notes open in .sp-notes-panel (encrypted; no external links). */
@font-face {
  font-family: Caveat;
  src: url("../fonts/Caveat-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: Caveat;
  src: url("../fonts/Caveat-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: "Courier Prime";
  src: url("../fonts/CourierPrime-Regular-v1-20260928.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --sp-wood: #6a3a18;
  --sp-ink: #3b3733;
  --sp-paper: #f8f4eb;
  --sp-mute: #6b6358;
  --sp-rule: #3b3733;
  --sp-foil-a: #d9a92b;
  --sp-foil-b: #f2d574;
  --sp-eraser: #e8a3a0;
  --sp-smudge: rgba(140, 110, 108, 0.18);
  --sp-shadow: 1px 1px 0 rgba(90, 70, 40, 0.28);
  --sp-plate: url("../assets/helpfulfilm-table-b12-plate-v1-20260927.webp");
  --sp-ui: Avenir, "Century Gothic", "Trebuchet MS", sans-serif;
  --sp-hand: Caveat, cursive;
  --sp-courier: "Courier Prime", Courier, "Courier New", monospace;
  --sp-letter-paper: #fff;
  --sp-letter-ink: #111110;
  --sp-note: #f8f4eb;
  --sp-pad: 0.75rem;
  --sp-sheet-max: 22rem;
  --sp-star-ms: 280ms;
  --sp-slide-ms: 720ms;
  --sp-check-ms: 280ms;
  --sp-write-ms: 400ms;
  --sp-nav: 2.75rem;
  --sp-mark-gap: 0.22rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  max-width: 100%;
}

html {
  background: var(--sp-wood);
}

body.sp {
  min-height: 100%;
  min-height: 100dvh;
  background: var(--sp-wood);
  color: var(--sp-ink);
  font-family: var(--sp-ui);
  overflow-x: hidden;
}

#sp-foil stop:first-child {
  stop-color: var(--sp-foil-a);
}

#sp-foil stop:last-child {
  stop-color: var(--sp-foil-b);
}

.sp-table {
  position: relative;
  min-height: 100dvh;
  max-width: 100%;
  background-color: var(--sp-wood);
  background-image: var(--sp-plate);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.sp-home {
  position: absolute;
  top: max(0.35rem, env(safe-area-inset-top));
  left: max(0.5rem, env(safe-area-inset-left));
  z-index: 12;
  color: #f1e8d8;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.sp-home:focus-visible,
.sp-nav a:focus-visible,
.sp-note summary:focus-visible,
.sp-sound:focus-visible,
.sp-tool:focus-visible {
  outline: 2px solid var(--sp-ink);
  outline-offset: 2px;
}

.sp-home:focus-visible {
  outline-color: #f1e8d8;
}

.sp-gate {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3.2rem var(--sp-pad) 3.5rem;
  overflow: hidden;
}

.sp-gate[hidden] {
  display: none !important;
}

.sp-sheet {
  position: relative;
  z-index: 2;
  width: 96vw;
  max-width: min(96vw, calc((100dvh - 6.5rem) * 8.5 / 11), var(--sp-sheet-max));
  aspect-ratio: 8.5 / 11;
  max-height: calc(100dvh - 6.5rem);
  background: var(--sp-paper);
  box-shadow: var(--sp-shadow);
  display: flex;
  flex-direction: column;
  padding: 8px 0 12px;
  overflow: hidden;
  transform: translate(0, 0);
  touch-action: manipulation;
}

@media (min-width: 480px) {
  .sp-sheet {
    width: 92vw;
    max-width: min(92vw, calc((100dvh - 6.5rem) * 8.5 / 11), 28rem);
  }
}

.sp-sheet.is-gesturing {
  will-change: transform;
}

.sp-sheet.away {
  animation: sp-sheet-slide var(--sp-slide-ms) cubic-bezier(0.22, 1, 0.32, 1) forwards;
}

.reduce-motion .sp-sheet.away {
  animation: sp-sheet-fade var(--sp-slide-ms) linear forwards;
}

.reduce-motion .sp-sheet.is-gesturing {
  will-change: opacity;
}

@keyframes sp-sheet-slide {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(112vw);
    opacity: 1;
  }
}

@keyframes sp-sheet-fade {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.sp-sheet-head {
  width: 88%;
  margin: 0 auto;
  flex: 0 0 auto;
}

.sp-be,
.sp-instruction,
.sp-name-label,
.sp-done-word {
  font-family: Avenir, "Century Gothic", "Trebuchet MS", sans-serif;
  color: #3b3733;
  font-style: normal;
}

.sp-be {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: clamp(1.15rem, 4.6vw, 1.85rem);
  line-height: 1.1;
}

.sp-instruction {
  margin: 0.22rem 0 0;
  font-size: clamp(0.72rem, 2.5vw, 0.98rem);
  font-weight: 400;
  letter-spacing: 0;
}

.sp-name-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  margin: 0.45rem auto 0.4rem;
  width: 88%;
  flex: 0 0 auto;
}

.sp-name-label {
  font-size: clamp(0.72rem, 2.4vw, 0.95rem);
  font-weight: 400;
  letter-spacing: 0;
  padding-bottom: 0.12rem;
  flex: 0 0 auto;
}

.sp-name-line {
  position: relative;
  flex: 1;
  height: 1.55rem;
  border-bottom: 1px solid var(--sp-rule);
  min-width: 0;
}

.sp-name-line:focus-within {
  border-bottom-width: 2px;
}

.sp-pass {
  position: absolute;
  inset: 0 1.7rem 0 0;
  z-index: 3;
  width: auto;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: transparent;
  font-size: 16px;
  letter-spacing: 0.45em;
  opacity: 0;
  touch-action: manipulation;
}

.sp-marks {
  position: absolute;
  inset: 0 1.7rem 0 0;
  z-index: 2;
  overflow-x: auto;
  overflow-y: hidden;
  pointer-events: none;
  display: block;
  padding: 0 0.12rem 0.18rem;
  scrollbar-width: none;
}

.sp-marks::-webkit-scrollbar {
  display: none;
}

.sp-marks-track {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: var(--sp-mark-gap);
  min-width: min-content;
  min-height: 100%;
}

.sp-mark {
  flex: 0 0 auto;
  width: var(--mark-w, 1.55px);
  height: var(--mark-h, 0.62rem);
  margin: 0 0 var(--mark-y, 0);
  background:
    repeating-linear-gradient(
      12deg,
      rgba(59, 55, 51, 0.22) 0 0.6px,
      transparent 0.6px 1.15px
    ),
    linear-gradient(
      90deg,
      rgba(59, 55, 51, 0.28),
      #3b3733 42%,
      rgba(90, 82, 74, 0.7) 78%,
      rgba(59, 55, 51, 0.35)
    );
  border-radius: 40% 60% 35% 65% / 12% 18% 82% 88%;
  transform: rotate(var(--mark-tilt, -8deg));
  opacity: var(--mark-op, 0.78);
  filter: blur(0.12px);
}

.sp-star-box {
  position: absolute;
  right: -0.12rem;
  bottom: -0.48rem;
  width: 1.55rem;
  height: 1.55rem;
  z-index: 4;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.sp-star {
  width: 100%;
  height: 100%;
  overflow: visible;
  transform-origin: 50% 50%;
  filter: drop-shadow(0.5px 1px 0.4px rgba(40, 20, 8, 0.32));
}

.sp-star.land {
  animation: sp-star-land var(--sp-star-ms) cubic-bezier(0.22, 1.12, 0.32, 1) both;
}

.reduce-motion .sp-star.land {
  animation: sp-star-fade 120ms linear both;
}

@keyframes sp-star-land {
  from {
    opacity: 0;
    transform: rotate(var(--tilt, 0deg)) scale(0.82);
  }
  to {
    opacity: 1;
    transform: rotate(var(--tilt, 0deg)) scale(1);
  }
}

@keyframes sp-star-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.sp-eraser {
  position: absolute;
  width: 38px;
  height: 22px;
  background: var(--sp-eraser);
  border-radius: 2px;
  z-index: 7;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 1px 0 rgba(90, 70, 40, 0.18);
  top: 50%;
  left: 0;
  margin-top: -11px;
}

.sp-eraser.go {
  opacity: 1;
}

.reduce-motion .sp-eraser.go {
  transition: opacity 220ms linear;
}

.sp-smudge {
  position: absolute;
  left: 0;
  right: 2.4rem;
  bottom: 0.1rem;
  height: 0.55rem;
  background: var(--sp-smudge);
  border-radius: 40% 55% 45% 50%;
  filter: blur(2px);
  z-index: 1;
  opacity: 0;
  pointer-events: none;
}

.sp-smudge.show {
  opacity: 1;
}

.sp-house-line {
  font-family: var(--sp-hand);
  font-weight: 700;
  font-style: normal;
  font-size: clamp(1.05rem, 3.4vw, 1.45rem);
  margin: 0.35rem auto 0;
  width: 88%;
  color: var(--sp-ink);
  clip-path: inset(0 100% 0 0);
  opacity: 0;
  pointer-events: none;
  transition: clip-path var(--sp-write-ms) linear, opacity 80ms linear;
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
  display: block;
}

.sp-house-line.show {
  clip-path: inset(0 0 0 0);
  opacity: 1;
}

.reduce-motion .sp-house-line {
  transition: opacity 120ms linear;
  clip-path: none;
}

.reduce-motion .sp-house-line.show {
  clip-path: none;
}

.sp-done-row {
  width: 88%;
  margin: 0.15rem auto 0;
  flex: 0 0 auto;
}

.sp-done {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  cursor: pointer;
  color: var(--sp-ink);
}

.sp-done:has(.sp-done-input:disabled:not(:checked)) {
  cursor: default;
  color: var(--sp-mute);
}

.sp-done-hit {
  position: relative;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
}

.sp-done-input {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.sp-done-input:disabled {
  cursor: default;
}

.sp-done-box {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1.2rem;
  height: 1.2rem;
  margin: -0.6rem 0 0 -0.6rem;
  pointer-events: none;
  border: 1.6px solid var(--sp-ink);
  border-radius: 14% 8% 16% 10% / 10% 16% 8% 14%;
  transform: rotate(-5deg);
  background:
    repeating-linear-gradient(
      14deg,
      rgba(59, 55, 51, 0.07) 0 0.55px,
      transparent 0.55px 1.35px
    );
  box-shadow: var(--sp-shadow);
}

.sp-done-input:disabled:not(:checked) + .sp-done-box {
  opacity: 0.38;
}

.sp-done-hit:has(.sp-done-input:focus-visible)::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1.5px solid var(--sp-ink);
  border-radius: 10% 16% 8% 14% / 14% 8% 16% 10%;
  transform: rotate(4deg);
  pointer-events: none;
}

.sp-done-mark {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.sp-done-mark path {
  fill: none;
  stroke: var(--sp-ink);
  stroke-width: 2.15;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.sp-done-input:checked + .sp-done-box .sp-done-mark path {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset var(--sp-check-ms) ease-out;
}

.sp-done-input:checked.wipe + .sp-done-box .sp-done-mark path {
  stroke-dashoffset: 1;
  transition: stroke-dashoffset calc(var(--sp-check-ms) * 2) linear;
}

.reduce-motion .sp-done-input:checked + .sp-done-box .sp-done-mark path,
.reduce-motion .sp-done-input:checked.wipe + .sp-done-box .sp-done-mark path {
  transition: none;
}

.sp-done-word {
  font-weight: 700;
  letter-spacing: 0;
  font-size: clamp(0.72rem, 2.4vw, 0.95rem);
  line-height: 1.1;
  padding-bottom: 0.08rem;
}

.sp-house-line.sp-not {
  position: absolute;
  left: 0;
  right: 1.7rem;
  bottom: 0.02rem;
  width: auto;
  max-width: 100%;
  margin: 0;
  z-index: 5;
  pointer-events: none;
  color: #3b3733;
  font-family: Caveat, cursive;
  font-weight: 700;
  font-style: normal;
  font-size: clamp(1.05rem, 3.4vw, 1.45rem);
  line-height: 1;
  white-space: nowrap;
  clip-path: inset(0 100% 0 0);
  opacity: 0;
  transition: clip-path var(--sp-write-ms) linear, opacity 80ms linear;
}

.sp-house-line.sp-not.show {
  clip-path: inset(0 0 0 0);
  opacity: 1;
}

.reduce-motion .sp-house-line.sp-not {
  clip-path: none;
  transition: opacity 120ms linear;
}

.sp-note:not([open]) .sp-note-body {
  display: none;
}

.sp-not.fade {
  opacity: 0;
  transition: opacity 600ms linear;
}

.sp-vh {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sp-sound {
  position: fixed;
  left: calc(12px + env(safe-area-inset-left));
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 30;
  min-height: 48px;
  min-width: 48px;
  padding: 0.45rem 0.7rem;
  border: 0;
  background: transparent;
  color: #f1e8d8;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

body.sp-open .sp-sound {
  display: none;
}

.sp-menu-slot {
  display: none;
}

body.sp-open .sp-menu-slot {
  display: block;
}

.sp-nav {
  background: var(--sp-paper);
  box-shadow: var(--sp-shadow);
  z-index: 11;
}

.sp-nav ol {
  list-style: none;
  margin: 0;
  padding: 0.15rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem;
  justify-content: flex-start;
}

.sp-nav li {
  margin: 0;
}

.sp-nav-scene {
  color: var(--sp-ink);
  text-decoration: none;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  font-family: var(--sp-ui);
  font-size: 0.95rem;
}

.sp-nav-num {
  border-bottom: 1.5px solid transparent;
  padding: 0 0.12rem 0.05rem;
  line-height: 1;
}

.sp-nav-scene.is-current .sp-nav-num {
  border-bottom-color: var(--sp-ink);
  transform: rotate(-2deg);
}

body.sp-open .sp-table {
  display: flex;
  flex-direction: column;
}

body.sp-open .sp-menu-slot,
body.sp-open .sp-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  flex: 0 0 auto;
  z-index: 11;
}

body.sp-open .sp-home {
  display: none;
}

body.sp-open .sp-stage {
  padding-top: 5.4rem;
}

body.sp-open .sp-gate,
body.sp-open .sp-gate[hidden] {
  display: none !important;
  pointer-events: none;
}

.sp-version-slot {
  display: none;
}

body.sp-open .sp-version-slot {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 12;
  padding: 0.45rem var(--sp-pad) 0.25rem;
  background: linear-gradient(
    to bottom,
    rgba(106, 58, 24, 0.96) 0%,
    rgba(106, 58, 24, 0.88) 70%,
    rgba(106, 58, 24, 0) 100%
  );
  pointer-events: none;
}

.sp-versions {
  pointer-events: auto;
  max-width: min(8.5in, 100%);
  margin: 0 auto;
}

.sp-versions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1.1rem;
  align-items: baseline;
  justify-content: flex-start;
}

.sp-version-row {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
}

.sp-version-btn {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0.2rem 0;
  margin: 0;
  color: #f1e8d8;
  font-family: var(--sp-ui);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  min-height: 44px;
}

.sp-version-btn.is-current {
  border-bottom: 1.5px solid #f1e8d8;
}

.sp-version-btn:focus-visible {
  outline: 2px solid #f1e8d8;
  outline-offset: 2px;
}

.sp-version-notes {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0.2rem 0;
  margin: 0;
  color: rgba(241, 232, 216, 0.72);
  font-family: var(--sp-ui);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.sp-version-notes:focus-visible {
  outline: 2px solid #f1e8d8;
  outline-offset: 2px;
}

.sp-notes-panel {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: max(3.5rem, env(safe-area-inset-top)) 0.75rem 1.5rem;
  box-sizing: border-box;
}

.sp-notes-panel[hidden] {
  display: none !important;
}

.sp-notes-backdrop {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  position: absolute;
  inset: 0;
  background: rgba(40, 22, 10, 0.55);
  cursor: pointer;
}

.sp-notes-sheet {
  position: relative;
  z-index: 1;
  width: min(36rem, 100%);
  max-height: min(78vh, 40rem);
  overflow: auto;
  background: var(--sp-letter-paper, #fff);
  color: #1a120c;
  border: 1px solid rgba(106, 58, 24, 0.28);
  box-shadow: 0 18px 48px rgba(20, 10, 4, 0.35);
  padding: 1rem 1.15rem 1.35rem;
  font-family: var(--sp-ui);
}

.sp-notes-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  position: sticky;
  top: 0;
  background: var(--sp-letter-paper, #fff);
  padding-bottom: 0.35rem;
}

.sp-notes-heading {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  line-height: 1.3;
}

.sp-notes-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: #6a3a18;
  font-family: var(--sp-ui);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
  min-height: 44px;
  padding: 0.25rem 0.1rem;
  flex: 0 0 auto;
}

.sp-notes-close:focus-visible {
  outline: 2px solid #6a3a18;
  outline-offset: 2px;
}

.sp-notes-body {
  font-size: 0.92rem;
  line-height: 1.45;
}

.sp-notes-html h2 {
  margin: 0 0 0.65rem;
  font-size: 1.05rem;
  font-weight: 650;
}

.sp-notes-html h3 {
  margin: 1rem 0 0.4rem;
  font-size: 0.95rem;
  font-weight: 650;
}

.sp-notes-html p {
  margin: 0 0 0.65rem;
}

.sp-notes-html ul {
  margin: 0 0 0.75rem;
  padding-left: 1.15rem;
}

.sp-notes-html li {
  margin: 0 0 0.4rem;
}

.sp-notes-html code {
  font-family: var(--sp-letter, "Courier Prime", monospace);
  font-size: 0.88em;
}

@media (min-width: 900px) {
  body.sp-open .sp-table {
    flex-direction: row;
    align-items: stretch;
  }

  body.sp-open .sp-home {
    display: none;
  }

  body.sp-open .sp-menu-slot,
  body.sp-open .sp-nav {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: var(--sp-nav);
    min-height: 100dvh;
    flex: 0 0 var(--sp-nav);
  }

  body.sp-open .sp-nav ol {
    flex-direction: column;
    padding: 3.2rem 0.1rem 1rem;
    align-items: center;
  }

  body.sp-open .sp-stage {
    padding-top: 3.2rem;
    padding-left: calc(var(--sp-nav) + var(--sp-pad));
  }

  body.sp-open .sp-version-slot {
    left: var(--sp-nav);
    padding-top: 0.7rem;
  }
}

.sp-stage {
  container-type: inline-size;
  container-name: stage;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: var(--sp-pad);
  padding-bottom: 2.5rem;
  flex: 1 1 auto;
  overflow-x: hidden;
}

.sp-page {
  font-family: var(--sp-courier);
  font-size: min(12pt, calc(12pt * 100cqw / 8.5in));
  line-height: 1;
  font-variant-ligatures: none;
  font-kerning: none;
  width: 100%;
  max-width: min(8.5in, 100%);
  min-height: 66em;
  margin: 0 auto 1.25rem;
  background: var(--sp-letter-paper);
  color: var(--sp-letter-ink);
  position: relative;
  overflow-x: hidden;
  box-shadow: var(--sp-shadow);
}

@container stage (max-width: 8.5in) {
  .sp-page {
    font-size: calc(12pt * 100cqw / 8.5in);
    max-width: none;
  }
}

.sp-page-num {
  position: absolute;
  top: 3em;
  right: 10ch;
  font-size: 1em;
  line-height: 1;
}

.sp-title-page .sp-page-num {
  display: none;
}

.sp-page-body {
  padding: 6em 0 3em;
}

.sp-line {
  height: 1em;
  white-space: pre;
  overflow: hidden;
}

.sp-blank {
  height: 1em;
}

.sp-scene,
.sp-action {
  margin-left: 15ch;
  width: 60ch;
  max-width: calc(100% - 15ch);
}

.sp-character,
.sp-more {
  margin-left: 37ch;
  width: 30ch;
  max-width: calc(100% - 37ch);
  text-transform: uppercase;
}

.sp-parenthetical {
  margin-left: 31ch;
  width: 25ch;
  max-width: calc(100% - 31ch);
}

.sp-dialogue,
.sp-lyrics {
  margin-left: 25ch;
  width: 35ch;
  max-width: calc(100% - 25ch);
}

.sp-lyrics {
  font-style: italic;
}

.sp-transition {
  margin-left: 55ch;
  width: 20ch;
  max-width: calc(100% - 55ch);
  text-align: right;
  text-transform: uppercase;
}

.sp-centered {
  margin-left: 15ch;
  width: 60ch;
  max-width: calc(100% - 15ch);
  text-align: center;
}

.sp-title-page .sp-page-body,
.sp-title-stack {
  min-height: 54em;
}

.sp-title-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8em 2ch 4em;
  gap: 1em;
}

.sp-title-name {
  margin: 0;
  font-size: 1em;
  letter-spacing: 0.35em;
  text-indent: 0.35em;
}

.sp-title-credit,
.sp-title-author,
.sp-title-note,
.sp-title-draft {
  margin: 0;
  font-size: 1em;
}

.sp-title-note {
  margin-top: 4em;
}

.sp-title-draft {
  margin-top: 1em;
}

/* Credits title page (payload title_page): centered stack, lower-left footer. */
.sp-tp-stack {
  gap: 0;
  padding: 18em 2ch 12em;
  justify-content: flex-start;
}

.sp-tp-stack .sp-title-name {
  margin-bottom: 0;
}

.sp-tp-line {
  margin: 0;
  font-size: 1em;
  line-height: 1;
}

.sp-tp-blank {
  height: 1em;
}

.sp-tp-footer {
  position: absolute;
  left: 15ch;
  bottom: 6em;
  margin: 0;
  font-size: 0.8em;
  line-height: 1;
}

.sp-note {
  margin: 0.35em auto 0.6em 15ch;
  width: 36ch;
  max-width: min(36ch, calc(100% - 18ch));
  background: var(--sp-note);
  color: var(--sp-ink);
  box-shadow: var(--sp-shadow);
}

.sp-note summary {
  cursor: pointer;
  list-style: none;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 0.6em;
  font-family: var(--sp-hand);
  font-weight: 700;
  font-size: 1em;
}

.sp-note summary::-webkit-details-marker {
  display: none;
}

.sp-note-body {
  padding: 0 0.6em 0.6em;
  font-family: var(--sp-ui);
  font-size: 1em;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

.sp-note-body p {
  margin: 0;
}

/* Screenplay stills: small, under the line they follow; click to enlarge.
   Margin stills (.sp-still-margin): desktop JS parks them in the right-hand
   gutter outside the white page (.sp-still-gutter) when there is ≥180px room;
   otherwise they fall inline in the text column (.sp-still-margin-inline).
   Phone (<700px) stays inline. Pre-wrapped .sp-line text never flows around
   a float, so gutter placement is absolute — never float:right inside the page. */
.sp-still {
  margin: 0.5em 0 0.2em 15ch;
  width: 24ch;
  max-width: calc(100% - 15ch);
}

.sp-still-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
}

.sp-still-btn:focus-visible {
  outline: 2px solid var(--sp-letter-ink);
  outline-offset: 3px;
}

.sp-still img {
  display: block;
  width: 100%;
  height: auto;
  box-shadow: var(--sp-shadow);
}

@media (min-width: 700px) {
  .sp-page {
    overflow: visible;
  }

  body.sp-open .sp-stage {
    overflow-x: visible;
  }

  /* Default before JS / when gutter is too narrow: inline in the text column. */
  .sp-still.sp-still-margin,
  .sp-still.sp-still-margin.sp-still-margin-inline {
    float: none;
    clear: none;
    position: static;
    width: 60ch;
    max-width: calc(100% - 15ch);
    margin: 0.4em 0 0.2em 15ch;
  }

  .sp-still.sp-still-margin.sp-still-gutter {
    position: absolute;
    float: none;
    clear: none;
    z-index: 2;
    margin: 0;
    max-width: none;
    /* top / left / width set by layoutMarginStills() */
  }

  .sp-still.sp-still-margin.sp-still-gutter .sp-still-btn,
  .sp-still.sp-still-margin.sp-still-gutter img {
    aspect-ratio: 16 / 9;
    width: 100%;
    height: auto;
  }
}

@media (max-width: 699px) {
  .sp-still.sp-still-margin {
    float: none;
    position: static;
    width: 100%;
    max-width: none;
    margin: 0.4em 0 0.2em;
  }
}

.sp-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(18, 14, 10, 0.88);
  cursor: zoom-out;
}

.sp-lightbox[hidden] {
  display: none;
}

.sp-lightbox:focus {
  outline: none;
}

.sp-lightbox-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

.sp-lightbox-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  color: #fff;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

body.sp-lightbox-open {
  overflow: hidden;
}

[id^="scene-"],
[id^="page-"],
[id^="narrative-"],
#title-page {
  scroll-margin-top: 4.25rem;
}

@media (min-width: 900px) {
  [id^="scene-"],
  [id^="page-"],
  [id^="narrative-"],
  #title-page {
    scroll-margin-top: 0.75rem;
    scroll-margin-left: 3.2rem;
  }
}

/* Phone: reflow the script at reading size instead of shrinking the letter.
   Wrapped lines of one paragraph (.sp-flow) run together; indents become
   percentages so nothing scrolls sideways. Desktop keeps the letter layout. */
@media (max-width: 699px) {
  body.sp-open .sp-stage {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .sp-page,
  .sp-stage .sp-page {
    font-size: 16px;
    line-height: 1.4;
    max-width: none;
    min-height: 0;
    margin-bottom: 0.75rem;
  }

  .sp-page-num {
    top: 0.9em;
    right: 1.1em;
  }

  .sp-page-body {
    padding: 2.6em 1.1em 1.4em;
  }

  .sp-line,
  .sp-blank {
    height: auto;
    min-height: 1.4em;
    white-space: normal;
    overflow: visible;
    overflow-wrap: anywhere;
  }

  .sp-flow > .sp-line {
    display: inline;
    min-height: 0;
  }

  .sp-flow > .sp-line::after {
    content: " ";
  }

  .sp-scene,
  .sp-action,
  .sp-centered,
  .sp-transition {
    margin-left: 0;
    width: auto;
    max-width: none;
  }

  .sp-character,
  .sp-more {
    margin-left: 30%;
    width: auto;
    max-width: none;
  }

  .sp-parenthetical {
    margin-left: 20%;
    margin-right: 12%;
    width: auto;
    max-width: none;
  }

  .sp-dialogue,
  .sp-lyrics {
    margin-left: 10%;
    margin-right: 6%;
    width: auto;
    max-width: none;
  }

  .sp-title-page .sp-page-body,
  .sp-title-stack {
    min-height: 0;
  }

  .sp-title-stack {
    padding: 5em 1.1em 4em;
  }

  .sp-title-name {
    letter-spacing: 0.25em;
    text-indent: 0.25em;
  }

  .sp-title-credits {
    min-height: 36em;
  }

  .sp-tp-stack {
    padding: 6em 1.1em 7em;
  }

  .sp-tp-footer {
    left: 1.4em;
    bottom: 2.2em;
  }

  .sp-note {
    margin: 0.35em 0 0.8em;
    width: auto;
    max-width: none;
  }

  .sp-still {
    margin: 0.4em 0 0.2em;
    width: 62%;
    max-width: 16rem;
  }
}

@page {
  size: letter;
  margin: 0;
}

@media print {
  html,
  body.sp,
  .sp-table {
    background: #fff;
    color: #000;
  }

  .sp-home,
  .sp-gate,
  .sp-nav,
  .sp-menu-slot,
  .sp-version-slot,
  .sp-versions,
  .sp-notes-panel,
  .sp-note,
  .sp-still,
  .sp-lightbox,
  .sp-sound {
    display: none !important;
  }

  .sp-stage {
    padding: 0;
  }

  .sp-page {
    font-size: 12pt;
    width: 8.5in;
    max-width: none;
    min-height: 11in;
    margin: 0;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }

  .sp-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }
}


/* —— Pencil draw (ephemeral; no save) —— */
.sp-draw-host {
  position: relative;
}

.sp-draw {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
  touch-action: manipulation;
}

body.sp-sheet-draw .sp-sheet.sp-draw-host {
  touch-action: none;
}

body.sp-coarse-touch.sp-open .sp-draw-tools {
  display: none;
}

.sp-draw-tools {
  position: fixed;
  right: calc(10px + env(safe-area-inset-right));
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 32;
  display: flex;
  flex-direction: row;
  gap: 0.35rem;
  pointer-events: auto;
}

.sp-tool {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  margin: 0;
  border: 1.5px solid var(--sp-ink);
  border-radius: 2px;
  background: var(--sp-paper);
  color: var(--sp-ink);
  box-shadow: var(--sp-shadow);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.sp-tool[hidden] {
  display: none !important;
}

.sp-tool svg {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.sp-erase-tool {
  color: #b86e6a;
}

.sp-erase-tool svg rect {
  fill: var(--sp-eraser);
  stroke: none;
  opacity: 1;
}

.sp-sweep-eraser {
  position: fixed;
  width: 42px;
  height: 24px;
  background: var(--sp-eraser);
  border-radius: 2px;
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 1px 0 rgba(90, 70, 40, 0.18);
  left: -48px;
  top: 42%;
}

.sp-sweep-eraser.go {
  opacity: 1;
}

.reduce-motion .sp-sweep-eraser.go {
  transition: opacity 220ms linear;
}

/* Keep password / checkbox / stills above the draw layer */
.sp-name-row,
.sp-done-row,
.sp-sheet-head,
.sp-still,
.sp-note {
  position: relative;
  z-index: 6;
}

.sp-page-num {
  z-index: 6;
}

.sp-page .sp-page-body {
  position: relative;
  z-index: 1;
}

.sp-page .sp-draw {
  z-index: 4;
}

.sp-still {
  z-index: 6;
}

@media print {
  .sp-draw,
  .sp-draw-tools,
  .sp-sweep-eraser {
    display: none !important;
  }
}


/* Ink-bounds auto-erase (worksheet only; wrong-password eraser unchanged) */
.sp-ink-eraser {
  position: absolute;
  width: 42px;
  height: 24px;
  background: var(--sp-eraser);
  border-radius: 2px;
  z-index: 8;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 1px 0 rgba(90, 70, 40, 0.18);
  left: 0;
  top: 0;
}

.sp-ink-eraser.go {
  opacity: 1;
}

.sp-ink-not {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 9;
  margin: 0;
  width: max-content;
  max-width: calc(100% - 12px);
  white-space: nowrap;
  pointer-events: none;
  color: #3b3733;
  font-family: Caveat, cursive;
  font-weight: 700;
  font-style: normal;
  font-size: clamp(1.05rem, 3.4vw, 1.45rem);
  line-height: 1;
  clip-path: inset(0 100% 0 0);
  opacity: 0;
  transition: clip-path var(--sp-write-ms) linear, opacity 80ms linear;
}

.sp-ink-not.show {
  clip-path: inset(0 0 0 0);
  opacity: 1;
}

.sp-ink-not.fade {
  opacity: 0;
  transition: opacity 180ms linear;
}

.sp-ink-not-measure {
  opacity: 0 !important;
  clip-path: none !important;
  visibility: hidden !important;
}

.reduce-motion .sp-ink-not {
  clip-path: none;
  transition: opacity 120ms linear;
}

.reduce-motion .sp-ink-not.show {
  clip-path: none;
}

@media print {
  .sp-ink-eraser,
  .sp-ink-not {
    display: none !important;
  }
}
