*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #fafaf8;
  --fg: #1a1a1a;
  --fg-muted: #444;
  --accent: #0b5394;
  --accent-hover: #073763;
  --disclaimer-bg: #fef9e7;
  --disclaimer-border: #c48a00;
  --nav-bg: #f0f0ed;
  --nav-border: #d4d4cf;
  --card-bg: #f5f5f2;
  --card-border: #d4d4cf;
  --link: #0b5394;
  --link-hover: #073763;
  --code-bg: #f0f0ed;
  --hr: #d4d4cf;
  --shadow: rgba(0,0,0,0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1b;
    --fg: #e8e8e4;
    --fg-muted: #b0b0a8;
    --accent: #6cb4ee;
    --accent-hover: #9dcdf5;
    --disclaimer-bg: #2a2714;
    --disclaimer-border: #9a8520;
    --nav-bg: #252525;
    --nav-border: #3a3a3a;
    --card-bg: #252525;
    --card-border: #3a3a3a;
    --link: #6cb4ee;
    --link-hover: #9dcdf5;
    --code-bg: #2a2a2a;
    --hr: #3a3a3a;
    --shadow: rgba(0,0,0,0.3);
  }
}

html {
  font-size: 18px;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  font-family: Georgia, "Times New Roman", "Palatino Linotype", serif;
  line-height: 1.75;
  color: var(--fg);
  background: var(--bg);
  margin: 0;
  padding: 0;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ── Header / Nav ── */

header {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  padding: 0.75rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

header nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.9rem;
  align-items: center;
}

header nav a {
  color: var(--accent);
  text-decoration: none;
  font-size: 1rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  white-space: nowrap;
  padding: 0.25rem 0;
}

header nav a:hover { text-decoration: underline; }

header .site-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--fg);
  text-decoration: none;
  margin-right: auto;
}

/* ── Disclaimer ── */

.disclaimer {
  background: var(--disclaimer-bg);
  border-left: 6px solid var(--disclaimer-border);
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  font-size: 1rem;
  line-height: 1.65;
  border-radius: 0 4px 4px 0;
}

.disclaimer p { margin: 0 0 0.5rem 0; }
.disclaimer ul { margin: 0.25rem 0 0 0; padding-left: 1.25rem; }
.disclaimer li { margin-bottom: 0.3rem; }

/* ── Main content ── */

main {
  padding: 1rem 0 2rem 0;
}

article h1, article h2, article h3 {
  scroll-margin-top: 4rem;
}

article h1 {
  font-size: 1.6rem;
  line-height: 1.3;
  margin: 1.5rem 0 1rem 0;
  color: var(--fg);
}

article h2 {
  font-size: 1.45rem;
  font-weight: 700;
  margin: 2.5rem 0 1rem 0;
  border-bottom: 1px solid var(--hr);
  padding-bottom: 0.35rem;
}

article h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 2rem 0 0.75rem 0;
}

article p {
  margin: 0.75rem 0;
  text-align: justify;
  text-indent: 1.5em;
  hyphens: auto;
}


article img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
}

article a {
  color: var(--link);
}

article a:hover {
  color: var(--link-hover);
}

article blockquote {
  border-left: 3px solid var(--accent);
  margin: 1rem 0;
  padding: 0.5rem 1rem;
  color: var(--fg-muted);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
}

article table {
  border-collapse: collapse;
  width: 100%;
  font-size: 1rem;
}

article th, article td {
  border: 1px solid var(--nav-border);
  padding: 0.6rem 0.8rem;
  text-align: left;
}

article th {
  background: var(--nav-bg);
}

article sup { font-size: 0.8em; }

article hr { border: none; border-top: 1px solid var(--hr); margin: 2rem 0; }

/* ── Chapter navigation ── */

.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 2.5rem 0 1rem 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--hr);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
}

.chapter-nav a {
  color: var(--accent);
  text-decoration: none;
  max-width: 48%;
  padding: 0.4rem 0;
}

