/* ==========================================================================
   components.css — buttons, cards, TOC, chapter nav, progress bar
   ========================================================================== */

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.75em 1.4em;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-decoration: none;
  border-radius: var(--radius);
  border: 1px solid var(--color-accent);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-bg-raised);
}
.btn-primary:hover { background: color-mix(in srgb, var(--color-accent) 85%, black); text-decoration: none; }

.btn-secondary {
  background: transparent;
  color: var(--color-accent);
}
.btn-secondary:hover { background: var(--color-accent-soft); text-decoration: none; }

.btn-row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ---- Hero ---- */
.hero {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: var(--space-5);
  align-items: start;
  padding-bottom: var(--space-2);
  position: relative;
}

/* Mobile: stack hero into a single column — cover below the text,
   sized to fit the screen width, instead of squeezing two columns
   into a narrow viewport. */
@media (max-width: 780px) {
  .hero {
    grid-template-columns: 1fr;
  }
  .hero-cover-wrap {
    max-width: 280px;
    /* order: -1 pulls the cover above the text block (which is the
       first child in source order) so mobile leads with the cover. */
    order: -1;
    margin: 0 auto var(--space-3);
  }
}

/* The section right after the hero already gets its visual break from
   the <hr> inside it — so drop its own top padding to avoid stacking
   hero's bottom padding + this section's top padding + the <hr>'s
   margin into one very large gap. */
.hero + .page {
  padding-top: 0;
}

.hero-cover-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  justify-self: center;
  width: 100%;
}

.hero-cover-wrap::before {
  content: "";
  position: absolute;
  inset: -8%;
  background: radial-gradient(closest-side, rgba(207, 166, 70, 0.34), rgba(42, 96, 104, 0.16) 55%, transparent 74%);
  filter: blur(26px);
  z-index: 0;
}

.hero-cover {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 340px;
  box-shadow:
    0 32px 60px -22px rgba(0,0,0,0.5),
    0 10px 24px -8px rgba(0,0,0,0.3);
  border-radius: 2px;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.hero-cover:hover {
  transform: translateY(-5px);
  box-shadow:
    0 40px 72px -20px rgba(0,0,0,0.55),
    0 12px 28px -8px rgba(0,0,0,0.32);
}

/* ---- Feature / topic cards ---- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0;
}

.card {
  border: 1px solid var(--color-rule);
  background: linear-gradient(165deg, var(--color-bg-raised) 0%, #EFEBE0 100%);
  padding: var(--space-4) var(--space-3) var(--space-3);
  border-radius: 6px;
  position: relative;
  overflow: hidden;
  text-align: center;
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
  cursor: default;
}

/* Gold top accent bar that grows on hover */
.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-brass), var(--color-header-accent));
  transform: scaleX(1);
  transform-origin: left;
  transition: height 0.22s ease;
}

.card:hover {
  transform: translateY(-6px);
  box-shadow: 0 16px 32px -12px rgba(20, 49, 56, 0.30);
  border-color: var(--color-brass);
}

.card:hover::before {
  height: 5px;
}

.card:hover .card-icon {
  transform: scale(1.15) translateY(-2px);
}

.card-icon-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-2);
  position: relative;
  z-index: 1;
}

.card-icon {
  width: 42px;
  height: 42px;
  color: var(--color-accent);
  transition: transform 0.22s ease, color 0.22s ease;
}

.card .eyebrow {
  margin-bottom: var(--space-1);
  position: relative;
  z-index: 1;
}
.card h4 { position: relative; z-index: 1; }
.card p { margin-bottom: 0; font-size: var(--step--1); color: var(--color-ink-soft); position: relative; z-index: 1; }

/* ---- Table of Contents ---- */
.toc-title-block {
  text-align: center;
  padding-bottom: var(--space-2);
}

.toc-title-block + .page {
  padding-top: 0;
}

.toc-cover-wrap {
  margin: 0 auto var(--space-4);
}

.toc-cover-wrap .hero-cover {
  max-width: 220px;
}

.toc-title-block h1 {
  margin-bottom: var(--space-1);
}

.toc-subtitle {
  font-family: var(--font-mono);
  font-size: var(--step-0);
  letter-spacing: 0.04em;
  color: var(--color-ink-soft);
  text-transform: uppercase;
  margin: 0 auto;
}

.toc-intro {
  max-width: 50ch;
  margin: var(--space-3) auto 0;
  font-style: italic;
  color: var(--color-ink-soft);
}

.toc-eyebrow {
  font-size: var(--step-0);
  margin-bottom: var(--space-3);
}

.toc-grid {
  list-style: none;
  margin: var(--space-4) 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
}

@media (max-width: 860px) {
  .toc-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .toc-grid { grid-template-columns: 1fr; }
}

.toc-card-item { display: contents; }

