/* Layout: a worktable. Left, the ledger where the audience finishes two sentences;
   right, the poem set like a broadside. Stage mode is a dark room with one poem in it. */
:root {
  --paper: #eceff3;
  --sheet: #f8f9fb;
  --ink: #181b27;
  --muted: #596074;
  --rule: #d2d6e0;
  --can: #f1dd4c;
  --can-ink: #181b27;
  --cannot: #5450cf;
  --cannot-wash: rgba(84, 80, 207, .13);
  --cannot-ink: #2b2873;
  --danger: #b3261e;
  --focus: #5450cf;
  --stage-bg: #0b0c11;
  --stage-fg: #ecebe4;
  --stage-muted: #8a8ea0;
  --stage-rule: #262938;
  --stage-can: #efdb48;
  --stage-cannot: #a29eff;
  --stage-cannot-wash: rgba(162, 158, 255, .17);
  --stage-cannot-ink: #e6e4ff;
  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --mono: "Martian Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #101218; --sheet: #161921; --ink: #e8e6df; --muted: #989db0; --rule: #2a2e3d;
    --can: #e8d443; --can-ink: #14151b; --cannot: #a29eff; --cannot-wash: rgba(162, 158, 255, .15);
    --cannot-ink: #dcdaff; --danger: #ff8a80; --focus: #a29eff; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #101218; --sheet: #161921; --ink: #e8e6df; --muted: #989db0; --rule: #2a2e3d;
  --can: #e8d443; --can-ink: #14151b; --cannot: #a29eff; --cannot-wash: rgba(162, 158, 255, .15);
  --cannot-ink: #dcdaff; --danger: #ff8a80; --focus: #a29eff; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--paper); color: var(--ink);
  font: 400 17px/1.55 var(--serif);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 28px 56px;
}
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.wrap { max-width: 1180px; margin: 0 auto; display: grid; gap: 28px; }
.label { font: 500 11px/1.4 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* Masthead */
.mast { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 16px 32px; }
.mast h1 { margin: 0; font: 400 clamp(44px, 8vw, 88px)/.95 var(--serif); font-variation-settings: "opsz" 72; letter-spacing: -.02em; text-wrap: balance; }
.mast h1 .slash { color: var(--muted); font-weight: 300; padding: 0 .08em; }
.mast .lede { margin: 12px 0 0; max-width: 52ch; color: var(--muted); }
.mast-side { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.mode { display: inline-flex; align-items: center; gap: 8px; }
.mode .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.mode[data-state="live"] .dot { background: #2f9e5b; box-shadow: 0 0 0 0 rgba(47, 158, 91, .5); animation: pulse 2.4s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(47, 158, 91, 0); } 100% { box-shadow: 0 0 0 0 rgba(47, 158, 91, 0); } }

/* Highlights: "can" is a marker stroke, "cannot" is a hatched outline (an empty space). */
.hl { color: var(--ink); padding: 0 .16em; margin: 0 -.04em; border-radius: .14em; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.hl-can { background: var(--can); color: var(--can-ink); }
.hl-cannot { background: repeating-linear-gradient(-45deg, var(--cannot-wash) 0 3px, transparent 3px 7px); box-shadow: inset 0 0 0 1.5px var(--cannot); color: var(--cannot-ink); font-style: italic; }
.hl.is-mine::after { content: "you"; font: 500 .42em/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; vertical-align: .9em; margin-left: .35em; font-style: normal; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; border: 1.5px solid var(--ink); border-radius: 3px; background: transparent; font: 500 12px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; cursor: pointer; }
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.solid { background: var(--ink); color: var(--paper); }
.btn.solid:hover { background: transparent; color: var(--ink); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.quiet { border-color: var(--rule); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: var(--paper); }
.grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 28px; align-items: start; }
@media (max-width: 860px) { .grid { grid-template-columns: minmax(0, 1fr); } }

/* Ledger: finish the sentence */
.ledger { display: grid; gap: 22px; min-width: 0; }
.prompt { display: grid; gap: 10px; padding-bottom: 18px; border-bottom: 1px solid var(--rule); }
.prompt-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px 12px; }
.stem { font: 400 30px/1.2 var(--serif); font-variation-settings: "opsz" 48; white-space: nowrap; }
.blank { flex: 1 1 200px; min-width: 0; border: 0; border-bottom: 1.5px solid var(--ink); background: transparent; padding: 4px 2px 6px; font: 400 24px/1.3 var(--serif); }
.blank::placeholder { color: var(--muted); opacity: .7; font-style: italic; }
.blank:focus-visible { outline: none; border-bottom-color: var(--focus); box-shadow: 0 2px 0 0 var(--focus); }
.prompt-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.count { font: 400 11px/1 var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.notice { margin: 0; padding: 12px 14px; border-left: 3px solid var(--cannot); background: var(--cannot-wash); font-size: 15px; }
.notice[data-tone="ok"] { border-left-color: var(--can); background: transparent; }

/* Pool of lines */
.pool { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
@media (max-width: 480px) { .pool { grid-template-columns: minmax(0, 1fr); } }
.pool h3 { margin: 0 0 8px; display: flex; justify-content: space-between; gap: 8px; }
.lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 360px; overflow-y: auto; }
.lines li { display: flex; align-items: baseline; gap: 8px; padding: 5px 0; border-bottom: 1px dotted var(--rule); font-size: 15px; line-height: 1.35; overflow-wrap: anywhere; }
.lines li .t { flex: 1; min-width: 0; }
.lines li .ago { font: 400 10px/1 var(--mono); color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.lines li.fresh .t { text-decoration: underline 2px var(--can); text-underline-offset: 3px; }
.lines .empty { color: var(--muted); font-style: italic; font-size: 15px; border: 0; }
.lines li[data-status="pending"] .t { color: var(--muted); font-style: italic; }
.lines li[data-status="dropped"] .t { color: var(--muted); text-decoration: line-through; }
.filtered { display: grid; gap: 8px; }
.filtered h3 { margin: 0; display: flex; justify-content: space-between; gap: 8px; }
.keep { border: 0; background: none; padding: 2px 4px; font: 500 10px/1 var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--ink); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.screen-status { font: 400 12px/1.5 var(--mono); color: var(--muted); }
.empty-note { color: var(--muted); max-width: 46ch; }
.stage .empty-note { color: var(--stage-muted); }
.x { border: 0; background: none; padding: 2px 4px; font: 500 10px/1 var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--danger); cursor: pointer; }
.host { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding-top: 6px; }
.host p { margin: 0; flex: 1 1 100%; font-size: 14px; color: var(--muted); }

/* The poem sheet */
.sheet { min-width: 0; background: var(--sheet); border: 1px solid var(--rule); padding: clamp(22px, 4vw, 52px); display: grid; gap: 22px; position: sticky; top: calc(env(safe-area-inset-top, 0px) + 16px); }
@media (max-width: 860px) { .sheet { position: static; } }
.sheet-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; align-items: baseline; }
.poem-title { margin: 0; font: italic 400 clamp(28px, 4vw, 42px)/1.1 var(--serif); font-variation-settings: "opsz" 60; text-wrap: balance; }
.poem { display: grid; gap: 1.1em; font-size: clamp(18px, 2.1vw, 22px); line-height: 1.6; }
.stanza { margin: 0; display: grid; }
.ln { display: block; text-wrap: pretty; }
.ln.in { animation: ink .7s cubic-bezier(.2, .7, .2, 1) both; animation-delay: calc(var(--i, 0) * 70ms); }
@keyframes ink { from { opacity: 0; filter: blur(5px); transform: translateY(.3em); } }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; font-size: 14px; color: var(--muted); }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 18px; border-top: 1px solid var(--rule); }
.sheet-actions .spacer { flex: 1; }
.toast { font: 400 11px/1 var(--mono); color: var(--muted); align-self: center; }

/* Stage: a dark room, always */
.stage { position: fixed; inset: 0; z-index: 50; overflow-y: auto; background: var(--stage-bg); color: var(--stage-fg);
  --ink: var(--stage-fg); --muted: var(--stage-muted); --rule: var(--stage-rule); --can: var(--stage-can); --can-ink: var(--stage-bg);
  --cannot: var(--stage-cannot); --cannot-wash: var(--stage-cannot-wash); --cannot-ink: var(--stage-cannot-ink); --paper: var(--stage-bg); --focus: var(--stage-cannot);
  color-scheme: dark; display: grid; grid-template-rows: auto 1fr auto;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) max(20px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 18px) max(20px, env(safe-area-inset-left, 0px)); gap: 20px; }
