/* ============================================================
   Context Is Everything — Web Ebook
   Design System: Crail Orange accent, serif body, mobile-first
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --accent: #C15F3C;
  --accent-light: #d4784f;
  --accent-dark: #a04e2e;

  /* Light mode */
  --bg: #FAFAF8;
  --bg-card: #F3F2EE;
  --bg-callout: #F0EDE7;
  --text: #1A1A1A;
  --text-muted: #555550;
  --text-subtle: #888880;
  --border: #DDD9D0;
  --border-accent: #C15F3C;
  --nav-bg: rgba(250, 250, 248, 0.95);
  --shadow: rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg: #111111;
  --bg-card: #1C1C1C;
  --bg-callout: #1E1B18;
  --text: #E8E4DF;
  --text-muted: #A8A49F;
  --text-subtle: #706C67;
  --border: #2A2A2A;
  --border-accent: #C15F3C;
  --nav-bg: rgba(17, 17, 17, 0.95);
  --shadow: rgba(0,0,0,0.4);
}

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

body {
  font-family: Georgia, Charter, 'Bitstream Charter', 'Sitka Text', Cambria, serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.8;
  min-height: 100vh;
  transition: background-color 0.25s ease, color 0.25s ease;
  overflow-x: hidden;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-family: Georgia, Charter, serif;
  line-height: 1.3;
  color: var(--text);
  font-weight: 700;
}

h1 { font-size: 2rem; margin-bottom: 1.2rem; }
h2 { font-size: 1.45rem; margin-top: 2.5rem; margin-bottom: 0.9rem; }
h3 { font-size: 1.2rem; margin-top: 2rem; margin-bottom: 0.7rem; }

p {
  margin-bottom: 1.3rem;
  font-size: 1rem;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

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

strong { font-weight: 700; }
em { font-style: italic; }

/* --- Layout --- */
.page-wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* --- Sticky Navigation --- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--nav-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  transition: background 0.25s ease, border-color 0.25s ease;
}

.site-nav__inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-nav__title {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
}

.site-nav__title:hover {
  color: var(--accent);
  text-decoration: none;
}

.site-nav__right {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

.progress-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.78rem;
  color: var(--text-subtle);
  white-space: nowrap;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg-card);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* --- Chapter Content --- */
.chapter-wrap {
  padding-top: 3rem;
  padding-bottom: 4rem;
}

.chapter-eyebrow {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.6rem;
}

.chapter-title {
  font-size: 2.1rem;
  line-height: 1.2;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.chapter-part {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.8rem;
  color: var(--text-subtle);
  margin-bottom: 2.5rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chapter-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* --- Pull Quotes --- */
.pull-quote {
  border-left: 3px solid var(--accent);
  padding: 1rem 1.5rem;
  margin: 2rem 0;
  background: var(--bg-callout);
  border-radius: 0 6px 6px 0;
}

.pull-quote p {
  font-size: 1.05rem;
  font-style: italic;
  color: var(--text);
  margin: 0;
  line-height: 1.7;
}

/* --- Callout Boxes (Key Terms, Notes) --- */
.callout {
  background: var(--bg-callout);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 1.1rem 1.4rem;
  margin: 2rem 0;
}

.callout__label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.4rem;
}

.callout p {
  font-size: 0.93rem;
  margin: 0;
  color: var(--text-muted);
  line-height: 1.7;
}

/* --- Reflect / Apply / Build Table --- */
.rab-table {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin: 2.5rem 0;
  width: 100%;
}

.rab-table__header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.rab-table__header span {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 0.7rem 0.8rem;
  text-align: center;
}

.rab-table__body {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}

.rab-table__cell {
  padding: 0.9rem 0.8rem;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
}

.rab-table__cell:last-child {
  border-right: none;
}

/* --- Lists --- */
ul, ol {
  padding-left: 1.5rem;
  margin-bottom: 1.3rem;
}

li {
  margin-bottom: 0.5rem;
  line-height: 1.7;
}

/* --- Visualization Container --- */
.viz-container {
  margin: 3rem 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem 1rem;
  overflow: hidden;
}

.viz-title {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: 1rem;
  text-align: center;
}

.viz-container svg {
  width: 100%;
  height: auto;
  display: block;
}

/* --- Chapter Navigation --- */
.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.chapter-nav__btn {
  display: flex;
  flex-direction: column;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  background: var(--bg-card);
  transition: border-color 0.2s ease, background 0.2s ease;
  min-height: 44px;
  color: var(--text);
}

.chapter-nav__btn:hover {
  border-color: var(--accent);
  background: var(--bg-callout);
  color: var(--text);
  text-decoration: none;
}

.chapter-nav__btn--prev {
  align-items: flex-start;
}

.chapter-nav__btn--next {
  align-items: flex-end;
  grid-column: 2;
  text-align: right;
}

.chapter-nav__btn--full {
  grid-column: 1 / -1;
  align-items: center;
  text-align: center;
}

.chapter-nav__label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.chapter-nav__name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

/* --- Landing / Index Page --- */
.landing {
  padding-top: 4rem;
  padding-bottom: 5rem;
}

.landing__eyebrow {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1rem;
}

.landing__title {
  font-size: 2.8rem;
  line-height: 1.15;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.landing__subtitle {
  font-size: 1.15rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  font-style: italic;
}

.landing__author {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.9rem;
  color: var(--text-subtle);
  margin-bottom: 2.5rem;
}

.landing__author strong {
  color: var(--text-muted);
}

.landing__cta {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.75rem 1.6rem;
  border-radius: 6px;
  text-decoration: none;
  transition: background 0.2s ease;
  min-height: 44px;
  margin-bottom: 3rem;
}

.landing__cta:hover {
  background: var(--accent-dark);
  color: #fff;
  text-decoration: none;
}

.landing__divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 3rem 0;
}

.toc__section-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin: 2rem 0 0.75rem;
}

.toc__list {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
}

.toc__item {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  margin: 0;
}

.toc__item:last-child {
  border-bottom: none;
}

.toc__num {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
  min-width: 1.8rem;
  flex-shrink: 0;
}

.toc__link {
  font-size: 0.95rem;
  color: var(--text);
  text-decoration: none;
  line-height: 1.4;
  font-family: Georgia, Charter, serif;
}

.toc__link:hover {
  color: var(--accent);
  text-decoration: none;
}

/* --- Footer --- */
.site-footer {
  padding: 2rem 1.25rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.site-footer p {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.78rem;
  color: var(--text-subtle);
  margin: 0;
}

/* --- Progress Bar --- */
.reading-progress {
  position: fixed;
  top: 55px;
  left: 0;
  width: 0%;
  height: 2px;
  background: var(--accent);
  z-index: 99;
  transition: width 0.1s linear;
}

/* --- Responsive --- */
@media (max-width: 600px) {
  html { font-size: 17px; }

  .chapter-title { font-size: 1.7rem; }
  .landing__title { font-size: 2rem; }

  .chapter-nav {
    grid-template-columns: 1fr;
  }

  .chapter-nav__btn--next {
    grid-column: 1;
    text-align: left;
    align-items: flex-start;
  }

  .rab-table__header,
  .rab-table__body {
    grid-template-columns: 1fr;
  }

  .rab-table__header span {
    border-bottom: 1px solid var(--border);
    border-right: none;
  }

  .rab-table__cell {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .rab-table__cell:last-child {
    border-bottom: none;
  }

  .site-nav__inner {
    height: 52px;
  }
}

@media (max-width: 400px) {
  html { font-size: 16px; }
  .page-wrap { padding: 0 1rem; }
}
