/* ============================================================
   START UGLY. BUILD SMART. — online reader
   Styled to match the Dirt Sites design system:
   dark charcoal surfaces, bone reading surface, signal yellow accent,
   Bebas Neue display + Instrument Sans body. Mobile-first.
   ============================================================ */

:root {
  --black: #0d0c0a;
  --black-2: #12100d;
  --card: #1b1915;
  --bone: #f4f1e9;
  --warm-card: #eae5d8;
  --white: #f8f6f0;
  --muted: #968c7d;
  --muted-2: #6b655a;

  --text-dark: #11100d;
  --text-dark-2: #3e3a33;

  --yellow: #f2c500;
  --yellow-dark: #d6a900;

  --line-dark: rgba(248, 246, 240, 0.12);
  --line-light: #d8d2c5;

  /* Reader surface theme (light = default; see html[data-theme="dark"]) */
  --reader-bg: #f4f1e9;
  --reader-fg: #11100d;
  --reader-fg-2: #3e3a33;
  --reader-card: #eae5d8;
  --reader-line: #d8d2c5;
  --reader-muted: #6b655a;
  --reader-nav-bg: rgba(255, 255, 255, 0.4);
  --reader-nav-hover: #ffffff;

  --font-headline: 'Bebas Neue', 'Arial Narrow', sans-serif;
  --font-body: 'Instrument Sans', 'Helvetica Neue', Arial, sans-serif;

  --pad: 20px;
  --radius: 12px;
  --ease: cubic-bezier(.22, .61, .36, 1);

  /* Reader typography scale (toggled by JS) */
  --reader-scale: 1;
  --reader-fs: calc(1.07rem * var(--reader-scale));

  --bar-h: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
}

html[data-theme="dark"] {
  --reader-bg: #0d0c0a;
  --reader-fg: #f5f3ee;
  --reader-fg-2: #d4d1c8;
  --reader-card: #1b1915;
  --reader-line: rgba(248, 246, 240, 0.14);
  --reader-muted: #9b938a;
  --reader-nav-bg: rgba(248, 246, 240, 0.05);
  --reader-nav-hover: rgba(248, 246, 240, 0.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  background: var(--black);
  color: var(--white);
  line-height: 1.5;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
body.drawer-open { overflow: hidden; }

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; color: inherit; background: none; border: none; }
ul, ol { list-style: none; }

h1, h2, h3, .display {
  font-family: var(--font-headline);
  font-weight: 400;
  line-height: 0.9;
  letter-spacing: .5px;
  text-transform: uppercase;
}

[hidden] { display: none !important; }

a:focus-visible, button:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
}

.container { max-width: 1280px; margin: 0 auto; padding: 0 var(--pad); }

/* ============================================================
   COVER
   ============================================================ */
.cover {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 82% 6%, rgba(242, 197, 0, 0.18), transparent 42%),
    radial-gradient(circle at 8% 100%, rgba(242, 197, 0, 0.08), transparent 40%),
    linear-gradient(180deg, #0d0c0a 0%, #12100d 100%);
}

.cover-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px var(--pad);
}
.cover-brand {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-headline);
  font-size: 20px;
  letter-spacing: 2px;
  color: var(--white);
  text-transform: uppercase;
}