.stage-top, .stage-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; }
.stage-body { display: grid; min-height: 0; overflow-y: auto; align-content: center; align-content: safe center; justify-items: start; max-width: 1100px; width: 100%; margin: 0 auto; gap: 26px; }
.stage .poem-title { font-size: clamp(30px, 4vw, 56px); color: var(--stage-muted); }
.stage .poem { font-size: clamp(22px, 3.1vw, 46px); line-height: 1.45; gap: .9em; }
.stage .ln.in { animation-duration: 1.1s; animation-delay: calc(var(--i, 0) * 420ms); }
.stage-foot { border-top: 1px solid var(--stage-rule); padding-top: 14px; }
.join { display: flex; align-items: center; gap: 14px; }
.qr-box { width: var(--qr-size, 160px); max-width: 100%; aspect-ratio: 1; display: grid; place-items: center; }
.qr-box canvas { display: block; image-rendering: pixelated; border-radius: 6px; }
.join { --qr-size: clamp(120px, 19vh, 230px); }
.join .label, .lobby-qr .label, .qr-overlay .label { color: var(--stage-fg); font-size: clamp(13px, 1.4vw, 18px); }
.stage-text { display: grid; gap: 26px; min-width: 0; justify-items: start; }
.stage.is-lobby .stage-body { grid-template-columns: minmax(0, 1fr) auto; column-gap: clamp(24px, 6vw, 110px); align-items: center; max-width: 1240px; }
.lobby-qr { margin: 0; display: grid; gap: 14px; justify-items: center; text-align: center; --qr-size: min(52vh, 36vw); }
@media (max-width: 700px) { .stage.is-lobby .stage-body { grid-template-columns: minmax(0, 1fr); } .lobby-qr { --qr-size: min(64vw, 40vh); } }
.qr-overlay { position: absolute; inset: 0; z-index: 2; background: var(--stage-bg); display: grid; place-content: center; justify-items: center; gap: 18px; padding: 24px; text-align: center; cursor: pointer; --qr-size: min(70vh, 84vw); }
.tally { font: 500 13px/1.5 var(--mono); font-variant-numeric: tabular-nums; }
.tally b { font-weight: 500; padding: 1px 6px; border-radius: 2px; }
.tally .c { background: var(--stage-can); color: var(--stage-bg); }
.tally .n { box-shadow: inset 0 0 0 1.5px var(--stage-cannot); color: var(--stage-cannot-ink); }
.ticker { font-size: 18px; color: var(--stage-muted); min-height: 1.6em; }
.ticker .hl { font-size: inherit; }
.ticker-line.in { animation: ink .6s ease both; }
.timer { width: 120px; height: 3px; background: var(--stage-rule); position: relative; overflow: hidden; }
.timer i { position: absolute; inset: 0; background: var(--stage-fg); transform-origin: left; transform: scaleX(var(--p, 0)); }
.stage-controls { display: flex; flex-wrap: wrap; gap: 8px; }

