/* 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;
  --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 { 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;
}

.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;
}

.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; }

.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;
}

@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; }
  .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; }

  .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; }
}
