/* Courier Prime (SIL Open Font License), served from FONT_DIR */
@font-face { font-family: "Courier Prime"; src: url("/fonts/CourierPrime-Regular.ttf") format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Courier Prime"; src: url("/fonts/CourierPrime-Italic.ttf") format("truetype"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Courier Prime"; src: url("/fonts/CourierPrime-Bold.ttf") format("truetype"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Courier Prime"; src: url("/fonts/CourierPrime-BoldItalic.ttf") format("truetype"); font-weight: 700; font-style: italic; font-display: swap; }

:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1f1d1a;
  --muted: #6b665e;
  --line: #e2ddd3;
  --accent: #8a2b2b;
  --accent-text: #ffffff;
  --del-bg: #fbe3e1;
  --del-strong: #f2b8b3;
  --ins-bg: #e2f3e4;
  --ins-strong: #a9dcb0;
  --mod-bar: #d9a441;
  --important: #b7791f;
  --script: "Courier Prime", "Courier New", Courier, monospace;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #211f1c;
    --text: #ece8e1;
    --muted: #a39d93;
    --line: #36322d;
    --accent: #d9776f;
    --accent-text: #1a1311;
    --del-bg: #3a2220;
    --del-strong: #6e302b;
    --ins-bg: #1d3322;
    --ins-strong: #2f6239;
    --mod-bar: #c08a2c;
    --important: #e0a84a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--ui); }
a { color: var(--accent); }
h1 { font-size: 1.7rem; margin: 0 0 1rem; line-height: 1.2; }
h2 { font-size: 1.2rem; margin: 2rem 0 .75rem; }
h3 { font-size: 1rem; margin: 0; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.muted, .meta, .hint { color: var(--muted); }
.meta { font-size: .9rem; }
.hint { font-size: .85rem; font-weight: normal; }
.eyebrow { text-transform: uppercase; letter-spacing: .06em; font-size: .75rem; color: var(--muted); }
.error { color: #b42318; white-space: pre-wrap; }
pre.error { background: var(--del-bg); padding: .75rem 1rem; border-radius: 6px; overflow-x: auto; color: inherit; }
.ok { background: var(--ins-bg); padding: .5rem .75rem; border-radius: 6px; }

/* ---------- header ---------- */
.top { background: var(--surface); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 1100px; margin: 0 auto; padding: .6rem 1rem; display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; }
.brand { font-family: var(--script); font-weight: bold; color: var(--text); text-decoration: none; font-size: 1.1rem; text-transform: uppercase; }
.top nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.top nav a { padding: .35rem .6rem; border-radius: 6px; text-decoration: none; color: var(--text); }
.top nav a:hover { background: var(--bg); }
.top nav a.active { background: var(--bg); font-weight: 600; }
.logout { display: flex; gap: .5rem; align-items: center; font-size: .9rem; }
.me { color: var(--muted); }

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
main.wide { max-width: 1500px; }

/* ---------- building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem 1.5rem; }
.narrow { max-width: 440px; margin: 3rem auto; }
.narrow-form { max-width: 560px; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.stack label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
label.check { display: inline-flex; flex-direction: row; align-items: center; gap: .4rem; font-weight: normal; }
input, select, textarea, button, .button { font: inherit; }
input:not([type=checkbox]), select, textarea {
  padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); width: 100%;
}
textarea { resize: vertical; }
button, .button {
  display: inline-block; padding: .45rem .9rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--muted); }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.primary:hover { filter: brightness(1.08); border-color: var(--accent); }
button.link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; }
.danger { color: #b42318; }
button.danger:not(.link) { border-color: #e4a39c; }
form.inline { display: inline; }
.badge { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); vertical-align: middle; }
.badge.important { background: var(--important); border-color: var(--important); color: #fff; }
.badge.add { background: var(--ins-strong); color: var(--text); border: none; }
.badge.del { background: var(--del-strong); color: var(--text); border: none; }
.chip { font-family: var(--script); font-size: .78rem; padding: 0 .35rem; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); }
details > summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
details.edit, details.warnings { margin: .75rem 0; }
details.edit > form, details.warnings > pre { margin-top: .75rem; }
details.warnings pre { white-space: pre-wrap; background: var(--surface); border: 1px solid var(--line); padding: .75rem; border-radius: 6px; }

/* ---------- versions ---------- */
.page-head, .current-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.page-head h1 { margin: .1rem 0 .2rem; }
.current h2 { margin: .2rem 0; }
.current h2 a { color: var(--text); text-decoration: none; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.summary { margin: 1rem 0 0; padding-left: 1.1rem; }
.summary li { margin: .2rem 0; }
.note { background: var(--surface); border-left: 3px solid var(--accent); padding: .25rem 1rem; margin: 1rem 0; border-radius: 0 6px 6px 0; }
table.list, table.stats { width: 100%; border-collapse: collapse; margin-top: 1.5rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.list th, table.list td, table.stats th, table.stats td { padding: .55rem .8rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th, table.stats th { font-size: .8rem; color: var(--muted); font-weight: 600; }
table.list tr:last-child td, table.stats tr:last-child td { border-bottom: none; }
td.num { font-variant-numeric: tabular-nums; width: 3rem; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions > * { margin-left: .75rem; }
table.stats { margin-top: .5rem; }
table.stats td:first-child { font-family: var(--script); }
.num-r { text-align: right !important; font-variant-numeric: tabular-nums; }
.bar-cell { width: 35%; }
.bar { display: block; height: .7rem; border-radius: 3px; background: var(--accent); margin-top: .35rem; min-width: 2px; }

/* ---------- changelog entries ---------- */
.entry { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .9rem 1.2rem; margin: .75rem 0; }
.entry.is-important { border-left: 4px solid var(--important); }
.entry.is-hidden { opacity: .55; }
.entry > header { display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; }
.entry > header h3 a { color: var(--text); }
.entry-text p { margin: .3rem 0; }
.discussion { margin-top: .5rem; }
.comments { margin-top: .5rem; }
.comment { border-top: 1px solid var(--line); padding: .5rem 0; }
.comment-head { font-size: .85rem; display: flex; gap: .5rem; align-items: baseline; }
.comment-body p { margin: .2rem 0; }
.comment-form { display: flex; gap: .5rem; align-items: flex-start; margin-top: .5rem; }
.comment-form textarea { flex: 1; }
.cl-version h2 { display: flex; gap: .75rem; align-items: baseline; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: .4rem; }
.cl-version h2 a { color: var(--text); text-decoration: none; }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end; margin-bottom: 1.25rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .75rem 1rem; }
.filters > label:not(.check) { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); gap: .2rem; }
.filters select { width: auto; max-width: 18rem; }
.filters .swap { font-size: 1.2rem; text-decoration: none; padding-bottom: .4rem; }
.cats { position: relative; align-self: center; }
.cat-list { position: absolute; z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; display: grid; gap: .3rem; margin-top: .3rem; min-width: 12rem; box-shadow: 0 6px 20px rgb(0 0 0 / .12); }

/* ---------- diff ---------- */
.diff-summary { display: flex; gap: 1rem; flex-wrap: wrap; }
.legend span { padding: 0 .3rem; border-radius: 3px; margin-left: .3rem; }
table.diff { width: 100%; border-collapse: collapse; table-layout: fixed; background: var(--surface); border: 1px solid var(--line); }
table.diff col.c-pg { width: 3rem; }
table.diff thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); text-align: left; font-size: .85rem; padding: .5rem .75rem; border-bottom: 2px solid var(--line); }
table.diff td { vertical-align: top; padding: .35rem .75rem; border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent); }
table.diff td.pg { color: var(--muted); font-size: .75rem; text-align: right; padding-right: .4rem; font-variant-numeric: tabular-nums; }
table.diff td.side.lft { border-right: 1px solid var(--line); }
table.diff.script td.side { font-family: var(--script); font-size: .95rem; }
tr.op-del td.side.lft, tr.op-del td.pg:first-child { background: var(--del-bg); }
tr.op-add td.side.rgt, tr.op-add td.pg:nth-child(3) { background: var(--ins-bg); }
tr.op-mod td.side.lft { box-shadow: inset 3px 0 var(--mod-bar); }
tr.op-mod td.side.rgt { box-shadow: inset 3px 0 var(--mod-bar); }
tr.op-same td.side { color: var(--muted); }
span.del { background: var(--del-strong); text-decoration: line-through; text-decoration-thickness: 1px; border-radius: 2px; }
span.ins { background: var(--ins-strong); border-radius: 2px; }
tr.folded { display: none; }
tr.fold-toggle td { text-align: center; background: var(--bg); padding: .2rem; font-size: .85rem; }
tbody.section { scroll-margin-top: 3rem; }
tr.sec-head td { background: var(--bg); font-family: var(--script); font-weight: bold; text-transform: uppercase; padding-top: .7rem; padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
tbody.act tr.sec-head td.side { text-decoration: underline; text-align: center; }
tbody.section:target tr.sec-head td { background: color-mix(in srgb, var(--important) 25%, var(--bg)); }
tr.sec-head.op-add td.side.rgt, tr.sec-head.op-mod td.side.rgt { color: var(--accent); }

.rec.dlg .who { text-align: center; text-transform: uppercase; color: var(--c, inherit); font-weight: 600; }
.rec.dlg .ext { font-weight: normal; }
.rec.dlg .emo { text-align: center; font-style: italic; }
.rec.dlg .line { margin: 0 8%; }
.rec.cue .tag, .rec.idea .tag { font-family: var(--ui); font-size: .72rem; padding: .05rem .4rem; border-radius: 4px; margin-right: .3rem; color: #222; vertical-align: 1px; }
.cue-light .tag { background: #b7e4b5; }
.cue-music .tag { background: #d6c1ea; }
.cue-effect .tag { background: #b9d3f2; }
.cue-prop .tag { background: #f2b5b5; }
.cue-join .tag { background: #f3e38c; }
.rec.cue.cue-join { font-style: italic; }
.rec.idea { font-size: .8rem; color: var(--muted); }
.rec.idea .tag { background: var(--line); color: var(--text); }
.rec.tr { text-align: right; text-transform: uppercase; }

.diff-file { margin-bottom: 2rem; }
.file-head { font-size: 1rem; display: flex; gap: .5rem; align-items: center; }
table.diff.code pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: .82rem; }
table.diff.code td { padding-top: .05rem; padding-bottom: .05rem; border-bottom: none; }

/* ---------- reading view ---------- */
:root { --mark: #fff1a8; --mark-text: inherit; }
@media (prefers-color-scheme: dark) { :root { --mark: #5c4d12; } }
.reader { display: grid; grid-template-columns: 16rem minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.reader-side { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow: auto; }
.toc-box > summary { font-weight: 600; color: var(--text); margin-bottom: .4rem; }
.toc { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.toc li { display: flex; gap: .4rem; align-items: baseline; padding: .15rem .3rem; border-radius: 4px; }
.toc li a { flex: 1; color: var(--text); text-decoration: none; display: flex; gap: .4rem; min-width: 0; }
.toc li a:hover .t { text-decoration: underline; }
.toc .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc .no { color: var(--muted); min-width: 1.4rem; text-align: right; font-variant-numeric: tabular-nums; }
.toc .pg { color: var(--muted); font-size: .75rem; }
.toc .toc-act { margin-top: .6rem; font-weight: 600; text-transform: uppercase; font-size: .78rem; letter-spacing: .04em; }
.toc .toc-act:first-child { margin-top: 0; }
.toc li.changed { background: color-mix(in srgb, var(--mod-bar) 18%, transparent); }
.toc li.changed::after { content: "●"; color: var(--mod-bar); font-size: .6rem; }

.reader-tools { position: sticky; top: 0; z-index: 4; }
.reader-tools .toggles { display: flex; gap: .9rem; flex-wrap: wrap; align-self: center; }
.reader-summary { margin: -.5rem 0 1rem; }
.lg { padding: 0 .4rem; border-radius: 3px; margin-left: .4rem; color: var(--text); }
.lg-add { background: var(--ins-bg); box-shadow: inset 3px 0 #3f9b52; }
.lg-mod { background: color-mix(in srgb, var(--mod-bar) 20%, transparent); box-shadow: inset 3px 0 var(--mod-bar); }
.lg-del { background: var(--del-bg); text-decoration: line-through; }

.playscript {
  font-family: var(--script); font-size: 1.02rem; line-height: 1.45;
  background: var(--surface); border: 1px solid var(--line); border-radius: 4px;
  max-width: 50rem; margin: 0 auto; padding: 2.5rem 4.5rem 4rem;
  box-shadow: 0 1px 3px rgb(0 0 0 / .06);
}
.playscript .ri { position: relative; scroll-margin-top: 6rem; }
.r-act { font-size: 1.02rem; font-weight: 400; text-align: center; text-transform: uppercase; text-decoration: underline; margin: 2.2em 0 1.4em; }
.r-scene { font-size: 1.02rem; font-weight: 700; text-transform: uppercase; margin: 2em 0 .9em; }
.r-scene .no { position: absolute; left: -3rem; width: 2.2rem; text-align: right; font-weight: 400; color: var(--muted); }
.r-action { margin: .9em 0; }
.r-speech { margin: 1em 0; }
.r-speech .name { text-align: center; text-transform: uppercase; color: var(--c, inherit); }
.r-speech .ext { text-transform: none; }
.r-speech .emo { text-align: center; font-style: italic; }
.r-speech .text { margin: 0 14%; }
.r-speech.mine .text { background: var(--mark); box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.r-speech.mine .name { font-weight: 700; }
.r-dual { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.r-dual .r-speech .text { margin: 0; }
.r-cue { margin: .5em 0; }
.r-cue .tag, .r-note .tag { font-family: var(--ui); font-size: .7rem; padding: .05rem .4rem; border-radius: 4px; margin-right: .3rem; color: #222; vertical-align: 2px; }
.r-cue.cue-light .tag { background: #b7e4b5; }
.r-cue.cue-music .tag { background: #d6c1ea; }
.r-cue.cue-effect .tag { background: #b9d3f2; }
.r-cue.cue-prop .tag { background: #f2b5b5; }
.r-cue.cue-join .tag { background: #f3e38c; }
.r-cue.cue-join { font-style: italic; }
.r-trans { text-align: right; text-transform: uppercase; margin: 1em 0; }
.r-note { font-size: .8rem; color: var(--muted); margin: .3em 0; }
.r-note .tag { background: var(--line); color: var(--text); }
.pg-mark { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-family: var(--ui); font-size: .72rem; margin: 1.6rem -2rem .6rem; text-transform: uppercase; letter-spacing: .06em; }
.pg-mark::before, .pg-mark::after { content: ""; flex: 1; border-top: 1px dashed var(--line); }
.pg-mark:first-child { margin-top: 0; }

/* change marking */
.playscript .op-add, .playscript .op-mod, .playscript .op-del { padding-left: .6rem; margin-left: -.6rem; padding-right: .3rem; border-radius: 0 3px 3px 0; }
.playscript .op-add { box-shadow: inset 3px 0 #3f9b52; background: var(--ins-bg); }
.playscript .op-mod { box-shadow: inset 3px 0 var(--mod-bar); }
.playscript .op-del { box-shadow: inset 3px 0 #c4554d; background: var(--del-bg); color: var(--muted); }
.playscript .op-del .text, .playscript p.op-del, .playscript .op-del.r-cue, .playscript .op-del.r-trans { text-decoration: line-through; }
.playscript .op-del::before { content: "cut"; position: absolute; right: .3rem; top: .1rem; font-family: var(--ui); font-size: .65rem; text-transform: uppercase; letter-spacing: .05em; color: #c4554d; }
.playscript span.ins { background: var(--ins-strong); border-radius: 2px; }

.playscript.hide-cues .r-cue { display: none; }
.playscript.hide-notes .r-note { display: none; }
.playscript.hide-cuts .op-del { display: none; }

@media (max-width: 1000px) {
  .reader { grid-template-columns: 1fr; }
  .reader-side { position: static; max-height: none; }
  .playscript { padding: 1.5rem 1.5rem 3rem; }
  .r-scene .no { position: static; margin-right: .6rem; }
  .pg-mark { margin-left: 0; margin-right: 0; }
}
@media (max-width: 600px) {
  .r-speech .text { margin: 0 4%; }
  .playscript { font-size: .95rem; padding: 1rem .9rem 2rem; }
  .reader-tools { position: static; }
}
@media print {
  .reader-side, .reader-tools, .reader-summary { display: none !important; }
  .reader { display: block; }
  .playscript { border: none; box-shadow: none; max-width: none; }
}

/* ---------- sign-in & account ---------- */
.small { font-size: .85rem; }
.login > * + * { margin-top: 1.25rem; }
.login-code, .login-mail { border-top: 1px solid var(--line); padding-top: 1.25rem; }
.wide-button { width: 100%; padding: .7rem; font-size: 1.05rem; }
.code-input { font-family: var(--script); font-size: 1.3rem; letter-spacing: .15em; text-transform: uppercase; text-align: center; }
.code-input::placeholder { opacity: .35; }
[hidden] { display: none !important; }
.card + .card { margin-top: 1rem; }
.card h2 { margin-top: 0; }
.welcome { border-left: 4px solid var(--accent); }
.plain-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.plain-list li { display: flex; gap: .75rem; align-items: baseline; flex-wrap: wrap; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.device-code { display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap; }
.device-code .qr { width: 180px; height: 180px; background: #fff; padding: 6px; border-radius: 6px; }
.device-code .qr svg { width: 100%; height: 100%; display: block; }
.big-code { font-family: var(--script); font-size: 2.2rem; letter-spacing: .12em; margin: .3rem 0; font-weight: 700; }
.link-panel { margin-bottom: 1.5rem; border-left: 4px solid var(--accent); }
.share-box textarea { font: inherit; font-size: .9rem; margin-bottom: .5rem; }
.button.whatsapp { background: #25d366; border-color: #25d366; color: #0b3d1f; }
a.me { color: var(--muted); text-decoration: none; }
a.me:hover { text-decoration: underline; }

@media (max-width: 760px) {
  main { padding: 1rem .6rem 3rem; }
  table.diff col.c-pg { width: 1.8rem; }
  table.diff td { padding: .3rem .35rem; }
  table.diff.script td.side { font-size: .8rem; }
  .rec.dlg .line { margin: 0; }
  .row-actions > * { margin-left: .4rem; }
  .bar-cell { display: none; }
}
@media print {
  .top, .filters, details.edit, .discussion, .fold-toggle { display: none !important; }
  tr.folded { display: table-row; }
  main { max-width: none; }
}
