:root {
  --course-accent: #1769aa;
  --course-accent-strong: #125184;
  --course-soft: #eaf4fb;
  --course-ink: #1f2937;
  --course-muted: #667085;
  --course-line: #e3e8ef;
}

html {
  scroll-behavior: smooth;
}

h2[id],
h3[id],
h4[id] {
  scroll-margin-top: 18px;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 2000;
  padding: 9px 13px;
  border-radius: 8px;
  color: white;
  background: #102a43;
  transform: translateY(-150%);
  transition: transform 120ms ease;
}

.skip-link:focus {
  color: white;
  transform: translateY(0);
}

.course-breadcrumb {
  margin: 0 0 1.35rem;
}

.reading-progress-track {
  position: fixed;
  inset: 0 0 auto;
  z-index: 1400;
  height: 3px;
  background: rgba(23, 105, 170, 0.1);
  pointer-events: none;
}

.reading-progress-track > span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #1769aa, #2b8a9e);
  transform: scaleX(0);
  transform-origin: left center;
}

.chapter-toc a.is-active {
  color: #125184;
  background: #eaf4fb;
  box-shadow: inset 3px 0 #1769aa;
  font-weight: 650;
}

.course-tools {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1250;
  display: flex;
  align-items: center;
  gap: 8px;
}

.course-tool,
.course-tools .back-to-top {
  position: static;
  display: inline-flex;
  width: 50px;
  height: 50px;
  padding: 0;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(23, 105, 170, 0.2);
  border-radius: 15px;
  color: #125184;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.15);
  font: 650 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  text-decoration: none;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: transform 150ms ease, background-color 150ms ease, color 150ms ease;
}

.course-tools .back-to-top {
  flex-direction: column;
  gap: 0;
  color: white;
  background: rgba(37, 99, 235, 0.95);
}

.course-tools .back-to-top[hidden] {
  display: none;
}

.course-tool:hover,
.course-tool:focus-visible,
.course-tools .back-to-top:hover,
.course-tools .back-to-top:focus-visible {
  transform: translateY(-2px);
  text-decoration: none;
}

.course-tool:hover,
.course-tool:focus-visible {
  color: white;
  background: #1769aa;
}

.course-tool:focus-visible,
.course-tools .back-to-top:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.3);
  outline-offset: 2px;
}

.course-search-dialog,
.svg-lightbox {
  border: 0;
  padding: 0;
  color: var(--course-ink);
  background: white;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.3);
}

.course-search-dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 40px));
  border-radius: 18px;
}

.course-search-dialog::backdrop,
.svg-lightbox::backdrop {
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(3px);
}

.search-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 10px;
}

.search-dialog-head h2 {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 1.25rem;
}

.dialog-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  color: var(--course-muted);
  background: #f3f5f8;
  font-size: 22px;
  cursor: pointer;
}

.course-search-input {
  display: block;
  width: calc(100% - 40px);
  margin: 0 20px 12px;
  padding: 13px 15px;
  border: 1px solid #cfd8e3;
  border-radius: 11px;
  color: var(--course-ink);
  background: white;
  font: inherit;
  outline: none;
}

.course-search-input:focus {
  border-color: #4b9ac9;
  box-shadow: 0 0 0 3px rgba(23, 105, 170, 0.12);
}

.course-search-results {
  max-height: min(560px, calc(100vh - 190px));
  padding: 0 12px 14px;
  overflow-y: auto;
}

.course-search-results a {
  display: block;
  padding: 11px 12px;
  border-radius: 10px;
  color: var(--course-ink);
}

.course-search-results a:hover,
.course-search-results a:focus-visible {
  background: var(--course-soft);
  text-decoration: none;
}

.course-search-results strong,
.course-search-results small {
  display: block;
}

.course-search-results small,
.search-empty {
  color: var(--course-muted);
  font-size: 0.82rem;
}

.search-empty {
  margin: 0;
  padding: 24px 12px 28px;
  text-align: center;
}

.chapter-completion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 3rem 0 0;
  padding: 18px 20px;
  border: 1px solid #cfe3f1;
  border-radius: 12px;
  background: #f5fbff;
}

.chapter-completion strong,
.chapter-completion span {
  display: block;
}

.chapter-completion span {
  margin-top: 2px;
  color: var(--course-muted);
  font-size: 0.88rem;
}

.chapter-completion button {
  flex: 0 0 auto;
  padding: 10px 14px;
  border: 1px solid #1769aa;
  border-radius: 9px;
  color: white;
  background: #1769aa;
  font: inherit;
  cursor: pointer;
}

