/* Native Apple Books–inspired pure-black Edition reading room (/notes/edition/). */

:root {
  color-scheme: dark;
}

body.book-edition-page {
  --book-bg: #000000;
  --book-ink: #f2f0ec;
  --book-muted: rgba(242, 240, 236, 0.54);
  --book-faint: rgba(242, 240, 236, 0.22);
  --book-pill: rgba(34, 34, 38, 0.72);
  --book-pill-hover: rgba(54, 54, 60, 0.86);
  --book-pill-border: rgba(255, 255, 255, 0.14);
  --book-gold: #ffd147;
  --book-serif: Lora, 'New York', 'Iowan Old Style', Georgia, serif;
  --book-ui: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  --book-size: 1.22rem;
  --book-measure: 36.5rem;

  margin: 0;
  min-height: 100svh;
  background: var(--book-bg);
  color: var(--book-ink);
  font-family: var(--book-serif);
  font-feature-settings: "kern" 1, "liga" 1, "onum" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.book-edition-page[data-book-size="sm"] { --book-size: 1.07rem; }
body.book-edition-page[data-book-size="md"] { --book-size: 1.22rem; }
body.book-edition-page[data-book-size="lg"] { --book-size: 1.38rem; }
body.book-edition-page[data-book-measure="wide"] { --book-measure: 44.5rem; }
body.book-edition-page.is-lightbox { overflow: hidden; }

body.book-edition-page [hidden] { display: none !important; }
body.book-edition-page :is(a, button, [role="slider"]):focus-visible {
  outline: 2px solid var(--book-gold);
  outline-offset: 3px;
}

/* 1. Apple Books Top Chrome (frosted floating pills + true Zen hide) */
.book-chrome-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
  padding: clamp(.8rem, 1.8vw, 1.15rem) clamp(1rem, 2.6vw, 1.75rem);
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.94) 0%, rgba(0, 0, 0, 0.68) 65%, rgba(0, 0, 0, 0) 100%);
  font-family: var(--book-ui);
  transition: opacity 320ms ease, transform 320ms cubic-bezier(.22, 1, .36, 1);
}
.book-chrome-top.is-zen {
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
}
.book-chrome-top:is(:hover, :focus-within) {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.book-chrome-left {
  display: flex;
  align-items: center;
}
.book-chrome-center {
  text-align: center;
  min-width: 0;
}
.book-chrome-title {
  margin: 0;
  font-family: var(--book-ui);
  font-size: .88rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.01em;
  color: rgba(242, 240, 236, 0.94);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-chrome-author {
  margin: .1rem 0 0;
  font-size: .74rem;
  line-height: 1.2;
  color: var(--book-muted);
}
.book-chrome-right {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: .55rem;
}

.book-pill-icon,
.book-pill-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--book-pill-border);
  background: var(--book-pill);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  color: rgba(242, 240, 236, 0.92);
  font-family: var(--book-ui);
  font-size: .82rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}
.book-pill-icon {
  width: 36px;
  padding: 0;
}
.book-pill-text {
  padding: 0 .88rem;
  letter-spacing: -.01em;
}
.book-pill-icon:hover,
.book-pill-text:hover,
.book-pill-icon[aria-expanded="true"],
.book-pill-text[aria-expanded="true"] {
  background: var(--book-pill-hover);
  border-color: rgba(242, 240, 236, 0.28);
  color: #ffffff;
}

/* Floating Popovers (Contents + Typography) */
.book-popover {
  position: fixed;
  top: 4.1rem;
  right: clamp(1rem, 2.6vw, 1.75rem);
  z-index: 50;
  width: min(268px, calc(100vw - 2rem));
  padding: .95rem 1rem 1.05rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(20, 20, 24, 0.88);
  -webkit-backdrop-filter: blur(22px);
  backdrop-filter: blur(22px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.86);
  font-family: var(--book-ui);
}
.book-popover-heading {
  margin: 0 0 .48rem;
  font-size: .67rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--book-muted);
}
.book-popover-heading:not(:first-child) {
  margin-top: .9rem;
}
.book-toc-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: .18rem;
}
.book-toc-list a {
  display: flex;
  align-items: baseline;
  gap: .65rem;
  padding: .45rem .55rem;
  border-radius: 8px;
  color: var(--book-ink);
  font-family: var(--book-serif);
  font-size: .88rem;
  line-height: 1.35;
  text-decoration: none;
  transition: background 140ms ease, color 140ms ease;
}
.book-toc-list a:hover {
  background: rgba(255, 255, 255, 0.09);
}
.book-toc-num {
  min-width: 1.4rem;
  font-family: var(--book-ui);
  font-size: .72rem;
  color: var(--book-gold);
}

