/* =====================================================================
   E-Book 서재 스타일 (v1.7 디자인 개편)
   방향: "종이와 잉크" — 따뜻한 미색 바탕, 잉크 남색, 바랜 금색 포인트,
         제목은 명조(Noto Serif KR), 본문·버튼은 Pretendard
   색은 모두 아래 변수(토큰)로만 씁니다. 어두운 화면은 변수 값만 바꿉니다.
   관리자 화면은 항상 밝은 화면(admin/index.html의 data-theme="light")입니다.
   ===================================================================== */
:root {
  --ink: #1e2a3a;            /* 헤더 바탕 (잉크 남색) */
  --ink-2: #2a3a4e;
  --on-ink: #f7f3ec;         /* 헤더 위 글자 */
  --on-ink-muted: #c9c0b0;
  --gold: #c9a86a;           /* 포인트: 선·진행 막대·책갈피 */
  --gold-text: #8a6a3a;      /* 금색 계열 글자 (밝은 바탕용) */

  --bg: #f7f3ec;             /* 종이색 바탕 */
  --card-bg: #ffffff;
  --surface-2: #efe9df;      /* 옅은 채움 (버튼 hover 등) */
  --border: #e6dfd3;
  --border-strong: #d3c8b6;
  --text: #1e2a3a;
  --text-muted: #7d766b;

  --primary: #1e2a3a;        /* 기본 버튼 */
  --primary-light: #3a4d63;
  --on-primary: #ffffff;
  --accent: #b08a4e;         /* 강조 버튼 (보내기·추가 등) */
  --on-accent: #ffffff;
  --danger: #b03a2e;
  --success: #2f7a4a;

  --frame-bg: #e6e0d5;       /* 책이 놓이는 바탕 */
  --page-shadow: rgba(30, 42, 58, 0.22);
  --page-filter: none;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(30, 42, 58, 0.05), 0 4px 14px rgba(30, 42, 58, 0.05);
  --shadow-hover: 0 10px 28px rgba(30, 42, 58, 0.14);

  --serif: "Noto Serif KR", "Nanum Myeongjo", "Batang", serif;
  --sans: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "맑은 고딕", sans-serif;
  color-scheme: light;
}

/* 어두운 화면: 독자가 직접 고른 경우 */
:root[data-theme="dark"] {
  --ink: #0f141b;
  --ink-2: #18202a;
  --on-ink: #ece6da;
  --on-ink-muted: #a39b8e;
  --gold-text: #d8bc85;
  --bg: #12161c;
  --card-bg: #1a2029;
  --surface-2: #232b36;
  --border: #2c3542;
  --border-strong: #3a4555;
  --text: #ece6da;
  --text-muted: #a39b8e;
  --primary: #d8bc85;
  --primary-light: #e6cfa0;
  --on-primary: #12161c;
  --accent: #c9a86a;
  --on-accent: #12161c;
  --danger: #e07a6e;
  --success: #6cc08b;
  --frame-bg: #0b0e12;
  --page-shadow: rgba(0, 0, 0, 0.6);
  --page-filter: brightness(0.9);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
  --shadow-hover: 0 10px 28px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}
/* 어두운 화면: 고르지 않았고 기기 설정이 어두운 화면인 경우 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #0f141b;
    --ink-2: #18202a;
    --on-ink: #ece6da;
    --on-ink-muted: #a39b8e;
    --gold-text: #d8bc85;
    --bg: #12161c;
    --card-bg: #1a2029;
    --surface-2: #232b36;
    --border: #2c3542;
    --border-strong: #3a4555;
    --text: #ece6da;
    --text-muted: #a39b8e;
    --primary: #d8bc85;
    --primary-light: #e6cfa0;
    --on-primary: #12161c;
    --accent: #c9a86a;
    --on-accent: #12161c;
    --danger: #e07a6e;
    --success: #6cc08b;
    --frame-bg: #0b0e12;
    --page-shadow: rgba(0, 0, 0, 0.6);
    --page-filter: brightness(0.9);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
    --shadow-hover: 0 10px 28px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  word-break: keep-all;
}

a { color: inherit; }
button, input, select, textarea { font-family: inherit; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* 선 아이콘 (글자색을 따라감) */
.ic {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}

