:root {
  --bg: #f5efe4;
  --surface: rgba(255, 252, 246, 0.88);
  --surface-strong: #fffaf1;
  --text: #2a241d;
  --muted: #66594b;
  --line: rgba(77, 56, 37, 0.14);
  --accent: #a5542a;
  --accent-strong: #7d3612;
  --accent-soft: #f0d7c3;
  --shadow: 0 18px 40px rgba(79, 47, 23, 0.12);
  --content-width: 760px;
  --base-font-size: 18px;
}

body[data-theme="dark"] {
  --bg: #1b1a18;
  --surface: rgba(37, 35, 31, 0.9);
  --surface-strong: #2b2824;
  --text: #f3ece1;
  --muted: #c2b4a3;
  --line: rgba(255, 243, 227, 0.12);
  --accent: #f2a46f;
  --accent-strong: #ffbf94;
  --accent-soft: rgba(242, 164, 111, 0.16);
  --shadow: 0 20px 44px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Noto Serif TC", "PMingLiU", serif;
  font-size: var(--base-font-size);
  line-height: 1.8;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.45), transparent 32%),
    linear-gradient(135deg, rgba(255, 236, 214, 0.7), transparent 42%),
    var(--bg);
}

a {
  color: inherit;
}

p,
li {
  color: var(--text);
}

.progress-bar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 20;
  height: 4px;
  background: rgba(0, 0, 0, 0.05);
}

.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
}

