/* ==========================================================
   A Modern Almagest — shared stylesheet
   ========================================================== */

@import url("https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@1,9..144,800&family=Inter:wght@400;600;700;800;900&display=swap");


:root {
  --ink: #2a2a3a;
  --ink-soft: #555;
  --ink-muted: #888;
  --paper: #fbfaf6;
  --rule: #d8d3c8;
  --accent: #8b3a3a;
  --term: #8b6914;
  --term-bg: #f5efdf;
  --serif: Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica,
    Arial, sans-serif;
  --mono: "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.7;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0px 24px 40px;
}

/* ---------- Masthead ---------- */

.masthead {
  text-align: center;
  padding: 10px 0 0px;

  margin-bottom: 0px;
}

.masthead .kicker {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 3px;
  color: var(--accent);
  text-transform: uppercase;
}

.masthead h1 {
  font-family: "Fraunces", Georgia, serif;
  font-variation-settings: "opsz" 144, "SOFT" 30, "WONK" 1;
  font-style: italic;
  font-size: 80px;
  font-weight: 800;
  margin: 2px 0 4px;
  letter-spacing: -1px;
  color: var(--ink);
}

.masthead .subtitle {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 16px;
  margin-top: 6px;
    margin-bottom: 0; 
}

/* ---------- Contents heading ---------- */

.contents-heading {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--ink-muted);
  text-transform: uppercase;
  margin: 30px 0 6px;
}

h2.contents-title {
  font-family: var(--sans);
  font-size: 28px;
  font-weight: 800;
  margin: 40px 0 6px;
  color: var(--ink);
}

/* ---------- Navigation ---------- */

.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin: 40px 0;
  padding: 16px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 14px;
}

.chapter-nav a {
  color: var(--accent);
  text-decoration: none;
}
.chapter-nav a:hover {
  text-decoration: underline;
}
.chapter-nav .spacer {
  color: var(--ink-muted);
}

/* ---------- Chapter headings ---------- */

.book-number {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--ink-muted);
  text-transform: uppercase;
  margin-top: 30px;
}

h1.chapter-title {
  font-family: var(--sans);
  font-size: 34px;
  font-weight: 800;
  line-height: 1.2;
  margin: 8px 0 40px;
  color: var(--ink);
}

h2 {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  margin: 50px 0 16px;
  color: var(--ink);
}

/* ---------- Body text ---------- */

p {
  margin: 0 0 22px;
}

ol.points {
  margin: 0 0 22px;
  padding-left: 24px;
}

ol.points li {
  margin-bottom: 10px;
}

p.lead::first-letter {
  font-size: 56px;
  font-weight: 700;
  float: left;
  line-height: 0.9;
  margin: 6px 8px 0 0;
  color: var(--accent);
  font-family: var(--serif);
}

/* ---------- Glossary terms ---------- */

.term {
  font-weight: 600;
  color: var(--term);
  border-bottom: 1px dotted var(--term);
  cursor: help;
  position: relative;
}

.term:hover {
  background: var(--term-bg);
}

