/* The Next World Up — reader styles extending the existing site system. */

.book-landing,
.book-reader {
  --reader-muted: #808080;
  --reader-focus: #b3b3b3;
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 60px 24px 96px;
}

.book-landing a:focus-visible,
.book-reader a:focus-visible {
  outline: 2px solid var(--reader-focus);
  outline-offset: 4px;
}

.book-hero {
  padding: 4px 0 56px;
  border-bottom: 1px solid var(--border);
}

.book-kicker,
.chapter-list-label,
.reader-top,
.reader-pager-label {
  font-family: 'Space Mono', monospace;
  color: var(--reader-muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}

.book-hero h1 {
  color: var(--bright);
  font-size: clamp(2.6rem, 9vw, 5.25rem);
  font-weight: 700;
  letter-spacing: -0.055em;
  line-height: 0.96;
  margin: 18px 0 24px;
  max-width: 650px;
}

.book-hero p {
  max-width: 520px;
  color: var(--text);
  font-size: 1.05rem;
  line-height: 1.8;
}

.book-teaser p { margin: 0; }
.book-teaser p + p { margin-top: 0.9rem; }

.book-landing > .back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--reader-muted);
}

.book-start {
  display: inline-flex;
  align-items: center;
  gap: 18px;
  min-height: 44px;
  margin-top: 22px;
  color: var(--bright);
  font-family: 'Space Mono', monospace;
  font-size: 0.78rem;
  text-decoration: none;
  border-bottom: 1px solid var(--dim);
}

.book-start:hover,
.book-start:focus-visible { border-color: var(--bright); }

.chapter-list { margin-top: 44px; }
.chapter-list-label { margin-bottom: 10px; }

.chapter-row {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  color: inherit;
  text-decoration: none;
  border-top: 1px solid var(--border);
  transition: border-color 150ms ease, color 150ms ease;
}
.chapter-row:last-child { border-bottom: 1px solid var(--border); }
.chapter-row:hover,
.chapter-row:focus-visible { border-color: var(--border-hover); color: var(--bright); }
.chapter-row:focus-visible { outline-color: var(--reader-focus); }

.chapter-number,
.chapter-arrow {
  color: var(--reader-muted);
  font-family: 'Space Mono', monospace;
  font-size: 0.74rem;
}
.chapter-title { color: var(--bright); font-size: 1.05rem; font-weight: 500; }
.chapter-arrow { font-size: 1rem; }

.reading-progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 10;
  height: 2px;
  background: transparent;
}
.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--bright);
  transform-origin: left center;
}

.reader-top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 20px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.reader-top a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--reader-muted);
  text-decoration: none;
}
.reader-top a:hover,
.reader-top a:focus-visible { color: var(--bright); }

.reader-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-bottom: 48px;
  font-family: 'Space Mono', monospace;
}

.reader-size-controls {
  display: flex;
  align-items: center;
}

.reader-size-controls > * { position: relative; }
.reader-size-controls button:hover,
.reader-size-controls button:focus-visible { z-index: 1; }

.reader-controls button,
.reader-size-controls output {
  min-height: 40px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--reader-muted);
  font: inherit;
  font-size: 0.72rem;
}

.reader-controls button {
  min-width: 42px;
  padding: 0 12px;
  cursor: pointer;
}

.reader-controls button:hover,
.reader-controls button:focus-visible {
  color: var(--bright);
  border-color: var(--reader-focus);
}

.reader-controls button:disabled {
  color: var(--dim);
  cursor: default;
  border-color: var(--border);
}

.reader-size-controls button + output,
.reader-size-controls output + button { margin-left: -1px; }

.reader-size-controls output {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  padding: 0 8px;
}

#reader-font-family {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 112px;
}

#reader-bookmark {
  display: inline-flex;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9;
  align-items: center;
  gap: 9px;
  min-width: 132px;
  background: #111;
  border-color: #3d3d3d;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.42);
}

.reader-control-label {
  color: var(--dim);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
}