/* 아이콘만 있는 버튼 */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn.on-ink { color: var(--on-ink); }
.icon-btn.on-ink:hover { background: rgba(255, 255, 255, 0.1); }
.icon-btn:focus-visible, .tb-btn:focus-visible, .chip:focus-visible, .seg-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ===== 공통 헤더 (관리자 화면에서 사용) ===== */
header.site-header {
  background: var(--ink);
  color: var(--on-ink);
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
header.site-header h1 {
  font-family: var(--serif);
  font-size: 19px;
  margin: 0;
  font-weight: 700;
}
header.site-header a.header-link {
  color: var(--on-ink);
  text-decoration: none;
  font-size: 13px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  padding: 6px 14px;
  transition: background 0.15s;
}
header.site-header a.header-link:hover { background: rgba(255, 255, 255, 0.1); }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

/* =====================================================================
   목록(서재) 화면
   ===================================================================== */
.library-header {
  background: var(--ink);
  color: var(--on-ink);
}
.lh-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 24px 24px;
}
.lh-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.lh-eyebrow {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--gold);
}
.lh-main {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.lh-title {
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.25;
  margin: 0;
  letter-spacing: -0.5px;
}
.lh-sub {
  font-family: var(--serif);
  font-size: 15px;
  color: var(--on-ink-muted);
  margin: 6px 0 0;
}
.lh-rule {
  display: block;
  width: 48px;
  height: 2px;
  background: var(--gold);
  margin-top: 20px;
}
.lh-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(340px, 100%);
  padding: 0 6px 0 16px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(247, 243, 236, 0.25);
  background: rgba(247, 243, 236, 0.08);
  color: var(--on-ink-muted);
  transition: border-color 0.15s, background 0.15s;
}
.lh-search:focus-within { border-color: var(--gold); background: rgba(247, 243, 236, 0.12); }
.lh-search input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--on-ink);
  font-size: 15px;
}
.lh-search input::placeholder { color: var(--on-ink-muted); }
.lh-search input::-webkit-search-cancel-button { display: none; }
.lh-search-clear {
  border: none;
  background: transparent;
  color: var(--on-ink-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.lh-search-clear .ic { width: 16px; height: 16px; }

main.library { padding-top: 24px; }

.section-title {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 12px;
}

/* 최근 읽은 책 */
.recent-section { margin-bottom: 26px; }
.recent-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.recent-item {
  flex: 0 0 240px;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  scroll-snap-align: start;
  transition: border-color 0.15s;
}
.recent-item:hover { border-color: var(--gold); }
.recent-thumb {
  flex: 0 0 48px;
  height: 64px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-2);
}
.recent-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.recent-info { min-width: 0; flex: 1; }
.recent-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.recent-page { margin: 2px 0 6px; font-size: 12px; color: var(--gold-text); }

/* 필터 (책종류 · 카테고리) */
.filter-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px 8px;
  margin-bottom: 18px;
}
.filter-toggle { display: none; }
.facet-group { margin-bottom: 10px; }
.facet-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}
.facet-title { font-size: 13px; font-weight: 700; }
.facet-all, .facet-none {
  border: none;
  background: none;
  padding: 2px 0;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--gold-text);
}
.facet-none { color: var(--text-muted); }
.facet-all:hover, .facet-none:hover { text-decoration: underline; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border-strong);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { border-color: var(--primary-light); }
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

/* 결과 수 · 정렬 */
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 12px;
  scroll-margin-top: 12px;
}
.result-count { font-size: 13px; color: var(--text-muted); }
.sort-select select {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
}

/* 책 카드 */
.grid-viewport { overflow: hidden; touch-action: pan-y; }
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: 22px;
}
.book-grid.slide-from-right { animation: slideFromRight 0.28s ease-out; }
.book-grid.slide-from-left { animation: slideFromLeft 0.28s ease-out; }
@keyframes slideFromRight { from { transform: translateX(36px); opacity: 0.2; } to { transform: none; opacity: 1; } }
@keyframes slideFromLeft { from { transform: translateX(-36px); opacity: 0.2; } to { transform: none; opacity: 1; } }

.book-card {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s;
}
.book-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-3px); border-color: var(--border-strong); }
.book-card .thumb-wrap {
  position: relative;
  aspect-ratio: 3 / 4;
  background: var(--surface-2);
  overflow: hidden;
}
.book-card .thumb-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-fallback {
  position: absolute;
  inset: auto 12px 12px 12px;
  font-family: var(--serif);
  font-size: 15px;
  color: var(--text-muted);
}
.view-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(20, 26, 36, 0.66);
  color: #f7f3ec;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
}
.view-badge .ic { width: 13px; height: 13px; }
.book-card .book-info { padding: 12px 14px 14px; flex: 1; display: flex; flex-direction: column; }
.book-card .book-type {
  margin: 0 0 4px;
  font-size: 11.5px;
  color: var(--gold-text);
  letter-spacing: 0.2px;
}
.book-card .book-title {
  font-family: var(--serif);
  font-size: 15.5px;
  font-weight: 700;
  margin: 0 0 4px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-card .book-author { font-size: 13px; color: var(--text-muted); margin: 0; }
.book-card .book-categories { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.book-card .cat-tag {
  font-size: 11px;
  background: var(--surface-2);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 999px;
}

/* 이어 읽기 진행 막대 */
.read-progress { margin-top: auto; padding-top: 10px; }
.read-progress-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
}
.read-progress-bar span { display: block; height: 100%; background: var(--gold); border-radius: 2px; }
.read-progress-text {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 5px;
  font-size: 11.5px;
  color: var(--gold-text);
}
.read-progress-text .ic { width: 13px; height: 13px; }

.library .empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 0;
  font-size: 14px;
}

/* 페이지 번호 */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 32px;
  flex-wrap: wrap;
}
.pagination button {
  min-width: 38px;
  height: 38px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}
.pagination button:hover:not(:disabled) { border-color: var(--primary-light); }
.pagination button.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.pagination button:disabled { opacity: 0.35; cursor: default; }
.pagination .page-gap { color: var(--text-muted); padding: 0 2px; }
.swipe-hint { text-align: center; font-size: 12px; color: var(--text-muted); margin: 10px 0 0; }

.library-footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 24px 32px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}
.footer-admin { color: var(--text-muted); text-decoration: none; }
.footer-admin:hover { text-decoration: underline; }

/* =====================================================================
   뷰어 화면: 화면 전체를 채우는 고정 리더
   ===================================================================== */
html:has(body.reader-body),
body.reader-body {
  height: 100%;
  overflow: hidden;
}
html { height: 100%; }