.chapter-completion.is-complete {
  border-color: #a7d8c0;
  background: #f2fbf6;
}

.chapter-completion.is-complete button {
  border-color: #28845a;
  background: #28845a;
}

.home-learning-status {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 20px;
  align-items: center;
  margin: 18px 0 0;
  padding: 15px 18px;
  border: 1px solid #d8e4ed;
  border-radius: 10px;
  background: white;
}

.home-learning-status strong,
.home-learning-status small {
  display: block;
}

.home-learning-status small {
  color: var(--course-muted);
}

.home-learning-status a {
  grid-row: span 2;
  padding: 8px 12px;
  border-radius: 8px;
  color: white;
  background: #1769aa;
}

.chapter-list a.is-complete {
  border-left: 3px solid #2a8c60;
  background: #f5fbf7;
}

.chapter-list a.is-complete::after {
  content: "✓";
  grid-column: 3;
  grid-row: 1 / span 2;
  align-self: center;
  color: #2a8c60;
  font-weight: 800;
}

.chapter-list.is-grouped {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.chapter-module {
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--course-line);
  border-radius: 13px;
  background: white;
}

.chapter-module:last-child {
  grid-column: 1 / -1;
}

.chapter-module > summary {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 2px 14px;
  padding: 16px 18px 13px;
  color: var(--course-ink);
  background: linear-gradient(135deg, #f8fbfd, #f1f7fb);
  list-style: none;
}

.chapter-module > summary::-webkit-details-marker {
  display: none;
}

.chapter-module > summary::after {
  content: "＋";
  grid-column: 3;
  grid-row: 1 / span 2;
  align-self: center;
  color: var(--course-accent);
  font-size: 1.2rem;
}

.chapter-module[open] > summary::after {
  content: "－";
}

.chapter-module > summary span {
  color: #c85a16;
  font: 700 0.7rem/1.4 Consolas, monospace;
  letter-spacing: 0.08em;
}

.chapter-module > summary strong {
  grid-column: 1;
  font-size: 1.02rem;
}

.chapter-module > summary small {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
  color: var(--course-muted);
  font-size: 0.72rem;
}

.chapter-module > p {
  margin: 0;
  padding: 11px 18px 6px;
  color: var(--course-muted);
  font-size: 0.83rem;
}

.module-chapters {
  padding: 0 8px 10px;
}

.chapter-list.is-grouped .module-chapters > a {
  grid-template-columns: 2.3rem 1fr auto;
}

.progress-shell {
  max-width: 1040px;
  margin: 0 auto;
}

.learning-progress-page {
  max-width: none !important;
}

.progress-hero {
  margin: 12px 0 28px;
  padding: 30px 32px;
  border-radius: 18px;
  color: white;
  background: linear-gradient(135deg, #102a43, #1769aa 70%, #2b8a9e);
}

.progress-hero span {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  opacity: 0.75;
}

.progress-hero h1,
.progress-hero p {
  color: white;
}

.progress-hero h1 {
  margin: 8px 0 6px;
}

.progress-hero p {
  max-width: 700px;
  margin: 0;
  opacity: 0.88;
}

.progress-overview {
  display: grid;
  grid-template-columns: 170px 1fr auto;
  gap: 22px;
  align-items: center;
  padding: 22px 24px;
  border: 1px solid var(--course-line);
  border-radius: 14px;
  background: #fbfcfe;
}

.progress-label,
.progress-overview strong,
.progress-overview small {
  display: block;
}

.progress-label,
.progress-overview small {
  color: var(--course-muted);
}

.progress-overview strong {
  margin: 2px 0;
  color: var(--course-accent-strong);
  font-size: 2rem;
  line-height: 1.15;
}

.progress-meter {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6ebf0;
}

.progress-meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1769aa, #2b8a9e);
  transition: width 220ms ease;
}

.continue-learning {
  padding: 10px 14px;
  border-radius: 9px;
  color: white;
  background: #1769aa;
  white-space: nowrap;
}

.continue-learning:hover {
  text-decoration: none;
  background: #125184;
}

.chapter-progress-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.progress-chapter-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 13px 14px;
  border: 1px solid var(--course-line);
  border-radius: 11px;
  background: white;
}

.progress-chapter-card.is-complete {
  border-color: #b7ddc9;
  background: #f5fbf7;
}

