:root {
  --bg: #f6f1e9;
  --bg-card: #fffdf9;
  --ink: #2a2420;
  --ink-soft: #6b5f54;
  --accent: #8a6d3b;
  --line: #e4dbc9;
  --shadow: 0 12px 30px rgba(40, 30, 15, 0.12);
  --header-bg: rgba(246, 241, 233, 0.92);
  --mark-bg: rgba(138, 109, 59, 0.28);
  --ad-dev-bg: rgba(138, 109, 59, 0.04);
  --radius: 14px;
  --font-size: 17px;
}

body.dark {
  --bg: #1c1815;
  --bg-card: #262019;
  --ink: #ece4d8;
  --ink-soft: #a89a86;
  --accent: #d9b872;
  --line: #3a332a;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  --header-bg: rgba(28, 24, 21, 0.92);
  --mark-bg: rgba(217, 184, 114, 0.32);
  --ad-dev-bg: rgba(217, 184, 114, 0.08);
}

.fs-sm { --font-size: 15px; }
.fs-md { --font-size: 17px; }
.fs-lg { --font-size: 20px; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

#app {
  min-height: 100vh;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

/* ── 공통 헤더 ───────────────────────────────────────── */

.top-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--header-bg);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.btn-icon {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: none;
  color: var(--ink-soft);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.btn-icon:hover { background: var(--bg-card); color: var(--ink); }

.top-header .brand {
  font-family: "Noto Serif KR", serif;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
}

.back-btn {
  display: inline-block;
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
}
.back-btn:hover { background: var(--bg-card); }

/* ── 목차(TOC) ───────────────────────────────────────── */

.toc-wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 36px 20px 80px;
}

.toc-title {
  font-family: "Noto Serif KR", serif;
  font-size: 2.1rem;
  font-weight: 700;
  margin: 8px 0 6px;
}

.toc-subtitle {
  color: var(--ink-soft);
  font-size: 1rem;
  margin: 0 0 10px;
}

.toc-intro {
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.6;
  margin: 0 0 32px;
  max-width: 56ch;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.chapter-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform 0.15s ease;
}
.chapter-card:hover { transform: translateY(-3px); }

.chapter-card .thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: var(--line);
}

.chapter-card .card-body {
  padding: 14px 16px 16px;
}

.chapter-card .card-index {
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.05em;
}

.chapter-card .card-title {
  font-family: "Noto Serif KR", serif;
  font-size: 1.08rem;
  font-weight: 600;
  margin: 4px 0 3px;
}

.chapter-card .card-subtitle {
  font-size: 0.84rem;
  color: var(--ink-soft);
  line-height: 1.4;
  margin: 0 0 8px;
}

.chapter-card .card-meta {
  font-size: 0.76rem;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

/* ── 리딩 뷰 ────────────────────────────────────────── */

.reader-wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 20px 100px;
}

.reader-hero {
  margin: 24px 0 8px;
}

.reader-hero figure {
  margin: 0;
}

.reader-hero img {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: block;
  background: var(--line);
}

.reader-hero figcaption {
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-top: 10px;
}

.reader-meta {
  text-align: center;
  margin: 28px 0 4px;
}

.reader-meta .eyebrow {
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.reader-title {
  font-family: "Noto Serif KR", serif;
  font-size: 1.9rem;
  font-weight: 700;
  margin: 8px 0 6px;
}

.reader-subtitle {
  font-size: 1.02rem;
  color: var(--ink-soft);
  margin: 0 0 6px;
}

.reader-artist {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.reader-body {
  margin-top: 32px;
  font-size: var(--font-size);
  line-height: 1.95;
  transition: font-size 0.15s ease;
}

.reader-body .lead {
  font-family: "Noto Serif KR", serif;
  font-size: 1.22em;
  font-weight: 600;
  line-height: 1.6;
  margin: 0 0 26px;
  color: var(--ink);
}

.reader-body p {
  margin: 0 0 22px;
  word-break: keep-all;
}

.reader-body strong {
  color: var(--accent);
  font-weight: 700;
}

.reader-body em {
  font-style: italic;
  color: var(--ink);
}

.reader-body mark {
  background: linear-gradient(to bottom, transparent 62%, var(--mark-bg) 62%);
  color: inherit;
  padding: 0 1px;
}

.detail-figure figcaption strong { color: var(--accent); font-weight: 700; }
.detail-figure figcaption em { font-style: italic; }

.reader-body .section-heading {
  font-family: "Noto Serif KR", serif;
  font-size: 1.12em;
  font-weight: 700;
  color: var(--accent);
  margin: 40px 0 16px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.reader-body .section-heading:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.detail-figure {
  margin: 8px 0 28px;
}

.detail-figure img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
  box-shadow: var(--shadow);
  background: var(--line);
}

.detail-figure figcaption {
  font-size: 0.82rem;
  color: var(--ink-soft);
  text-align: center;
  margin-top: 8px;
  line-height: 1.5;
}

.link-card {
  display: flex;
  margin: 24px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, transform 0.2s;
}

.link-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.link-card-thumb {
  flex-shrink: 0;
  width: 130px;
  height: 100px;
  background-color: var(--line);
  background-size: cover;
  background-repeat: no-repeat;
}

.link-card-content {
  flex: 1;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.link-card-label {
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 4px;
}

.link-card-title {
  font-family: "Noto Serif KR", serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-card-desc {
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (max-width: 480px) {
  .link-card-thumb { width: 96px; height: 96px; }
  .link-card-content { padding: 10px 14px; }
}

.ad-slot {
  margin: 28px 0;
  text-align: center;
  overflow: hidden;
}

.ad-slot::before {
  content: "AD";
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  opacity: 0.55;
  margin-bottom: 8px;
}

.ad-slot-dev {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 18px 12px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  background: var(--ad-dev-bg);
}

.ad-slot-dev::before {
  content: "";
  margin: 0;
}

.nav-footer {
  display: flex;
  gap: 12px;
  margin-top: 48px;
  border-top: 1px solid var(--line);
  padding-top: 24px;
}

.nav-link {
  flex: 1;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px 18px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  min-width: 0;
}

.nav-link .nav-dir {
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 700;
}

.nav-link .nav-title {
  font-family: "Noto Serif KR", serif;
  font-size: 1rem;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-link.next { text-align: right; }
.nav-link.toc-link { flex: none; width: 56px; text-align: center; }

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 36px;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--bg-card);
  color: inherit;
  text-decoration: none;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  border: 1px solid transparent;
}

a.page-btn:hover { border-color: var(--accent); }

.page-btn.active {
  background: var(--accent);
  color: var(--bg-card);
  font-weight: 700;
  box-shadow: none;
}

.page-btn.disabled {
  opacity: 0.35;
  box-shadow: none;
}

.page-btn.ellipsis {
  background: transparent;
  box-shadow: none;
}

@media (max-width: 480px) {
  .toc-title { font-size: 1.7rem; }
  .reader-title { font-size: 1.5rem; }
}