.book-segmented {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
}
.book-segmented button {
  min-height: 32px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--book-muted);
  font-family: var(--book-ui);
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}
.book-segmented button:hover { color: var(--book-ink); }
.book-segmented button[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

/* 2. Reading Canvas & Fine-Press Literary Typography */
.book-canvas {
  width: auto;
  max-width: none;
  margin: 0;
  min-height: 100svh;
  padding: clamp(6.25rem, 15vh, 10rem) clamp(1.35rem, 5vw, 3.5rem) clamp(7rem, 14vh, 9.5rem);
}
.book-folio {
  width: min(100%, var(--book-measure));
  margin: 0 auto;
  font-size: var(--book-size);
  line-height: 1.74;
  letter-spacing: -.003em;
  color: var(--book-ink);
}

.book-section {
  scroll-margin-top: 5.5rem;
}
.book-section + .book-section {
  margin-top: clamp(4.75rem, 11vh, 7.5rem);
}

/* Punchy, minimal fine-press chapter separator with monumental Roman numeral */
.book-section-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 0 clamp(2.25rem, 5vh, 3rem);
  text-align: center;
}
.book-chapter-rule {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  width: min(100%, 22rem);
  margin-bottom: clamp(1.5rem, 3.6vh, 2.2rem);
}
.book-chapter-rule span {
  display: block;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(242, 240, 236, 0.34));
  transform-origin: right center;
  transform: scaleX(0.35);
  opacity: 0.4;
  transition: transform 780ms cubic-bezier(.22, 1, .36, 1), opacity 600ms ease;
}
.book-chapter-rule span:last-child {
  background: linear-gradient(to left, transparent, rgba(242, 240, 236, 0.34));
  transform-origin: left center;
}
.book-section-head.is-visible .book-chapter-rule span {
  transform: scaleX(1);
  opacity: 1;
}
.book-chapter-rule i {
  display: block;
  width: 6px;
  height: 6px;
  transform: rotate(45deg);
  background: var(--book-gold);
  box-shadow: 0 0 12px rgba(255, 209, 71, 0.45);
}
.book-section-numeral {
  font-family: var(--book-serif);
  font-size: clamp(2.5rem, 5vw, 3.6rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: .14em;
  padding-left: .14em;
  color: #ffffff;
  font-feature-settings: "kern" 1, "lnum" 1;
}
.book-section-head h2 {
  margin: .78rem 0 0;
  font-family: var(--book-serif);
  font-size: clamp(1.06rem, 1.8vw, 1.24rem);
  font-weight: 400;
  font-style: italic;
  letter-spacing: .01em;
  color: rgba(242, 240, 236, 0.72);
}

.book-folio p {
  margin: 0;
  hanging-punctuation: first last;
}
@media (min-width: 640px) {
  body.book-edition-page[data-book-align="book"] .book-folio p {
    text-align: justify;
    hyphens: auto;
    -webkit-hyphens: auto;
  }
}
.book-folio p.book-indent {
  text-indent: 1.75em;
}
.book-folio p + p:not(.book-indent) {
  margin-top: 1.25em;
}
.book-opening-p::after {
  content: '';
  display: block;
  clear: both;
}

/* Fine-press tracked small-caps lead-in bridging drop cap -> prose */
.book-lead-in {
  font-size: .78em;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-weight: 500;
  color: rgba(242, 240, 236, 0.96);
}

/* Printer's mathematical Q.E.D. endmark on final paragraph */
.book-endmark {
  display: inline-block;
  margin-left: .48em;
  font-size: .72em;
  line-height: 1;
  vertical-align: .06em;
  color: var(--book-gold);
  opacity: 0.85;
}

/* 3. Sculpted Drop Cap (snapped flush to line-1 cap height) */
.book-dropcap {
  float: left;
  width: clamp(5.8rem, 13vw, 7.2rem);
  margin: -.14em .82rem .14rem -.22rem;
  line-height: 0;
  user-select: none;
}
.book-initial-svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Inline Apple Books Footnote Reference & Popover */
.book-fn-ref {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25em;
  height: 1.25em;
  padding: 0 .22em;
  margin: 0 .06em;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 209, 71, 0.12);
  color: var(--book-gold);
  font-family: var(--book-ui);
  font-size: .62em;
  font-weight: 600;
  line-height: 1;
  vertical-align: .42em;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, transform 140ms ease;
}
.book-fn-ref:hover,
.book-fn-ref[aria-expanded="true"] {
  background: var(--book-gold);
  color: #000000;
}