.progress-chapter-card input {
  width: 20px;
  height: 20px;
  accent-color: #28845a;
}

.progress-chapter-card a,
.progress-chapter-card small {
  display: block;
}

.progress-chapter-card a {
  color: var(--course-ink);
  font-weight: 600;
}

.progress-chapter-card small {
  color: var(--course-muted);
  font-size: 0.76rem;
}

.progress-chapter-card > span:last-child {
  color: #a0a9b4;
  font-size: 0.8rem;
}

.progress-chapter-card.is-complete > span:last-child {
  color: #28845a;
}

.review-link-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.review-link-grid a {
  padding: 15px 16px;
  border: 1px solid var(--course-line);
  border-radius: 11px;
  color: var(--course-ink);
}

.review-link-grid a:hover {
  border-color: #93c5e5;
  background: #f8fcff;
  text-decoration: none;
}

.review-link-grid strong,
.review-link-grid span {
  display: block;
}

.review-link-grid span {
  margin-top: 3px;
  color: var(--course-muted);
  font-size: 0.83rem;
}

.table-scroll {
  max-width: 100%;
  margin: 1rem 0;
  overflow-x: auto;
  border-radius: 8px;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

.table-scroll > table {
  margin: 0;
}

.svg-zoomable {
  cursor: zoom-in;
}

.svg-zoomable:focus-visible {
  outline: 3px solid rgba(23, 105, 170, 0.28);
  outline-offset: 4px;
}

.svg-lightbox {
  width: calc(100vw - 32px);
  height: calc(100vh - 32px);
  max-width: none;
  max-height: none;
  border-radius: 16px;
  overflow: hidden;
}

.lightbox-head {
  display: flex;
  height: 52px;
  padding: 0 10px 0 18px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--course-line);
}

.lightbox-head strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox-stage {
  display: grid;
  height: calc(100% - 52px);
  padding: 20px;
  place-items: center;
  overflow: auto;
  background: #f3f6f9;
}

.lightbox-stage img {
  width: auto;
  max-width: 100%;
  max-height: 100%;
  margin: 0;
  border-radius: 8px;
  background: white;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.12);
}

@media (max-width: 760px) {
  .course-tools {
    right: 12px;
    bottom: 12px;
    gap: 6px;
  }

  .course-tool,
  .course-tools .back-to-top {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    font-size: 11px;
  }

  .chapter-page .chapter-content > h1 {
    font-size: 1.9rem;
  }

  .site-home .hero {
    padding-top: 42px;
    padding-bottom: 38px;
  }

  .site-home .hero h1 {
    font-size: 2.15rem;
  }

  .site-home .lead {
    font-size: 1.06rem;
  }

  .site-home .hero-actions {
    margin-top: 1.35rem;
  }

  .chapter-list.is-grouped {
    grid-template-columns: 1fr;
  }

  .chapter-module:last-child {
    grid-column: auto;
  }

  .chapter-completion {
    display: block;
  }

  .chapter-completion button {
    width: 100%;
    margin-top: 14px;
  }

  .progress-hero {
    padding: 24px 20px;
  }

  .progress-overview {
    grid-template-columns: 1fr auto;
    gap: 15px;
  }

  .progress-meter {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .continue-learning {
    grid-column: 2;
    grid-row: 1;
  }

  .chapter-progress-grid,
  .review-link-grid {
    grid-template-columns: 1fr;
  }

  .table-scroll > table {
    min-width: 640px;
  }

  .course-search-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    border-radius: 14px;
  }

  .svg-lightbox {
    width: calc(100vw - 12px);
    height: calc(100vh - 12px);
    border-radius: 12px;
  }

  .lightbox-stage {
    padding: 8px;
  }
}

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

  .course-tool,
  .progress-meter span {
    transition: none;
  }
}

@media print {
  @page {
    margin: 18mm;
  }

  body,
  body:not(.site-home),
  .chapter-page {
    max-width: none !important;
    padding: 0 !important;
    color: #000;
    background: #fff;
  }

  .course-tools,
  .reading-progress-track,
  .chapter-toc,
  .chapter-completion,
  .chapter-pager,
  .skip-link {
    display: none !important;
  }

  .chapter-shell {
    display: block !important;
    max-width: none !important;
  }

  .chapter-content {
    width: 100% !important;
    max-width: none !important;
  }

  a {
    color: #000;
    text-decoration: none;
  }

  img,
  table,
  pre,
  blockquote {
    break-inside: avoid;
  }
}