.reader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.reader-top {
  background: var(--ink);
  color: var(--on-ink);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  z-index: 30;
}
.reader-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--on-ink);
  text-decoration: none;
  font-size: 13.5px;
  padding: 7px 10px 7px 6px;
  border-radius: var(--radius-sm);
  flex: 0 0 auto;
}
.reader-back:hover { background: rgba(255, 255, 255, 0.1); }
.reader-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
  flex: 1;
}
.reader-top h1 {
  font-family: var(--serif);
  font-size: 17px;
  margin: 0;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-top .viewer-meta { font-size: 12.5px; color: var(--on-ink-muted); white-space: nowrap; }

.reader-main {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

/* ---- 공통 버튼 ---- */
.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--primary);
  color: var(--on-primary);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13.5px;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.tb-btn:hover:not(:disabled) { background: var(--primary-light); }
.tb-btn:disabled { opacity: 0.45; cursor: default; }
.tb-btn.primary { background: var(--accent); color: var(--on-accent); }
.tb-btn.primary:hover:not(:disabled) { filter: brightness(1.06); background: var(--accent); }
.tb-btn.ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.tb-btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.tb-btn.wide { width: 100%; justify-content: flex-start; }
.tb-btn .ic { width: 18px; height: 18px; }
.tb-btn.is-marked { border-color: var(--gold); color: var(--gold-text); }
.tb-btn.is-marked .ic { fill: var(--gold); stroke: var(--gold); }

/* ===== PC 좌측 세로 툴바 ===== */
.toolbar-side {
  flex: 0 0 216px;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  padding: 16px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.ts-group { display: flex; flex-direction: column; gap: 8px; }
.ts-label { font-size: 12px; color: var(--text-muted); font-weight: 600; display: flex; justify-content: space-between; }
.ts-hint { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.ts-nav { display: flex; align-items: center; gap: 6px; }
.ts-nav .icon-btn { border: 1px solid var(--border-strong); }
.ts-page { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12.5px; color: var(--text-muted); }
.ts-page input[type="number"] {
  width: 100%;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 14px;
  background: var(--card-bg);
  color: var(--text);
}

/* 한 장 / 두 장 선택 */
.seg { display: flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px 0;
  font-size: 13px;
  cursor: pointer;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border-strong); }
.seg-btn.active { background: var(--primary); color: var(--on-primary); }

/* ---- 확대/축소 · 진행 막대 슬라이더 ---- */
.zoom-slider,
.reader-progress input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  outline: none;
  cursor: pointer;
}
.zoom-slider::-webkit-slider-thumb,
.reader-progress input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--card-bg);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}
.zoom-slider::-moz-range-thumb,
.reader-progress input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--card-bg);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

/* ===== 휴대폰 상단 툴바 (PC에서는 숨김) ===== */
.toolbar-mobile { display: none; }
.more-wrap { position: relative; }
.more-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  padding: 6px;
  z-index: 60;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 11px 10px;
  font-size: 14px;
  text-align: left;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }
.menu-zoom {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 6px 8px 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.menu-zoom > span:first-child { flex: 1; }
.menu-zoom .icon-btn { border: 1px solid var(--border-strong); width: 36px; height: 36px; }
.menu-zoom .m-zoom-level { min-width: 46px; text-align: center; font-size: 13px; color: var(--text-muted); }

/* ===== 책이 놓이는 영역 ===== */
.reader-stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--frame-bg);
}
.flipbook-outer {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  /* 예전에는 align-items:center; justify-content:center로 가운데 정렬했는데,
     확대해서 내용이 프레임보다 커지면 이 방식이 "위/왼쪽으로 넘친 부분"을
     스크롤로도 우클릭 드래그로도 절대 닿을 수 없게 만드는 잘 알려진 flexbox
     동작이 있습니다(넘친 만큼을 상하좌우로 똑같이 나눠 밀어내는데, 스크롤
     컨테이너는 원점보다 위/왼쪽으로는 스크롤할 수 없기 때문). 대신 아래
     .flipbook-scale-wrap에 margin:auto를 줘서, 여백이 남을 땐 그대로
     가운데 정렬되지만 넘칠 땐 자동으로 원점(왼쪽 위)부터 정상적으로
     스크롤 가능한 상태가 되도록 했습니다. */
  background: var(--frame-bg);
  overflow: auto;
  user-select: none;
  min-width: 0;
  min-height: 0;
  padding: 18px 16px;
  /* 이 요소는 <main>이라 위의 공통 main 규칙(가운데 정렬·최대 폭)이 걸리지 않게 되돌립니다. */
  margin: 0;
  max-width: none;
}

/* JS가 확대율에 맞춰 실제 픽셀 크기를 지정하는 래퍼.
   내부 #flipbook은 항상 "원본 크기"로 그려지고, transform:scale로 시각적으로만 축소/확대됩니다.
   이렇게 하면 StPageFlip 라이브러리의 내부 자동 크기 계산에 전혀 기대지 않으므로,
   확대율과 무관하게 크기가 항상 정확합니다. */
.flipbook-scale-wrap {
  flex: 0 0 auto;
  position: relative;
  overflow: hidden;
  margin: auto;
}
/* v1.7: 쪽을 넘길 때 짧게 미끄러지는 효과 */
.flipbook-scale-wrap.page-anim-next { animation: pageInNext 0.22s ease-out; }
.flipbook-scale-wrap.page-anim-prev { animation: pageInPrev 0.22s ease-out; }
@keyframes pageInNext { from { transform: translateX(22px); opacity: 0.35; } to { transform: none; opacity: 1; } }
@keyframes pageInPrev { from { transform: translateX(-22px); opacity: 0.35; } to { transform: none; opacity: 1; } }