.chapter-nav a:hover { text-decoration: underline; }
.chapter-nav .next { margin-left: auto; text-align: right; }

/* ── Back to TOC & Chapter progress ── */

.back-to-toc {
  display: inline-block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.95rem;
  color: var(--accent);
  text-decoration: none;
  padding: 0.3rem 0;
  margin-bottom: 0.25rem;
}

.back-to-toc:hover { text-decoration: underline; }

.chapter-progress {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.9rem;
  color: var(--fg-muted);
  margin: -0.5rem 0 1.25rem 0;
}

/* ── In-chapter TOC ── */

.chapter-toc {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin: 1rem 0 1.5rem 0;
}

.chapter-toc-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  margin: 0 0 0.5rem 0;
  color: var(--fg);
}

.chapter-toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.chapter-toc li {
  padding: 0.2rem 0;
}

.chapter-toc li a {
  color: var(--link);
  text-decoration: none;
  font-size: 0.95rem;
}

.chapter-toc li a:hover { text-decoration: underline; }

.chapter-toc .chapter-toc-h3 {
  padding-left: 1.25rem;
  font-size: 0.9rem;
}

/* ── Changelog entries (appendix summary pages) ── */

.changelog-entry {
  font-size: 0.95rem;
  margin: 0.5rem 0;
  padding: 0.4rem 0 0.4rem 1rem;
  border-left: 3px solid var(--hr);
  text-indent: 0;
}

/* ── Glossary ── */

.glossary dt {
  margin-top: 1.25rem;
  font-size: 1.05rem;
}

.glossary dd {
  margin: 0.25rem 0 0 0;
  padding-left: 0;
  line-height: 1.65;
}

/* ── Footer ── */

footer {
  border-top: 1px solid var(--hr);
  padding: 1.5rem 0;
  margin-top: 2rem;
  font-size: 0.95rem;
  color: var(--fg-muted);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

/* ── Landing page ── */

.hero {
  text-align: center;
  padding: 2rem 0 1rem 0;
}

.hero h1 {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
}

.hero .subtitle {
  color: var(--fg-muted);
  font-size: 1rem;
  margin-top: 0;
}

.book-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0;
  box-shadow: 0 2px 4px var(--shadow);
}

.book-card .book-card-inner {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
}

.book-card .cover-img {
  width: 120px;
  min-width: 120px;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 2px 6px var(--shadow);
}

.book-card h2 {
  font-size: 1.25rem;
  margin: 0 0 0.5rem 0;
  border: none;
  padding: 0;
}

.book-card h2 a {
  color: var(--accent);
  text-decoration: none;
}

.book-card h2 a:hover { text-decoration: underline; }

.book-card .meta {
  font-size: 0.95rem;
  color: var(--fg-muted);
  margin-bottom: 0.75rem;
}

.book-card .toc-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
}

.book-card .toc-list li {
  padding: 0.3rem 0;
}

.book-card .toc-list a {
  color: var(--link);
  text-decoration: none;
  font-size: 1rem;
}

.book-card .toc-list a:hover { text-decoration: underline; }

.book-card .toc-list .part-header {
  font-weight: bold;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ── Downloads ── */

.download-group {
  margin: 1.5rem 0;
}

.download-group h3 {
  margin: 0 0 0.75rem 0;
}

.download-table {
  width: 100%;
  border-collapse: collapse;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.95rem;
}

.download-table th,
.download-table td {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--nav-border);
  text-align: left;
}

.download-table th {
  background: var(--nav-bg);
}

.download-table td:last-child {
  white-space: nowrap;
}

.download-table a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.download-table a:hover { text-decoration: underline; }

/* ── Print ── */