.book-fn-popover {
  position: fixed;
  z-index: 60;
  width: min(330px, calc(100vw - 2rem));
  padding: .9rem 1rem 1rem;
  border-radius: 13px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(20, 20, 24, 0.92);
  -webkit-backdrop-filter: blur(22px);
  backdrop-filter: blur(22px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.9);
  font-family: var(--book-ui);
}
.book-fn-head {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  margin-bottom: .45rem;
}
.book-fn-num {
  color: var(--book-gold);
  font-size: .72rem;
  font-weight: 600;
}
.book-fn-label {
  font-size: .76rem;
  font-weight: 600;
  color: var(--book-ink);
  flex: 1;
}
.book-fn-close {
  border: 0;
  background: transparent;
  color: var(--book-muted);
  font-size: 1.05rem;
  line-height: 1;
  padding: .1rem .25rem;
  cursor: pointer;
}
.book-fn-close:hover { color: #ffffff; }
.book-fn-body {
  margin: 0;
  font-family: var(--book-serif);
  font-size: .86rem;
  line-height: 1.58;
  color: rgba(242, 240, 236, 0.88);
}

/* Pull-quote */
.book-quote {
  margin: clamp(2.1rem, 4.5vh, 3rem) 0;
  padding: .25rem 0 .25rem 1.45rem;
  border-left: 1.5px solid rgba(242, 240, 236, 0.36);
  font-style: italic;
  color: rgba(242, 240, 236, 0.92);
}
.book-quote p {
  font-size: 1.06em;
  line-height: 1.65;
  text-align: left !important;
}
.book-quote cite {
  display: block;
  margin-top: .65rem;
  font-style: normal;
  font-family: var(--book-ui);
  font-size: .74rem;
  letter-spacing: .02em;
  color: var(--book-muted);
}

/* Book fleuron divider */
.book-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: clamp(2.4rem, 5.5vh, 3.6rem) 0;
  color: var(--book-muted);
  font-size: .85rem;
}
.book-divider::before,
.book-divider::after {
  content: '';
  width: 3.2rem;
  height: 1px;
  background: var(--book-faint);
}

/* 4. Borderless High-Contrast Living Plates */
.book-plate {
  margin: clamp(2.8rem, 6.5vh, 4.5rem) 0;
  opacity: 0.14;
  transform: translateY(14px);
  transition: opacity 640ms cubic-bezier(.22, 1, .36, 1), transform 640ms cubic-bezier(.22, 1, .36, 1);
}
.book-plate.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.book-plate.is-wide {
  width: min(calc(100vw - 2.7rem), 49rem);
  margin-left: 50%;
  transform: translate(-50%, 14px);
}
.book-plate.is-wide.is-visible {
  transform: translate(-50%, 0);
}

.book-plate-stage {
  padding: clamp(.75rem, 2vw, 1.35rem) 0;
  border-top: 1px solid rgba(242, 240, 236, 0.14);
  border-bottom: 1px solid rgba(242, 240, 236, 0.14);
  background: transparent;
}
.plate-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.plate-svg.plate-interactive {
  cursor: crosshair;
  touch-action: pan-y;
}

/* Staggered SVG choreography (paths, nodes, bars) */
.book-plate .plate-fade {
  opacity: 0;
  transition: opacity 520ms ease var(--fade-delay, 0ms);
}
.book-plate.is-visible .plate-fade {
  opacity: 1;
}
.book-plate .plate-bar {
  transform-box: fill-box;
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 820ms cubic-bezier(.22, 1, .36, 1) var(--bar-delay, 0ms);
}
.book-plate.is-visible .plate-bar {
  transform: scaleX(1);
}

.book-plate-caption {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .85rem;
  max-width: var(--book-measure);
  margin: .85rem auto 0;
  font-family: var(--book-ui);
  font-size: .78rem;
  line-height: 1.55;
  color: var(--book-muted);
}
.book-plate-caption-body {
  display: flex;
  align-items: baseline;
  gap: .7rem;
  min-width: 0;
}
.book-plate-num {
  flex-shrink: 0;
  font-family: var(--book-serif);
  font-style: italic;
  color: var(--book-ink);
}
.book-plate-expand {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: transparent;
  color: var(--book-muted);
  font-size: .78rem;
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
}
.book-plate-expand:hover {
  color: var(--book-gold);
  border-color: rgba(255, 209, 71, 0.45);
  background: rgba(255, 255, 255, 0.05);
}