#flipbook {
  position: relative;
  transform-origin: top left;
  filter: drop-shadow(0 8px 26px var(--page-shadow));
  /* StPageFlip 라이브러리가 이 요소에 자체적으로 .stf__parent 클래스를 붙이고
     touch-action: pan-y(세로 이동만 허용)를 걸어둡니다. touch-action은 자식이
     느슨하게 풀어도 조상이 더 제한적이면 조상 값이 그대로 적용되는 방식이라,
     .text-layer 등 자식 요소에 auto를 줘도 이 요소(조상) 자체가 막고 있으면
     소용이 없습니다. 라이브러리의 자체 터치 넘김 기능은 쓰지 않으므로
     (v1.7의 손가락 넘김은 viewer.js가 직접 감지), 여기서 완전히 풀어줘도 됩니다. */
  touch-action: auto !important;
}

.pf-page {
  background: #ffffff;
  overflow: hidden;
  position: relative;
}
.pf-page canvas {
  display: block;
  width: 100%;
  height: 100%;
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;
  filter: var(--page-filter); /* 어두운 화면에서는 흰 종이를 살짝 낮춰 눈부심을 줄임 */
}

/* ---- 텍스트 레이어 (형광펜용, 보이지 않는 선택 가능 텍스트) ---- */
.text-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  z-index: 2;
  /* .flipbook-outer에 user-select: none이 걸려 있어서(마우스 드래그 시 프레임 전체가
     끌리는 것을 막기 위함) 그 상속을 여기서 다시 텍스트 선택 가능으로 되돌립니다.
     이게 빠져 있으면 형광펜을 위한 텍스트 드래그 선택 자체가 안 됩니다. */
  user-select: text;
  -webkit-user-select: text;
  /* StPageFlip 라이브러리가 #flipbook에 자체적으로 .stf__parent { touch-action: pan-y }를
     넣는데, 이게 모바일에서 손가락 롱프레스-드래그로 텍스트를 선택하는 제스처를 막습니다.
     텍스트 레이어에서만 이를 다시 풀어줍니다. */
  touch-action: auto;
}
.text-layer span {
  position: absolute;
  color: transparent;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  user-select: text;
  -webkit-user-select: text;
}
.hl-mark {
  position: absolute;
  pointer-events: none;
  mix-blend-mode: multiply;
  border-radius: 2px;
  /* .text-layer(z-index:2)보다 위에 있어야 클릭/탭이 형광펜 표시에 먼저
     닿아서 지우기 동작이 됩니다. 이전에는 이 값이 1이라 text-layer가 항상
     클릭을 먼저 가로채서, 칠해진 부분을 눌러도 지우기가 아니라 새 선택이
     시작되는 버그가 있었습니다. */
  z-index: 3;
}

/* ---- 이전/다음 화살표 ---- */
.corner-arrow {
  position: absolute;
  bottom: 20px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.18);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.94;
  transition: transform 0.12s, opacity 0.12s;
}
.corner-arrow .ic { width: 22px; height: 22px; }
.corner-arrow:hover:not(:disabled) { opacity: 1; transform: scale(1.06); }
.corner-arrow:disabled { opacity: 0.25; cursor: default; }
.corner-arrow-left { left: 20px; }
.corner-arrow-right { right: 20px; }

/* ---- 형광펜 색상 팝업 ---- */
.hl-popup {
  position: absolute;
  display: none;
  gap: 6px;
  background: var(--ink);
  border-radius: 999px;
  padding: 7px 8px 7px 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  z-index: 40;
  align-items: center;
}
.hl-popup.show { display: flex; }
.hl-popup-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  cursor: pointer;
  padding: 0;
}
.hl-popup-remove {
  background: transparent;
  border: none;
  color: var(--on-ink);
  cursor: pointer;
  padding: 2px 4px;
  display: inline-flex;
}
.hl-popup-remove .ic { width: 16px; height: 16px; }

/* ---- 이어 읽기 안내 ---- */
.resume-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 35;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  padding: 8px 8px 8px 14px;
  background: var(--ink);
  color: var(--on-ink);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  font-size: 13.5px;
  white-space: nowrap;
  animation: fadeDown 0.25s ease-out;
}
.resume-banner .ic { color: var(--gold); width: 18px; height: 18px; }
.resume-banner button {
  border: none;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}