.cover-hero {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 64px 0 80px;
}
.cover-hero .container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto 0 0;
}
.cover-hero-copy { max-width: 100%; }
.cover-eyebrow {
  font-family: var(--font-headline);
  font-size: 14px;
  letter-spacing: 3.5px;
  color: var(--yellow);
  text-transform: uppercase;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.cover-eyebrow::before {
  content: "";
  width: 38px;
  height: 2px;
  background: var(--yellow);
}

.cover-title {
  font-size: clamp(64px, 16vw, 168px);
  line-height: 0.84;
  letter-spacing: 1px;
}
.cover-title .row { display: block; }
.cover-title .row + .row { margin-top: 2px; }
.cover-title .accent { color: var(--yellow); }
.cover-title .period { color: var(--yellow); }

.cover-subtitle {
  margin-top: 22px;
  max-width: 640px;
  font-size: 17px;
  color: #ece8de;
  line-height: 1.5;
}

.cover-author {
  margin-top: 16px;
  font-family: var(--font-headline);
  font-size: 16px;
  letter-spacing: 3px;
  color: #ece8de;
  text-transform: uppercase;
}
.cover-author strong { color: var(--white); font-weight: 400; }

.cover-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 32px;
  max-width: 460px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 56px;
  padding: 16px 26px;
  font-family: var(--font-headline);
  font-size: 19px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  border-radius: 10px;
  transition: background .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease);
}
.btn--primary { background: var(--yellow); color: var(--black); box-shadow: 0 10px 30px rgba(242, 197, 0, 0.22); }
.btn--primary:hover { background: var(--yellow-dark); }
.btn--ghost { background: rgba(248, 246, 240, 0.05); color: var(--white); border: 1px solid var(--line-dark); }
.btn--ghost:hover { border-color: var(--yellow); color: var(--yellow); }
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.cover-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin-top: 34px;
  font-family: var(--font-headline);
  font-size: 14px;
  letter-spacing: 2px;
  color: #d8d3c8;
  text-transform: uppercase;
}
.cover-meta strong { color: var(--white); font-weight: 400; }

/* Table of contents */
.toc {
  border-top: 1px solid var(--line-dark);
  padding: 56px 0 20px;
}
.toc-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}
.toc-title { font-size: clamp(36px, 7vw, 60px); }
.toc-title .accent { color: var(--yellow); }
.toc-count { font-family: var(--font-headline); font-size: 15px; letter-spacing: 2px; color: var(--muted); text-transform: uppercase; }

.toc-list { border-top: 1px solid var(--line-dark); }
.toc-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 20px 2px;
  border-bottom: 1px solid var(--line-dark);
  transition: background .16s var(--ease);
}
.toc-item:hover { background: rgba(248, 246, 240, 0.03); }
.toc-item .num {
  font-family: var(--font-headline);
  font-size: 22px;
  color: var(--yellow);
  min-width: 44px;
  letter-spacing: 1px;
}
.toc-item .name {
  font-family: var(--font-headline);
  font-size: 24px;
  letter-spacing: .5px;
  line-height: 1;
  text-transform: uppercase;
  color: var(--white);
}
.toc-item .name small {
  display: block;
  margin-top: 5px;
  font-family: var(--font-body);
  font-size: 13px;
  letter-spacing: .2px;
  text-transform: none;
  color: var(--muted);
  line-height: 1.4;
}
.toc-item .state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-headline);
  font-size: 13px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.toc-item .state .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid var(--muted);
  flex-shrink: 0;
}
.toc-item.is-read .state { color: var(--yellow); }
.toc-item.is-read .state .dot { background: var(--yellow); border-color: var(--yellow); }
.toc-item.is-current .name { color: var(--yellow); }
.toc-item .arrow {
  color: var(--muted);
  font-size: 18px;
  transition: transform .16s var(--ease), color .16s var(--ease);
}
.toc-item:hover .arrow { transform: translateX(4px); color: var(--yellow); }