.book-prose {
  --reader-body-size: 1.125rem;
  color: #cbc9c2;
  font-family: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  font-size: var(--reader-body-size);
  font-kerning: normal;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
}
.book-reader[data-reader-font="serif"] .book-prose {
  font-family: 'Source Serif 4', Georgia, 'Times New Roman', serif;
}
.book-reader[data-reader-font="sans"] .book-prose {
  font-family: 'Space Grotesk', sans-serif;
}
.book-reader[data-reader-font="mono"] .book-prose {
  font-family: 'Space Mono', monospace;
}
.book-prose > :first-child { margin-top: 0; }

.book-prose h1 {
  color: #efeee9;
  font-size: clamp(2rem, 6vw, 3.25rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.08;
  margin: 0 0 42px;
}

.book-prose h2,
.book-prose h3 {
  color: var(--bright);
  line-height: 1.25;
  margin: 44px 0 20px;
}

.book-prose p {
  color: inherit;
  font-size: 1em;
  line-height: 1.76;
  margin-bottom: 1.38em;
}

.book-prose strong { color: #e4e2dc; font-weight: 600; }
.book-prose em { color: #d9d6ce; }
.book-prose a {
  color: var(--bright);
  text-decoration-color: var(--dim);
  text-underline-offset: 3px;
}
.book-prose a:hover,
.book-prose a:focus-visible { text-decoration-color: var(--bright); }

.book-prose blockquote {
  margin: 36px 0;
  padding: 20px 24px;
  border-left: 2px solid #626262;
  background: #111;
}
.book-prose blockquote p {
  color: #c1c0ba;
  font-family: 'Space Mono', monospace;
  font-size: 0.8em;
  line-height: 1.78;
  margin-bottom: 14px;
}
.book-prose blockquote p:last-child { margin-bottom: 0; }
.book-prose blockquote strong { font-size: 0.74rem; letter-spacing: 0.04em; }

.book-prose hr {
  width: 44px;
  height: 1px;
  border: 0;
  background: var(--dim);
  margin: 64px auto;
}

.book-prose ul,
.book-prose ol { margin: 0 0 28px 24px; }
.book-prose li { padding-left: 6px; margin-bottom: 10px; }
.book-prose code {
  color: var(--bright);
  background: var(--surface);
  padding: 0.12em 0.32em;
  border-radius: 2px;
}

.reader-pager {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 22px;
  margin-top: 72px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}
.reader-pager-side { display: flex; flex-direction: column; gap: 6px; }
.reader-pager-next { text-align: right; align-items: flex-end; }
.reader-pager a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--bright);
  text-decoration: none;
}
.reader-pager a:hover,
.reader-pager a:focus-visible { text-decoration: underline; text-underline-offset: 4px; }
.reader-contents {
  color: var(--reader-muted) !important;
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

@media (max-width: 600px) {
  .book-landing,
  .book-reader { padding: 38px 20px 72px; }
  .book-hero { padding-bottom: 42px; }
  .book-hero h1 { letter-spacing: -0.045em; }
  .reader-top { align-items: flex-start; margin-bottom: 16px; }
  .reader-top span { max-width: 170px; text-align: right; line-height: 1.6; }
  .reader-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 40px;
  }
  .reader-size-controls { grid-column: 1 / -1; justify-content: flex-end; }
  #reader-font-family { width: 100%; justify-content: center; }
  #reader-bookmark {
    right: 14px;
    bottom: 14px;
    width: auto;
    justify-content: center;
  }
  .reader-controls button,
  .reader-size-controls output { min-height: 44px; }
  .book-prose h1 { margin-bottom: 34px; }
  .book-prose p { line-height: 1.72; margin-bottom: 1.32em; }
  .book-prose blockquote { margin: 30px -4px; padding: 18px 18px; }
  .book-prose blockquote p { overflow-wrap: anywhere; }
  .reader-pager { grid-template-columns: 1fr 1fr; align-items: start; }
  .reader-contents { grid-column: 1 / -1; grid-row: 2; justify-content: center; text-align: center; padding-top: 8px; }

  body:has(.book-landing) .footer,
  body:has(.book-reader) .footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    line-height: 1.5;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chapter-row { transition: none; }
}