.resume-go { background: var(--gold); color: #1e2a3a; font-weight: 600; }
.resume-close { background: transparent; color: var(--on-ink-muted); }
@keyframes fadeDown { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---- 이 쪽 책갈피 표시 (리본) ---- */
.bm-ribbon {
  position: absolute;
  top: 0;
  right: 28px;
  z-index: 15;
  color: var(--gold);
  pointer-events: none;
}
.bm-ribbon .ic { width: 30px; height: 38px; fill: var(--gold); stroke: var(--gold); }
.icon-btn.is-marked { color: var(--gold-text); }
.icon-btn.is-marked .ic { fill: var(--gold); stroke: var(--gold); }

/* ---- 읽은 진행 막대 ---- */
.reader-progress {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px 12px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
}
.reader-progress input[type="range"] { flex: 1; }
.progress-text { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; min-width: 84px; text-align: right; }

#viewer-status {
  text-align: center;
  color: var(--text-muted);
  padding: 8px 0;
  margin: 0;
  font-size: 13px;
  flex: 0 0 auto;
  background: var(--card-bg);
}
#viewer-status:empty { display: none; }

/* ===== 모달 (인쇄 범위 · 책갈피 · 오탈자) ===== */
.print-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.print-modal-backdrop.show { display: flex; }
.print-modal {
  background: var(--card-bg);
  color: var(--text);
  border-radius: var(--radius);
  padding: 24px 26px;
  width: 340px;
  max-width: 92vw;
  box-shadow: var(--shadow-hover);
}
.print-modal h2 { margin: 0 0 14px; font-size: 17px; font-family: var(--serif); }
.print-modal-row { display: flex; gap: 12px; margin-bottom: 12px; }
.print-modal-row label { font-size: 12.5px; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; }
.print-modal-row input {
  width: 100px;
  padding: 7px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  text-align: center;
  background: var(--card-bg);
  color: var(--text);
}
.print-modal-hint { font-size: 12px; color: var(--text-muted); margin: 0 0 16px; }
.print-modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { margin: 0; }

/* 책갈피 목록 */
.bm-modal { width: 400px; max-height: 86vh; display: flex; flex-direction: column; }
.bm-current {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
}
.bm-current-label { font-size: 13px; margin-bottom: 8px; }
.bm-add-row { display: flex; gap: 8px; }
.bm-add-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 16px; /* 휴대폰에서 입력할 때 화면이 확대되는 것 방지 */
}
.bm-add-row input:disabled { opacity: 0.6; }
.bm-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.bm-item { display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.bm-item.current .bm-page { color: var(--gold-text); }
.bm-go {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 12px 4px;
  cursor: pointer;
  font-size: 14px;
}
.bm-go:hover .bm-page { text-decoration: underline; }
.bm-page { font-weight: 700; min-width: 52px; }
.bm-memo { flex: 1; min-width: 0; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm-date { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.bm-del { width: 34px; height: 34px; color: var(--text-muted); }
.bm-del .ic { width: 16px; height: 16px; }
.bm-empty { font-size: 13px; color: var(--text-muted); margin: 8px 0; line-height: 1.6; }
.bm-note-hint { font-size: 11.5px; color: var(--text-muted); margin: 10px 0 0; }

/* 화면에서는 인쇄 영역 숨김 */
#print-area { display: none; }

@media print {
  .reader-top, .toolbar-side, .toolbar-mobile, .reader-stage, #viewer-status,
  .print-modal-backdrop {
    display: none !important;
  }
  body.reader-body, html { overflow: visible !important; height: auto !important; }
  .reader { position: static !important; }
  #print-area {
    display: block !important;
  }
  #print-area .print-page {
    position: relative;
    page-break-after: always;
    width: 100%;
  }
  #print-area .print-page img { width: 100%; display: block; }
  #print-area .print-watermark {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(-32deg);
    font-size: 42px;
    font-weight: 800;
    color: rgba(180, 20, 20, 0.28);
    letter-spacing: 4px;
    text-align: center;
    pointer-events: none;
    white-space: nowrap;
  }
}

/* ===== 관리자 화면 (기능 위주, 단순 스타일) ===== */
.login-box {
  max-width: 320px;
  margin: 80px auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
}

.login-box h2 { margin-top: 0; }

.login-box input[type="password"] {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 12px 0;
  font-size: 14px;
}

.login-box button, .btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
}

.btn.danger { background: var(--danger); }
.btn.secondary { background: #6b7785; }
.btn.small { padding: 5px 10px; font-size: 12px; }

.form-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}

.admin-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.admin-section h2 {
  margin-top: 0;
  font-size: 16px;
  color: var(--primary);
}

.form-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}

