:root {
  color-scheme: light;
  --bg: #f7f8f6;
  --surface: #ffffff;
  --surface-strong: #eef3ee;
  --ink: #18201d;
  --muted: #66706a;
  --line: #d8ded8;
  --accent: #0f7b68;
  --accent-strong: #095d50;
  --amber: #b96f16;
  --rose: #a13d4a;
  --shadow: 0 18px 50px rgba(20, 31, 28, 0.1);
  --radius: 8px;
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover,
button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent-strong);
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
  padding: 22px 18px;
}

.nav-backdrop {
  display: none;
}

.brand {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--ink);
  color: #f4fbf7;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.search {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 13px;
}

.search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  padding: 11px 12px;
  color: var(--ink);
}

.chapter-list {
  display: grid;
  gap: 6px;
}

.chapter-item {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 50px;
  padding: 9px 10px;
  text-align: left;
}

.chapter-item[aria-current="true"] {
  background: var(--surface-strong);
  border-color: #b8c9bf;
}

.chapter-num {
  color: var(--accent);
  font-weight: 800;
  font-size: 13px;
}

.chapter-name {
  font-size: 14px;
  line-height: 1.35;
}

.reader {
  min-width: 0;
}

.reader-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  min-height: 70px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 248, 246, 0.94);
  backdrop-filter: blur(14px);
  padding: 12px 26px;
}

.icon-button {
  display: none;
  width: 42px;
  padding: 0;
  place-items: center;
  gap: 4px;
}

.icon-button span {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
}

.current-meta {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.current-meta span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.current-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.progress {
  position: sticky;
  top: 70px;
  z-index: 4;
  height: 3px;
  background: transparent;
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
}

.intro-panel {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(260px, 0.55fr);
  gap: 24px;
  align-items: end;
  max-width: 1180px;
  margin: 30px auto 0;
  padding: 0 30px 24px;
  border-bottom: 1px solid var(--line);
}

.intro-kicker {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.intro-panel h2 {
  margin: 0;
  max-width: 760px;
  font-size: clamp(30px, 4vw, 54px);
  line-height: 1.05;
  letter-spacing: 0;
}

.intro-panel > p {
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
}

.content-layout {
  display: grid;
  grid-template-columns: minmax(0, 820px) 240px;
  gap: 42px;
  align-items: start;
  max-width: 1180px;
  margin: 0 auto;
  padding: 34px 30px 60px;
}

.content {
  min-width: 0;
  overflow-x: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(24px, 4vw, 48px);
}

.content h1,
.content h2,
.content h3,
.content h4 {
  letter-spacing: 0;
  line-height: 1.25;
}

.content h1 {
  margin: 0 0 26px;
  font-size: clamp(28px, 5vw, 46px);
}

.content h2 {
  margin: 46px 0 18px;
  padding-top: 8px;
  font-size: 26px;
}

.content h3 {
  margin: 34px 0 14px;
  color: var(--accent-strong);
  font-size: 20px;
}

.content h4 {
  margin: 24px 0 12px;
  font-size: 17px;
}

.content p,
.content li,
.content blockquote {
  font-size: 16px;
  line-height: 1.9;
}

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

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

.content blockquote {
  margin: 18px 0;
  border-left: 4px solid var(--accent);
  background: #f4faf7;
  padding: 14px 18px;
  color: #33413c;
}

.content .figure-note {
  border: 1px dashed #d6b27d;
  border-left: 4px solid var(--amber);
  background: #fff8ec;
  color: #5f421c;
}

.content .practice-block {
  margin: 32px 0;
  border: 1px solid #b7d6cc;
  border-radius: 8px;
  background: #f3fbf8;
  padding: 22px;
}

.content .practice-block h2,
.content .practice-block h3 {
  margin-top: 0;
}

.content code {
  border-radius: 4px;
  background: #edf2ef;
  padding: 2px 5px;
  font-size: 0.92em;
}

.content pre {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151c19;
  color: #eef7f2;
  padding: 16px;
  line-height: 1.65;
}

.content .table-text {
  background: #f8faf8;
  color: #24302b;
  white-space: pre;
}

.content a {
  color: var(--accent-strong);
  text-underline-offset: 3px;
}

.toc {
  position: sticky;
  top: 104px;
  max-height: calc(100vh - 120px);
  overflow: auto;
  border-left: 1px solid var(--line);
  padding-left: 18px;
}

.toc h2 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
}

.toc a {
  display: block;
  border-radius: 6px;
  padding: 7px 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.4;
}

.toc a:hover {
  background: var(--surface-strong);
  color: var(--accent-strong);
}

.chapter-pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  max-width: 1180px;
  margin: 0 auto 50px;
  padding: 0 30px;
}

.chapter-pager button {
  min-width: 120px;
}

.hidden {
  display: none !important;
}

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

  body.nav-open {
    overflow: hidden;
  }

  .sidebar {
    display: none;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    width: min(86vw, 330px);
    box-shadow: var(--shadow);
  }

  .nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9;
    display: none;
    background: rgba(18, 32, 28, 0.34);
  }

  body.nav-open .sidebar,
  .sidebar.is-open {
    display: block;
  }

  body.nav-open .nav-backdrop,
  .nav-backdrop.is-open {
    display: block;
  }

  .icon-button {
    display: grid;
  }

  .intro-panel,
  .content-layout {
    grid-template-columns: 1fr;
  }

  .toc {
    position: static;
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 18px 0 0;
  }
}

@media (max-width: 640px) {
  .reader-toolbar {
    grid-template-columns: auto 1fr;
    padding: 10px 14px;
  }

  .toolbar-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .toolbar-actions button {
    flex: 1 1 150px;
  }

  .intro-panel,
  .content-layout,
  .chapter-pager {
    padding-left: 16px;
    padding-right: 16px;
  }

  .content {
    padding: 22px 16px;
  }

  .content .practice-block {
    padding: 18px 14px;
  }

  .content h2 {
    font-size: 22px;
  }
}

@media (max-width: 360px) {
  .reader-toolbar {
    gap: 10px;
  }

  .toolbar-actions button {
    flex-basis: 100%;
  }

  .intro-panel h2 {
    font-size: 26px;
  }

  .content p,
  .content li,
  .content blockquote {
    font-size: 15px;
  }
}
