/* =========================================================
   웹북 리더기 스타일시트 - 서버 없이 만드는 나만의 웹 카카오톡 PC
   ========================================================= */
:root {
  --accent: #FEE500;
  --accent-deep: #381E1F;
  --accent-border: #EBD200;

  --bg: #F7F8FA;
  --paper: #FFFFFF;
  --sidebar-bg: #FFFFFF;
  --surface-sub: #F3F5F8;
  --border: #E5E8EC;

  --text: #1B1E23;
  --text-secondary: #4E5663;
  --text-muted: #848D9A;

  --code-bg: #1E222A;
  --code-text: #E6EDF3;
  --inline-code-bg: #F0F2F5;
  --inline-code-text: #C92A2A;

  --callout-tip-bg: #FFFBE6;
  --callout-tip-border: #F5C400;
  --callout-warn-bg: #FFF4F0;
  --callout-warn-border: #FF6B4A;
  --callout-info-bg: #EFF6FF;
  --callout-info-border: #3B82F6;

  --font-size: 16px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.08);
}

/* 세피아 (눈 편한 전자책 테마) */
body[data-theme="sepia"] {
  --bg: #EFE8D8;
  --paper: #FBF7EE;
  --sidebar-bg: #F5EFE0;
  --surface-sub: #EFE7D5;
  --border: #DFD5BF;
  --text: #2F261B;
  --text-secondary: #5C4E3C;
  --text-muted: #8C7C65;
  --inline-code-bg: #EAE1CE;
  --inline-code-text: #9C3618;
  --callout-tip-bg: #F8F0D4;
}

/* 다크 모드 */
body[data-theme="dark"] {
  --bg: #111317;
  --paper: #181B21;
  --sidebar-bg: #14171C;
  --surface-sub: #21252D;
  --border: #2B303A;
  --text: #E9ECEF;
  --text-secondary: #ADB5BD;
  --text-muted: #7C8594;
  --code-bg: #0D1016;
  --inline-code-bg: #272C35;
  --inline-code-text: #FF8787;
  --callout-tip-bg: rgba(254, 229, 0, 0.09);
  --callout-tip-border: #D9B600;
  --callout-warn-bg: rgba(255, 107, 74, 0.12);
  --callout-info-bg: rgba(59, 130, 246, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: transparent;
}

[hidden] {
  display: none !important;
}

/* =========================================================
   상단 리더기 툴바
   ========================================================= */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 58px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  gap: 12px;
  z-index: 40;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.book-mini-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-deep);
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.topbar-title-group {
  min-width: 0;
}
.topbar-book-title {
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-chapter-label {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-box input {
  width: 190px;
  padding: 6px 12px 6px 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-sub);
  font-size: 12.5px;
  outline: none;
  transition: width 0.18s, border-color 0.15s;
}
.search-box input:focus {
  width: 240px;
  border-color: var(--accent-border);
}
.search-icon {
  position: absolute;
  left: 10px;
  font-size: 12px;
  pointer-events: none;
  opacity: 0.65;
}

.tb-btn {
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--surface-sub);
  border: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.14s, border-color 0.14s;
}
.tb-btn:hover {
  border-color: var(--accent-border);
}
.tb-btn.active {
  background: var(--accent);
  color: var(--accent-deep);
  border-color: var(--accent-border);
}
.tb-btn-primary {
  background: var(--accent);
  color: var(--accent-deep);
  border-color: var(--accent-border);
  font-weight: 700;
}
.tb-btn-primary:hover {
  filter: brightness(0.96);
}

.progress-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: transparent;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #FEE500, #F59F00);
  transition: width 0.2s ease-out;
}

/* =========================================================
   메인 2단 리더 레이아웃 (목차 사이드바 + 본문 페이지)
   ========================================================= */
.reader-layout {
  display: flex;
  padding-top: 58px;
  min-height: 100vh;
}

.toc-sidebar {
  position: fixed;
  top: 58px;
  left: 0;
  bottom: 0;
  width: 292px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 30;
  transition: transform 0.22s ease;
}

.toc-header {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.toc-progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 7px;
}
.toc-bar {
  height: 6px;
  background: var(--surface-sub);
  border-radius: 999px;
  overflow: hidden;
}
.toc-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s;
}

.toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 20px;
  list-style: none;
}

.toc-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 3px;
  transition: background 0.14s;
}
.toc-item:hover {
  background: var(--surface-sub);
}
.toc-item.active {
  background: var(--callout-tip-bg);
  box-shadow: inset 3px 0 0 var(--accent-deep);
}
body[data-theme="dark"] .toc-item.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.toc-num {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-sub);
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-top: 1px;
}
.toc-item.active .toc-num {
  background: var(--accent);
  color: var(--accent-deep);
}