/* Full-Viewport Pure-Black Plate Lightbox */
.book-lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: clamp(2rem, 5vw, 4rem);
  background: rgba(0, 0, 0, 0.97);
}
.book-lightbox-close {
  position: fixed;
  top: 1.15rem;
  right: 1.35rem;
  z-index: 95;
}
.book-lightbox-stage {
  width: min(92vw, 1020px);
  max-height: 76svh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.book-lightbox-stage svg {
  width: 100%;
  max-height: 76svh;
  height: auto;
}
.book-lightbox-caption {
  margin: 0;
  max-width: 58ch;
  text-align: center;
  font-family: var(--book-ui);
  font-size: .82rem;
  line-height: 1.55;
  color: var(--book-muted);
}

/* Colophon */
.book-colophon {
  margin-top: clamp(4.5rem, 10vh, 7rem);
  padding-top: 1.65rem;
  border-top: 1px solid rgba(242, 240, 236, 0.14);
  font-family: var(--book-ui);
  font-size: .8rem;
  line-height: 1.6;
  color: var(--book-muted);
}
.book-colophon p {
  margin: 0;
  text-align: left !important;
}
.book-colophon-specs {
  margin-bottom: .5rem !important;
  font-family: var(--book-serif);
  font-style: italic;
  font-size: .84rem;
  color: rgba(242, 240, 236, 0.72);
}
.book-colophon-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .75rem 1.5rem;
  margin-top: 1.05rem;
}
.book-colophon-links a {
  color: var(--book-ink);
  text-decoration: none;
  border-bottom: 1px solid rgba(242, 240, 236, 0.28);
  padding-bottom: 2px;
  transition: border-color 150ms ease, color 150ms ease;
}
.book-colophon-links a:hover {
  color: var(--book-gold);
  border-bottom-color: var(--book-gold);
}

/* 5. Apple Books Bottom Reading Scrubber + Chapter Ticks + Live Tooltip */
.book-chrome-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(240px, 42vw) minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
  padding: .9rem clamp(1rem, 2.6vw, 1.75rem) clamp(.85rem, 1.8vw, 1.15rem);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.94) 0%, rgba(0, 0, 0, 0.68) 65%, rgba(0, 0, 0, 0) 100%);
  font-family: var(--book-ui);
  font-size: .74rem;
  color: var(--book-muted);
  font-variant-numeric: tabular-nums;
  transition: opacity 320ms ease, transform 320ms cubic-bezier(.22, 1, .36, 1);
}
.book-chrome-bottom.is-zen {
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
}
.book-chrome-bottom:is(:hover, :focus-within) {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.book-progress-section {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-progress-pct {
  text-align: right;
  white-space: nowrap;
}

.book-scrubber-wrap {
  position: relative;
}
.book-scrub-tip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: .34rem .68rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(24, 24, 28, 0.94);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  color: rgba(242, 240, 236, 0.94);
  font-size: .7rem;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.78);
}

.book-scrubber {
  display: flex;
  align-items: center;
  height: 24px;
  cursor: pointer;
  touch-action: none;
}
.book-scrubber-track {
  position: relative;
  display: block;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}
.book-scrubber-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: rgba(242, 240, 236, 0.86);
  transition: width 70ms linear;
}
.book-scrubber-ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.book-scrubber-tick {
  position: absolute;
  top: 50%;
  width: 2px;
  height: 7px;
  border-radius: 1px;
  transform: translate(-50%, -50%);
  background: rgba(242, 240, 236, 0.34);
}
.book-scrubber-tick.is-plate {
  height: 5px;
  background: rgba(255, 209, 71, 0.58);
}

/* Reduced motion & mobile adjustments */
@media (prefers-reduced-motion: reduce) {
  .book-plate,
  .book-plate.is-wide,
  .book-plate .plate-fade,
  .book-plate .plate-bar,
  .book-chapter-rule span {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  .book-plate.is-wide {
    margin-left: 50%;
    transform: translateX(-50%) !important;
  }
  .plate-draw {
    stroke-dashoffset: 0 !important;
    transition: none !important;
  }
}

@media (max-width: 640px) {
  .book-dropcap {
    width: 5.2rem;
    margin: -.1em .75rem .15rem -.15rem;
  }
  .book-chrome-bottom {
    grid-template-columns: 1fr auto;
  }
  .book-progress-section {
    display: none;
  }
  .book-scrubber-wrap {
    width: 100%;
  }
}
