:root {
  --ink: #1f2937;
  --muted: #5b6472;
  --line: #d7dde8;
  --paper: #ffffff;
  --surface: #f6f8fb;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #eef7f6;
  --accent-border: #bddbd7;
  --action: #2563eb;
  --code-bg: #111827;
  --code-fg: #e5e7eb;
  --content-max: 1180px;
  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

  *,
  *::before,
  *::after {
    transition: none !important;
  }
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--surface);
  font-family: var(--font-body);
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  top: -48px;
  left: 12px;
  z-index: 100;
  padding: 8px 14px;
  color: #ffffff;
  background: var(--accent-dark);
  border-radius: 0 0 8px 8px;
  font-weight: 600;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 0;
  text-decoration: none;
  color: #ffffff;
}

.progress-track {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  height: 3px;
  background: transparent;
  pointer-events: none;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--action));
  transition: width 0.1s linear;
}

.ebook-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.book-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--paper);
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
}

.book-main {
  min-width: 0;
  padding: 28px clamp(18px, 4vw, 56px) 48px;
}

.book-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 20px 18px;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}

.book-brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  font-weight: 800;
  font-size: 1.2rem;
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.28);
}

.book-brand small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.topic-nav {
  padding: 10px 12px 20px;
}

.nav-section {
  margin: 14px 4px 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.nav-section:first-child {
  margin-top: 6px;
}

.topic-nav .nav-link {
  display: grid;
  gap: 3px;
  padding: 9px 11px;
  border-radius: 8px;
  color: var(--ink);
  border: 1px solid transparent;
  font-size: 0.92rem;
  line-height: 1.35;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.topic-nav .nav-link:hover {
  background: var(--accent-soft);
  text-decoration: none;
}

.topic-nav .nav-link.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-day,
.topic-day {
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.book-header {
  max-width: var(--content-max);
  margin: 0 auto 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.book-header h1,
.cover-panel h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.9rem, 4vw, 3.2rem);
  font-weight: 800;
  line-height: 1.1;
  text-wrap: balance;
}

.book-header .lead {
  max-width: 920px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: clamp(1.02rem, 1.6vw, 1.16rem);
  line-height: 1.55;
}

.content-tools {
  position: sticky;
  top: 0;
  z-index: 10;
  max-width: var(--content-max);
  margin: 0 auto 18px;
  padding: 8px 0;
  background: rgba(246, 248, 251, 0.92);
  backdrop-filter: blur(10px);
}

.toc-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 6px 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(31, 41, 55, 0.06);
}

.toc-strip h2 {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 10px 0 2px;
  color: var(--accent-dark);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-right: 1px solid var(--line);
}

.toc-strip nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0;
  scrollbar-width: thin;
}

.article-card,
.cover-panel {
  max-width: var(--content-max);
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 18px 50px rgba(31, 41, 55, 0.08);
}

.article-card {
  padding: clamp(22px, 4vw, 52px);
  font-size: 1.04rem;
  overflow-wrap: break-word;
}

.article-card h2 {
  margin-top: 2.35rem;
  margin-bottom: 0.9rem;
  padding-bottom: 0.45rem;
  font-size: clamp(1.4rem, 2.4vw, 1.7rem);
  font-weight: 700;
  line-height: 1.25;
  border-bottom: 2px solid var(--accent-soft);
  scroll-margin-top: 96px;
}

.article-card h3 {
  margin-top: 1.65rem;
  margin-bottom: 0.65rem;
  font-size: clamp(1.15rem, 2vw, 1.32rem);
  font-weight: 700;
  scroll-margin-top: 96px;
}

.article-card p,
.article-card li {
  line-height: 1.7;
}

.article-card p {
  margin-bottom: 1rem;
}

.article-card code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.article-card :not(pre) > code {
  padding: 0.1em 0.35em;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-radius: 5px;
}

.topic-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.topic-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
  background: #f8fafc;
}

