:root {
  --bg: #fbfaf7;
  --ink: #111111;
  --muted: #6b6a66;
  --rule: #d9d6cf;
  --serif: "Instrument Serif", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --video-w: 960px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Corners */
.corner {
  position: fixed;
  top: 28px;
  z-index: 30;
  font-size: 13px;
  line-height: 1.4;
  letter-spacing: 0.01em;
}
.corner-left { left: 32px; }
.corner-left span { display: block; }
.corner-right { right: 32px; text-align: right; }
.corner-center { left: 50%; transform: translateX(-50%); text-align: center; white-space: nowrap; }
.bib-link { color: var(--ink); text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 3px; transition: text-decoration-color .2s; }
.bib-link:hover { text-decoration-color: var(--ink); }

/* Bibliography page */
.bib-page { position: fixed; inset: 0; z-index: 25; overflow-y: auto; background: var(--bg); animation: fadeIn .4s ease both; }
.bib-page::before { content: ""; position: sticky; top: 0; display: block; height: 96px; margin-bottom: -96px; z-index: 1; background: linear-gradient(var(--bg) 60%, rgba(251,250,247,0)); pointer-events: none; }
.bib-wrap { width: min(760px, calc(100% - 32px)); margin: 0 auto; padding: 130px 0 100px; }
.bib-wrap h1 { margin-bottom: 40px; text-align: center; }
.bib-wrap h3 { margin: 44px 0 16px; text-align: center; font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 500; }
.bib-wrap ul { list-style: none; margin: 0; padding: 0; }
.bib-wrap li { font-size: 15px; line-height: 1.55; margin-bottom: 12px; padding-left: 2em; text-indent: -2em; }
.bib-wrap a { color: inherit; text-underline-offset: 2px; }
body.bib-open .pager { display: none; }

.file-warning {
  position: fixed; left: 50%; top: 24px; transform: translateX(-50%);
  z-index: 40; max-width: 560px; padding: 10px 14px;
  background: #111; color: #fff; font-size: 13px; border-radius: 6px; text-align: center;
}
.file-warning code { background: rgba(255,255,255,.14); padding: 1px 5px; border-radius: 3px; }

/* Slides */
main { position: relative; height: 100vh; }
.slide {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  animation: fadeIn .5s ease both;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Text slides */
.slide-text .text-wrap { width: min(680px, 86vw); }
.slide-text .text-wrap.wide { width: min(980px, 88vw); }
.kicker {
  margin: 0 0 18px; font-size: 12px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted);
}
h1 {
  margin: 0; font-family: var(--serif); font-weight: 400;
  font-size: clamp(44px, 6vw, 84px); line-height: .98; letter-spacing: -0.01em;
}
.subtitle { margin: 14px 0 30px; font-family: var(--serif); font-style: italic; font-size: 24px; color: var(--muted); }
h1 + .intro-body { margin-top: 32px; }
.intro-body p { margin: 0 0 14px; font-size: 16px; max-width: 600px; }
.howto { margin: 26px 0 0; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.howto::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--ink); flex: none; }
.begin {
  margin-top: 34px; padding: 12px 22px; border: 1px solid var(--ink); background: transparent;
  border-radius: 999px; cursor: pointer; font-size: 14px; transition: background .2s, color .2s;
}
.begin:hover { background: var(--ink); color: var(--bg); }

.outro { margin: 0 0 40px; font-family: var(--serif); font-size: clamp(26px, 3vw, 38px); line-height: 1.18; max-width: 860px; }
.cited { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; border-top: 1px solid var(--rule); padding-top: 24px; max-height: 46vh; overflow: auto; }
.cited h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 500; }
.cited ul { list-style: none; margin: 0 0 22px; padding: 0; }
.cited li { font-size: 13px; line-height: 1.45; margin-bottom: 9px; padding-left: 1.6em; text-indent: -1.6em; }
.cited a { color: inherit; text-underline-offset: 2px; }

/* Ad slide */
.slide-ad { gap: 0; }
.video-frame {
  position: relative; width: var(--video-w); aspect-ratio: 16 / 9; background: #000;
  box-shadow: 0 30px 60px -30px rgba(0,0,0,.35);
}
.video-frame iframe, #player { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.preview-placeholder {
  position: absolute; inset: 0; background: #1b1b1b center / cover no-repeat;
  display: flex; align-items: center; justify-content: center; color: #8a8a8a; font-size: 13px;
}
.edit-catcher { position: absolute; inset: 0; cursor: crosshair; z-index: 5; background: rgba(255,255,255,.04); outline: 1px dashed rgba(255,255,255,.6); outline-offset: -1px; }

.timeline { position: relative; width: var(--video-w); height: 18px; margin-top: 10px; }
.timeline::before { content: ""; position: absolute; left: 0; right: 0; top: 8px; height: 1px; background: var(--rule); }
.timeline-progress { position: absolute; left: 0; top: 8px; height: 1px; width: 0; background: var(--ink); }
.tick {
  position: absolute; top: 4px; width: 9px; height: 9px; margin-left: -4.5px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--ink); cursor: pointer; padding: 0;
  transition: background .2s, transform .2s;
}
.tick:hover { transform: scale(1.3); }
.tick.done, .tick.active { background: var(--ink); }

.ad-info { width: var(--video-w); margin-top: 8px; display: flex; justify-content: space-between; align-items: baseline; gap: 20px; }
.ad-info h2 { margin: 0; font-size: 15px; font-weight: 600; }
.ad-info .sep { color: var(--muted); font-weight: 400; margin: 0 4px; }
.ad-info p { margin: 0; font-size: 13px; color: var(--muted); }

