:root {
  --bg: #f7f3ea;
  --paper: #fffdf8;
  --ink: #1e211d;
  --muted: #6e6a60;
  --line: #ded5c3;
  --accent: #245c4f;
  --accent-2: #9d3f2f;
  --soft: #e9efe8;
  --mark: #fff0a8;
  --shadow: 0 18px 55px rgba(35, 28, 18, 0.12);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Serif KR", "Nanum Myeongjo", "Apple SD Gothic Neo", Georgia, serif;
  line-height: 1.78;
  word-break: keep-all;
  overflow-x: clip;
}
a { color: var(--accent); text-decoration-thickness: 0.08em; text-underline-offset: 0.18em; }
.skip { position: absolute; left: -999px; top: 1rem; background: var(--ink); color: white; padding: .6rem .8rem; z-index: 20; }
.skip:focus { left: 1rem; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.hero {
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(30px, 5vw, 58px) 22px clamp(28px, 4vw, 46px);
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(250px, 0.58fr);
  gap: clamp(26px, 4vw, 52px);
  align-items: center;
}
.hero-copy { min-width: 0; }
.hero-title-viewport {
  width: min(100%, 760px);
  overflow: visible;
}
.hero-title-image {
  display: block;
  width: 100%;
  height: auto;
  margin-block: -12%;
}
.hero-description {
  max-width: 720px;
  margin-top: clamp(18px, 2.4vw, 30px);
  padding-left: clamp(14px, 2vw, 24px);
  border-left: 3px solid color-mix(in srgb, var(--accent) 56%, transparent);
}
.hero p { margin: 0; color: #4e4a42; font-size: clamp(.98rem, 1.25vw, 1.08rem); line-height: 1.78; }
.hero p + p { margin-top: .85em; color: #686258; font-size: clamp(.9rem, 1.1vw, 1rem); }
.cover { margin: 0; border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow); padding: 10px; transform: rotate(1.2deg); }
.cover img { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(247, 243, 234, 0.94);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 22px;
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: center;
}
.tabs, .toc-actions { display: flex; gap: 8px; flex-wrap: wrap; }
button, .search input { font: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  min-height: 38px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
}
button:hover, button.active { border-color: var(--accent); background: var(--soft); }
.search { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.search input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: var(--paper);
  color: var(--ink);
}
.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 22px 80px;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 34px;
  align-items: start;
}
aside {
  position: sticky;
  top: 78px;
  max-height: calc(100vh - 94px);
  overflow: auto;
  border-right: 1px solid var(--line);
  padding-right: 18px;
}
.toc-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.toc-head h2 { margin: 0; font-size: 1.18rem; }
details.toc-book { border-bottom: 1px solid var(--line); padding: 10px 0; }
details.toc-book > summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--accent);
  list-style: none;
}
details.toc-book > summary::-webkit-details-marker { display: none; }
details.toc-book > summary::before { content: "▸"; display: inline-block; width: 1.2em; }
details.toc-book[open] > summary::before { content: "▾"; }
.toc-list, .toc-list ol { list-style: none; margin: 8px 0 0; padding-left: 14px; }
.toc-list li { margin: 4px 0; }
.toc-list a {
  display: inline-block;
  padding: 3px 0;
  color: #3d403a;
  text-decoration: none;
  font-size: .93rem;
  line-height: 1.42;
  overflow-wrap: anywhere;
}
.toc-list a:hover { color: var(--accent-2); text-decoration: underline; }
main { min-width: 0; }
.book {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: clamp(22px, 4vw, 54px);
  margin-bottom: 28px;
}
.book.hidden { display: none; }
.book.loading { min-height: 320px; color: var(--muted); }
.book-chunk {
  content-visibility: auto;
  contain: layout style paint;
  contain-intrinsic-size: auto var(--chunk-height, 4200px);
}
.book-chunk.chunk-placeholder {
  min-height: var(--chunk-height, 4200px);
  position: relative;
}
.chunk-loading {
  position: absolute;
  top: 36px;
  left: 50%;
  width: 34px;
  height: 34px;
  margin-left: -17px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: chunk-spin .8s linear infinite;
}
.chunk-error { color: #a23a2a; padding: 24px 0; }
@keyframes chunk-spin { to { transform: rotate(360deg); } }
.book-label {
  display: inline-block;
  color: var(--accent-2);
  font-weight: 700;
  margin-bottom: 8px;
  font-family: "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
}
h1, h2, h3, h4, h5, h6 { line-height: 1.32; letter-spacing: 0; scroll-margin-top: 96px; }
.book > h1:first-child { margin-top: 0; }
.body-graphic-title,
.reference-graphic-title {
  position: relative;
  margin: clamp(1rem, 2vw, 1.8rem) 0 clamp(3rem, 6vw, 5.2rem);
}
.body-graphic-title img,
.reference-graphic-title img {
  display: block;
  width: min(100%, 960px);
  height: auto;
  margin: -8% auto -6%;
}
.reference-graphic-title { margin-bottom: clamp(3.4rem, 7vw, 6rem); }
.reference-graphic-title img { margin-top: -6%; margin-bottom: -5%; }
.body-graphic-title .anchor,
.reference-graphic-title .anchor { position: absolute; right: 0; bottom: 0; }
h2 { font-size: 2rem; margin: 2.2rem 0 1rem; }
h3 { font-size: 1.42rem; margin: 1.8rem 0 .85rem; }
h4 { font-size: 1.14rem; margin: 1.5rem 0 .65rem; color: #3e443c; }
p { margin: .82rem 0; }
blockquote {
  margin: 1.2rem 0;
  padding: .8rem 1rem;
  border-left: 4px solid var(--accent);
  background: var(--soft);
  color: #3c433b;
}
.chapter-illustration, .episode-card figure {
  margin: 1.1rem 0 1.7rem;
  border: 1px solid var(--line);
  background: #f4efe4;
  padding: 8px;
}
.chapter-illustration img, .episode-card img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}
.chapter-illustration figcaption, .episode-card figcaption {
  margin: 7px 4px 1px;
  color: var(--muted);
  font-size: .9rem;
  font-family: "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  line-height: 1.45;
}
.episode-box {
  margin: 1.25rem 0 2rem;
  border: 1px solid #cfc3ad;
  background: #fbf7ee;
  border-radius: 8px;
  overflow: hidden;
}
.episode-box > summary {
  cursor: pointer;
  list-style: none;
  padding: .85rem 1rem;
  font-family: "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  font-weight: 800;
  color: var(--accent);
  background: linear-gradient(90deg, #edf3eb, #fbf7ee);
}
.episode-box > summary::-webkit-details-marker { display: none; }
.episode-box > summary::before { content: "▸"; display: inline-block; width: 1.2em; }
.episode-box[open] > summary::before { content: "▾"; }
.episode-list { padding: 0 1rem 1rem; }
.episode-card {
  border-top: 1px solid var(--line);
  padding: 1rem 0 .4rem;
}
.episode-card:first-child { border-top: 0; }
.episode-card h4 {
  margin-top: .3rem;
  color: #27382f;
  font-family: "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
}
hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }
ul, ol { padding-left: 1.35rem; }
li { margin: .28rem 0; }
.table-wrap { overflow-x: auto; margin: 1.1rem 0; }
table { border-collapse: collapse; width: 100%; min-width: 520px; background: white; }
th, td { border: 1px solid var(--line); padding: .55rem .7rem; vertical-align: top; }
th { background: var(--soft); }
.anchor { opacity: 0; margin-left: .45rem; font-size: .8em; text-decoration: none; }
h1:hover .anchor, h2:hover .anchor, h3:hover .anchor, h4:hover .anchor, h5:hover .anchor, h6:hover .anchor { opacity: 1; }
.search-panel {
  display: none;
  max-width: 1180px;
  margin: 18px auto 0;
  padding: 0 22px;
}
.search-panel.active { display: block; }
.search-card {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 16px;
}
.result-meta { color: var(--muted); margin: 0 0 10px; }
.result-item { border-top: 1px solid var(--line); padding: 12px 0; content-visibility: auto; contain-intrinsic-size: auto 92px; }
.result-item:first-of-type { border-top: 0; }
.result-item a { font-weight: 700; line-height: 1.55; }
.result-item p { margin: 5px 0 0; color: #575249; line-height: 1.65; }
.result-book { color: var(--muted); font-weight: 500; font-size: .9em; }
mark { background: var(--mark); color: inherit; padding: 0 .12em; border-radius: 2px; }
#searchResults[aria-busy="true"] { min-height: 48px; opacity: .72; }
.no-results { color: var(--muted); }
.source-note {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 22px 36px;
  color: var(--muted);
  font-size: .92rem;
}
.copyright-table {
  width: min(760px, calc(100% - 44px));
  margin: 0 auto 56px;
  border-collapse: collapse;
  color: var(--ink);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", Arial, sans-serif;
  font-weight: 700;
}
.copyright-table td { border: 0; vertical-align: middle; padding: 0; }
.copyright-table .logo-cell { width: 116px; text-align: center; }
.copyright-table img { display: block; width: 100px; height: 100px; object-fit: contain; background: transparent; }
.copyright-table .copyright-text { padding-left: 18px; font-size: 1rem; line-height: 1.55; letter-spacing: 0; }
.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  border-radius: 50%;
  border-color: #b9aa91;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 10px 30px rgba(35, 28, 18, 0.18);
  font-size: 1.35rem;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity .18s ease, transform .18s ease, background .18s ease;
}
.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.back-to-top:hover { background: var(--soft); }
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; padding-top: 26px; }
  .hero-title-viewport { width: min(100%, 720px); }
  .hero-description { max-width: 700px; }
  .cover { width: min(78%, 440px); justify-self: center; transform: none; }
  .topbar-inner { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }
  aside { position: relative; top: auto; max-height: none; border-right: 0; padding-right: 0; }
  .book { padding: 22px 18px; }
  h2 { font-size: 1.62rem; }
}
@media (max-width: 560px) {
  .hero { padding-inline: 16px; gap: 24px; }
  .hero-title-viewport { width: 100%; margin-left: 0; }
  .hero-description { margin-top: 12px; padding-left: 12px; }
  .cover { width: min(92%, 400px); }
}