.form-row label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="file"] {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

.tag-input-box {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
}

.tag-input-box .tag-chip {
  background: #eef2f8;
  color: var(--primary);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.tag-input-box .tag-chip button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  line-height: 1;
}

.tag-input-box input {
  border: none;
  outline: none;
  flex: 1;
  min-width: 100px;
  font-size: 13px;
  padding: 4px;
}

/* ===== 책종류 / 카테고리 마스터 목록 관리 ===== */
.master-list-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.master-list-block h3 {
  font-size: 13.5px;
  margin: 0 0 8px;
  color: var(--text);
}

.master-add-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.master-add-row input[type="text"] {
  flex: 1;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

.master-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ===== 체크박스 그룹 (등록 폼의 카테고리 선택) ===== */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  cursor: pointer;
}

/* ===== 관리자 도서 목록 필터 ===== */
.admin-filter-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.admin-filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.admin-filter-group-label {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-right: 2px;
}

/* ===== v1.2 관리자: 책종류 순서 · 드래그 정렬 ===== */
.notice-banner {
  background: #fff6e5;
  border: 1px solid #f0c674;
  color: #7a5200;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}
.notice-banner .btn { margin-right: 4px; }

.form-row select {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
}

.type-order-list { list-style: none; margin: 0; padding: 0; }
.type-order-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  font-size: 13px;
}
.type-order-item .row-num { width: 22px; text-align: center; font-weight: 600; color: var(--primary); }
.type-order-item .type-name { flex: 1; font-weight: 600; min-width: 0; }
.type-order-item .type-count { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.type-order-item .type-actions { display: flex; gap: 4px; flex-shrink: 0; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table.admin-table { min-width: 760px; }
.table-scroll table.admin-table th { white-space: nowrap; }

.master-chip-list .tag-chip {
  background: #eef2f8;
  color: var(--primary);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.master-chip-list .tag-chip button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  line-height: 1;
}
table.admin-table .col-handle { width: 36px; text-align: center; }
table.admin-table .col-num { width: 52px; text-align: center; font-weight: 600; color: var(--primary); }

.drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  font-size: 20px;
  line-height: 1;
  color: #8a96a6;
  cursor: grab;
  border-radius: 6px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none; /* 모바일: 손잡이에서만 드래그, 목록 스크롤과 충돌 방지 */
}
.drag-handle:hover { background: #eef2f8; color: var(--primary); }
.drag-handle:active { cursor: grabbing; }

.sortable-ghost { opacity: 0.35; background: #dce8f5 !important; }
.sortable-chosen { background: #f3f7fc; }

.order-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.order-actions .status-msg { margin: 0 auto 0 0; }
.btn:disabled { opacity: 0.4; cursor: default; }

.admin-section.is-dirty,
.master-list-block.is-dirty { border-radius: var(--radius-sm); box-shadow: 0 0 0 2px rgba(217, 142, 58, 0.35); }
.master-list-block.is-dirty { padding: 6px; }

.type-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.type-tab {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}
.type-tab:hover { border-color: var(--primary-light); color: var(--primary); }
.type-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.type-tab .tab-count {
  display: inline-block;
  min-width: 20px;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  font-size: 11.5px;
}
.type-tab.active .tab-count { background: rgba(255, 255, 255, 0.25); }
.type-tab.warn { border-color: #f0c674; color: #7a5200; background: #fff6e5; }
.type-tab.warn.active { background: #d98e3a; border-color: #d98e3a; color: #fff; }

table.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.admin-table th, table.admin-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 6px;
  text-align: left;
  vertical-align: middle;
}

table.admin-table th {
  color: var(--text-muted);
  font-weight: 600;
}

table.admin-table img.thumb-mini {
  width: 40px;
  height: 54px;
  object-fit: cover;
  border-radius: 4px;
  background: #dfe4ea;
}

.progress-wrap {
  background: #e2e6ec;
  border-radius: 6px;
  overflow: hidden;
  height: 10px;
  margin-top: 8px;
  display: none;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.2s;
}

.status-msg {
  font-size: 13px;
  margin-top: 8px;
}

.status-msg.ok { color: var(--success); }
.status-msg.err { color: var(--danger); }

.row-actions button { margin-right: 4px; }

/* =====================================================================
   반응형
   ===================================================================== */
@media (max-width: 640px) {
  header.site-header { padding: 14px 16px; }
  main { padding: 18px 14px 40px; }
  .master-list-grid { grid-template-columns: 1fr; }

  .lh-inner { padding: 18px 16px 20px; }
  .lh-title { font-size: 28px; }
  .lh-sub { font-size: 14px; }
  .lh-search { width: 100%; }
  .lh-rule { margin-top: 16px; }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .book-card .book-info { padding: 10px 11px 12px; }
  .book-card .book-title { font-size: 14.5px; }
  .recent-item { flex-basis: 220px; }
  .library-footer { padding: 16px 16px 28px; }
}

/* 목록 화면 필터: 휴대폰에서는 접었다 펼침 */
@media (max-width: 820px) {
  .filter-panel { padding: 0; }
  .filter-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text);
    padding: 13px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }
  .filter-summary { margin-left: auto; font-weight: 400; color: var(--text-muted); font-size: 13px; }
  .filter-toggle .chev { transition: transform 0.2s; }
  .filter-panel.open .filter-toggle .chev { transform: rotate(180deg); }
  .filter-body { display: none; padding: 0 16px 8px; }
  .filter-panel.open .filter-body { display: block; }
  .chip { padding: 8px 14px; font-size: 13.5px; }
}

/* ===== 뷰어: PC ↔ 휴대폰 툴바 전환 ===== */
@media (min-width: 821px) {
  .toolbar-side { display: flex; }
  .toolbar-mobile { display: none !important; }
}

@media (max-width: 820px) {
  .toolbar-side { display: none; }
  .reader-top { padding: 6px 8px; gap: 6px; }
  .reader-back-text { display: none; }
  .reader-back { padding: 7px; }
  .reader-title-wrap { flex-direction: column; align-items: flex-start; gap: 0; }
  .reader-top h1 { font-size: 15px; max-width: 100%; }
  .reader-top .viewer-meta { font-size: 11.5px; }
  #book-viewcount { display: none; }

  .toolbar-mobile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2px;
    background: var(--card-bg);
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding: 4px 6px;
    flex: 0 0 auto;
    position: relative;
    z-index: 25;
  }
  .toolbar-mobile .icon-btn { width: 40px; height: 40px; }
  .toolbar-mobile .tb-page {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-muted);
  }
  .toolbar-mobile .tb-page input[type="number"] {
    width: 46px;
    padding: 6px 2px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 16px; /* 입력 시 화면 확대 방지 */
    background: var(--card-bg);
    color: var(--text);
  }
  .toolbar-mobile .tb-sep { width: 1px; height: 22px; background: var(--border); flex: 0 0 auto; }

  .flipbook-outer { padding: 12px 10px; }
  .corner-arrow { width: 42px; height: 42px; bottom: 12px; }
  .corner-arrow-left { left: 10px; }
  .corner-arrow-right { right: 10px; }
  .bm-ribbon { right: 16px; }
  .reader-progress { padding: 8px 14px 10px; gap: 10px; }
  .progress-text { min-width: 70px; font-size: 12px; }
  .resume-banner { top: 10px; font-size: 13px; gap: 6px; padding-left: 12px; }
  .resume-banner button { padding: 7px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .book-grid.slide-from-right, .book-grid.slide-from-left,
  .flipbook-scale-wrap.page-anim-next, .flipbook-scale-wrap.page-anim-prev,
  .resume-banner { animation: none; }
  .book-card { transition: none; }
}

/* ===== 오탈자 수정요청 모달 (v1.5) ===== */
.errata-modal {
  width: 440px;
  max-height: 92vh;
  overflow-y: auto;
}
.errata-book {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
  word-break: keep-all;
}
/* 입력창 뒤 화면을 어둡게 막지 않고 그대로 보이게 함 (책장 넘기기·스크롤 가능). 입력창만 클릭을 받음 */
#errata-modal-backdrop.show { background: transparent; pointer-events: none; }
#errata-modal-backdrop .errata-modal {
  pointer-events: auto;
  box-shadow: 0 12px 40px rgba(10, 14, 20, 0.35);
  border: 1px solid var(--border);
}
/* 제목 줄: 잡고 끌어서 입력창 이동 */
.errata-handle {
  margin: -10px -12px 14px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  cursor: move;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.errata-handle h2 { margin: 0 0 2px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.errata-grip { font-size: 11.5px; font-weight: 400; color: var(--text-muted); font-family: var(--sans); }
.errata-modal .print-modal-row { align-items: flex-end; }
.errata-modal .print-modal-row .errata-grow { flex: 1; }
.errata-modal .print-modal-row .errata-grow input { width: 100%; box-sizing: border-box; text-align: left; }
.errata-modal .print-modal-row input,
.errata-modal .errata-field input,
.errata-modal .errata-field textarea {
  font-size: 16px;            /* 모바일에서 입력 시 화면이 확대되는 것을 방지 */
  font-family: inherit;
}
.errata-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.errata-field input,
.errata-field textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
}
.errata-field textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
.errata-field input:focus,
.errata-field textarea:focus,
.errata-modal .print-modal-row input:focus {
  outline: 2px solid var(--gold);
  outline-offset: -1px;
}
.errata-counter { align-self: flex-end; font-size: 11.5px; }
.errata-honey { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.errata-privacy { margin: 0 0 8px; font-size: 11.5px; color: var(--text-muted); }
.errata-notice { min-height: 18px; margin: 0 0 10px; font-size: 13px; }
.errata-notice.error { color: var(--danger); }
.errata-notice.ok { color: var(--success); font-weight: 600; }

/* =====================================================================
   v1.8 은혜나누기 — PC: 오른쪽 패널(360px) / 휴대폰: 아래에서 올라오는 시트
   ===================================================================== */
.cmt-panel {
  flex: 0 0 360px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--card-bg);
  border-left: 1px solid var(--border);
}
.cmt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 10px 18px;
  border-bottom: 1px solid var(--border);
}
.cmt-head h2 { margin: 0; font-family: var(--serif); font-size: 17px; }
.cmt-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 18px 24px; }
.cmt-form { display: flex; flex-direction: column; gap: 8px; padding-bottom: 14px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.cmt-rule { margin: 0; font-size: 12px; color: var(--text-muted); line-height: 1.55; }
.cmt-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 16px; /* 휴대폰에서 입력할 때 화면이 확대되는 것 방지 */
  font-family: inherit;
}
textarea.cmt-input { resize: vertical; min-height: 96px; line-height: 1.55; }
.cmt-input:focus { outline: 2px solid var(--gold); outline-offset: -1px; }
.cmt-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--gold-text);
  font-size: 12.5px;
}
.cmt-chip button, .cmt-quote button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  padding: 2px;
}
.cmt-chip .ic, .cmt-quote .ic { width: 14px; height: 14px; }
.cmt-quote {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  padding: 8px 8px 8px 12px;
  border-left: 3px solid var(--gold);
  background: var(--surface-2);
  font-family: var(--serif);
  font-size: 13.5px;
  line-height: 1.6;
}
.cmt-quote span { flex: 1; }
.cmt-form-foot { display: flex; align-items: center; justify-content: space-between; }
.cmt-counter { font-size: 12px; color: var(--text-muted); }
.cmt-notice { margin: 0; font-size: 13px; }
.cmt-notice:empty { display: none; }
.cmt-notice.error { color: var(--danger); }
.cmt-notice.ok { color: var(--success); }
.cmt-resting { font-size: 14px; color: var(--text-muted); text-align: center; padding: 24px 0; margin: 0; }

