/* Screenwriter — web client.
   Colour carries meaning here rather than decoration: the status tints are the
   production revision sequence (white, blue, pink, yellow) that script offices
   use to mark which pass a page belongs to. Synced = white stock. */

:root {
  --page: #fcfbf8;
  --ink: #1c1a17;
  --ink-soft: #5d5950;
  --desk: #35362f;
  --desk-line: #4a4b43;
  --rule: #d9d5c9;
  --rev-blue: #9fc0d9;
  --rev-pink: #e9a9be;
  --rev-yellow: #ebd87a;
  /* Rest of the industry revision-page sequence (white, blue, pink, yellow,
     green, goldenrod, buff, salmon, cherry, then repeat) -- used only as
     Revision Mode page tints (see exportPdfWithRevisions), not app chrome. */
  --rev-green: #b7d3b0;
  --rev-goldenrod: #ddc27a;
  --rev-buff: #e3cd9e;
  --rev-salmon: #e3a999;
  --rev-cherry: #d98fa0;
  --focus: #2f6f8f;

  --gutter: clamp(1rem, 4vw, 2.5rem);
  --page-width: 62ch;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font-family: Archivo, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button, input, textarea, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- shell ---------- */

.masthead {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.85rem var(--gutter);
  background: var(--desk);
  border-bottom: 1px solid var(--desk-line);
  color: #e8e6dd;
}

.masthead h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
}

.masthead .spacer { flex: 1; }

.status {
  font-size: 0.85rem;
  color: #b9b6aa;
  font-variant-numeric: tabular-nums;
}

.status[data-state="dirty"] { color: var(--rev-yellow); }
.status[data-state="error"] { color: var(--rev-pink); }
.status[data-state="synced"] { color: #b9b6aa; }

.linkish {
  background: none;
  border: 0;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 0.2rem;
}

/* ---------- auth ---------- */

.auth {
  max-width: 26rem;
  margin: 12vh auto;
  background: var(--page);
  padding: 2rem;
  border-radius: 2px;
}

.auth h2 { margin: 0 0 0.35rem; font-size: 1.3rem; }
.auth p { margin: 0 0 1.4rem; color: var(--ink-soft); }

.field { display: block; margin-bottom: 0.9rem; }
.field span { display: block; font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 0.25rem; }

.field input {
  width: 100%;
  padding: 0.6rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: #fff;
}

.field--checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.field--checkbox input { width: auto; }
.field--checkbox span { display: inline; margin-bottom: 0; }

.btn {
  padding: 0.6rem 1.1rem;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--page);
  border-radius: 2px;
  cursor: pointer;
}

.btn:hover { background: #2c2a25; }

.btn--quiet {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule);
}

.btn--quiet:hover { background: #f0ede4; }

.notice {
  margin: 0 0 1rem;
  padding: 0.6rem 0.75rem;
  border-left: 3px solid var(--rev-pink);
  background: #fdf3f6;
  font-size: 0.9rem;
}

.notice:empty { display: none; }

/* ---------- library ---------- */

.library {
  max-width: 54rem;
  margin: 0 auto;
  padding: var(--gutter);
}

.library-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
  color: #e8e6dd;
}

.library-head h2 { margin: 0; font-size: 1.15rem; font-weight: 600; }

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

.script-card {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  width: 100%;
  text-align: left;
  background: var(--page);
  border: 0;
  border-left: 4px solid var(--rev-blue);
  padding: 0.85rem 1rem;
  cursor: pointer;
}