.toc-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  height: 100%;
  background: var(--color-bg-raised);
  border: 1px solid var(--color-rule);
  border-left: 3px solid var(--color-brass);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--color-ink);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

a.toc-card {
  cursor: pointer;
}

a.toc-card:hover,
a.toc-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 14px 28px -16px rgba(20, 39, 35, 0.35);
  border-left-color: var(--color-accent);
  text-decoration: none;
}

.toc-card-num {
  font-family: var(--font-mono);
  font-size: var(--step-2);
  font-weight: 500;
  color: var(--color-brass);
  line-height: 1;
}

.toc-card-title {
  font-family: var(--font-display);
  font-size: var(--step-0);
  font-weight: 600;
  line-height: 1.25;
  flex-grow: 1;
}


.toc-card-arrow {
  align-self: flex-end;
  font-size: var(--step-1);
  color: var(--color-accent);
  opacity: 0;
  transform: translateX(-6px);
  transition: transform 0.18s ease, opacity 0.18s ease;
}

a.toc-card:hover .toc-card-arrow,
a.toc-card:focus-visible .toc-card-arrow {
  opacity: 1;
  transform: translateX(0);
}

.toc-card-status {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.03em;
  color: var(--color-ink-soft);
  white-space: nowrap;
}

.toc-card-disabled {
  border-left-color: var(--color-rule);
  color: var(--color-ink-soft);
  cursor: default;
}

.toc-card-disabled .toc-card-num {
  color: var(--color-ink-soft);
  opacity: 0.6;
}

/* ---- Chapter nav (top of reading pages) ---- */
.chapter-toolbar {
  position: sticky;
  top: 47px;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-4);
  background: var(--color-bg-raised);
  border-bottom: 1px solid var(--color-rule);
  box-shadow: 0 1px 0 0 rgba(207, 166, 70, 0.28);
  font-family: var(--font-mono);
  font-size: var(--step--1);
}

.chapter-toolbar select {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  background: transparent;
  border: 1px solid var(--color-rule);
  color: var(--color-ink);
  padding: 0.4em 0.6em;
  border-radius: var(--radius);
  max-width: 40vw;
  justify-self: center;
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chapter-toolbar select:hover,
.chapter-toolbar select:focus {
  border-color: var(--color-brass);
  box-shadow: 0 0 0 2px rgba(207, 166, 70, 0.20);
  outline: none;
}

.chapter-toolbar a,
.chapter-toolbar .chapter-toolbar-disabled {
  text-decoration: none;
  color: var(--color-ink-soft);
  white-space: nowrap;
}

/* First column (Previous) sits at the left edge, last column (Next)
   sits at the right edge, keeping the dropdown centered regardless
   of which side is disabled. */
.chapter-toolbar a:first-child,
.chapter-toolbar .chapter-toolbar-disabled:first-child {
  justify-self: start;
}
.chapter-toolbar a:last-child,
.chapter-toolbar .chapter-toolbar-disabled:last-child {
  justify-self: end;
}

.chapter-toolbar a:hover { color: var(--color-accent); }
.chapter-toolbar a[aria-disabled="true"],
.chapter-toolbar .chapter-toolbar-disabled {
  pointer-events: none;
  opacity: 0.35;
}

/* ---- Progress bar ---- */
.reading-progress {
  display: none;
  position: sticky;
  top: 0;
  z-index: 60;
  height: 5px;
  background: var(--color-rule);
}

body.is-chapter .reading-progress {
  display: block;
}

.reading-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #143138, #2A6068);
  box-shadow: 0 0 6px 0 rgba(42, 96, 104, 0.5);
  transition: width 0.1s linear;
}

/* ---- Chapter footer nav (prev/next big buttons) ---- */
.chapter-footnav {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-rule);
}

.chapter-footnav a {
  flex: 0 1 calc(50% - var(--space-3) / 2);
}

.chapter-footnav .next {
  margin-left: auto;
}

.chapter-footnav a {
  display: block;
  padding: var(--space-3);
  border: 1px solid var(--color-rule);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--color-ink);
}

.chapter-footnav a:hover { border-color: var(--color-accent); }

.chapter-footnav .direction {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--color-ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3em;
}

.chapter-footnav .next { text-align: right; }

@media (max-width: 600px) {
  /* Keep Previous / Next side by side on mobile (two equal columns)
     rather than stacked. Padding and title size are pulled in so the
     pair fits a phone width without feeling cramped; titles wrap and
     both boxes stretch to equal height. */
  .chapter-footnav {
    gap: var(--space-2);
    align-items: stretch;
  }
  .chapter-footnav a {
    flex: 1 1 0;
    min-width: 0;
    padding: var(--space-2);
    font-size: var(--step--1);
    line-height: 1.35;
  }
  .chapter-footnav .direction {
    font-size: 0.7rem;
  }
}

/* ---- Books page layout ---- */
.book-row {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: var(--space-6);
  align-items: start;
  margin-bottom: var(--space-4);
}

