:root {
  color-scheme: light;
  --bg: #eef5ff;
  --surface: #ffffff;
  --surface-soft: #f7fbff;
  --line: #d8e7fb;
  --line-strong: #b8d1f0;
  --text: #143250;
  --muted: #607a96;
  --primary: #2f8fe6;
  --primary-deep: #1f73d1;
  --primary-soft: #ebf4ff;
  --shadow: 0 16px 40px rgba(26, 88, 153, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans SC", sans-serif;
  color: var(--text);
  background:
    linear-gradient(180deg, #2f8fe6 0, #2f8fe6 88px, var(--bg) 88px, var(--bg) 100%);
}

a,
button,
input {
  font: inherit;
}

.topbar {
  background: linear-gradient(180deg, #2f8fe6 0%, #2c88db 100%);
  box-shadow: 0 6px 20px rgba(18, 82, 140, 0.12);
}

.topbar__inner {
  width: min(1320px, calc(100% - 32px));
  min-height: 88px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #fff;
}

.brand__logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.26);
  font-size: 22px;
  font-weight: 800;
}

.brand__eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.9;
}

.brand h1,
.reader-panel__header h2,
.sidebar-card h2 {
  margin: 0;
}

.brand h1 {
  font-size: clamp(24px, 4vw, 32px);
  font-weight: 700;
}

.topbar__actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.button,
.zoom-btn {
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    transform 0.2s ease;
}

.button:hover,
.zoom-btn:hover {
  transform: translateY(-1px);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 18px;
  text-decoration: none;
}

.button--primary {
  background: #fff;
  color: var(--primary-deep);
}

.button--secondary {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.28);
}

.button--pay {
  background: #ffdf8a;
  color: #7a4300;
  border-color: rgba(255, 255, 255, 0.32);
  font-weight: 700;
}

.button--paid,
.button:disabled {
  cursor: not-allowed;
  opacity: 0.72;
  transform: none;
}

.layout {
  width: min(1320px, calc(100% - 32px));
  margin: 28px auto 40px;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 260px;
  gap: 24px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-card,
.reader-panel,
.message-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.sidebar-card {
  padding: 20px;
}

.sidebar-card__label,
.reader-panel__eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-card h2 {
  font-size: 24px;
  margin-bottom: 10px;
}

.sidebar-card__text,
.reader-panel__hint,
.feature-list,
.info-list dt {
  color: var(--muted);
}

.sidebar-card__text,
.reader-panel__hint,
.feature-list {
  line-height: 1.8;
  font-size: 14px;
}

.info-list {
  margin: 0;
}

.info-list > div + div {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.info-list dt {
  font-size: 13px;
}

.info-list dd {
  margin: 8px 0 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

.feature-list {
  margin: 0;
  padding-left: 18px;
}

.reader-panel {
  padding: 22px;
}

.reader-panel--content-only {
  padding-top: 26px;
}

.reader-panel__header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.reader-panel__header h2 {
  font-size: 32px;
}

.message-card {
  width: min(760px, 100%);
  margin: 0 auto 18px;
  padding: 14px 18px;
  text-align: center;
}

.message-card--error {
  background: #fff4f4;
  border-color: #f0c7c7;
  color: #a53d3d;
}

.hidden {
  display: none !important;
}

.nav-card {
  padding-bottom: 12px;
}

.chapter-nav,
.course-nav,
.toc-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.course-nav .nav-link {
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
}

.course-link {
  border: 1px solid transparent;
}

.nav-link {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  line-height: 1.5;
  transition:
    background 0.2s ease,
    color 0.2s ease;
}

.nav-link:hover {
  background: var(--surface-soft);
  color: var(--primary-deep);
}

.nav-link.is-active {
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-weight: 700;
  border-color: rgba(47, 143, 230, 0.12);
}

.toc-nav .nav-link {
  font-size: 14px;
}

.toc-nav .nav-link--level-3 {
  padding-left: 24px;
  font-size: 13px;
}

.doc-content {
  min-height: 520px;
}

.doc-content > :first-child {
  margin-top: 0;
}

.doc-content h1,
.doc-content h2,
.doc-content h3 {
  color: var(--primary-deep);
  line-height: 1.3;
  scroll-margin-top: 100px;
}

.doc-content h1 {
  margin: 0 0 22px;
  font-size: clamp(34px, 4vw, 42px);
  color: var(--text);
}

.doc-content h2 {
  margin: 42px 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  font-size: 30px;
}

.doc-content h3 {
  margin: 26px 0 12px;
  font-size: 22px;
}

.doc-content p,
.doc-content li {
  color: var(--text);
  font-size: 17px;
  line-height: 1.9;
}

.doc-content p {
  margin: 0 0 16px;
}

.doc-content img {
  display: block;
  width: auto;
  max-width: 100%;
  margin: 18px auto 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(24, 76, 126, 0.08);
  cursor: zoom-in;
}

.doc-content ul,
.doc-content ol {
  padding-left: 24px;
  margin: 0 0 16px;
}

.doc-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
}

.doc-content th,
.doc-content td {
  border: 1px solid var(--line);
  padding: 12px;
  text-align: left;
}

.toc-panel {
  position: sticky;
  top: 24px;
}

.empty-nav {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.pay-dialog {
  position: fixed;
  inset: 0;
  z-index: 950;
}

.pay-dialog__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 18, 36, 0.58);
  backdrop-filter: blur(4px);
}

.pay-dialog__panel {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100% - 32px));
  margin: min(12vh, 96px) auto 0;
  padding: 28px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 24px 70px rgba(7, 18, 36, 0.24);
  text-align: center;
}

