:root {
  color-scheme: light;
  --reader-scale: 1;
  --paper: oklch(94.8% 0.018 83);
  --paper-deep: oklch(89% 0.03 82);
  --ink: oklch(26% 0.025 55);
  --muted: oklch(48% 0.028 59);
  --faint: oklch(65% 0.032 72);
  --red: oklch(46% 0.11 28);
  --moss: oklch(37% 0.055 138);
  --rule: oklch(69% 0.05 76 / .75);
  --selection: oklch(84% 0.09 84 / .68);
  --serif: "Source Serif 4", Iowan Old Style, Georgia, serif;
  --display: "Fraunces", Iowan Old Style, Georgia, serif;
  --mono: "DM Mono", ui-monospace, monospace;
}

:root[data-theme="night"] {
  color-scheme: dark;
  --paper: oklch(20% 0.018 62);
  --paper-deep: oklch(25% 0.022 62);
  --ink: oklch(89% 0.025 79);
  --muted: oklch(71% 0.028 77);
  --faint: oklch(55% 0.03 75);
  --red: oklch(72% 0.1 34);
  --moss: oklch(72% 0.07 140);
  --rule: oklch(48% 0.04 73 / .8);
  --selection: oklch(48% 0.08 86 / .72);
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body { min-width: 320px; margin: 0; background: var(--paper); color: var(--ink); font-family: var(--serif); }
button, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible, textarea:focus-visible { outline: 2px solid var(--red); outline-offset: 4px; }
button:disabled { cursor: not-allowed; opacity: .25; }
a { color: inherit; text-decoration-color: var(--red); text-underline-offset: 3px; }
::selection { background: var(--selection); }
.paper-grain { position: fixed; z-index: -1; inset: 0; pointer-events: none; opacity: .36; background-image: radial-gradient(var(--ink) .45px, transparent .7px); background-size: 7px 7px; mix-blend-mode: soft-light; }

.topbar { position: sticky; z-index: 11; top: 0; min-height: 76px; display: flex; justify-content: space-between; align-items: center; padding: 13px clamp(20px, 4vw, 68px); background: var(--paper); border-bottom: 1px solid var(--rule); }
.wordmark, .icon-button, .text-button { border: 0; background: transparent; cursor: pointer; }
.wordmark { display: grid; gap: 1px; padding: 0; font-family: var(--display); font-size: 1.22rem; text-align: left; }
.wordmark-kicker, .eyebrow, .card-label { color: var(--red); font-family: var(--mono); font-size: .62rem; font-weight: 500; letter-spacing: .095em; line-height: 1.35; text-transform: uppercase; }
.wordmark-kicker { font-size: .54rem; }
.top-actions { display: flex; align-items: center; gap: 13px; }
.top-progress { color: var(--muted); font-family: var(--mono); font-size: .62rem; letter-spacing: .03em; }
.icon-button { width: 34px; height: 34px; padding: 0; border: 1px solid var(--rule); border-radius: 50%; font-family: var(--serif); font-size: 1rem; }
.type-controls { display: flex; overflow: hidden; border: 1px solid var(--rule); }
.type-button { min-width: 30px; height: 32px; padding: 0 6px; color: var(--muted); font-family: var(--serif); font-size: .79rem; border: 0; background: transparent; cursor: pointer; }
.type-button + .type-button { border-left: 1px solid var(--rule); }

.panel { position: fixed; z-index: 10; top: 76px; bottom: 0; width: min(390px, 100%); padding: 33px clamp(24px, 3vw, 46px); overflow: auto; background: color-mix(in oklch, var(--paper) 96%, var(--paper-deep)); border-right: 1px solid var(--rule); box-shadow: 15px 0 44px oklch(25% 0.03 65 / .12); }
.notes-panel { right: 0; left: auto; border-right: 0; border-left: 1px solid var(--rule); box-shadow: -15px 0 44px oklch(25% 0.03 65 / .12); }
.panel-heading { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--rule); }
.text-button { padding: 5px 0; color: var(--red); font-family: var(--mono); font-size: .68rem; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.book-detail { padding: 28px 0 22px; border-bottom: 1px solid var(--rule); }
.book-detail h2 { margin: 0; font-family: var(--display); font-size: 1.7rem; font-weight: 500; line-height: .98; }
.book-detail p { margin: 9px 0 0; color: var(--muted); line-height: 1.25; }
.book-detail .byline { color: var(--red); font-family: var(--mono); font-size: .66rem; text-transform: uppercase; }
.toc { margin-top: 16px; }
.toc-item { width: 100%; display: grid; grid-template-columns: 28px 1fr 32px; gap: 8px; align-items: baseline; padding: 14px 0; color: var(--muted); text-align: left; border: 0; border-bottom: 1px solid color-mix(in oklch, var(--rule) 70%, transparent); background: transparent; cursor: pointer; }
.toc-item span, .toc-item small { font-family: var(--mono); font-size: .58rem; }
.toc-item strong { font-family: var(--serif); font-size: .96rem; font-weight: 500; line-height: 1.05; }
.toc-item.is-active { color: var(--ink); }
.toc-item.is-active strong { color: var(--red); }
.panel-footnote, .empty-note { margin-top: 32px; color: var(--muted); font-size: .89rem; font-style: italic; line-height: 1.35; }

.shell { display: grid; grid-template-columns: minmax(90px, .75fr) minmax(0, 720px) minmax(245px, .75fr); max-width: 1480px; min-height: calc(100vh - 76px); margin: 0 auto; }
.route-column { position: sticky; top: 0; align-self: start; min-height: 350px; padding: clamp(37px, 7vw, 102px) clamp(20px, 3vw, 54px); border-right: 1px solid var(--rule); }
.route-rule { width: 1px; height: 55px; background: var(--red); }
.route-number { margin: 20px 0 2px; color: var(--red); font-family: var(--display); font-size: clamp(3rem, 4.5vw, 5rem); font-variant-numeric: oldstyle-nums; line-height: .8; }
.route-label { margin: 7px 0 20px; color: var(--muted); font-family: var(--mono); font-size: .61rem; }
.route-meter { position: relative; width: 4px; height: 115px; overflow: hidden; background: var(--paper-deep); }
.route-meter span { position: absolute; bottom: 0; width: 100%; background: var(--moss); transition: height .55s cubic-bezier(.16, 1, .3, 1); }
.bookmark-button { margin-top: 20px; padding: 0; color: var(--muted); font-family: var(--mono); font-size: .58rem; line-height: 1.35; text-align: left; border: 0; background: transparent; cursor: pointer; }
.bookmark-button::before { content: "◇ "; color: var(--red); }
.bookmark-button.is-saved { color: var(--red); }
.bookmark-button.is-saved::before { content: "◆ "; }

.reader { padding: clamp(42px, 9vw, 120px) clamp(27px, 7.5vw, 106px) 78px; outline: none; }
.reading-header { margin-bottom: clamp(40px, 7vw, 72px); }
.reading-header h1 { max-width: 630px; margin: 12px 0 17px; font-family: var(--display); font-size: clamp(2.7rem, 6vw, 5.45rem); font-weight: 500; letter-spacing: -.055em; line-height: .9; }
.reading-deck { max-width: 350px; margin: 0; color: var(--muted); font-size: .96rem; font-style: italic; line-height: 1.35; }
.reader-content { font-size: calc(1.18rem * var(--reader-scale)); line-height: 1.68; }
.reader-content > p { margin: 0 0 1.42em; }
.reader-content > p:first-child::first-letter { float: left; margin: .07em .11em 0 0; color: var(--red); font-family: var(--display); font-size: 4.55em; line-height: .72; }
.reader-content blockquote { margin: 2.7em -1.8em; padding: 0 1.8em; color: color-mix(in oklch, var(--ink) 88%, var(--red)); font-family: var(--display); font-size: 1.3em; font-weight: 500; letter-spacing: -.015em; line-height: 1.28; border-left: 2px solid var(--red); }
.reader-content .attribution { margin: -1.8em 0 2.7em; color: var(--muted); font-size: .87em; font-style: italic; text-align: right; }
.reader-content .verse { white-space: pre-line; font-style: italic; }
.in-text-heading { max-width: 460px; margin: 2.5em 0 1em; font-family: var(--display); font-size: 1.58em; font-weight: 500; letter-spacing: -.03em; line-height: 1.02; }
.inline-figure { margin: clamp(36px, 6vw, 68px) 0; }
.inline-figure img { display: block; width: 100%; max-height: 620px; object-fit: contain; background: var(--paper-deep); border: 1px solid var(--rule); }
.inline-figure figcaption { display: grid; grid-template-columns: 45px 1fr; gap: 9px; margin-top: 10px; color: var(--muted); font-size: .8rem; font-style: italic; line-height: 1.3; }
.inline-figure figcaption span { color: var(--red); font-family: var(--mono); font-size: .58rem; font-style: normal; letter-spacing: .04em; text-transform: uppercase; }
.footnote { display: inline-flex; align-items: center; justify-content: center; min-width: 1.8rem; min-height: 1.8rem; margin: 0 .04em; padding: 0 .32rem; vertical-align: .42em; color: var(--red); font-family: var(--mono); font-size: .52em; font-weight: 500; line-height: 1; border: 1px solid color-mix(in oklch, var(--red) 50%, transparent); border-radius: 50%; background: color-mix(in oklch, var(--paper) 70%, transparent); cursor: pointer; }
.footnote:hover, .footnote:focus { color: var(--paper); background: var(--red); }
.endnote-popover { position: fixed; z-index: 15; max-height: min(420px, calc(100vh - 32px)); padding: 19px 20px 17px; overflow: auto; color: var(--ink); background: color-mix(in oklch, var(--paper) 97%, var(--paper-deep)); border: 1px solid var(--rule); box-shadow: 0 15px 35px oklch(22% 0.025 55 / .18); }
.endnote-heading { display: flex; justify-content: space-between; align-items: baseline; padding-bottom: 10px; border-bottom: 1px solid var(--rule); }
.endnote-content p { margin: 13px 0 0; font-size: .92rem; line-height: 1.45; }
mark { padding: .01em .05em; color: inherit; background: var(--selection); }

.passage-summary { max-width: 530px; margin: clamp(58px, 8vw, 100px) 0 44px; padding: 23px 0 4px; border-top: 1px solid var(--red); }
.passage-summary p:last-child { margin: 8px 0 0; color: var(--muted); font-family: var(--display); font-size: 1.26rem; font-weight: 500; letter-spacing: -.02em; line-height: 1.15; }
.annotation-workbench { max-width: 530px; padding: 19px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.annotation-header { display: flex; justify-content: space-between; align-items: baseline; }
.annotation-workbench label { display: block; margin: 15px 0 6px; font-family: var(--mono); font-size: .65rem; text-transform: uppercase; }
.annotation-workbench label span { color: var(--muted); text-transform: none; }
.annotation-workbench textarea { width: 100%; resize: vertical; padding: 10px; color: var(--ink); background: color-mix(in oklch, var(--paper-deep) 72%, transparent); border: 1px solid var(--rule); border-radius: 0; line-height: 1.3; }
.selected-passage { margin: 13px 0 0; color: var(--muted); font-size: .93rem; font-style: italic; line-height: 1.32; }
.annotation-actions { display: flex; gap: 17px; align-items: center; margin-top: 11px; }
.button { padding: 8px 12px; color: var(--paper); font-family: var(--mono); font-size: .65rem; border: 0; background: var(--red); cursor: pointer; }
.annotation-status { min-height: 1.2em; margin: 10px 0 0; color: var(--red); font-family: var(--mono); font-size: .63rem; }
.reader-nav { display: flex; justify-content: space-between; gap: 24px; margin-top: 42px; padding: 16px 0; border-top: 1px solid var(--rule); }
.nav-button { padding: 0; color: var(--ink); font-family: var(--display); font-size: 1.25rem; border: 0; background: transparent; cursor: pointer; }
.nav-button.next { color: var(--red); text-align: right; }
.nav-button.is-complete { color: var(--faint); cursor: default; }

.section-progress { position: fixed; bottom: 0; left: 0; right: 0; height: 3px; z-index: 6; background: color-mix(in oklch, var(--rule) 40%, transparent); pointer-events: none; }
.section-progress-fill { height: 100%; width: 0; background: var(--red); transition: width .15s linear; }

.toc-item.has-bookmark strong::after { content: " \25C6"; color: var(--red); font-size: .6em; vertical-align: .15em; }
@keyframes bookmark-flash { 0% { background: transparent; } 30% { background: color-mix(in oklch, var(--red) 18%, transparent); } 100% { background: transparent; } }
.bookmark-button.flash { animation: bookmark-flash .7s ease-out; }

.sync-link { display: block; margin-top: 10px; }
.sync-modal-overlay { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; background: oklch(22% 0.02 55 / .55); }
.sync-modal-overlay[hidden] { display: none; }
.sync-modal { width: min(380px, calc(100% - 40px)); padding: 28px clamp(22px, 4vw, 36px); background: var(--paper); border: 1px solid var(--rule); box-shadow: 0 20px 60px oklch(20% 0.03 55 / .3); }
.sync-instructions { margin: 18px 0 22px; color: var(--muted); font-size: .9rem; line-height: 1.35; }
.sync-qr { display: block; margin: 0 auto 20px; }
.sync-url-label { display: block; color: var(--muted); font-family: var(--mono); font-size: .6rem; text-transform: uppercase; }
.sync-url-input { width: 100%; margin-top: 6px; padding: 8px 10px; color: var(--ink); font-family: var(--mono); font-size: .65rem; background: var(--paper-deep); border: 1px solid var(--rule); border-radius: 0; }

.field-notes { align-self: start; padding: clamp(42px, 7vw, 102px) clamp(22px, 3vw, 48px); border-left: 1px solid var(--rule); }
.field-notes-intro { max-width: 190px; margin-bottom: 29px; }
.field-notes-intro p:last-child { margin: 7px 0 0; color: var(--muted); font-size: .9rem; font-style: italic; line-height: 1.3; }
.field-notes-intro .field-notes-count { margin: 13px 0 0; color: var(--moss); font-family: var(--mono); font-size: .58rem; font-style: normal; letter-spacing: .04em; text-transform: uppercase; }
.context-cards { display: grid; gap: 0; border-top: 1px solid var(--rule); }
.context-card { position: relative; padding: 20px 0 21px 16px; border-bottom: 1px solid var(--rule); }
.context-card::before { position: absolute; top: 23px; bottom: 23px; left: 0; width: 2px; content: ""; background: var(--moss); }
.context-media { margin: 0 0 13px; }
.context-media img { display: block; width: 100%; max-height: 210px; object-fit: cover; border: 1px solid var(--rule); }
.context-media figcaption { margin-top: 6px; color: var(--faint); font-family: var(--mono); font-size: .53rem; line-height: 1.35; }
.context-media figcaption a { color: inherit; font-size: inherit; text-decoration: underline; }
.context-card h2 { margin: 5px 0 6px; font-family: var(--display); font-size: 1.34rem; font-weight: 500; letter-spacing: -.025em; line-height: 1; }
.context-card p { margin: 0 0 10px; color: var(--muted); font-size: .83rem; line-height: 1.32; }
.context-card a { color: var(--red); font-family: var(--mono); font-size: .6rem; text-decoration: none; }
.context-card a:hover { text-decoration: underline; text-underline-offset: 3px; }
.resource-meta { display: flex; flex-wrap: wrap; gap: 5px 10px; margin-bottom: 9px; color: var(--faint); font-family: var(--mono); font-size: .56rem; letter-spacing: .04em; }

.saved-note { padding: 22px 0; border-bottom: 1px solid var(--rule); }
.saved-note blockquote { margin: 0; font-family: var(--display); font-size: 1.05rem; line-height: 1.18; }
.saved-note p { color: var(--muted); line-height: 1.35; }

@media (max-width: 1050px) {
  .shell { grid-template-columns: 86px minmax(0, 1fr) 230px; }
  .reader { padding-right: clamp(30px, 5vw, 58px); padding-left: clamp(30px, 5vw, 58px); }
  .field-notes { padding-right: 23px; padding-left: 23px; }
}
:root[data-focus="true"] .shell { display: block; max-width: 830px; }
:root[data-focus="true"] .route-column, :root[data-focus="true"] .field-notes { display: none; }
:root[data-focus="true"] .reader { max-width: 720px; margin: 0 auto; }
@media (max-width: 780px) {
  .topbar { min-height: 64px; padding: 9px 18px; }
  .top-progress { display: none; }
  .type-controls { display: none; }
  .panel { top: 64px; }
  .shell { display: block; }
  .route-column { position: relative; min-height: 0; display: grid; grid-template-columns: 35px auto 1fr auto; gap: 11px; align-items: center; padding: 18px 24px; border-right: 0; border-bottom: 1px solid var(--rule); }
  .route-rule { width: 25px; height: 1px; }
  .route-number { margin: 0; font-size: 2.1rem; }
  .route-label { margin: 0; }
  .route-meter { justify-self: end; width: 64px; height: 4px; }
  .route-meter span { right: auto; left: 0; bottom: 0; height: 100% !important; width: var(--meter-width, 30%); }
  .bookmark-button { grid-column: 2 / -1; margin: 0; }
  .reader { padding: 54px 24px 38px; }
  .reader-content { font-size: calc(1.13rem * var(--reader-scale)); }
  .reader-content blockquote { margin-right: 0; margin-left: -.85em; padding-left: 1em; }
  .field-notes { padding: 34px 24px 65px; border-top: 1px solid var(--rule); border-left: 0; }
  .context-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
}
@media (max-width: 520px) {
  .wordmark { font-size: 1.08rem; }
  .wordmark-kicker { display: none; }
  .reader { padding-right: 21px; padding-left: 21px; }
  .reading-header h1 { font-size: clamp(2.75rem, 16vw, 4rem); }
  .context-cards { grid-template-columns: 1fr; }
  .nav-button { font-size: 1.08rem; }
  .nav-button span { display: none; }
}
@media (max-width: 600px) {
  .endnote-popover { top: auto !important; right: 0; bottom: 0; left: 0 !important; width: 100% !important; max-height: min(52vh, 450px); padding: 21px 24px; border-right: 0; border-bottom: 0; border-left: 0; }
  .footnote { min-width: 2.15rem; min-height: 2.15rem; font-size: .58em; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; } }
