/* ============================================================
   layout.css — shared layout, prose, and table styles
   The Eight Characters · BaZi reading template
   ============================================================ */

/* ============================================================
   Top bar — sticky navigation (content pages)
   ============================================================ */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 16px var(--pad-page);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--hairline-2);
  backdrop-filter: saturate(140%) blur(6px);
  -webkit-backdrop-filter: saturate(140%) blur(6px);
  background: rgba(245, 241, 232, 0.92);
}

/* Back link (← CONTENTS) — used on section pages */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  transition: color 200ms var(--ease);
}
.back-link:hover { color: var(--ink); }
.back-link .arrow {
  font-family: var(--font-mono);
  font-size: 14px;
}

/* Home link (← COVER) — used on TOC */
.home-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  transition: color 200ms var(--ease);
}
.home-link:hover { color: var(--ink); }
.home-link .arrow {
  font-family: var(--font-mono);
  font-size: 14px;
}

/* Right side of top bar */
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.top-bar-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
}
.home-glyph {
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--ink-faint);
  transition: color 200ms var(--ease);
  line-height: 1;
}
.home-glyph:hover { color: var(--ink); }

/* ============================================================
   Section page layout
   ============================================================ */
.section-page {
  padding: 0 0 120px;
}

.section-content {
  max-width: var(--max-content);
  margin: 0 auto;
  padding: 56px var(--pad-page) 0;
}

.section-num {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
  margin-bottom: 16px;
}
.section-title {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(30px, 6.5vw, 42px);
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--ink);
  margin: 0 0 32px;
}

/* ============================================================
   Body prose
   ============================================================ */
.section-content p {
  max-width: var(--max-text);
  margin: 0 0 1.2em;
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.7;
  color: var(--ink);
}
.section-content p.lede {
  font-style: italic;
  font-size: 18px;
  color: var(--ink-soft);
}
.section-content p.intro {
  font-size: 18px;
  line-height: 1.7;
  color: var(--ink-soft);
}

/* ---- h2: major division within a section ---- */
.section-content h2 {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(22px, 5vw, 28px);
  letter-spacing: -0.005em;
  line-height: 1.2;
  margin: 64px 0 24px;
  padding-top: 32px;
  border-top: 1px solid var(--hairline);
  color: var(--ink);
  max-width: var(--max-text);
}
.section-title + h2,
.epigraph + h2 {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.section-content h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 18px;
  letter-spacing: 0;
  margin: 48px 0 16px;
  color: var(--ink);
  max-width: var(--max-text);
}
.section-content h4 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 36px 0 12px;
  color: var(--ink-soft);
  max-width: var(--max-text);
}
.section-content ul {
  max-width: var(--max-text);
  margin: 0 0 1.4em;
  padding: 0;
  list-style: none;
}
.section-content ul li {
  position: relative;
  padding-left: 22px;
  margin-bottom: 0.8em;
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.7;
}
.section-content ul li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.85em;
  width: 8px;
  height: 1px;
  background: var(--ink-faint);
}
.section-content em { font-style: italic; }
.section-content strong { font-weight: 500; color: var(--ink); }
.section-content .hanzi {
  font-family: var(--font-mono);
  font-weight: 500;
}
.term {
  white-space: nowrap;
}
.pinyin {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 0.95em;
}

/* ============================================================
   Pull quote
   ============================================================ */
.pull {
  max-width: var(--max-text);
  margin: 56px 0;
  padding: 0;
  border-left: 1px solid var(--ink);
  padding-left: 24px;
  font-family: var(--font-body);
  font-style: italic;
  font-size: 20px;
  line-height: 1.55;
  color: var(--ink);
}

/* ============================================================
   Epigraph — attributed opening quote
   ============================================================ */
.epigraph {
  max-width: var(--max-text);
  margin: 0 0 48px;
  padding: 0;
}
.epigraph p {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-muted);
  margin: 0;
}
.epigraph cite {
  display: block;
  margin-top: 8px;
  font-family: var(--font-display);
  font-style: normal;
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

/* ============================================================
   Coda — closing flourish
   ============================================================ */
.section-content .coda {
  max-width: 520px;
  margin: 48px auto 0;
  font-family: var(--font-body);
  font-style: italic;
  font-size: 18px;
  line-height: 1.65;
  color: var(--ink-soft);
  text-align: center;
}

/* ============================================================
   Ornament (section divider)
   ============================================================ */
.ornament {
  max-width: var(--max-text);
  margin: 56px 0;
  height: 1px;
  background: var(--hairline);
}

/* ============================================================
   Callout
   ============================================================ */
.callout {
  max-width: var(--max-text);
  margin: 32px 0;
  padding: 20px 24px;
  background: var(--paper-deep);
  border-left: 2px solid var(--seal);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-soft);
}
.callout strong { color: var(--ink); }