.site-header,
.site-footer,
main {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  position: sticky;
  top: 4px;
  z-index: 10;
  margin-top: 20px;
  display: grid;
  grid-template-columns: 1.5fr auto auto;
  gap: 16px;
  align-items: center;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.brand-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.brand {
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 700;
}

.top-nav,
.reader-controls,
.cta-row,
.chapter-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.top-nav a,
.button,
.reader-controls button,
.preview-card a {
  text-decoration: none;
  border-radius: 999px;
  transition: transform 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.top-nav a {
  padding: 8px 12px;
}

.top-nav a:hover,
.button:hover,
.reader-controls button:hover,
.preview-card a:hover {
  transform: translateY(-1px);
}

.reader-controls button,
.button {
  border: 1px solid var(--line);
  padding: 10px 14px;
  font: inherit;
  color: var(--text);
  background: var(--surface-strong);
  cursor: pointer;
}

.button.primary {
  border-color: transparent;
  color: #fff9f4;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.button.secondary,
.preview-card a {
  background: var(--accent-soft);
}

main {
  padding: 44px 0 80px;
}

.hero {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 24px;
  align-items: stretch;
}

.hero-copy,
.hero-panel,
.card,
.preview-card,
.chapter-article,
.reading-note {
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-copy {
  padding: 40px;
}

.hero-copy h1,
.section-heading h1,
.chapter-header h1 {
  margin: 0;
  line-height: 1.15;
  font-size: clamp(2.2rem, 4vw, 4.2rem);
}

.subtitle {
  margin: 12px 0 20px;
  font-size: 1.2rem;
  color: var(--accent-strong);
}

.lead {
  max-width: 58ch;
  font-size: 1.05rem;
}

.hero-panel {
  padding: 28px;
  align-self: end;
}

.hero-panel h2,
.card h2,
.preview-card h3,
.chapter-article h2,
.reading-note h2 {
  line-height: 1.3;
}

.content-grid,
.preview-list {
  display: grid;
  gap: 20px;
  margin-top: 28px;
}

.content-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card,
.preview-card,
.reading-note {
  padding: 24px;
}

.section-heading {
  max-width: 760px;
  margin: 52px auto 20px;
}

.section-heading.wide {
  max-width: 960px;
}

.chapter-preview {
  margin-top: 24px;
}

.preview-list {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chapter-tag {
  margin: 0 0 8px;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.reader-controls button {
  white-space: nowrap;
}

.preview-card a {
  display: inline-flex;
  margin-top: 8px;
  padding: 10px 14px;
}

.toc-layout {
  max-width: 960px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin: 22px 0 0;
}

.status-card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.status-card h2 {
  margin: 0 0 10px;
  font-size: 1.2rem;
}

.status-card p:last-child {
  margin-bottom: 0;
}

.toc-list {
  margin: 28px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: chapter;
}

.toc-list li {
  counter-increment: chapter;
  margin-bottom: 14px;
}

.toc-list a {
  display: block;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.toc-list a::before {
  content: counter(chapter, decimal-leading-zero) ". ";
  color: var(--accent-strong);
  font-weight: 700;
}

.toc-list a[data-ready="true"]::after {
  content: "已完成內容";
  display: inline-flex;
  margin-left: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.76rem;
  vertical-align: middle;
}

.toc-list a.is-current {
  outline: 2px solid var(--accent);
  background: var(--accent-soft);
}

.page-shell {
  display: flex;
  justify-content: center;
}

.chapter-article {
  width: min(var(--content-width), 100%);
  padding: 38px 32px;
}

.chapter-header {
  margin-bottom: 26px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.chapter-summary {
  margin: 14px 0 0;
  font-size: 1.02rem;
  color: var(--muted);
}

.chapter-en-term {
  margin: 6px 0 0;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-family: "Inter", "SF Pro Text", system-ui, sans-serif;
}

.reading-time {
  margin: 10px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.03em;
}

.chapter-article section + section {
  margin-top: 28px;
}

.chapter-article blockquote {
  margin: 18px 0;
  padding: 18px 20px;
  border-left: 4px solid var(--accent);
  border-radius: 0 18px 18px 0;
  background: var(--accent-soft);
}

.chapter-article ul,
.chapter-article ol {
  padding-left: 24px;
}

.chapter-article h3 {
  margin: 20px 0 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-strong);
  letter-spacing: 0.02em;
}

.chapter-article ol li {
  margin-bottom: 6px;
}

.chapter-figure {
  margin: 24px 0;
  text-align: center;
}

.chapter-figure svg {
  width: 100%;
  max-width: 520px;
  height: auto;
  border-radius: 14px;
  background: var(--surface);
  padding: 16px;
  border: 1px solid var(--line);
}

.chapter-figure figcaption {
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--muted);
  font-style: italic;
}

/* Audience tags */
.audience-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 0;
}

.audience-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  font-size: 0.76rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* Next chapter preview */
.next-chapter-preview {
  margin: 28px 0 8px;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 16px;
}

.next-chapter-preview .ncp-label {
  flex-shrink: 0;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
}

.next-chapter-preview p {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
}

/* Review questions */
.review-questions {
  margin: 28px 0;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.review-questions h3 {
  margin: 0 0 12px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-strong);
  letter-spacing: 0.04em;
}

.review-questions ol {
  margin: 0;
  padding-left: 22px;
}

.review-questions ol li {
  margin-bottom: 8px;
  font-size: 0.95rem;
  color: var(--text);
}

/* dfn term highlighting */
dfn {
  font-style: normal;
  font-weight: 700;
  color: var(--accent-strong);
  border-bottom: 2px solid var(--accent-soft);
  text-decoration: none;
}

/* TOC search bar */
.toc-search {
  margin: 20px 0 0;
  position: relative;
}

.toc-search input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.2s ease;
}

.toc-search input:focus {
  border-color: var(--accent);
}

.toc-search input::placeholder {
  color: var(--muted);
}

/* TOC progress */
.reading-progress-bar {
  margin: 8px 0 0;
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.reading-progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 0.4s ease;
}

.reading-progress-label {
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.site-footer {
  padding: 0 0 72px;
  color: var(--muted);
}

.back-to-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 920px) {
  .site-header {
    position: static;
    grid-template-columns: 1fr;
  }

  .hero,
  .status-grid,
  .content-grid,
  .preview-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    font-size: calc(var(--base-font-size) - 1px);
  }

  main {
    padding: 28px 0 64px;
  }

  .site-header,
  main,
  .site-footer {
    width: min(100% - 20px, 1120px);
  }

  .hero-copy,
  .hero-panel,
  .chapter-article,
  .card,
  .preview-card,
  .reading-note,
  .status-card,
  .toc-list a {
    padding: 20px;
  }
}

@media print {
  .progress-bar,
  .site-header,
  .site-footer,
  .chapter-nav,
  .back-to-top,
  .reader-controls,
  .next-chapter-preview,
  .review-questions {
    display: none !important;
  }

  body {
    background: white;
    color: black;
    font-size: 12pt;
    line-height: 1.6;
  }

  .chapter-article {
    box-shadow: none;
    border: none;
    padding: 0;
    width: 100%;
    max-width: 100%;
  }

  .chapter-header {
    border-bottom: 1pt solid #ccc;
  }

  .chapter-article blockquote {
    border-color: #888;
    background: #f5f5f5;
  }

  .chapter-figure svg {
    border: 1pt solid #ddd;
    background: white;
  }

  a {
    text-decoration: underline;
    color: black;
  }

  h1, h2, h3 {
    page-break-after: avoid;
  }

  p, li {
    orphans: 3;
    widows: 3;
  }

  section {
    page-break-inside: avoid;
  }
}