@media print {
  header, .chapter-nav, footer, .back-to-toc, .chapter-progress, .breadcrumb, .skip-link { display: none; }
  body { font-size: 12pt; color: #000; background: #fff; line-height: 1.6; }
  .container { max-width: 100%; padding: 0; }
  .disclaimer { background: #f5f5f5; border-left-color: #999; break-inside: avoid; }
  .chapter-toc { break-inside: avoid; background: #f5f5f5; }
  article h1 { font-size: 18pt; }
  article h2 { font-size: 14pt; break-after: avoid; }
  article h3 { font-size: 12pt; break-after: avoid; }
  article p { orphans: 3; widows: 3; }
  article img { max-width: 80%; break-inside: avoid; }
  a { color: #000; text-decoration: underline; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 9pt; color: #555; }
}

/* ── Skip link ── */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 999;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.85rem;
  text-decoration: none;
}

.skip-link:focus {
  left: 0;
}

/* ── Focus indicators ── */

a:focus-visible, button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ── Screen-reader-only utility ── */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Breadcrumb ── */

.breadcrumb {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.9rem;
  color: var(--fg-muted);
  margin: 1rem 0 0.5rem 0;
}

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

.breadcrumb a:hover { text-decoration: underline; }

/* ── Responsive ── */

/* Tablet */
@media (max-width: 800px) {
  .container { padding: 0 1rem; }

  .book-card { padding: 1.25rem; }

  .download-table { font-size: 0.8rem; }
  .download-table th,
  .download-table td { padding: 0.4rem 0.5rem; }
}

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

  .container { padding: 0 0.85rem; }

  /* Header: stack nav vertically, not sticky on mobile */
  header { padding: 0.5rem 0; position: static; }
  header nav {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }
  header .site-title {
    margin-right: 0;
    margin-bottom: 0.25rem;
  }
  header nav a { font-size: 1rem; padding: 0.2rem 0; }

  /* Larger tap targets for 50+ audience */
  a { min-height: 44px; display: inline-flex; align-items: center; }
  article a { min-height: auto; display: inline; }

  /* Headings */
  article h1 { font-size: 1.35rem; }
  article h2 { font-size: 1.15rem; }
  article h3 { font-size: 1.05rem; }
  .hero h1 { font-size: 1.4rem; }

  /* Text: left-align on mobile (justified text is hard to read on narrow screens) */
  article p { text-align: left; hyphens: none; }

  /* Chapter navigation: stack vertically, bigger tap targets */
  .chapter-nav {
    flex-direction: column;
    gap: 0.75rem;
  }
  .chapter-nav a {
    max-width: 100%;
    padding: 0.6rem 0;
    font-size: 0.9rem;
  }
  .chapter-nav .next { text-align: left; margin-left: 0; }

  /* Book cards */
  .book-card { padding: 1rem; margin: 1rem 0; }
  .book-card .book-card-inner { flex-direction: column; }
  .book-card .cover-img { width: 100px; }
  .book-card h2 { font-size: 1.1rem; }

  /* TOC list: more spacing for tap targets */
  .book-card .toc-list li { padding: 0.35rem 0; }
  .book-card .toc-list a { font-size: 0.95rem; }
  .toc-list li { padding: 0.35rem 0; }

  /* Download table: responsive layout */
  .download-table,
  .download-table thead,
  .download-table tbody,
  .download-table tr,
  .download-table th,
  .download-table td {
    display: block;
    width: 100%;
  }
  .download-table thead { display: none; }
  .download-table tr {
    margin-bottom: 0.75rem;
    border: 1px solid var(--nav-border);
    border-radius: 4px;
    padding: 0.5rem;
  }
  .download-table td {
    border: none;
    padding: 0.25rem 0.5rem;
    text-align: left;
  }
  .download-table td:first-child {
    font-weight: 700;
    padding-top: 0.4rem;
  }

  /* Disclaimer — keep readable on mobile */
  .disclaimer { padding: 0.75rem 0.85rem; font-size: 0.95rem; }
  .disclaimer ul { padding-left: 1rem; }

  /* Breadcrumb */
  .breadcrumb { font-size: 0.85rem; }

  /* Footer */
  footer { font-size: 0.9rem; }
}

/* Very small screens */
@media (max-width: 380px) {
  html { font-size: 16px; }
  .container { padding: 0 0.65rem; }
  article h1 { font-size: 1.25rem; }
}