.script-card:hover { background: #fff; }
.script-card .title { font-weight: 600; }
.script-card .meta { color: var(--ink-soft); font-size: 0.85rem; margin-left: auto; }

/* Episodic Scripts: a show groups its scripts under a collapsible header,
   sorted by season/episode. Standalone scripts (no show) stay in the plain
   .script-list below, unchanged. */
.show-group { margin-bottom: 0.9rem; }
.show-group .script-list { margin-top: 0.4rem; margin-left: 1.2rem; }
.show-group-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: #e8e6dd;
  padding: 0.4rem 0;
  cursor: pointer;
  font: inherit;
}
.show-group-head .meta { color: #b9b6aa; font-size: 0.85rem; margin-left: auto; }

.empty {
  background: var(--page);
  padding: 1.5rem;
  color: var(--ink-soft);
}

/* ---------- editor ---------- */

.editor {
  display: grid;
  grid-template-columns: 17rem 1fr;
  gap: 1px;
  background: var(--desk-line);
  min-height: calc(100vh - 3.4rem);
}

.scenes {
  background: var(--desk);
  padding: 0.75rem;
  overflow-y: auto;
  max-height: calc(100vh - 3.4rem);
}

.scene-row {
  display: flex;
  align-items: stretch;
  gap: 2px;
  margin-bottom: 0.4rem;
}

.scene-card {
  display: block;
  flex: 1;
  min-width: 0;
  text-align: left;
  background: var(--page);
  border: 0;
  border-left: 4px solid transparent;
  padding: 0.6rem 0.7rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.scene-card[aria-current="true"] { background: #fff; box-shadow: inset 0 0 0 1px var(--ink); }
.scene-card[data-state="dirty"] { border-left-color: var(--rev-yellow); }
.scene-card[data-state="conflict"] { border-left-color: var(--rev-pink); }
.scene-card[data-state="synced"] { border-left-color: var(--rev-blue); }

.scene-card .n {
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  margin-right: 0.45rem;
}

.scene-card .h {
  font-family: "Courier Prime", ui-monospace, "Courier New", monospace;
  display: inline;
}

.scene-move {
  width: 1.6rem;
  border: 0;
  background: var(--page);
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.65rem;
}

.scene-move:hover:not(:disabled) { background: #fff; color: var(--ink); }
.scene-move:disabled { opacity: 0.3; cursor: default; }

.page-wrap {
  background: var(--desk);
  padding: var(--gutter) 0;
  overflow-y: auto;
  max-height: calc(100vh - 3.4rem);
}

.page {
  width: min(100%, 48rem);
  margin: 0 auto;
  background: var(--page);
  padding: clamp(1.5rem, 5vw, 3.5rem);
  min-height: 24rem;
}

.page textarea {
  width: 100%;
  min-height: 60vh;
  border: 0;
  background: transparent;
  resize: vertical;
  font-family: "Courier Prime", ui-monospace, "Courier New", monospace;
  font-size: 1rem;
  line-height: 1.6;
}

/* Screenplay page geometry, scaled from the 12pt Courier standard:
   dialogue indented ~2.5", character ~3.7", both on a 6" text column. */
.el { margin: 0 0 1em; font-family: "Courier Prime", ui-monospace, "Courier New", monospace; }
.el--scene { font-weight: 700; margin-top: 1.5em; }
.el--action { }
.el--character { margin-left: 34%; margin-bottom: 0; }
.el--parenthetical { margin-left: 26%; margin-bottom: 0; color: var(--ink-soft); }
.el--dialogue { margin-left: 18%; margin-right: 18%; }
.el--transition { text-align: right; }
.el--centered { text-align: center; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0 0 0.75rem;
}

.toolbar .grow { flex: 1; }

.conflict-bar {
  border-left: 3px solid var(--rev-pink);
  background: #fdf3f6;
  padding: 0.6rem 0.8rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* ---------- shot designer ---------- */

.shot-list { display: grid; gap: 0.5rem; }

.shot-row {
  display: flex;
  align-items: stretch;
  gap: 2px;
}

.shot-card {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex: 1;
  min-width: 0;
  text-align: left;
  background: var(--page);
  border: 0;
  border-left: 4px solid var(--rev-blue);
  padding: 0.6rem 0.7rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.shot-card:hover { background: #fff; }
.shot-card .n { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.shot-card .h { font-weight: 600; }
.shot-card .meta { color: var(--ink-soft); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.shot-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1.4;
  border: 1px solid var(--rule);
  touch-action: none;
  cursor: crosshair;
}

.frame-thumb {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border: 1px solid var(--rule);
  margin-bottom: 0.6rem;
}

.camera-capture { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 0.5rem; }

.camera-frame { position: relative; overflow: hidden; border: 1px solid var(--rule); }

.camera-capture video { display: block; width: 100%; background: #000; }

.camera-mask { position: absolute; background: var(--ink); opacity: 0.7; pointer-events: none; }

.comment-list { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }

.comment-row { display: flex; align-items: flex-start; gap: 0.5rem; }

.comment-card {
  flex: 1;
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.5rem 0.65rem;
  background: var(--page);
}

.comment-card .meta { display: block; font-size: 0.8rem; color: var(--ink-soft); margin-bottom: 0.15rem; }
.comment-card p { margin: 0; white-space: pre-wrap; }

/* Same meaning as the synced-elsewhere revision colour -- a script shared
   with you, not one you own. No new colours, per the project convention. */
.badge {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 2px;
  background: var(--rev-blue);
  color: var(--ink);
  font-size: 0.78rem;
}

#furniture-preset, #marker-label, #camera-ratio {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--page);
}

#marker-label:disabled { opacity: 0.5; }

.control-label { font-size: 0.82rem; color: var(--ink-soft); }

@media (max-width: 760px) {
  .editor { grid-template-columns: 1fr; }
  .scenes { max-height: 12rem; }
  .page-wrap { max-height: none; }
  .el--character { margin-left: 24%; }
  .el--dialogue { margin-left: 10%; margin-right: 6%; }
  .el--parenthetical { margin-left: 18%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- PDF export ----------
   Populated only when exporting; invisible on screen, laid out with real
   US Letter measurements (not the percentage margins used for on-screen
   reading) only when the browser's print engine takes over. */

.print-pages { display: none; }

@media print {
  @page { size: letter; margin: 1in 1in 1in 1.5in; }

  body > *:not(#print-pages) { display: none !important; }
  #print-pages { display: block !important; width: 6in; }

  .print-pages .el {
    font-family: "Courier Prime", "Courier New", Courier, monospace;
    font-size: 12pt;
    line-height: 12pt;
    margin: 0 0 12pt;
  }
  .print-pages .el--scene { font-weight: 700; text-transform: uppercase; margin-top: 24pt; position: relative; }
  .print-pages .el--character { margin-left: 2.2in; margin-bottom: 0; text-transform: uppercase; }
  .print-pages .el--parenthetical { margin-left: 1.6in; margin-right: 2in; margin-bottom: 0; }
  .print-pages .el--dialogue { margin-left: 1in; margin-right: 1.5in; }
  .print-pages .el--transition { text-align: right; text-transform: uppercase; }
  .print-pages .el--centered { text-align: center; }

  /* A character/dialogue run shouldn't split mid-sentence across a page
     break. Browsers can't inject "(MORE)" / "(CONT'D)" at the exact break
     point the way native pagination can (that's what the Android PDF export
     does instead) — keeping the block whole is the honest equivalent here. */
  .print-pages .run { break-inside: avoid; }

  .print-pages .dual { display: flex; gap: 12pt; break-inside: avoid; }
  .print-pages .dual-col { flex: 1; min-width: 0; }
  .print-pages .dual-col .el--character { margin-left: 0; }
  .print-pages .dual-col .el--parenthetical { margin-left: 0.2in; margin-right: 0; }
  .print-pages .dual-col .el--dialogue { margin-left: 0; margin-right: 0; }
  .print-pages .dual .el { font-size: 10pt; line-height: 10pt; }

  /* Printed in the page's own margin gutter, not the 6in text column. */
  .scene-num {
    position: absolute;
    font-weight: 400;
    top: 0;
  }
  .scene-num--left { left: -0.8in; }
  .scene-num--right { right: -0.6in; }

  /* Revision Mode (exportPdfWithRevisions): a changed scene gets a tinted
     background wash behind its lines and an asterisk in the margin gutter
     next to every line -- the same mechanism as .scene-num above,
     generalized from "scene headings only" to "any line in a changed
     scene". A true whole-*page* tint (Android's PdfExport draws one) isn't
     achievable here since the browser's print engine, not this code, decides
     where page breaks fall -- tinting the changed scene's own lines is the
     honest equivalent for a print-CSS pipeline. */
  .revision-scene--changed { background: var(--revision-tint); }
  .revision-scene--changed .el { position: relative; }
  .revision-scene--changed .el::after {
    content: "*";
    position: absolute;
    right: -0.35in;
    top: 0;
  }

  /* Custom Headers & Footers / Custom Watermarking (pageDecorationHtml).
     position: fixed repeats these on every printed page in Chrome/Firefox --
     confirmed behavior, and the only mechanism available since @page
     margin-box content is unsupported in Chromium. */
  .print-header, .print-footer {
    position: fixed;
    left: 0;
    right: 0;
    text-align: center;
    font-family: "Courier Prime", "Courier New", Courier, monospace;
    font-size: 9pt;
    color: #444;
  }
  .print-header { top: 0.3in; }
  .print-footer { bottom: 0.3in; }

  .print-watermark {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
    font-family: Archivo, "Helvetica Neue", Arial, sans-serif;
    font-weight: 700;
    font-size: 48pt;
    color: rgba(0, 0, 0, 0.08);
    white-space: nowrap;
    pointer-events: none;
  }

  .title-page {
    height: 9in;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    page-break-after: always;
    font-family: "Courier Prime", "Courier New", Courier, monospace;
  }
  .title-page h1 { font-size: 14pt; text-transform: uppercase; margin: 0 0 2em; }
  .title-page .by { margin: 0; }
  .title-page .author { margin: 0.5em 0 0; }
  .title-page .date { margin: 3em 0 0; }

  .shot-print { font-family: Archivo, "Helvetica Neue", Arial, sans-serif; }
  .shot-print h1 { font-size: 16pt; margin: 0 0 16pt; }
  .shot-print h2 {
    font-size: 12pt; margin: 20pt 0 6pt; border-bottom: 1pt solid #000; padding-bottom: 3pt;
  }
  .shot-print-entry { break-inside: avoid; margin: 0 0 14pt; }
  .shot-print-entry h3 { font-size: 11pt; margin: 0 0 3pt; }
  .shot-print-meta { font-size: 9pt; color: #444; margin: 0 0 3pt; }
  .shot-print-entry p { font-size: 10pt; margin: 0 0 6pt; }
  .shot-print-media { display: flex; gap: 10pt; flex-wrap: wrap; }
  .shot-print-frame { max-width: 2.2in; max-height: 1.6in; border: 1pt solid #ccc; }
  .shot-print-diagram { width: 2.2in; height: 1.5in; border: 1pt solid #ccc; }
}

/* Dual dialogue reads side by side everywhere, not just in print. */
.dual { display: flex; gap: 1rem; }
.dual-col { flex: 1; min-width: 0; }
