/* ============ Two Field Guides — shared styles ============ */

:root {
  --accent: #0e7a5f;
  --accent-soft: rgba(14, 122, 95, 0.12);
  --gold: #b45309;

  --bg: #faf7f1;
  --surface: #fffdf8;
  --surface-2: #f3eee4;
  --ink: #26221c;
  --ink-2: #4a453c;
  --muted: #83796a;
  --line: #e4ddcf;
  --line-strong: #d5ccb9;

  --serif: Georgia, "Times New Roman", Times, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --topbar-h: 56px;
  --sidebar-w: 304px;
  --content-max: 46rem;
}

[data-theme="dark"] {
  --bg: #17150f;
  --surface: #1f1c15;
  --surface-2: #262219;
  --ink: #e9e4d9;
  --ink-2: #c8c1b2;
  --muted: #948b7a;
  --line: #34301f;
  --line-strong: #453f2c;
  --accent-soft: rgba(14, 122, 95, 0.22);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.075rem;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* long unbroken tokens (URLs, hashes) must wrap on narrow screens */
.reading p, .reading li, .reading h2, .footnote { overflow-wrap: anywhere; }

/* ---------- reading progress ---------- */
.progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  z-index: 100;
  transition: width 0.08s linear;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  gap: 16px;
  padding: env(safe-area-inset-top, 0px) 20px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-transform: uppercase;
}
.brand:hover { text-decoration: none; }
.brand-dot { color: var(--gold); }

.bookswitch { margin-left: auto; }
.switch-link {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 5px 14px;
  transition: color 0.15s, border-color 0.15s;
}
.switch-link:hover {
  color: var(--ink);
  border-color: var(--accent);
  text-decoration: none;
}

.theme-toggle {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.theme-toggle:hover { color: var(--ink); background: var(--surface-2); }

.nav-toggle {
  display: none;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 8px;
}
.nav-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--ink);
  margin: 4px 0;
  border-radius: 2px;
}

/* ---------- shell / sidebar ---------- */
.shell { display: flex; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  height: calc(100vh - var(--topbar-h) - env(safe-area-inset-top, 0px));
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 20px 16px calc(40px + env(safe-area-inset-bottom, 0px));
  scrollbar-width: thin;
}

.sidebar-inner { display: flex; flex-direction: column; gap: 4px; }

.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 4px 8px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.book-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  margin-top: 7px;
  flex-shrink: 0;
}
.sidebar-book {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--ink);
  line-height: 1.3;
}
.sidebar-sub {
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.4;
}

.nav-group { margin-bottom: 2px; }
.nav-group-title {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 9px 8px 5px;
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group[open] > .nav-group-title::after { content: "−"; }
.nav-group > .nav-group-title::after { content: "+"; color: var(--line-strong); }

.nav-link {
  display: block;
  font-family: var(--sans);
  font-size: 0.84rem;
  color: var(--ink-2);
  padding: 5px 8px 5px 18px;
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
  line-height: 1.45;
}
.nav-link:hover {
  color: var(--ink);
  background: var(--surface-2);
  text-decoration: none;
}
.nav-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.nav-link.download {
  margin-top: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 9px 12px;
  text-align: center;
  font-weight: 600;
}
.sidebar-foot {
  margin-top: 18px;
  font-family: var(--sans);
  font-size: 0.68rem;
  color: var(--muted);
  padding: 0 8px;
  line-height: 1.5;
}

.nav-search {
  font-family: var(--sans);
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.82rem;
  margin-bottom: 8px;
}
.nav-search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- content ---------- */
.content {
  flex: 1;
  min-width: 0;
  padding: 48px clamp(20px, 6vw, 64px) calc(120px + env(safe-area-inset-bottom, 0px));
}

/* centered reading column: block layout + auto margins keeps wide tables
   scrolling inside .tablewrap instead of overflowing the viewport */
.reading, .book-landing, .landing, .prevnext {
  margin-left: auto;
  margin-right: auto;
  min-width: 0;
}
.reading { max-width: var(--content-max); width: 100%; }

.article-head { margin-bottom: 40px; }
.kicker {
  font-family: var(--sans);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 14px;
}
.article-head h1 {
  font-family: var(--sans);
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0 0 14px;
}
.meta {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

/* ---------- prose ---------- */
.reading p { margin: 0 0 1.1em; }
.reading h2 {
  font-family: var(--sans);
  font-size: 1.28rem;
  letter-spacing: -0.01em;
  margin: 2.2em 0 0.7em;
  color: var(--ink);
}
.reading .lead {
  font-size: 1.12rem;
  color: var(--ink-2);
  font-style: italic;
}

.reading ul { margin: 0 0 1.2em; padding-left: 1.4em; }
.reading li { margin-bottom: 0.45em; }
.reading li::marker { color: var(--gold); }

/* ---------- callouts ---------- */
.callout {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  padding: 18px 22px 14px;
  margin: 1.8em 0;
}
.callout-label {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 8px;
}
.callout-body p { margin: 0; }
.callout-body p + p { margin-top: 0.8em; }

.callout-from-your-father {
  background: var(--surface-2);
  border-left-color: var(--gold);
  font-style: italic;
}
.callout-from-your-father .callout-label { color: var(--gold); }

.callout-decision-gate, .callout-golden-rule {
  border-left-color: var(--gold);
}
.callout-decision-gate .callout-label,
.callout-golden-rule .callout-label { color: var(--gold); }

.callout-do-this-now .callout-label { color: var(--gold); }

/* ---------- tables ---------- */
.tablewrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.6em 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.85rem;
  line-height: 1.5;
}
th {
  text-align: left;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--surface-2);
  color: var(--ink);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }

/* ---------- footnotes ---------- */
.footnote {
  font-family: var(--sans);
  font-size: 0.76rem;
  color: var(--muted);
  border-top: 1px dashed var(--line-strong);
  padding-top: 10px;
  margin-top: 2.2em;
}

/* ---------- prev / next ---------- */
.prevnext {
  max-width: var(--content-max);
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.pn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--sans);
  max-width: 46%;
}
.pn:hover { text-decoration: none; }
.pn-k { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.pn-t { font-size: 0.9rem; font-weight: 600; color: var(--ink); }
.pn:hover .pn-t { color: var(--accent); }
.pn.next { text-align: right; align-items: flex-end; }

/* ---------- book landing page ---------- */
.book-landing { max-width: 52rem; width: 100%; }
.book-hero { padding: 10px 0 8px; }
.book-hero h1 {
  font-family: var(--sans);
  font-size: clamp(2.2rem, 5vw, 3.2rem);
  letter-spacing: -0.02em;
  line-height: 1.08;
  margin: 0 0 12px;
}
.book-subtitle {
  font-size: 1.25rem;
  color: var(--ink-2);
  margin: 0 0 10px;
}
.book-tagline { color: var(--ink-2); margin: 0 0 16px; max-width: 44rem; }
.book-seq {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold);
  margin: 0 0 26px;
}
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }

.btn {
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: var(--surface);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s;
}
.btn:hover {
  text-decoration: none;
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.ghost { background: transparent; }

.book-about {
  margin: 40px 0;
  padding: 26px 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 1.06rem;
}
.book-about p { margin: 0; }

.section-title {
  font-family: var(--sans);
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  margin: 0 0 18px;
}
.section-title.small { font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.part-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  margin-bottom: 34px;
}
.part-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  transition: border-color 0.15s, transform 0.12s;
}
.part-card:hover {
  text-decoration: none;
  border-color: var(--accent);
  transform: translateY(-2px);
}
.part-roman {
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.part-title { font-family: var(--sans); font-weight: 700; font-size: 1rem; line-height: 1.35; }
.part-chs { font-family: var(--sans); font-size: 0.76rem; color: var(--muted); }
.part-sum { font-family: var(--sans); font-size: 0.78rem; color: var(--muted); line-height: 1.55; }

.tools-row { margin-top: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--ink-2);
  background: var(--surface);
}
.chip:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.fm-title {
  font-family: var(--sans);
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  margin: 2.6em 0 0.6em;
  padding-bottom: 0.4em;
  border-bottom: 2px solid var(--line);
}

/* ---------- landing page ---------- */
.landing { max-width: 64rem; width: 100%; }
.landing-hero { padding: 46px 0 20px; }
.landing-hero .kicker { margin-bottom: 18px; }
.landing-hero h1 {
  font-family: var(--sans);
  font-size: clamp(2.4rem, 6vw, 3.8rem);
  line-height: 1.04;
  letter-spacing: -0.025em;
  margin: 0 0 22px;
}
.landing-sub {
  font-size: 1.16rem;
  color: var(--ink-2);
  max-width: 46rem;
  margin: 0;
}

.book-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
  margin: 48px 0;
}
.book-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: 16px;
  padding: 30px;
  display: flex;
  flex-direction: column;
}
.book-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-family: var(--sans);
}
.book-count {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.book-stats { font-size: 0.72rem; color: var(--muted); }
.book-card h2 { font-family: var(--sans); font-size: 1.5rem; margin: 0 0 6px; letter-spacing: -0.01em; }
.book-sub { font-size: 1rem; color: var(--ink-2); margin: 0 0 12px; font-style: italic; }
.book-tag { font-family: var(--sans); font-size: 0.86rem; color: var(--ink-2); line-height: 1.55; margin: 0 0 16px; }
.book-blurb { font-size: 0.98rem; color: var(--muted); margin: 0 0 24px; line-height: 1.7; }
.book-actions { margin-top: auto; display: flex; gap: 10px; flex-wrap: wrap; }

.landing-note {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 34px;
  margin: 20px 0 40px;
}
.landing-note h2 { font-family: var(--sans); font-size: 1.2rem; margin: 0 0 12px; }
.landing-note p { margin: 0; color: var(--ink-2); }

.landing-foot { padding: 10px 0 30px; font-family: var(--sans); font-size: 0.8rem; color: var(--muted); }
.landing-foot .muted { font-size: 0.72rem; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .nav-toggle {
    display: block;
    min-width: 44px;
    min-height: 44px;
    margin-left: -10px;
  }
  .sidebar {
    position: fixed;
    top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    left: 0;
    z-index: 60;
    height: calc(100vh - var(--topbar-h) - env(safe-area-inset-top, 0px));
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  }
  .sidebar.open { transform: translateX(0); }
  body.nav-open::after {
    content: "";
    position: fixed;
    inset: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)) 0 0 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 55;
  }
  .content { padding: 30px 20px calc(90px + env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 420px) {
  .topbar { gap: 10px; padding-left: 12px; padding-right: 12px; }
  .brand { font-size: 0.85rem; }
  .switch-link { padding: 5px 10px; font-size: 0.74rem; }
  .content { padding-left: 16px; padding-right: 16px; }
  .book-card { padding: 22px; }
  .book-about, .landing-note { padding: 20px; }
  .callout { padding: 15px 16px 12px; }
  .part-grid { grid-template-columns: 1fr; }
  .book-cards { grid-template-columns: 1fr; }
}