.pay-dialog__close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.pay-dialog__eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.pay-dialog h2 {
  margin: 0 0 12px;
  font-size: 26px;
  color: var(--text);
}

.pay-dialog__message {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.7;
}

.pay-dialog__qr {
  display: grid;
  justify-items: center;
  gap: 12px;
  margin-top: 8px;
}

.pay-dialog__qr canvas,
.pay-dialog__qr-image {
  width: 220px;
  height: 220px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.pay-dialog__qr p,
.pay-dialog__success span {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.pay-dialog__success {
  display: grid;
  gap: 8px;
  padding: 18px;
  border-radius: 16px;
  background: #effaf1;
  color: #167a2f;
}

.pay-dialog__success strong {
  font-size: 22px;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.image-viewer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 18, 36, 0.82);
  backdrop-filter: blur(4px);
}

.image-viewer__panel {
  position: relative;
  z-index: 1;
  width: min(1200px, calc(100% - 32px));
  height: min(92vh, calc(100vh - 32px));
  margin: 16px auto;
  display: flex;
  flex-direction: column;
  background: rgba(250, 252, 255, 0.98);
  border: 1px solid rgba(216, 231, 251, 0.8);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.image-viewer__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.image-viewer__title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.image-viewer__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.viewer-btn {
  min-width: 40px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--primary-deep);
  cursor: pointer;
}

.viewer-btn--close {
  min-width: 64px;
}

.image-viewer__zoom {
  min-width: 52px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}

.image-viewer__content {
  flex: 1;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 24px;
  user-select: none;
}

.image-viewer__img {
  display: block;
  max-width: none;
  max-height: none;
  transform-origin: center center;
  transition: transform 0.18s ease;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
}

.image-viewer__img.is-draggable {
  cursor: grab;
}

.image-viewer__img.is-dragging {
  cursor: grabbing;
  transition: none;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .toc-panel {
    position: static;
  }

  .reader-panel__header {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 720px) {
  body {
    background:
      linear-gradient(180deg, #2f8fe6 0, #2f8fe6 74px, var(--bg) 74px, var(--bg) 100%);
  }

  .topbar__inner,
  .layout {
    width: min(100% - 20px, 100%);
  }

  .topbar__inner {
    min-height: 74px;
    padding: 12px 0;
    flex-direction: column;
    align-items: flex-start;
  }

  .page-card,
  .reader-panel,
  .sidebar-card {
    border-radius: 14px;
  }

  .reader-panel,
  .sidebar-card {
    padding: 16px;
  }

  .doc-content h2 {
    font-size: 24px;
  }

  .doc-content h3 {
    font-size: 19px;
  }

  .doc-content p,
  .doc-content li {
    font-size: 16px;
  }

  .image-viewer__panel {
    width: min(100% - 16px, 100%);
    height: min(94vh, calc(100vh - 16px));
    margin: 8px auto;
  }

  .image-viewer__toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .image-viewer__content {
    padding: 12px;
  }

  .pay-dialog__panel {
    width: min(100% - 20px, 100%);
    margin-top: 72px;
    padding: 24px 18px;
  }
}