.book-row--muted {
  opacity: 0.55;
}

.book-cover-img {
  width: 100%;
  border-radius: 4px;
  display: block;
}

.book-cover-placeholder {
  width: 100%;
  aspect-ratio: 6 / 9;
  background: var(--color-bg-raised);
  border: 1px solid var(--color-rule);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-ink-soft);
  font-size: 0.85em;
}

.book-title {
  margin-bottom: var(--space-3);
}

@media (max-width: 600px) {
  .book-row {
    grid-template-columns: 1fr;
    /* The 6rem (--space-6) column gap becomes a huge vertical gap once
       the row stacks — pull it in to a normal stack spacing. */
    gap: var(--space-3);
  }
  .book-cover-img,
  .book-cover-placeholder {
    max-width: 180px;
  }
}

/* ---- TOC title button ---- */
.toc-title-btn {
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: none;
  transition: color 0.15s ease;
}

.toc-title-btn:hover {
  color: var(--color-brass);
}

/* ---- Front matter modal ---- */
.fm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 12, 0.72);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
}

.fm-overlay[hidden] {
  display: none;
}

.fm-modal {
  background: var(--color-bg);
  border: 1px solid var(--color-brass);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0,0,0,0.35);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.fm-close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--color-ink-soft);
  cursor: pointer;
  line-height: 1;
  z-index: 1;
}

.fm-close:hover {
  color: var(--color-ink);
}

.fm-pages {
  flex: 1;
  overflow-y: auto;
}

.fm-page-inner {
  padding: var(--space-5) var(--space-5) var(--space-4);
  min-height: 320px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Half title page */
.fm-halftitle {
  text-align: center;
}

.fm-half-title {
  font-family: var(--font-display);
  font-size: var(--step-2);
  font-variant: small-caps;
  letter-spacing: 0.08em;
  color: var(--color-ink);
  margin: 0;
}

/* Full title page */
.fm-fulltitle {
  text-align: center;
  gap: var(--space-3);
}

.fm-title {
  font-family: var(--font-display);
  font-size: var(--step-4);
  font-variant: small-caps;
  letter-spacing: 0.06em;
  color: var(--color-ink);
  margin: 0 0 var(--space-2);
  line-height: 1.1;
}

.fm-subtitle {
  font-family: var(--font-body);
  font-style: italic;
  font-size: var(--step-1);
  color: var(--color-ink-soft);
  margin: 0 0 var(--space-3);
}

.fm-author {
  font-family: var(--font-display);
  font-size: var(--step-0);
  font-variant: small-caps;
  letter-spacing: 0.1em;
  color: var(--color-ink);
  margin: 0;
}

/* Copyright page */
.fm-copyright {
  justify-content: center;
  text-align: center;
}

.fm-copyright p {
  font-family: var(--font-body);
  font-size: var(--step-0);
  color: var(--color-ink-soft);
  margin: 0;
}

/* Dedication page */
.fm-dedication {
  text-align: center;
}

.fm-dedication p {
  font-family: var(--font-body);
  font-style: italic;
  font-size: var(--step-0);
  color: var(--color-ink-soft);
  margin: 0;
}

.fm-epigraph-attribution {
  margin-top: var(--space-2) !important;
  font-style: normal !important;
  font-family: var(--font-mono);
  font-size: var(--step--1) !important;
  letter-spacing: 0.03em;
}

/* Modal nav */
.fm-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--color-rule);
  background: var(--color-bg-raised);
}

.fm-btn {
  background: none;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius);
  padding: 0.3rem 0.8rem;
  font-size: 1rem;
  cursor: pointer;
  color: var(--color-ink);
  transition: background 0.15s;
}

.fm-btn:hover:not(:disabled) {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
}

.fm-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.fm-page-indicator {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--color-ink-soft);
  letter-spacing: 0.05em;
}
/* ---- Mobile chapter-toolbar overrides ----
   Placed at the end of the file ON PURPOSE: the base .chapter-toolbar
   rules are defined further up but LATER than the other @media blocks,
   so an early mobile block would lose the source-order tie. Keeping
   these last guarantees they win at <=600px. */
@media (max-width: 600px) {
  /* Top toolbar keeps only the jump-to dropdown — the prev/next arrows
     are redundant with the big prev/next nav at the foot of every
     chapter, and dropping them lets the dropdown span the full width
     instead of being squeezed to a truncated "02 — What is …". */
  .chapter-toolbar {
    grid-template-columns: 1fr;
    padding: var(--space-1) var(--space-2);
    gap: 0;
  }
  .chapter-toolbar a,
  .chapter-toolbar .chapter-toolbar-disabled {
    display: none;
  }
  .chapter-toolbar select {
    max-width: 100%;
    width: 100%;
    justify-self: stretch;
    font-size: var(--step--1);
    padding: 0.45em 0.6em;
  }
}