.cmt-list { list-style: none; margin: 0; padding: 0; }
.cmt-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.cmt-item-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.cmt-nick { font-weight: 700; font-size: 14px; }
.cmt-date { font-size: 12px; color: var(--text-muted); }
.cmt-page-tag {
  margin-left: auto;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--gold-text);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  cursor: pointer;
}
.cmt-page-tag:hover { border-color: var(--gold); }
.cmt-item-quote {
  margin: 8px 0 0;
  padding: 4px 0 4px 10px;
  border-left: 3px solid var(--gold);
  color: var(--text-muted);
  font-family: var(--serif);
  font-size: 13px;
  line-height: 1.6;
}
.cmt-item-body { margin: 8px 0 0; font-size: 14.5px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.cmt-item-actions { margin-top: 6px; text-align: right; }
.cmt-item-actions button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
}
.cmt-item-actions button:hover:not(:disabled) { text-decoration: underline; }
.cmt-item-actions button:disabled { cursor: default; opacity: 0.6; }
.cmt-empty { font-size: 13px; color: var(--text-muted); text-align: center; padding: 20px 0; margin: 0; }
.cmt-more { width: 100%; justify-content: center; margin-top: 12px; }
.toolbar-side .cmt-open-btn .cmt-count:not(:empty)::before { content: "("; }
.toolbar-side .cmt-open-btn .cmt-count:not(:empty)::after { content: ")"; }
.cmt-mobile-btn { display: none; }
.cmt-backdrop { display: none; }