.cover-footer {
  border-top: 1px solid var(--line-dark);
  padding: 28px 0 calc(40px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cover-footer p { font-size: 13px; color: var(--muted-2); }

/* ============================================================
   READER
   ============================================================ */
.reader { min-height: 100vh; background: var(--reader-bg); color: var(--reader-fg); }

.reader-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  height: calc(var(--bar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: rgba(13, 12, 10, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-dark);
  color: var(--white);
}
.reader-bar-inner {
  max-width: 860px;
  margin: 0 auto;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
}
.bar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 12px;
  border-radius: 9px;
  font-family: var(--font-headline);
  font-size: 14px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--white);
  border: 1px solid var(--line-dark);
  white-space: nowrap;
  transition: border-color .16s var(--ease), color .16s var(--ease);
}
.bar-btn:hover { border-color: var(--yellow); color: var(--yellow); }
.bar-btn--icon { width: 42px; padding: 0; font-size: 16px; }
.bar-btn svg { width: 17px; height: 17px; flex-shrink: 0; }

/* Theme toggle icon */
#btn-theme .icon-sun { display: none; }
html[data-theme="dark"] #btn-theme .icon-sun { display: block; }
html[data-theme="dark"] #btn-theme .icon-moon { display: none; }

.reader-bar .bar-spacer { flex: 1; min-width: 0; }
.reader-bar .bar-chapter {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 0;
  line-height: 1.1;
}
.reader-bar .bc-pos {
  font-family: var(--font-headline);
  font-size: 13px;
  letter-spacing: 1.5px;
  color: var(--muted);
  text-transform: uppercase;
  white-space: nowrap;
}
.reader-bar .bc-pos strong { color: var(--yellow); font-weight: 400; }
.reader-bar .bc-pct {
  font-family: var(--font-body);
  font-size: 11px;
  letter-spacing: .3px;
  color: var(--muted-2);
  margin-top: 1px;
}
.reader-bar .bc-pct:empty { display: none; }

.reader-progress {
  position: fixed;
  top: calc(var(--bar-h) + var(--safe-top));
  left: 0;
  right: 0;
  height: 3px;
  z-index: 51;
  background: rgba(248, 246, 240, 0.08);
}
.reader-progress .bar-fill {
  height: 100%;
  width: 0;
  background: var(--yellow);
  transition: width .1s linear;
}

/* Reading surface */
.reader-main {
  padding: calc(var(--bar-h) + var(--safe-top) + 6px) 0 0;
  max-width: 760px;
  margin: 0 auto;
}
.reader-content {
  padding: 40px 24px 120px;
}
@media (min-width: 640px) {
  .reader-content { padding-left: 48px; padding-right: 48px; }
}

.chapter-head { margin-bottom: 40px; padding-bottom: 28px; border-bottom: 1px solid var(--reader-line); }
.chapter-kicker {
  font-family: var(--font-headline);
  font-size: 14px;
  letter-spacing: 4px;
  color: var(--yellow-dark);
  text-transform: uppercase;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.chapter-kicker::before {
  content: "";
  width: 34px;
  height: 2px;
  background: var(--yellow-dark);
}
.chapter-title {
  font-size: clamp(44px, 10vw, 80px);
  line-height: 0.9;
  color: var(--reader-fg);
}
.chapter-title .accent { color: var(--yellow-dark); }

/* Blocks */
.blocks { display: grid; gap: 0; }
.blocks h2 {
  font-size: clamp(30px, 6vw, 44px);
  line-height: 0.95;
  color: var(--reader-fg);
  margin: 52px 0 18px;
}
.blocks h3 {
  font-size: clamp(24px, 5vw, 30px);
  line-height: 1;
  color: var(--reader-fg);
  margin: 40px 0 14px;
}
.blocks p {
  font-size: var(--reader-fs);
  line-height: 1.78;
  color: var(--reader-fg-2);
  margin: 0 0 22px;
}
.blocks p + p { margin-top: -2px; }
.blocks p strong { color: var(--reader-fg); font-weight: 650; }
.blocks p em { color: var(--reader-fg); }

.blocks ul, .blocks ol {
  margin: 4px 0 26px;
  padding-left: 2px;
  display: grid;
  gap: 12px;
}
.blocks li {
  position: relative;
  padding-left: 28px;
  font-size: var(--reader-fs);
  line-height: 1.6;
  color: var(--reader-fg-2);
}
.blocks ul li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.62em;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  background: var(--yellow-dark);
}
.blocks ol { counter-reset: bl; }
.blocks ol li { counter-increment: bl; }
.blocks ol li::before {
  content: counter(bl);
  position: absolute;
  left: 0;
  top: 0;
  font-family: var(--font-headline);
  font-size: 20px;
  color: var(--yellow-dark);
}
.blocks li strong { color: var(--reader-fg); }

/* Pull quote */
.blocks .quote {
  margin: 34px 0;
  padding: 26px 28px;
  border-left: 4px solid var(--yellow-dark);
  background: var(--reader-card);
  border-radius: 0 12px 12px 0;
  font-family: var(--font-headline);
  font-size: calc(clamp(1.5rem, 4vw, 2rem) * var(--reader-scale));
  line-height: 1.08;
  text-transform: uppercase;
  color: var(--reader-fg);
  white-space: pre-line;
}
.blocks .quote--small {
  font-family: var(--font-body);
  font-size: var(--reader-fs);
  line-height: 1.6;
  text-transform: none;
  color: var(--reader-fg-2);
  white-space: pre-line;
}

/* Chapter nav */
.chapter-nav {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 56px;
  padding-top: 28px;
  border-top: 1px solid var(--reader-line);
}
.chapter-nav-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.nav-link {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 20px;
  border-radius: 12px;
  border: 1px solid var(--reader-line);
  background: var(--reader-nav-bg);
  transition: border-color .16s var(--ease), background .16s var(--ease);
}
.nav-link:hover { border-color: var(--yellow-dark); background: var(--reader-nav-hover); }
.nav-link .nav-dir {
  font-family: var(--font-headline);
  font-size: 12px;
  letter-spacing: 2.5px;
  color: var(--reader-muted);
  text-transform: uppercase;
}
.nav-link .nav-title {
  font-family: var(--font-headline);
  font-size: 21px;
  letter-spacing: .5px;
  line-height: 1;
  color: var(--reader-fg);
  text-transform: uppercase;
}
.nav-link--next { text-align: right; align-items: flex-end; }
.nav-link--next .nav-dir { color: var(--yellow-dark); }
.nav-link--disabled { opacity: .4; pointer-events: none; }

.nav-toc {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-headline);
  font-size: 15px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--reader-muted);
  transition: color .16s var(--ease);
}
.nav-toc:hover { color: var(--reader-fg); }

