:root {
  --bg: #eef1f4;
  --paper: #ffffff;
  --ink: #1f2933;
  --accent: #1f5f8b;
  --accent-soft: #eaf2f9;
  --border: #d7e0e8;
  --code-bg: #0f1720;
  --code-fg: #dce7f2;
}

body.chapter-theme {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(180deg, #f7f9fb 0%, var(--bg) 100%);
}

.chapter-topnav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 0.62rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
  font: 600 0.88rem/1.2 "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

.chapter-topnav a,
.chapter-topnav .disabled {
  padding: 0.18rem 0.56rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.chapter-topnav a {
  text-decoration: none;
  color: var(--accent);
  background: var(--accent-soft);
}

.chapter-topnav a:hover {
  background: #dcebf8;
}

.chapter-topnav .disabled {
  color: #8a99a8;
  background: #f3f6f9;
}

.chapter-content {
  max-width: 860px;
  margin: 0.82rem auto 1.24rem;
  padding: 1.18rem clamp(0.78rem, 1.35vw, 1.4rem);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 8px 20px rgba(31, 41, 51, 0.08);
}

.chapter-content h1,
.chapter-content h2,
.chapter-content h3,
.chapter-content h4 {
  color: #162330 !important;
  line-height: 1.16;
  letter-spacing: -0.01em;
}

.chapter-content h1 {
  margin: 0.04rem 0 0.62rem;
  padding-bottom: 0.52rem;
  border-bottom: 2px solid #e3ebf2;
  font-size: clamp(1.42rem, 2.2vw, 1.86rem);
}

.chapter-content h2 {
  margin: 1.04rem 0 0.3rem;
  font-size: clamp(1.08rem, 1.6vw, 1.24rem);
}

.chapter-content p,
.chapter-content li {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 0.95rem;
  line-height: 1.32;
  color: var(--ink);
}

.chapter-content p span,
.chapter-content li span {
  font-family: inherit !important;
  font-size: inherit !important;
  line-height: inherit !important;
  color: inherit !important;
  background: transparent !important;
}

.chapter-content p {
  margin-top: 0.34rem;
  margin-bottom: 0.4rem;
}

.chapter-content ul,
.chapter-content ol {
  padding-left: 1.22rem;
  margin-top: 0.28rem;
  margin-bottom: 0.4rem;
}

.chapter-content img {
  max-width: 100%;
  height: auto !important;
  border-radius: 8px;
}

/* Normalize Google Docs exported image wrappers that can hide images in some browsers. */
.chapter-content span[style*="overflow: hidden"][style*="display: inline-block"] {
  overflow: visible !important;
  height: auto !important;
  max-width: 100% !important;
}

.chapter-content span[style*="overflow: hidden"][style*="display: inline-block"] > img {
  display: block;
  transform: none !important;
  -webkit-transform: none !important;
}

.chapter-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.6rem 0 0.75rem;
  border: 1px solid var(--border);
}

.chapter-content th,
.chapter-content td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.54rem;
  text-align: left;
  font: 500 0.86rem/1.22 "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

.chapter-content th {
  background: #f1f6fb;
  font-weight: 700;
}

.chapter-content pre,
.chapter-content .auto-code {
  background: var(--code-bg) !important;
  color: var(--code-fg) !important;
  border-radius: 10px;
  border: 1px solid rgba(166, 187, 212, 0.28);
  padding: 0.62rem 0.76rem;
  margin: 0.56rem 0;
  overflow-x: auto;
  white-space: pre;
  font: 500 0.81rem/1.36 "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace !important;
}

.chapter-content code,
.chapter-content .inline-code {
  background: #e8f0f8;
  color: #13293f;
  border-radius: 5px;
  padding: 0.03rem 0.28rem;
  font: 500 0.86em/1.2 "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (max-width: 760px) {
  .chapter-topnav {
    padding: 8px 10px;
    gap: 0.48rem;
  }

  .chapter-topnav a,
  .chapter-topnav .disabled {
    padding: 0.16rem 0.48rem;
  }

  .chapter-content {
    margin: 0.45rem 0.45rem 0.9rem;
    padding: 0.74rem 0.66rem;
    border-radius: 10px;
  }

  .chapter-content p,
  .chapter-content li {
    font-size: 0.93rem;
    line-height: 1.3;
  }
}