/* Annotations */
.lines { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 20; overflow: visible; }
.lines .ann-line { fill: none; stroke: var(--ink); stroke-width: 1.25; transition: stroke-dashoffset .7s cubic-bezier(.6,0,.2,1), opacity .4s; }
.lines .ann-dot { fill: #000; stroke: #fff; stroke-width: 2; transform-box: fill-box; transform-origin: center; animation: pop .35s cubic-bezier(.3,1.6,.5,1) both; transition: opacity .4s; }
.lines .ann-pulse { fill: none; stroke: #fff; stroke-width: 1.5; transform-box: fill-box; transform-origin: center; animation: pulse 1.6s ease-out infinite; }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes pulse { from { transform: scale(1); opacity: .9; } to { transform: scale(3.2); opacity: 0; } }
.lines .leaving { opacity: 0; }

.blurbs { position: fixed; inset: 0; pointer-events: none; z-index: 21; }
.blurb {
  position: absolute; width: 280px;
  opacity: 0; transform: translateY(4px); transition: opacity .45s ease .35s, transform .45s ease .35s;
}
.blurb.show { opacity: 1; transform: none; }
.blurb.leaving { opacity: 0; transition-delay: 0s; }
.blurb .label { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin-bottom: 6px; }
.blurb .text { font-family: var(--serif); font-size: 21px; line-height: 1.22; }
.blurb.right { text-align: left; }
.blurb.left { text-align: right; }
.blurb.below { text-align: left; }

.blurb .more {
  pointer-events: auto; margin-top: 10px; padding: 0; border: 0; background: none; cursor: pointer;
  font-family: var(--sans); font-size: 12px; letter-spacing: .04em; color: var(--ink);
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--rule);
  transition: text-decoration-color .2s;
}
.blurb .more:hover { text-decoration-color: var(--ink); }
.blurb .countdown { height: 1px; margin-top: 12px; background: var(--ink); transform: scaleX(0); opacity: 0; }
.blurb.left .countdown { transform-origin: right; }
.blurb.right .countdown, .blurb.below .countdown { transform-origin: left; }
.blurb .countdown.run { opacity: .35; animation: countdown linear both; }
.blurb .countdown.done { animation: none; opacity: 0; transition: opacity .3s; }
@keyframes countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* Read more popup */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(251, 250, 247, .82); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fadeIn .3s ease both; }
.modal-panel {
  position: relative; width: min(640px, 100%); max-height: min(78vh, 760px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border: 1px solid var(--rule); border-radius: 4px; padding: 44px 48px 48px;
  box-shadow: 0 40px 80px -40px rgba(0,0,0,.35); outline: none; animation: fadeIn .35s ease both;
}
.modal-close {
  position: sticky; top: 0; float: right; margin: -24px -28px 0 0; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--rule); background: var(--bg); cursor: pointer; font-size: 20px; line-height: 1;
  transition: background .2s, color .2s, border-color .2s;
}
.modal-close:hover { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.modal-panel h2 { margin: 0 0 14px; font-family: var(--serif); font-weight: 400; font-size: clamp(30px, 4vw, 40px); line-height: 1.05; }
.modal-lead { margin: 0 0 24px; padding-bottom: 22px; border-bottom: 1px solid var(--rule); font-family: var(--serif); font-style: italic; font-size: 21px; line-height: 1.3; color: var(--muted); }
.modal-body p { margin: 0 0 16px; font-size: 16px; line-height: 1.65; }
.modal-body p:last-child { margin-bottom: 0; }
@media (max-width: 600px) { .modal-panel { padding: 32px 22px 32px; } .modal-close { margin: -14px -8px 0 0; } }

/* Pager */
.pager {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; gap: 18px; font-size: 12px; letter-spacing: .12em; color: var(--muted);
}
.pager button {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--rule); background: var(--bg);
  cursor: pointer; font-size: 17px; color: var(--ink); transition: border-color .2s, background .2s, color .2s;
}
.pager button:hover:not(:disabled) { border-color: var(--ink); background: var(--ink); color: var(--bg); }
.pager button:disabled { opacity: .3; cursor: default; }

/* Edit mode */
.edit-panel {
  position: fixed; left: 24px; bottom: 24px; z-index: 40; width: 300px; max-height: 40vh; overflow: auto;
  background: #111; color: #eee; border-radius: 8px; padding: 12px 14px; font-size: 12px;
}
.edit-time { font-size: 18px; font-variant-numeric: tabular-nums; margin-bottom: 4px; }
.edit-hint { color: #aaa; margin-bottom: 8px; }
.edit-panel pre { margin: 0; white-space: pre-wrap; font-size: 11px; color: #cfe; }

/* Narrow screens (body.narrow, set from app.js): notes go under the video and the page scrolls */
.note-slot { display: none; }
body.narrow { overflow: auto; height: auto; }
body.narrow main { height: auto; min-height: 100vh; }
body.narrow .slide { position: relative; inset: auto; min-height: 100vh; justify-content: flex-start; padding: 110px 16px 120px; }
body.narrow .slide-text { justify-content: center; }
body.narrow .corner { position: absolute; top: 16px; }
body.narrow .corner-left { left: 16px; }
body.narrow .corner-right { right: 16px; }
@media (max-width: 560px) { .corner-center { top: 70px; font-size: 12px; color: var(--muted); } body.narrow .corner-center { top: 70px; } }
body.narrow .lines, body.narrow .blurbs { position: absolute; }
body.narrow .note-slot { display: block; width: var(--video-w); min-height: 190px; margin-top: 28px; }
body.narrow .cited { grid-template-columns: 1fr; max-height: none; }
body.narrow .ad-info { flex-direction: column; gap: 2px; }