/* 형광펜 팝업의 [나누기] */
.hl-popup-share {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: var(--on-ink);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}

@media (max-width: 820px) {
  .cmt-mobile-btn {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    border: none;
    background: transparent;
    color: var(--text);
    padding: 4px 2px 4px 6px;
    font-size: 12.5px;
    cursor: pointer;
  }
  .cmt-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 80dvh;
    max-height: 90vh;
    z-index: 90;
    border-left: none;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
    animation: sheetUp 0.22s ease-out;
  }
  .cmt-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 85;
    background: rgba(10, 14, 20, 0.45);
  }
  .cmt-scroll { padding: 12px 16px 24px; }
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .cmt-panel { animation: none; } }

/* =====================================================================
   v1.8 관리자: 이용 통계 · 은혜나누기 관리 (관리자 화면은 항상 밝은 화면)
   ===================================================================== */
.admin-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.admin-nav a {
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text);
}
.admin-nav a:hover { border-color: var(--primary-light); }
.admin-nav .badge {
  display: inline-block;
  min-width: 18px;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  text-align: center;
}
.admin-nav .badge:empty { display: none; }
.admin-section { scroll-margin-top: 80px; }

.stat-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.stat-controls select, .stat-controls input[type="date"] {
  padding: 7px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  font-family: inherit;
}
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat-card { background: var(--bg); border-radius: var(--radius-sm); padding: 12px 14px; }
.stat-card .label { font-size: 12px; color: var(--text-muted); }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat-card .sub { font-size: 11.5px; color: var(--text-muted); }
.stat-chart { width: 100%; height: 190px; display: block; margin-bottom: 4px; }
.stat-chart .bar { fill: var(--gold); }
.stat-chart .bar:hover { fill: var(--accent); }
.stat-chart .axis { fill: var(--text-muted); font-size: 10px; }
.stat-chart .grid { stroke: var(--border); stroke-width: 1; }
.stat-legend { font-size: 12px; color: var(--text-muted); margin: 0 0 14px; }
.stat-sub-title { font-size: 14px; margin: 18px 0 8px; }
table.admin-table td.num, table.admin-table th.num { text-align: right; white-space: nowrap; }
.stat-reset {
  margin-top: 20px;
  padding: 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fffaf2;
}
.stat-reset h3 { margin: 0 0 6px; font-size: 14px; }
.stat-reset label { display: block; font-size: 13px; margin: 4px 0; }

.cmt-mode-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 10px; }
.cmt-mode-row label {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  cursor: pointer;
  flex: 1 1 180px;
  background: #fff;
}
.cmt-mode-row label:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.cmt-mode-row small { display: block; color: var(--text-muted); margin-top: 2px; }
.cmt-admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 12px; }
.cmt-admin-grid textarea, .cmt-admin-grid select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}
.cmt-filter { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.cmt-admin-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.cmt-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}
.cmt-card.pending { border-color: var(--gold); background: #fffaf0; }
.cmt-card.is-hidden { opacity: 0.65; }
.cmt-card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; color: var(--text-muted); font-size: 12px; }
.cmt-card-meta b { color: var(--text); font-size: 13px; }
.cmt-card-book { font-size: 12px; color: var(--gold-text); }
.cmt-card-body { white-space: pre-wrap; word-break: break-word; line-height: 1.6; margin: 0; }
.cmt-card-quote { margin: 0; padding-left: 8px; border-left: 3px solid var(--gold); color: var(--text-muted); }
.cmt-card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.cmt-card-actions .btn { padding: 9px 14px; }
.status-pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; background: var(--surface-2); color: var(--text); }
.status-pill.pending { background: #fbe7c3; color: #7a5200; }
.status-pill.published { background: #dcefe2; color: #1f5a35; }
.status-pill.hidden { background: #eee; color: #666; }
@media (max-width: 640px) {
  .cmt-admin-grid { grid-template-columns: 1fr; }
  .cmt-card-actions .btn { flex: 1; }
}

/* v1.8: 관리자 [인쇄] — 이용 통계 부분만 인쇄 */
@media print {
  body.print-stats header.site-header,
  body.print-stats .admin-nav,
  body.print-stats #dashboard-section > :not(#sec-stats),
  body.print-stats #logout-btn,
  body.print-stats .stat-controls,
  body.print-stats .stat-reset,
  body.print-stats #stat-status { display: none !important; }
  body.print-stats main { padding: 0; max-width: none; }
  body.print-stats #sec-stats { border: none; padding: 0; }
  body.print-stats .table-scroll { overflow: visible; }
  body.print-stats .table-scroll table.admin-table { min-width: 0; }
}