/* ============================================================
   Aside — lightweight annotation (monospace whisper)
   ============================================================ */
.aside {
  max-width: var(--max-text);
  margin: 32px 0;
  padding: 16px 20px;
  border-left: 1px solid var(--hairline);
  font-family: var(--font-ledger);
  font-size: 13px;
  line-height: 1.6;
  letter-spacing: 0.01em;
  color: var(--ink-muted);
}
.aside strong {
  font-weight: 500;
  color: var(--ink-soft);
}
.aside em {
  font-style: italic;
}
.aside .hanzi {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 1.1em;
}

/* ============================================================
   Figure + caption — generic image container
   ============================================================ */
.figure {
  max-width: var(--max-text);
  margin: 40px 0 48px;
}
.figure img {
  width: 100%;
  height: auto;
  display: block;
}
.figure-caption {
  margin-top: 12px;
  font-family: var(--font-ledger);
  font-size: 11px;
  letter-spacing: 0.04em;
  line-height: 1.5;
  color: var(--ink-muted);
}

/* ============================================================
   Tables — celestial ledger
   IBM Plex Mono, 0.45px rules, alternating row tint
   ============================================================ */
.table-wrap {
  margin: 32px 0 40px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
.table-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 16px;
  width: 32px;
  background: linear-gradient(to right, transparent, var(--paper));
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms var(--ease);
}
.table-wrap.is-overflowing::after { opacity: 1; }

table {
  width: auto;
  min-width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ledger);
  font-size: 12px;
  font-weight: 300;
  line-height: 1.45;
  color: var(--ink);
}
@media (max-width: 720px) {
  table { width: max-content; min-width: 100%; }
}

/* Cells */
table th, table td {
  text-align: left;
  padding: 8px 20px 8px 0;
  border-bottom: 0.45px solid var(--ink-rule);
  border-right: 0.45px solid #1A161412;
  vertical-align: top;
}
table th:first-child,
table td:first-child {
  padding-left: 0;
}
table th:last-child,
table td:last-child {
  border-right: none;
  padding-right: 0;
}

/* Alternating row tint */
table tbody tr:nth-child(odd) td {
  background: #1A161406;
}

/* Label column */
table td:first-child {
  white-space: nowrap;
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  padding-right: 24px;
  min-width: 80px;
}

/* Header row */
table thead th {
  font-weight: 500;
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: #1A16140A;
  border-bottom: 0.45px solid var(--ink-rule);
  padding-top: 7px;
  padding-bottom: 7px;
}

/* Closing rule */
table tr:last-child td {
  border-bottom: 0.45px solid var(--ink-rule);
}

/* CJK in cells */
table td .cn {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
  margin-right: 6px;
  display: inline;
  line-height: 1;
}
table td .py {
  color: var(--ink-muted);
  font-size: 11px;
}

/* Numeric cells */
table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  padding-right: 24px;
}

/* Day Master row highlight */
table tr.day-master td {
  background: linear-gradient(to right, var(--seal-soft), transparent 30%);
  position: relative;
}
table tr.day-master td:first-child {
  box-shadow: inset 0.9px 0 0 var(--seal);
}
table tr.day-master td .cn { color: var(--seal); font-weight: 500; }

/* Element key inline */
.el {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 0 4px;
}

/* ============================================================
   Prev / Next page navigation
   ============================================================ */
.page-nav {
  max-width: var(--max-text);
  margin-top: 80px;
  padding: 24px 0;
  border-top: 1px solid var(--hairline);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.page-nav-link {
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: opacity 200ms var(--ease);
}
.page-nav-link:hover { opacity: 0.6; }
.page-nav-link.next {
  margin-left: auto;
  text-align: right;
}
.page-nav-dir {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.page-nav-title {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--ink);
}

/* ============================================================
   Desktop refinements
   ============================================================ */
@media (min-width: 720px) {
  :root { --pad-page: 40px; }
  body { font-size: 18px; }
  .section-content p   { font-size: 18px; }
  .section-content ul li { font-size: 18px; }
  .section-content p.intro { font-size: 19px; }
  .section-content .coda   { font-size: 19px; }
  .epigraph p           { font-size: 16px; }
  .aside                { font-size: 13.5px; }
  .figure-caption        { font-size: 11.5px; }
  table { font-size: 12.5px; }
}

@media (min-width: 1024px) {
  :root { --pad-page: 48px; }
}

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
