/* THE LONG WAY BACK — modern editorial theme
   ---------------------------------------------------------------- */

:root {
  --bg: #ffffff;
  --bg-raised: #f4f5f7;
  --text: #15171c;
  --text-soft: #535863;
  --text-faint: #8a8f99;
  --rule: #e7e8ec;
  --accent: #4f46e5;
  --accent-soft: #6a61ea;
  --on-accent: #ffffff;
  --pull-bg: #f2f2fb;
  --shadow: 0 1px 2px rgba(15, 17, 21, 0.06), 0 10px 30px rgba(15, 17, 21, 0.08);
  --max-w: 40rem;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #0c0d10;
  --bg-raised: #17181d;
  --text: #f1f2f4;
  --text-soft: #b3b7c1;
  --text-faint: #767b86;
  --rule: #26282f;
  --accent: #8b85f5;
  --accent-soft: #a29cf8;
  --on-accent: #0c0d10;
  --pull-bg: #16161f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0d10;
    --bg-raised: #17181d;
    --text: #f1f2f4;
    --text-soft: #b3b7c1;
    --text-faint: #767b86;
    --rule: #26282f;
    --accent: #8b85f5;
    --accent-soft: #a29cf8;
    --on-accent: #0c0d10;
    --pull-bg: #16161f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-soft); }

img, svg { max-width: 100%; }

::selection { background: var(--accent); color: var(--on-accent); }

/* ---------- Site header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-body);
}

.site-header .brand {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.015em;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-header nav {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  font-size: 0.85rem;
}

.site-header nav a {
  color: var(--text-soft);
  text-decoration: none;
  font-weight: 500;
}
.site-header nav a:hover { color: var(--accent); }

.site-header nav .short-label { display: none; }

.theme-toggle {
  border: 1px solid var(--rule);
  background: var(--bg-raised);
  color: var(--text);
  border-radius: 8px;
  width: 2.15rem;
  height: 2.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  flex: 0 0 auto;
  transition: border-color 120ms ease;
}
.theme-toggle:hover { border-color: var(--accent); }

/* ---------- Progress bar ---------- */
.progress-bar {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  background: var(--accent);
  z-index: 30;
  transition: width 80ms linear;
}

/* ---------- Cover / hero ---------- */

.cover {
  min-height: 92vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
  background:
    radial-gradient(ellipse at 50% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 60%),
    var(--bg);
}

.cover .kicker {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 1.5rem;
}

.cover h1 {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: clamp(2.6rem, 7vw, 5rem);
  line-height: 1.02;
  margin: 0 0 1rem;
  max-width: 16ch;
}

.cover .subtitle {
  font-family: var(--font-body);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.1rem, 2.6vw, 1.4rem);
  color: var(--text-soft);
  margin: 0 0 2.25rem;
}

.cover .author {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 3rem;
}

.cover .cover-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  justify-content: center;
}

.btn {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.8rem 1.6rem;
  border-radius: 6px;
  text-decoration: none;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover { background: var(--accent-soft); color: var(--on-accent); }

.btn-ghost {
  background: transparent;
  border-color: var(--rule);
  color: var(--text);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.cover .scroll-hint {
  margin-top: 3.5rem;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

/* ---------- Generic page shell ---------- */

.page {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 3.5rem 1.5rem 6rem;
}

.page-narrow { max-width: 36rem; }

.breadcrumb {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 1.75rem;
}
.breadcrumb a { color: var(--text-faint); }
.breadcrumb a:hover { color: var(--accent); }

h1.page-title {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.015em;
  font-size: clamp(1.9rem, 4.5vw, 2.6rem);
  line-height: 1.15;
  margin: 0 0 2rem;
}

/* ---------- Table of contents ---------- */

.toc-intro {
  color: var(--text-soft);
  margin-bottom: 2.5rem;
}

.toc-part {
  margin-bottom: 2.5rem;
}

.toc-part-label {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 0.9rem;
  display: block;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}

.toc-list li {
  border-bottom: 1px solid var(--rule);
}

.toc-list a {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  padding: 0.85rem 0.6rem;
  margin: 0 -0.6rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  transition: background-color 120ms ease;
}
.toc-list a:hover { background: var(--bg-raised); }

.toc-list a:hover .toc-chapter-title { color: var(--accent); }

.toc-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
  font-size: 0.9rem;
  min-width: 1.6rem;
}

.toc-chapter-title {
  flex: 1;
  font-size: 1.02rem;
  font-weight: 500;
}

.toc-arrow {
  color: var(--text-faint);
  font-family: var(--font-body);
  font-size: 0.9rem;
}

/* ---------- Chapter page ---------- */

.part-divider {
  text-align: center;
  margin: 0 0 3rem;
  padding-bottom: 2.25rem;
  border-bottom: 1px solid var(--rule);
}

.part-divider .part-eyebrow {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 0.6rem;
}

.part-divider .part-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--text-soft);
}

.chapter-kicker {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-faint);
  margin-bottom: 0.9rem;
}
.chapter-kicker .accent { color: var(--accent); }

h1.chapter-title {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: clamp(2rem, 5.5vw, 3rem);
  line-height: 1.08;
  margin: 0 0 3rem;
}

.chapter-body p {
  margin: 0 0 1.35em;
}

.chapter-body p.pull-line {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  line-height: 1.42;
  letter-spacing: -0.005em;
  color: var(--text);
  background: var(--pull-bg);
  border-left: 3px solid var(--accent);
  padding: 1rem 1.25rem;
  margin: 1.75em 0;
}

.chapter-body p.beat-line {
  font-style: italic;
  color: var(--text-soft);
}

.chapter-body strong { font-weight: 700; color: var(--text); }
.chapter-body em { font-style: italic; }

/* ---------- Chapter footer nav ---------- */

.chapter-nav {
  margin-top: 4.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-family: var(--font-body);
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  text-decoration: none;
  max-width: 46%;
}

.chapter-nav .dir {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
}

.chapter-nav .label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--text);
  line-height: 1.3;
}
.chapter-nav a:hover .label { color: var(--accent); }

.chapter-nav .next { text-align: right; margin-left: auto; align-items: flex-end; }

.chapter-nav .toc-link {
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 0.8rem;
}

/* ---------- Footer ---------- */

.site-footer {
  text-align: center;
  padding: 3rem 1.5rem 4rem;
  color: var(--text-faint);
  font-family: var(--font-body);
  font-size: 0.82rem;
  border-top: 1px solid var(--rule);
}
.site-footer a { color: var(--text-faint); }
.site-footer a:hover { color: var(--accent); }

.site-counter {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.45rem;
  margin-top: 1.25rem;
}
.site-counter[hidden] { display: none; }

.site-counter-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.site-counter-label {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.7rem;
  color: var(--text-faint);
}

/* ---------- Read-all page ---------- */

.readall-chapter {
  margin-bottom: 4.5rem;
  padding-bottom: 3rem;
  border-bottom: 1px solid var(--rule);
}
.readall-chapter:last-child { border-bottom: none; }

.jumpnav-toggle {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 25;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 10px;
  width: 3rem;
  height: 3rem;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .site-header nav .full-label { display: none; }
  .site-header nav .short-label { display: inline; }
  .site-header { padding: 0.85rem 1rem; gap: 0.5rem; }
  .site-header nav { gap: 0.85rem; font-size: 0.82rem; }
  .page { padding: 2.25rem 1.25rem 4.5rem; }
  .chapter-nav { flex-direction: column; }
  .chapter-nav a { max-width: 100%; }
  .chapter-nav .next { text-align: left; align-items: flex-start; }
}