.outcome-note {
  margin: 0 0 1.4rem;
  padding: 0.9rem 1.1rem;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: 0 8px 8px 0;
  color: var(--ink);
}

.outcome-note strong {
  color: var(--accent-dark);
}

.quick-answer {
  margin: 0.75rem 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdff;
  overflow: hidden;
}

.quick-answer summary {
  cursor: pointer;
  padding: 0.9rem 1rem;
  color: var(--ink);
  font-weight: 600;
  line-height: 1.5;
  list-style-position: outside;
  transition: background-color 0.15s ease;
}

.quick-answer summary:hover {
  color: var(--accent-dark);
  background: #f1f8f7;
}

.quick-answer[open] summary {
  border-bottom: 1px solid var(--line);
  background: var(--accent-soft);
}

.quick-answer p {
  margin: 0;
  padding: 1rem;
}

.table-frame {
  margin: 1.15rem 0 1.35rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.table {
  margin-bottom: 0;
  font-size: 0.98em;
}

.table th {
  color: #111827;
  background: #f1f5f9;
  white-space: nowrap;
}

.table th,
.table td {
  padding: 0.75rem 0.9rem;
}

.code-panel {
  position: relative;
  margin: 1rem 0 1.35rem;
  padding: 18px 64px 18px 20px;
  color: var(--code-fg);
  background: var(--code-bg);
  border-radius: 10px;
  overflow-x: auto;
  border: 1px solid #0f172a;
}

.code-panel code {
  color: inherit;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.6;
}

.copy-code {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.76rem;
  font-family: var(--font-body);
  padding: 4px 10px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.copy-code:hover {
  background: rgba(255, 255, 255, 0.2);
}

.figure-svg {
  margin: 1.25rem auto;
  padding: 16px;
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

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

.figure-narrow {
  max-width: 820px;
}

.figure-svg figcaption {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}

.toc-link {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin: 0;
  padding: 4px 11px;
  color: var(--ink);
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.88rem;
  white-space: nowrap;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.toc-link:hover {
  color: var(--accent-dark);
  border-color: #86bdb7;
  text-decoration: none;
}

.toc-link.active {
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-color: var(--accent-border);
  font-weight: 600;
}

.toc-h3 {
  color: var(--muted);
  font-size: 0.82rem;
}

.toc-empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.page-turner {
  max-width: var(--content-max);
  margin: 24px auto 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.pager-link {
  display: grid;
  gap: 3px;
  padding: 14px 18px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(31, 41, 55, 0.05);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pager-link:hover {
  border-color: #86bdb7;
  box-shadow: 0 10px 28px rgba(15, 118, 110, 0.12);
  text-decoration: none;
}

.pager-link small {
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.pager-link span {
  font-weight: 600;
  line-height: 1.35;
}

.pager-next {
  text-align: right;
}

.pager-prev small::before {
  content: "\2190\00a0";
}

.pager-next small::after {
  content: "\00a0\2192";
}

.book-footer {
  max-width: var(--content-max);
  margin: 36px auto 0;
  padding-top: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 0.86rem;
  border-top: 1px solid var(--line);
}

.footer-credit {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.footer-credit span {
  color: var(--accent-dark);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.footer-credit strong {
  color: var(--ink);
  font-size: 0.98rem;
  font-weight: 700;
}

.footer-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: right;
}

.cover-credit {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 20px !important;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.cover-credit span {
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.cover-credit strong {
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
}

.cover-hero {
  max-width: var(--content-max);
  margin: 0 auto 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 18px 50px rgba(31, 41, 55, 0.08);
}

.cover-hero svg {
  display: block;
  width: 100%;
  height: auto;
}

.cover-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.7fr);
  gap: 28px;
  padding: clamp(24px, 5vw, 48px);
}

.index-page .cover-panel {
  gap: 20px;
  padding: clamp(22px, 4vw, 34px);
}

.index-page .cover-panel h2 {
  font-size: clamp(1.6rem, 3vw, 2.35rem);
  line-height: 1.12;
}

.cover-panel p {
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.index-page .cover-panel p {
  margin-top: 10px;
  line-height: 1.55;
}

.coverage-box {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
}

.index-page .coverage-box {
  padding: 16px 18px;
}

.coverage-box h3 {
  margin: 0 0 12px;
  font-size: 1.15rem;
}

.index-page .coverage-box h3 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.coverage-box ul {
  padding-left: 18px;
  margin-bottom: 0;
}

.coverage-box li {
  line-height: 1.45;
  margin-bottom: 4px;
}

.topic-grid {
  max-width: var(--content-max);
  margin: 24px auto 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.topic-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  min-height: 150px;
  padding: 20px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(31, 41, 55, 0.06);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.topic-card:hover {
  border-color: #86bdb7;
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(15, 118, 110, 0.12);
}

.topic-card strong,
.topic-card > span:last-child {
  grid-column: 2;
}

.topic-number {
  grid-row: span 3;
  color: var(--accent);
  font-weight: 800;
  font-size: 1.25rem;
}

.topic-card > span:last-child {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.55;
}

@media (max-width: 1180px) {
  .ebook-shell {
    grid-template-columns: 224px minmax(0, 1fr);
  }
}

@media (max-width: 1080px) {
  .ebook-shell {
    display: block;
  }

  .book-sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
  }

  .book-brand {
    flex: 0 0 220px;
    padding: 12px 16px;
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }

  .topic-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    flex: 1 1 auto;
    padding: 10px 12px;
    -webkit-overflow-scrolling: touch;
  }

  .nav-section {
    flex: 0 0 auto;
    margin: 0 2px;
    max-width: 96px;
    white-space: normal;
    font-size: 0.66rem;
    line-height: 1.3;
  }

  .topic-nav .nav-link {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 190px;
    max-width: 230px;
    padding: 8px 10px;
    font-size: 0.88rem;
  }

  .topic-nav .nav-link.active {
    box-shadow: none;
  }

  .topic-nav .nav-link span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .book-main {
    padding: 24px 16px 42px;
  }

  .article-card {
    padding: 22px;
  }

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

@media (max-width: 760px) {
  .book-sidebar {
    display: block;
  }

  .book-brand {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .book-header h1,
  .cover-panel h2 {
    font-size: 1.85rem;
  }

  .toc-strip {
    display: block;
  }

  .toc-strip h2 {
    display: block;
    padding: 0 0 6px;
    margin-bottom: 7px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .cover-panel,
  .topic-grid {
    grid-template-columns: 1fr;
  }

  .page-turner {
    grid-template-columns: 1fr;
  }

  .pager-next {
    text-align: left;
  }
}

@media (max-width: 480px) {
  .book-main {
    padding: 18px 12px 36px;
  }

  .article-card {
    padding: 18px 14px;
    font-size: 1rem;
  }

  .book-header h1,
  .cover-panel h2 {
    font-size: 1.6rem;
  }

  .code-panel {
    padding: 14px;
  }

  .code-panel code {
    font-size: 0.85rem;
  }

  .table th,
  .table td {
    padding: 0.6rem 0.65rem;
    font-size: 0.92rem;
  }

  .topic-meta span {
    font-size: 0.78rem;
  }

  .book-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .footer-meta {
    text-align: left;
  }
}

@media print {
  .book-sidebar,
  .content-tools,
  .page-turner,
  .progress-track,
  .skip-link,
  .copy-code {
    display: none !important;
  }

  .ebook-shell {
    display: block;
  }

  .book-main {
    padding: 0;
  }

  .article-card,
  .cover-panel {
    box-shadow: none;
    border: 0;
  }

  .quick-answer {
    break-inside: avoid;
  }

  .quick-answer summary {
    font-weight: 700;
  }

  .code-panel {
    color: #111827;
    background: #f8fafc;
    border: 1px solid #d7dde8;
  }

  .code-panel code {
    color: inherit;
  }

  .figure-svg,
  .table-frame {
    break-inside: avoid;
  }
}