/* In-page confirm */
.confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 14px; border: 1.5px solid var(--danger); }
.confirm p { margin: 0; flex: 1 1 220px; font-size: 15px; }

/* Audience view (the stage QR, …#add): the two sentences and the viewer's own lines, nothing else. */
.lede-audience, .mine { display: none; }
.audience .lede-host, .audience .mast-side, .audience #sheet, .audience .pool, .audience #filtered, .audience #host { display: none; }
.audience .lede-audience { display: block; }
.audience .mine { display: grid; gap: 8px; }
.audience .wrap { max-width: 640px; }
.audience .grid { grid-template-columns: minmax(0, 1fr); }
.audience .mast h1 { font-size: clamp(40px, 12vw, 64px); }

@media (prefers-reduced-motion: reduce) {
  .ln.in, .stage .ln.in, .ticker-line.in { animation: none; }
  .mode[data-state="live"] .dot { animation: none; }
}

/* Host passcode gate on /stage */
.gate { max-width: 420px; margin: 12vh auto 0; display: grid; gap: 14px; }
.gate h1 { margin: 0; font: italic 400 40px/1.1 var(--serif); }
.gate p { margin: 0; color: var(--muted); }
.gate form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.gate .blank { font-size: 20px; }
.gate .error { color: var(--danger); font-size: 15px; }