.term::after {
  content: attr(data-def);
  position: absolute;
  bottom: 130%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  font-weight: 400;
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 14px;
  border-radius: 4px;
  width: 260px;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.term:hover::after {
  opacity: 1;
}

/* ---------- Accordions (asides / expansions) ---------- */

details.aside {
  margin: 24px 0;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #f8f7f2;
  overflow: hidden;
}

details.aside summary {
  padding: 12px 18px;
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

details.aside summary::-webkit-details-marker {
  display: none;
}

details.aside summary::before {
  content: "▸";
  font-size: 14px;
  transition: transform 0.2s;
  flex-shrink: 0;
}

details.aside[open] summary::before {
  transform: rotate(90deg);
}

details.aside[open] {
  overflow: visible;
}

details.aside summary:hover {
  background: #f0eee6;
}

details.aside .aside-body {
  padding: 4px 18px 18px;
  font-size: 16px;
  line-height: 1.7;
  border-top: 1px solid var(--rule);
  border-radius: 0 0 6px 6px;
}

details.aside .aside-body p {
  margin: 14px 0 0;
}

details.aside .aside-body p:first-child {
  margin-top: 10px;
}

/* ---------- Aside boxes (diagram commentary, updates) ---------- */

.aside-box {
  margin: 30px 0;
  padding: 20px 22px;
  background: #f0eff8;
  border-left: 4px solid #9999bb;
  border-radius: 0 6px 6px 0;
  font-size: 16px;
  line-height: 1.7;
}

.aside-box p {
  margin: 0 0 14px;
}

.aside-box p:last-child {
  margin-bottom: 0;
}

.aside-box h2 {
  font-family: var(--sans);
  font-size: 20px;
  font-weight: 800;
  margin: 0 0 16px;
  color: var(--ink);
}

.aside-box .diagram-frame {
  margin: 24px -22px;
  border-radius: 0;
}

.aside-box .diagram-caption {
  margin-left: 0;
  margin-right: 0;
}

/* ---------- Diagrams ---------- */

.diagram-frame {
  margin: 40px -60px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--rule);
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

.diagram-frame iframe {
  display: block;
  width: 100%;
  height: 780px;
  border: 0;
}

/* The "tall" diagram iframe holds two stacked aspect-ratio canvases plus
   chrome. Its natural height scales with iframe width, so on narrow viewports
   we compute the parent height from viewport width to match. */
.diagram-frame-tall {
  height: 1200px;
}

.diagram-frame.diagram-frame-tall iframe {
  height: 100%;
}

/* The "mid" diagram iframe holds a single taller-than-default canvas. */
.diagram-frame-mid {
  height: 980px;
}

.diagram-frame.diagram-frame-mid iframe {
  height: 100%;
}

@media (max-width: 820px) {
  .diagram-frame.diagram-frame-mid {
    height: calc(100vw * 11 / 16 + 180px);
  }
}
@media (max-width: 500px) {
  .diagram-frame.diagram-frame-mid {
    height: calc(100vw * 3 / 4 + 150px);
  }
}

@media (max-width: 820px) {
  .diagram-frame.diagram-frame-tall {
    /* top canvas 16:11 + bottom 16:9 + ~170px chrome, with iframe spanning
       container width (viewport - 0 due to negative-margin bleed at this bp) */
    height: calc(100vw * 11 / 16 + 100vw * 9 / 16 + 180px);
  }
}
@media (max-width: 500px) {
  .diagram-frame.diagram-frame-tall {
    /* top 4:3 + bottom 3:2 + ~150px chrome */
    height: calc(100vw * 3 / 4 + 100vw * 2 / 3 + 150px);
  }
}

.diagram-caption {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-muted);
  text-align: center;
  margin: 12px 0 0;
  font-style: italic;
}

/* ---------- In-text links ---------- */

article a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(139, 58, 58, 0.3);
  transition: border-color 0.2s;
}

article a:hover {
  border-bottom-color: var(--accent);
}

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

footer {
  margin-top: 80px;
  padding-top: 30px;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-muted);
  text-align: center;
  line-height: 1.6;
}

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

/* ---------- TOC ---------- */

.toc-list {
  list-style: none;
  padding: 0;
  margin: 20px 0 40px;
}

.toc-book {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--ink-muted);
  text-transform: uppercase;
  margin: 30px 0 12px;
}

.toc-chapter {
  padding: 14px 0;
  border-bottom: 1px solid var(--rule);
}

.toc-chapter a {
  color: var(--ink);
  text-decoration: none;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 20px;
}

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

.toc-chapter .ch-title {
  font-size: 18px;
  flex: 1;
}

.toc-chapter .ch-number {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.intro {
  margin: 30px 0 50px;
  font-size: 18px;
  line-height: 1.7;
}

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

@media (max-width: 820px) {
  .diagram-frame {
    margin: 30px -24px;
    border-radius: 0;
  }
  .diagram-frame iframe {
    height: 600px;
  }
  .masthead h1 {
    font-size: 56px;
  }
  h1.chapter-title {
    font-size: 28px;
  }
  body {
    font-size: 17px;
  }
}

@media (max-width: 500px) {
  .container {
    padding: 30px 18px 60px;
  }
  .diagram-frame iframe {
    height: 420px;
  }
  .term::after {
    display: none;
  }
  .masthead h1 {
    font-size: 54px;
  }
}