.toc-text {
  flex: 1;
  min-width: 0;
}
.toc-title {
  display: block;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.38;
}
.toc-sub {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.toc-marks {
  display: flex;
  gap: 3px;
  font-size: 12px;
  flex-shrink: 0;
}

.toc-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-sub);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.live-app-link {
  display: block;
  text-align: center;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-deep);
  font-size: 12.5px;
  font-weight: 800;
  text-decoration: none;
}
.live-app-link:hover {
  filter: brightness(0.96);
}
.toc-shortcut-hint {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

/* 본문 읽기 영역 */
.reader-main {
  flex: 1;
  margin-left: 292px;
  padding: 32px 28px 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.book-sheet {
  width: 100%;
  max-width: 820px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 46px 52px;
  box-shadow: var(--shadow-md);
  font-size: var(--font-size);
  line-height: 1.85;
}

/* =========================================================
   표지 페이지 (Cover)
   ========================================================= */
.cover-hero {
  background: linear-gradient(135deg, #FEE500 0%, #FFD400 55%, #FFC300 100%);
  color: #2B1819;
  border-radius: 18px;
  padding: 44px 40px;
  position: relative;
  overflow: hidden;
  margin-bottom: 32px;
  box-shadow: 0 12px 30px rgba(254, 229, 0, 0.25);
}
.cover-badge {
  display: inline-block;
  background: #381E1F;
  color: #FEE500;
  font-size: 11.5px;
  font-weight: 800;
  padding: 5px 12px;
  border-radius: 999px;
  letter-spacing: 0.4px;
  margin-bottom: 16px;
}
.cover-hero h1 {
  font-size: 2.15em;
  line-height: 1.25;
  font-weight: 900;
  letter-spacing: -0.8px;
  margin-bottom: 14px;
  color: #1F1213;
}
.cover-subtitle {
  font-size: 1.02em;
  line-height: 1.6;
  color: #3D2526;
  max-width: 580px;
  margin-bottom: 24px;
  font-weight: 500;
}
.cover-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 26px;
}
.cover-chip {
  background: rgba(56, 30, 31, 0.1);
  color: #2B1819;
  font-size: 12.5px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 8px;
}
.cover-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.btn-cover-start {
  background: #381E1F;
  color: #FEE500;
  font-size: 14.5px;
  font-weight: 800;
  padding: 12px 24px;
  border-radius: 12px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-cover-start:hover {
  background: #241314;
}
.btn-cover-sub {
  background: rgba(255, 255, 255, 0.72);
  color: #2B1819;
  font-size: 14px;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 12px;
  text-decoration: none;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 20px;
}
.chapter-card {
  text-align: left;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-sub);
  transition: transform 0.14s, border-color 0.14s;
}
.chapter-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-border);
}
.chapter-card-kicker {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.chapter-card-title {
  font-size: 14.5px;
  font-weight: 800;
  margin-bottom: 4px;
  line-height: 1.38;
}
.chapter-card-desc {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* =========================================================
   본문 타이포그래피 & 요소
   ========================================================= */
.chapter-kicker {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  color: var(--accent-deep);
  background: var(--accent);
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 12px;
}

.chapter-title {
  font-size: 1.85em;
  line-height: 1.32;
  font-weight: 900;
  letter-spacing: -0.6px;
  margin-bottom: 10px;
}

.chapter-lead {
  font-size: 1.03em;
  color: var(--text-secondary);
  padding-bottom: 22px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.chapter-body h2 {
  font-size: 1.32em;
  font-weight: 800;
  margin: 34px 0 12px;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chapter-body h2::before {
  content: "";
  width: 4px;
  height: 1.05em;
  border-radius: 999px;
  background: var(--accent);
  flex-shrink: 0;
}

.chapter-body h3 {
  font-size: 1.08em;
  font-weight: 800;
  margin: 22px 0 8px;
  color: var(--text);
}

.chapter-body p {
  margin-bottom: 15px;
}

.chapter-body ul,
.chapter-body ol {
  margin: 10px 0 18px 22px;
}
.chapter-body li {
  margin-bottom: 7px;
}

.chapter-body code:not(pre code) {
  background: var(--inline-code-bg);
  color: var(--inline-code-text);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.88em;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
}

/* 콜아웃 박스 */
.callout {
  border-radius: 14px;
  padding: 16px 18px;
  margin: 20px 0;
  border-left: 4px solid var(--callout-tip-border);
  background: var(--callout-tip-bg);
  font-size: 0.94em;
}
.callout.warn {
  background: var(--callout-warn-bg);
  border-left-color: var(--callout-warn-border);
}
.callout.info {
  background: var(--callout-info-bg);
  border-left-color: var(--callout-info-border);
}
.callout-title {
  font-weight: 800;
  margin-bottom: 6px;
  display: block;
}

/* 비교 테이블 */
.book-table-wrap {
  overflow-x: auto;
  margin: 18px 0 22px;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.book-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
}
.book-table th,
.book-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.book-table th {
  background: var(--surface-sub);
  font-weight: 800;
}
.book-table tr:last-child td {
  border-bottom: none;
}

/* 코드 블록 + 복사 버튼 */
.code-block {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 14px;
  overflow: hidden;
  margin: 18px 0 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 12px;
  color: #9BA3B0;
}
.code-copy-btn {
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: #E6EDF3;
  font-size: 11.5px;
  font-weight: 600;
}
.code-copy-btn:hover {
  background: var(--accent);
  color: #191919;
}
.code-block pre {
  padding: 16px 18px;
  overflow-x: auto;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 0.85em;
  line-height: 1.6;
}

/* SVG 다이어그램 카드 */
.diagram-card {
  background: var(--surface-sub);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin: 22px 0;
  text-align: center;
}
.diagram-card svg {
  max-width: 100%;
  height: auto;
}
.diagram-caption {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 10px;
}

/* 인터랙티브 체크리스트 (8장) */
.checklist {
  list-style: none !important;
  margin: 16px 0 !important;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.checklist li {
  margin: 0;
}
.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--surface-sub);
  border: 1px solid var(--border);
  cursor: pointer;
}
.check-row input {
  margin-top: 4px;
  width: 17px;
  height: 17px;
  accent-color: #381E1F;
}
.check-row.checked span {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* 하단 이전/다음 장 네비게이션 */
.chapter-pager {
  width: 100%;
  max-width: 820px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 22px;
}
.pager-btn {
  padding: 16px 20px;
  border-radius: 14px;
  background: var(--paper);
  border: 1px solid var(--border);
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.14s, transform 0.12s;
}
.pager-btn:hover {
  border-color: var(--accent-border);
  transform: translateY(-1px);
}
.pager-btn.next {
  text-align: right;
}
.pager-dir {
  display: block;
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 3px;
}
.pager-title {
  display: block;
  font-size: 14.5px;
  font-weight: 800;
}

/* 검색 결과 오버레이 */
.search-results-panel {
  position: fixed;
  top: 64px;
  right: 18px;
  width: min(380px, calc(100vw - 36px));
  max-height: 70vh;
  overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  z-index: 50;
  padding: 10px;
}
.search-hit-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  display: block;
}
.search-hit-item:hover {
  background: var(--surface-sub);
}
.search-hit-item strong {
  display: block;
  font-size: 13px;
  margin-bottom: 3px;
}
.search-hit-item p {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.45;
}
.search-hit-item mark {
  background: var(--accent);
  color: #191919;
  padding: 0 2px;
  border-radius: 3px;
}

/* 모바일 드로어 백드롭 */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 25;
}
.mobile-only {
  display: none;
}

@media (max-width: 960px) {
  .mobile-only {
    display: inline-flex;
  }
  .toc-sidebar {
    transform: translateX(-100%);
  }
  .toc-sidebar.open {
    transform: translateX(0);
  }
  .reader-main {
    margin-left: 0;
    padding: 20px 14px 64px;
  }
  .book-sheet {
    padding: 28px 22px;
    border-radius: 16px;
  }
  .chapter-grid {
    grid-template-columns: 1fr;
  }
  .search-box {
    display: none;
  }
}

/* =========================================================
   전체 책 PDF 인쇄 모드 (@media print)
   ========================================================= */
.print-all-container {
  display: none;
}

@media print {
  body {
    background: #FFFFFF !important;
    color: #111111 !important;
  }
  .topbar,
  .toc-sidebar,
  .drawer-backdrop,
  .search-results-panel,
  .reader-layout {
    display: none !important;
  }
  .print-all-container {
    display: block !important;
  }
  .print-chapter {
    page-break-after: always;
    padding: 12mm 6mm;
    font-size: 11pt;
    line-height: 1.7;
  }
  .print-chapter:last-child {
    page-break-after: auto;
  }
  .code-copy-btn {
    display: none !important;
  }
  .code-block {
    background: #F4F5F7 !important;
    color: #191919 !important;
    border: 1px solid #D0D7DE !important;
  }
  .code-head {
    background: #E9ECEF !important;
    color: #333 !important;
  }
}