/* ============================================================
   TOC DRAWER
   ============================================================ */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s var(--ease);
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 91;
  width: min(360px, 88vw);
  background: var(--black-2);
  color: var(--white);
  border-left: 1px solid var(--line-dark);
  transform: translateX(100%);
  transition: transform .3s var(--ease);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: var(--safe-top);
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line-dark);
}
.drawer-head .t {
  font-family: var(--font-headline);
  font-size: 20px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.drawer-close {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  border: 1px solid var(--line-dark);
  font-size: 18px;
  color: var(--white);
}
.drawer-close:hover { border-color: var(--yellow); color: var(--yellow); }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0 calc(env(safe-area-inset-bottom, 0px) + 10px);
  -webkit-overflow-scrolling: touch;
}
.drawer-item {
  display: flex;
  gap: 14px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 15px 20px;
  border-bottom: 1px solid rgba(248, 246, 240, 0.06);
  transition: background .14s var(--ease);
}
.drawer-item:hover { background: rgba(248, 246, 240, 0.05); }
.drawer-item .num {
  font-family: var(--font-headline);
  font-size: 19px;
  color: var(--yellow);
  min-width: 26px;
}
.drawer-item .name {
  flex: 1;
  font-family: var(--font-headline);
  font-size: 18px;
  letter-spacing: .5px;
  line-height: 1;
  text-transform: uppercase;
  color: var(--white);
}
.drawer-item.is-current .name { color: var(--yellow); }
.drawer-item.is-read .name { color: var(--muted); }
.drawer-item.is-read .name::after { content: " \u2713"; color: var(--yellow); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (min-width: 700px) {
  :root { --pad: 36px; }
  .cover-actions { flex-direction: row; }
  .cover-actions .btn { flex: 1; }
  .toc-item { padding: 24px 4px; }
  .toc-item .name { font-size: 30px; }
  .toc-item .num { font-size: 26px; }
  .chapter-nav-row { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1024px) {
  :root { --pad: 56px; }
  .cover-hero { padding: 96px 0 120px; }
  .toc { padding: 72px 0 20px; }
  .reader-main { max-width: 780px; }
  .reader-content { padding-left: 56px; padding-right: 56px; }
}

@media (max-width: 400px) {
  .bar-btn .bar-label { display: none; }
  .bar-btn { padding: 0 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
