/* 부처님과 그의 담마 — 독서본 스타일
   한국어 명조체 중심, 독서에 최적화된 우아한 타이포그래피 */

/* ── 프리젠테이션 폰트 선택(A/B/C/D)용 추가 서체 ──
   Bulgwang 루트 fonts/ 에 자가호스팅된 파일을 참조한다(dhammabook → ../fonts/).
   · Paperlogy — Medium/Bold/Black (OFL 1.1, freesentation.blog)
   · Jeju Hallasan — 제주 무료 배포체
   ⚠ Jeju Hallasan 은 **원본 TTF(6.7MB, 18,315글리프)** 를 직접 참조한다 — 경전 한글이
     모두 난다. 같은 폴더의 240자 서브셋(36KB)은 지도 지명 전용이라 본문에 쓰면 글자가 빠진다. */
@font-face {
  font-family: "Paperlogy";
  src: url("../fonts/paperlogy/Paperlogy-7Bold.ttf") format("truetype");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Jeju Hallasan";
  src: url("../fonts/jejuhallasan/JejuHallasan.ttf") format("truetype");
  font-weight: 400; font-style: normal; font-display: swap;
}

:root {
  --paper: #faf6ee;          /* 본문 배경 - 은은한 아이보리 */
  --paper-bright: #fffdf7;
  --ink: #2b251c;            /* 본문 글자 */
  --ink-soft: #5a5144;
  --ink-faint: #8a8071;
  --accent: #9a6b27;         /* 고동색/금 계열 강조 */
  --accent-deep: #7a521d;
  --line: #e6ddcc;           /* 구분선 */
  --highlight: #f5e3a8;      /* 형광펜 (노랑) */
  --highlight-active: #f3d878;
  /* 저장한 경구 표시용 (푸른 형광펜) */
  --quote-blue: #a8d8f0;
  --quote-blue-active: #7cc4e8;
  /* 책 본문 서체: 마루부리(자가호스팅, fonts/maruburi.css)를 최우선으로.
     마루부리는 KS X 1001 완성형 한글을 포함하므로 일상 한글은 모두 렌더된다.
     폰트에 없는 글자(한자·일부 기호)는 아래 시스템 명조체로 폴백한다. */
  --serif: "MaruBuri", "Apple Myungjo", "Apple SD Gothic Neo", "Nanum Myeongjo",
           "Noto Serif KR", "Malgun Gothic", "Batang", "Gulim", serif;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--serif);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.95;
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- 상단 바 ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 60px;
  background: rgba(250, 246, 238, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 12px;
  z-index: 100;
}

.icon-btn {
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  background: var(--paper-bright);
  color: var(--ink);
  border-radius: 10px;
  cursor: pointer;
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
  flex: none;
}
.icon-btn:hover { background: #f0e8d8; border-color: var(--accent); }
.icon-btn:active { transform: scale(.96); }

/* 상단 제목 2줄: 위 = 책 제목, 아래 = 현재 장 */
.topbar-titles {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.25;
  overflow: hidden;
}
.topbar-book {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .6px;
  color: var(--accent, #9a6b3f);
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.topbar-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  color: var(--ink);
}

/* ---------- 목차 드로어 ---------- */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(30, 24, 16, 0.35);
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
  z-index: 200;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.toc-drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 320px; max-width: 84vw;
  background: var(--paper-bright);
  border-right: 1px solid var(--line);
  transform: translateX(-100%);
  transition: transform .28s cubic-bezier(.2,.7,.3,1);
  z-index: 210;
  display: flex; flex-direction: column;
  box-shadow: 4px 0 24px rgba(0,0,0,.08);
}
.toc-drawer.open { transform: translateX(0); }

.toc-head {
  position: relative;                 /* 닫기 버튼(✕)의 기준 */
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}

/* 패널 닫기 버튼 — 목차(왼쪽)·경전(오른쪽) 두 패널 모두 머리글 오른쪽 위에 둔다. */
.drawer-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit;
  font-size: 15px; line-height: 1;
  color: var(--ink-soft, #6b6b6b);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.drawer-close:hover { background: #f2ead9; color: var(--ink); border-color: rgba(200,148,45,.55); }
.drawer-close:active { transform: scale(.95); }
.drawer-close:focus-visible { outline: 2px solid var(--ink-faint); outline-offset: 2px; }
/* 머리글 제목이 ✕ 자리에 겹치지 않게 오른쪽 여백을 비워 둔다 */
.toc-head h2, .toc-head .toc-meta { padding-right: 40px; }
.toc-head h2 {
  font-size: 20px; font-weight: 700; color: var(--ink);
  letter-spacing: .5px;
}
.toc-head .toc-meta {
  font-size: 12.5px; color: var(--ink-faint); margin-top: 5px;
  line-height: 1.6;
}

/* ---------- 경전 선택 드로어 (오른쪽) ----------
   경전 이동 버튼은 목차 패널에 두지 않는다 — 우측 상단 📚 버튼으로 여는 이 패널이 맡는다.
   각 경전은 세로로 한 줄씩 늘어선 카드(cover + 제목·부제)다. */
.books-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 320px; max-width: 84vw;
  background: var(--paper-bright);
  border-left: 1px solid var(--line);
  transform: translateX(100%);          /* 오른쪽에서 들어온다 — 왼쪽 목차와 반대 방향 */
  transition: transform .28s cubic-bezier(.2,.7,.3,1);
  z-index: 210;
  display: flex; flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,.08);
}
.books-drawer.open { transform: translateX(0); }

.books-list {
  flex: 1; overflow-y: auto;
  padding: 14px 16px 24px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.books-list:empty { display: none; }

/* 카드 하나 = 경전 하나. 세로 1열이라 긴 제목도 두 줄까지 읽힌다. */
.book-tab {
  display: flex; align-items: center; gap: 13px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  font-family: inherit;
  color: var(--ink-soft, #6b6b6b);
  background: rgba(0,0,0,.015);
  border: 1px solid var(--line);
  border-radius: 13px;
  cursor: pointer;
  transition: background .16s, color .16s, border-color .16s, transform .16s;
  -webkit-tap-highlight-color: transparent;
}
.book-tab:hover { background: #f5efe2; border-color: rgba(200,148,45,.55); transform: translateY(-1px); }
.book-tab.on {
  color: var(--ink);
  background: #f2ead9;
  border-color: var(--accent, #9a6b3f);
}
.book-tab:focus-visible { outline: 2px solid var(--ink-faint); outline-offset: 2px; }

/* 책 표지 대신 글리프 한 장 — 이모지가 없는 환경에서도 상자가 무너지지 않게 고정 크기 */
.book-tab .bt-cover {
  flex: none;
  width: 40px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  border-radius: 4px 9px 9px 4px;
  background: linear-gradient(160deg, #fdf8ee, #efe3cb);
  border: 1px solid var(--line);
  box-shadow: inset 3px 0 0 rgba(154,107,63,.35);
}
.book-tab.on .bt-cover {
  background: linear-gradient(160deg, #fbf3e2, #e7d6b6);
  border-color: rgba(154,107,63,.45);
}
.book-tab .bt-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.book-tab .bt-title {
  font-size: 14.5px; font-weight: 700; line-height: 1.35;
  color: inherit;
}
.book-tab .bt-sub {
  font-size: 11.5px; color: var(--ink-faint); letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-tab.on .bt-title { color: var(--ink); }

/* 경전 본문 분할 로딩 안내 — books/<id>.js 를 받는 짧은 순간 보인다(.boot 과 같은 문구). */
.book-loading {
  padding: 18vh 24px 0;
  text-align: center;
  color: var(--ink-faint);
  font-size: 14px;
  letter-spacing: .3px;
}
.book-loading::after {
  content: "";
  display: block;
  width: 26px; height: 26px;
  margin: 18px auto 0;
  border: 2px solid rgba(0,0,0,.12);
  border-top-color: var(--accent, #9a6b3f);
  border-radius: 50%;
  animation: book-loading-spin .9s linear infinite;
}
@keyframes book-loading-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .book-loading::after { animation: none; }
}

.toc-body {
  flex: 1; overflow-y: auto; padding: 10px 0 20px;
  -webkit-overflow-scrolling: touch;
}

.toc-chapter {
  display: block;
  width: 100%;
  text-align: left;
  background: none; border: none; cursor: pointer;
  padding: 11px 20px;
  font-family: var(--serif);
  font-size: 15.5px;
  color: var(--ink);
  line-height: 1.5;
  border-left: 3px solid transparent;
  transition: background .12s, border-color .12s;
}
.toc-chapter:hover { background: #f5efe2; }
.toc-chapter.current {
  background: #f2ead9;
  border-left-color: var(--accent);
  font-weight: 700;
}
.toc-chapter .toc-num {
  color: var(--accent-deep);
  font-size: 13px;
  margin-right: 8px;
  font-weight: 700;
}

/* 목차 하위 확장: 부(h2) / 절(h3) — 접이식(아코디언) */
.toc-chap { border-bottom: 1px solid var(--line); }
.toc-chap-head {
  display: flex;
  align-items: center;
  gap: 4px;
}
.toc-chap-head .toc-chapter { flex: 1; }

/* 토글 화살표 버튼 */
.toc-toggle {
  flex: none;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  font-size: 13px; color: var(--ink-faint);
  border-radius: 7px;
  transition: background .12s, transform .18s;
}
.toc-toggle:hover { background: #f0e8d8; color: var(--ink); }
.toc-toggle-mini { width: 24px; height: 24px; font-size: 11px; }

/* 장 하위 목차: 기본 접힘, .expanded 시 펼침 */
.toc-sub {
  max-height: 0;
  overflow: hidden;
  transition: max-height .28s ease;
}
.toc-chap.expanded .toc-sub { max-height: 4000px; }

/* 부(h2) 행 */
.toc-h2-row {
  display: flex;
  align-items: center;
  gap: 2px;
}
.toc-h2-row .toc-h2 { flex: 1; }

.toc-h2, .toc-h3 {
  display: block;
  width: 100%;
  text-align: left;
  background: none; border: none; cursor: pointer;
  font-family: var(--serif);
  color: var(--ink-soft);
  line-height: 1.45;
  transition: background .12s, color .12s;
  word-break: keep-all;
}
.toc-h2 {
  padding: 7px 20px 5px 30px;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-deep);
}
.toc-h3 {
  padding: 4px 20px 4px 44px;
  font-size: 13px;
}
.toc-h2:hover { background: #f2ead9; color: var(--accent-deep); }
.toc-h3:hover { background: #f5efe2; color: var(--ink); }

/* 절(h3) 목록: 부 단위로 접을 수 있음 */
.toc-h3-wrap {
  max-height: 4000px;
  overflow: hidden;
  transition: max-height .28s ease;
}
.toc-h3-wrap.collapsed { max-height: 0; }

/* ---------- 본문 ---------- */
.reader {
  max-width: 760px;
  margin: 0 auto;
  padding: 90px 24px 120px;
}

.reader h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1.4;
  margin: 12px 0 18px;
  color: var(--ink);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 16px;
}

.reader h2 {
  font-size: 1.45rem;
  font-weight: 700;
  margin: 48px 0 16px;
  color: var(--accent-deep);
  letter-spacing: -.5px;
}

.reader h3 {
  font-size: 1.16rem;
  font-weight: 700;
  margin: 30px 0 12px;
  padding-left: 14px;
  border-left: 4px solid var(--accent);
  color: var(--ink);
  letter-spacing: -.3px;
}

.reader h4 {
  text-align: center;
  color: var(--ink-faint);
  letter-spacing: 4px;
  margin: 28px 0;
  font-weight: 400;
}

.reader p {
  margin: 15px 0;
  text-align: justify;
  word-break: keep-all;
}

/* 소절 제목(p.sec) — 디가 니까야의 '### n. …' 소절. 경 제목(h3)보다 한 단계 작게, 절 제목처럼. */
.reader p.sec {
  margin: 34px 0 6px;
  text-align: left;
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: -.2px;
  color: var(--accent-deep);
}

/* 권 부제(p.vol) — 맛지마의 '### 제1권 …'. 장 제목(h1) 아래 작은 줄 —
   품 이름을 h1 에 두고 권 이름을 여기에 내려 15품 목차가 짧고 고르게 읽히게 한다. */
/* 율장의 굵은 계목·용어 줄(p.term) — 원고의 **…** 줄을 작은 제목처럼 그린다. */
.reader p.term {
  margin: 20px 0 8px;
  text-align: left;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.7;
}

.reader p.vol {
  margin: -6px 0 26px;
  text-align: left;
  font-size: .9rem;
  color: var(--muted);
  letter-spacing: 0;
}

.reader ol {
  margin: 12px 0;
  padding-left: 0;
  list-style: none;
}
.reader ol > li {
  position: relative;
  margin: 13px 0;
  text-align: justify;
  word-break: keep-all;
}

.reader blockquote {
  margin: 18px 0;
  padding: 14px 20px;
  border-left: 3px solid var(--accent);
  background: #f5efe2;
  border-radius: 0 10px 10px 0;
  color: var(--ink-soft);
  font-style: italic;
}

.reader em { font-style: italic; }
.reader strong { font-weight: 700; }

/* 형광펜 */
mark, .hl {
  background: var(--highlight);
  color: var(--ink);
  padding: 1px 2px;
  border-radius: 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  cursor: pointer;
  position: relative;
  transition: background .15s;
}
mark:hover, .hl:hover { background: var(--highlight-active); }

/* 저장한 경구 — 푸른색 형광펜.
   mark, .hl 규칙(명시도 0,0,1 / 0,1,0)보다 선택자가 길어 항상 우선 적용된다.
   그래서 경구가 노란 형광펜과 겹쳐도 푸른색으로 보인다. */
mark.hl-quote, .hl-quote {
  background: var(--quote-blue);
  color: var(--ink);
}
mark.hl-quote:hover, .hl-quote:hover {
  background: var(--quote-blue-active);
}
/* 경구임을 한눈에 알 수 있게 왼쪽에 얇은 푸른 선을 둔다
   (노란 형광펜과 색 구분이 약한 환경에서도 식별 가능). */
mark.hl-quote {
  box-shadow: inset 3px 0 0 0 var(--quote-blue-active);
}

/* 선택(드래그) 스타일 */
::selection { background: var(--highlight-active); }

/* ---------- 경구 선택 툴팁 ---------- */
.quote-tip {
  position: fixed;
  background: var(--ink);
  color: #fff;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 13.5px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  z-index: 300;
  font-family: var(--serif);
  letter-spacing: .5px;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  animation: tipin .15s ease;
  /* [iOS 대응] 탭 지연 방지 + 툴팁 자체가 텍스트 선택되지 않도록 */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
@keyframes tipin {
  from { opacity: 0; transform: translate(-50%, -90%); }
  to { opacity: 1; transform: translate(-50%, -100%); }
}

/* ---------- 토스트 ---------- */
.toast {
  position: fixed;
  bottom: 80px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: all .3s;
  z-index: 400;
  font-family: var(--serif);
  letter-spacing: .4px;
  max-width: 88vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 하단 내비게이션 ---------- */
.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 60px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.pager-btn {
  font-family: var(--serif);
  background: var(--paper-bright);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 14.5px;
  cursor: pointer;
  transition: all .15s;
  letter-spacing: .3px;
}
.pager-btn:hover { border-color: var(--accent); background: #f0e8d8; }
.pager-btn:disabled { opacity: .35; cursor: not-allowed; }
.pager-btn .dir { color: var(--accent-deep); font-weight: 700; margin-right: 6px; }

.pager-pos { color: var(--ink-faint); font-size: 13px; white-space: nowrap; }

/* ---------- 빈 상태 ---------- */
.reader .empty {
  text-align: center;
  color: var(--ink-faint);
  padding: 80px 20px;
  font-size: 17px;
}

/* 프리젠테이션 모드 (틸트 제거: 정면 표시) */
.pres-overlay {
  position: fixed; inset: 0;
  z-index: 1000;
  display: none;
  overflow: hidden;
  background: #05050a;
}
.pres-overlay.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* WebGL 배경 (orbit_presentation 과 동일 엔진) — 오버레이 맨 아래.
   프리젠테이션이 비활성일 때는 display:none 으로 렌더 루프까지 멈춘다.
   ⚠ 크기를 CSS 로 건드리지 말 것 — 엔진의 resize() 가 버퍼 크기로 gl.viewport 를 잡는다. */
.pres-overlay #bg-gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  pointer-events: none;
  /* 첫 프레임(엔진 clearColor)이 어둡기 때문에, 켜지는 순간 톤이 튀지 않게 한다 */
  transition: opacity 500ms linear;
  opacity: 0;
}
.pres-overlay.active #bg-gl { opacity: 1; }

/* 배경 색 크로스페이드 레이어 2장.
   [요구사항] 배경은 다양한 색으로 끊임 없이 트윈되어야 한다(약 1분 주기).
   [성능] 단색(background-color) 레이어 2장을 겹쳐 opacity 만 보간한다.
     - opacity/transform 은 GPU 합성이므로 CPU 페인트가 없다(저성능 크롬북 안전).
     - 단색이라 이전 radial-gradient 의 '검은 테두리' 문제가 원천적으로 없다.
     - inset:0(화면 크기) 그대로 두고 position 에 의한 이동은 하지 않는다.
   ⚠ 이제 WebGL 레이어가 배경이므로, 색 레이어는 그 '위'에 얹는 반투명 색조다.
     불투명하게 두면 WebGL 을 통째로 덮어버린다 — opacity 를 낮게 유지하라. */
.pres-bg {
  position: absolute;
  inset: 0;
  z-index: 0;              /* GPU 색조 패스로 이관됨 — 아래는 폴백 전용 */
  pointer-events: none;
  background: transparent;
}
.pres-bg .bg-plane {
  position: absolute;
  inset: 0;
  pointer-events: none;
  /* ⚠ 불투명도 상한(--pres-tint-max)을 넘지 않게 한다. WebGL 배경이 보여야 한다. */
  opacity: 0;
  transition: opacity 200ms linear;
  will-change: opacity;
  backface-visibility: hidden;
}
/* GPU 이관 후: 색조는 #bg-gl 안에서 그려진다 — DOM 레이어는 구형 폴백 전용으로 숨긴다. */
.pres-overlay.gpu-pres .pres-bg { display: none; }

/* 비네트 제거됨(사용자 요청) — 배경을 감광하지 않는다.
   GPU 패스는 orbit-atmosphere.js 에서 지웠고, DOM 레이어(.pres-vignette)도 항상 숨긴다. */
.pres-vignette { display: none; }

/* orbit 세 점 — 홈페이지 orbit 이미지의 황금 점 3개를 프리젠테이션 배경에
   은은하게 블렌드해 띄운다. 텍스트 가독성을 해치지 않도록 작고 반투명하게,
   배경(색 그라데이션)과 비네트 위, 텍스트 아래에 둔다.
   각 점의 랜덤 위치/움직임은 JS가 개별 transform으로 제어한다. */
/* orbit — 홈페이지 orbit 처럼 원 3개 + 점 3개를 묶은 컨테이너.
   이 컨테이너는 3D perspective 공간만 제공한다(틸트는 각 원이 개별 담당).
   점 3개는 .pres-orbit-dots 가 함께 회전하고, 원 3개는 각자 개별 틸트+공전. */
.pres-orbit {
  position: absolute;
  inset: 0;
  z-index: 2;              /* 비네트와 동일 레벨(배경 위, 텍스트 아래) */
  pointer-events: none;
  perspective: 1200px;     /* 3D 깊이감(틸트) 기준 */
  perspective-origin: 50% 50%;
  transform-style: preserve-3d;
}
.pres-orbit-dots {
  position: absolute;
  inset: 0;
  pointer-events: none;
  /* 홈페이지 orbit 처럼 점 3개를 '하나의 덩어리'로 함께 회전시킨다. */
  transform-style: preserve-3d;
  animation: pres-spin-slow 45s linear infinite;
  will-change: transform;
}
@keyframes pres-spin-slow {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.pres-dot {
  position: absolute;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f0d68a 0%, #c8942d 55%, #8a6418 100%);
  box-shadow: 0 0 14px rgba(200, 148, 45, .6), 0 0 28px rgba(200, 148, 45, .22);
  /* 은은하게: 배경색 위에 살짝 떠 보이도록 낮은 opacity + screen 블렌드 */
  opacity: .55;
  mix-blend-mode: screen;
  will-change: transform, opacity;
  /* 홈페이지처럼 점 위치는 inline style(top/bottom/left/right)이 잡는다.
     보정 transform 없이 상대 좌표 그대로 배치한다. */
}

/* orbit 선 원(ring) — 홈페이지 orbit 의 선으로 그려진 원 3개를 프리젠테이션
   배경에 가져와 다양한 방향으로 천천히 틸트하며 회전시킨다.
   3D perspective 안에서 각 원을 서로 다른 축으로 기울여(rotateX/rotateY)
   \"공중에 떠 있는 궤도\"처럼 보이게 하고, 그 평면 위를 각자 다른 속도/방향으로
   돈다. 텍스트 가독성을 해치지 않도록 아주 흐리고 낮은 opacity 로 둔다. */
.pres-orbit-rings {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transform-style: preserve-3d;
}
.pres-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(120vmin, 780px);
  height: min(120vmin, 780px);
  border-radius: 50%;
  border: 2px solid rgba(200, 148, 45, .34);   /* 금색 (기본 r1) */
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: .44;
  box-shadow: 0 0 18px rgba(200, 148, 45, .12);   /* 흐릿한 글로우로 존재감 */
  will-change: transform;
  transform: translate(-50%, -50%);
  transform-style: preserve-3d;
}
.pres-ring.r2 {
  width: min(100vmin, 660px);
  height: min(100vmin, 660px);
  border-color: rgba(140, 47, 57, .34);        /* 진한 붉은색 */
  box-shadow: 0 0 18px rgba(140, 47, 57, .12);
}
.pres-ring.r3 {
  width: min(80vmin, 540px);
  height: min(80vmin, 540px);
  border-color: rgba(201, 106, 106, .32);      /* 연한 붉은색 */
  box-shadow: 0 0 18px rgba(201, 106, 106, .12);
}

/* 원 3개는 같은 중심을 공유하면서, 각각 서로 다른 틸트 축/각도로 누워 있고
   그 평면 위를 각자 다른 속도·방향으로 공전한다.
   [요구사항] 중앙점을 공유한 상태에서 각 원이 서로 다른 틸트 값으로 움직인다.
   → 틸트를 .pres-orbit 컨테이너(전체 공통)가 아니라 각 원 keyframe 에
     개별 rotateX/rotateY 로 넣는다. 각 원의 틸트 각도를 서로 다르게 한다. */
@keyframes pres-ring1 {
  /* 금색 원: X축으로 크게 기울고, 세로축(rotateZ)으로 공전 */
  0%   { transform: translate(-50%, -50%) rotateX(58deg) rotateY(0deg) rotateZ(0deg); }
  50%  { transform: translate(-50%, -50%) rotateX(42deg) rotateY(16deg) rotateZ(180deg); }
  100% { transform: translate(-50%, -50%) rotateX(58deg) rotateY(0deg) rotateZ(360deg); }
}
@keyframes pres-ring2 {
  /* 붉은 원: Y축으로 크게 기울고 역방향 공전, 반대 위상 */
  0%   { transform: translate(-50%, -50%) rotateX(0deg) rotateY(58deg) rotateZ(0deg); }
  50%  { transform: translate(-50%, -50%) rotateX(-14deg) rotateY(44deg) rotateZ(-180deg); }
  100% { transform: translate(-50%, -50%) rotateX(0deg) rotateY(58deg) rotateZ(-360deg); }
}
@keyframes pres-ring3 {
  /* 연붉은 원: 사선(대각) 축으로 누워 공전, 중간 속도 */
  0%   { transform: translate(-50%, -50%) rotateX(34deg) rotateY(34deg) rotateZ(0deg); }
  50%  { transform: translate(-50%, -50%) rotateX(50deg) rotateY(20deg) rotateZ(180deg); }
  100% { transform: translate(-50%, -50%) rotateX(34deg) rotateY(34deg) rotateZ(360deg); }
}
.pres-ring[data-ring="0"] { animation: pres-ring1 30s ease-in-out infinite; }
.pres-ring[data-ring="1"] { animation: pres-ring2 22s ease-in-out infinite; }
.pres-ring[data-ring="2"] { animation: pres-ring3 16s ease-in-out infinite; }

/* .pres-orbit 컨테이너의 전체 틸트는 제거했다(원마다 개별 틸트로 대체).
   컨테이너는 이제 3D perspective 공간만 제공한다. */

/* 접근성: 움직임 최소화 시 원·점 회전·틸트 정지 */
@media (prefers-reduced-motion: reduce) {
  .pres-ring[data-ring] { animation: none; }
  .pres-orbit-dots { animation: none; }
}

/* 본문 텍스트: 틸트 없이 정면. 색은 노랑→사이언 그라데이션이 천천히 회전하며
   텍스트 클리핑(background-clip: text)으로 매핑된다.
   겹치는 레이어 2장(.pres-fill / .pres-fill-2): 아래층 = 상시 그라데이션(밑바탕 색 보장),
   위층 = 노랑→사이언→노랑 4스톱 로테이션. opacity는 JS가 인라인으로 제어(알파 페이드). */
.pres-text {
  position: relative;
  z-index: 3;
  width: min(62ch, 86vw);
  color: #faf3e3;
  font-family: "Hahmlet", "Diphylleia", "Apple Myungjo", "Nanum Myeongjo",
               "Noto Serif KR", "Gungsuh", "Batang", "Malgun Gothic", serif;
  /* [사용자 지정] 폰트 크기 상·하한을 36pt / 18pt로 고정한다.
     CSS의 pt는 브라우저에서 96dpi 기준 1pt = 1.333px 로 고정 변환되므로
       36pt = 48px,  18pt = 24px
     clamp()로 하한/상한을 걸어 어떤 경우에도 이 범위를 벗어나지 않는다.
     중간값은 화면 폭에 따라 유동적이며, JS(fitPresText)가 긴 문단에 대해
     이 범위 안에서 추가로 축소한다(하한 18pt 미만으로는 내려가지 않는다). */
  font-size: clamp(18pt, 6vw, 36pt);
  line-height: 1.7;
  text-align: center;
  font-weight: 400;
  letter-spacing: .02em;
  opacity: 0;
  word-break: keep-all;
  /* [최적화] 이전에는 drop-shadow 2겹(22px + 30px 블러)을 걸었다.
     background-clip:text 때문에 text-shadow를 못 쓰는 상황에서 그림자를 만들려던 것인데,
     큰 폰트에 대한 2겹 가우시안 블러는 매 프레임 재합성되어
     저사양 기기에서 가장 무거운 요소 중 하나였다. 배경이 어둡고 비네트로
     대비가 확보되므로 그림자를 완전히 제거해도 가독성은 유지된다. */
  filter: none;
  /* transition은 JS가 상황에 맞게 지정(인라인) */
  transition: opacity .4s linear;
}
/* GPU 이관 후: .pres-text 는 '측정용'(폰트·폭·줄수)으로만 남고 화면엔 안 보인다.
   보이는 글자는 #bg-gl 안의 텍스처 레이어가 그린다 — 크기 로직을 그대로 재사용하기 위함이다. */
.pres-overlay.gpu-pres .pres-text {
  visibility: hidden;
  opacity: 0;
}
.pres-overlay.gpu-pres .pres-text .pres-fill { display: none; }

/* 그라데이션 레이어: 텍스트를 마스크로 사용.
   z-index로 본문(크림색) 위에 올려야 그라데이션이 실제로 보인다.
   [최적화] 이전에는 레이어 2장(밑바탕 + 42초 회전 애니메이션층)을 겹쳤다.
   background-clip:text 합성은 저사양 기기에서 비싸므로 1장으로 줄이고,
   무한 회전 애니메이션(background-position 매프레임 재페인트)도 제거했다.
   색 변화는 문단마다 JS가 배경 이미지를 한 번만 갈아끼우는 것으로 충분하다. */
.pres-fill {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  text-align: center;
  white-space: inherit;
  word-break: keep-all;
  z-index: 1;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  pointer-events: none;
  user-select: none;
  text-shadow: none;
  filter: none;
}
/* 밑바탕: 그라데이션 밖으로 새는 부분에도 색이 남도록 하는 기준 레이어 */
.pres-fill-1 {
  background-image: linear-gradient(90deg, #ffd166 0%, #7ee8fa 45%, #ffd166 100%);
  background-size: 100% 100%;
  background-position: 0% 50%;
}
/* 두 번째 레이어는 더 이상 쓰지 않는다(합성 비용 절감). 항상 숨김. */
.pres-fill-2 { display: none; }
/* 화면 밖 텍스트가 완전히 사라진 뒤의 빈 상태: 그라데이션 없이 켜지지 않도록 안전장치 */
.pres-text:empty .pres-fill { background-image: none; }


/* 하단 진행바
   [최적화] width 애니메이션은 매 프레임 레이아웃/페인트를 유발한다.
   scaleX로 바꾸면 GPU 합성만으로 처리된다(JS가 transform을 갱신).
   box-shadow 글로우도 매 프레임 블러 재계산을 유발하므로 제거했다. */
.pres-progress {
  position: absolute;
  bottom: 0; left: 0;
  height: 3px;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, transparent, rgba(247, 240, 226, .75), transparent);
  will-change: transform;
}

/* 종료 버튼: 하단 우측, 아주 작아 간신히 보이게 */
/* 📖 프리젠테이션 좌하단 — 지금 보여주는 경전·장 제목 (2026-10-09 사용자 요청).
   🔴 TV 화면 송출용으로 조정(2026-10-09 2차 지시):
      "글씨 크기를 1.5배 정도 키우고 안전 영역으로 옮겨라. TV 화면에 띄울거다."

   TV 안전 영역(Title Safe) 기준
     · 방송 관행: 화면 가장자리에서 **가로 5% / 세로 5%** 안쪽에 둔다.
       TV 는 오버스캔으로 가장자리가 잘릴 수 있어 바깥 5% 는 위험하다.
     · 그래서 고정 px 이 아니라 **vw/vh 백분율**로 잡는다 —
       어느 해상도에서도 같은 비율의 안전 여백이 유지된다.
     · 5% 는 너무 붙어 보여 **가로 5.5%, 세로 7%** 로 약간 더 안쪽에 뒀다.

   크기: 13px → 20px (1.54배). TV 시청 거리에서도 읽히게.
   ⚠ 이 값을 다시 줄이지 마라 — 사용자가 TV 송출용으로 키운 것이다.
   ⚠ 밝기는 올리지 마라(명상 화면에서 산만해진다). 크기만 키운다. */
.pres-label {
  position: absolute;
  left: max(5.5vw, 40px);
  bottom: max(7vh, 40px);
  max-width: 60%;
  display: flex; align-items: baseline; gap: 10px;
  /* 🔴 1080p 에서 20px 이 되도록 vw 로 준다(고정 px 이면 4K 에서 너무 작다).
     20/1920 = 1.042vw. 상한/하한을 두어 극단적 화면에서도 읽히게 한다. */
  font-size: clamp(20px, 1.05vw, 42px);
  letter-spacing: .02em;
  color: rgba(247, 240, 226, .40);
  text-shadow: 0 1px 8px rgba(0, 0, 0, .55);
  pointer-events: none;                 /* 클릭 방해 금지 */
  opacity: 0;
  transition: opacity .9s ease;
  z-index: 1010;
}
.pres-label.on { opacity: 1; }
.pres-label-book { font-weight: 600; color: rgba(247, 240, 226, .55); }
.pres-label-sep { color: rgba(247, 240, 226, .22); }
.pres-label-ch { color: rgba(247, 240, 226, .42); }

/* 작은 화면(태블릿·폰)에서만 축소 — TV 는 위 기본값을 그대로 쓴다 */
@media (max-width: 900px) {
  .pres-label { left: max(4vw, 20px); bottom: max(4vh, 20px); font-size: clamp(13px, 1.7vw, 17px); max-width: 66%; }
}
@media (max-width: 640px) {
  .pres-label { font-size: 12px; }
  .pres-label-sep { display: none; }
}

.pres-exit {
  position: absolute;
  right: 14px; bottom: 14px;
  width: 34px; height: 34px;
  border: none;
  background: rgba(255, 255, 255, .08);
  color: rgba(247, 240, 226, .55);
  font-size: 14px;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;                      /* 기본 숨김 — 하단 호버(.bottom-hover) 시 표시 */
  pointer-events: none;
  transition: opacity .25s, background .25s, color .25s;
  z-index: 1010;
}
.pres-overlay.bottom-hover .pres-exit { opacity: .35; pointer-events: auto; }
.pres-overlay.bottom-hover .pres-exit:hover {
  opacity: .85;
  background: rgba(255, 255, 255, .16);
  color: rgba(247, 240, 226, .95);
}

/* ---------- 폰트 선택 (A/B/C/D) ----------
   종료 버튼 왼쪽에 아주 어둡게 둔다(눈에 띄지 않게). 호버하면 살짝 밝아진다.
   현재 선택된 글자는 .on 으로 표시한다. */
.pres-fontpick {
  position: absolute;
  right: 58px; bottom: 20px;      /* 종료 버튼(34px) 왼쪽 */
  display: flex; gap: 6px;
  z-index: 1010;
  opacity: 0;                      /* 기본 숨김 — 하단 호버 시 표시 */
  pointer-events: none;
  transition: opacity .25s;
}
.pres-overlay.bottom-hover .pres-fontpick { opacity: .18; pointer-events: auto; }
.pres-overlay.bottom-hover .pres-fontpick:hover { opacity: .7; }
.pf-btn {
  width: 20px; height: 20px;
  border: none; border-radius: 50%;
  background: rgba(255, 255, 255, .10);
  color: rgba(247, 240, 226, .85);
  font: 11px/1 "Paperlogy", "MaruBuri", system-ui, sans-serif;
  cursor: pointer; padding: 0;
  transition: background .2s, color .2s;
}
.pf-btn:hover { background: rgba(255, 255, 255, .22); color: #fff; }
.pf-btn.on { background: rgba(247, 240, 226, .30); color: #fff; }

/* ---------- 씬 선택 (Scene1/Scene2) ----------
   폰트 선택 버튼 바로 왼쪽에 둔다(right = 폰트 선택 오른쪽 오프셋 + 4버튼 폭 + 간격).
   같은 어둡기로 두어 눈에 띄지 않게 하고, 현재 씬을 .on 으로 표시한다.
   버튼은 원형이 아니라 알약형 — 글자가 들어가므로 폭을 늘린다. */
.pres-scenepick {
  position: absolute;
  right: 164px; bottom: 20px;     /* 폰트 선택(58px 시작 + 약 98px 폭 = 156px) 왼쪽에 8px 간격 */
  display: flex; gap: 6px;
  z-index: 1010;
  opacity: 0;                      /* 기본 숨김 — 하단 호버 시 표시 */
  pointer-events: none;
  transition: opacity .25s;
}
.pres-overlay.bottom-hover .pres-scenepick { opacity: .18; pointer-events: auto; }
.pres-overlay.bottom-hover .pres-scenepick:hover { opacity: .7; }
.pf-btn.sc-btn {
  width: auto; min-width: 44px; height: 20px;
  padding: 0 8px;
  border-radius: 10px;
  font: 10px/1 "Paperlogy", "MaruBuri", system-ui, sans-serif;
  letter-spacing: .02em;
}

/* 씬 번호 단추(1~11) — 동그란 숫자. 이름은 title(툴팁)에 있다. */
.pres-scenepick { gap: 4px; }
.pf-btn.sc-btn.sc-num {
  width: 20px; min-width: 20px; height: 20px;
  padding: 0;
  border-radius: 50%;
  font: 10px/20px "Paperlogy", "MaruBuri", system-ui, sans-serif;
  letter-spacing: 0;
  text-align: center;
}

/* ---------- 시간대 선택 (새벽/아침/오전/오후/저녁/밤) ----------
   씬 선택 버튼 왼쪽. 같은 알약형 .sc-btn 을 쓴다. */
.pres-timepick {
  position: absolute;
  right: 432px; bottom: 20px;    /* 씬 선택(164px + 11단추 약 260px 폭) 왼쪽에 8px 간격 */
  display: flex; gap: 6px;
  z-index: 1010;
  opacity: 0;                      /* 기본 숨김 — 하단 호버 시 표시 */
  pointer-events: none;
  transition: opacity .25s;
}
.pres-overlay.bottom-hover .pres-timepick { opacity: .18; pointer-events: auto; }
.pres-overlay.bottom-hover .pres-timepick:hover { opacity: .7; }

/* ---------- 접근성: 움직임 최소화 선호 ----------
   배경 색 그라데이션 레이어가 제거되어 색 크로스페이드가 없으므로
   이 블록은 별도 조정이 필요 없다. */

/* ---------- 반응형 ---------- */
@media (max-width: 640px) {
  body { font-size: 16.5px; }
  .reader { padding: 84px 18px 100px; }
  .reader h1 { font-size: 1.6rem; }
  .reader h2 { font-size: 1.3rem; }
  .reader h3 { font-size: 1.08rem; }
  .topbar-book { font-size: 11px; }
  .topbar-title { font-size: 15px; }
}
/* 경전 넘김 카드 — 한 경전이 끝나면 다음 경전 제목을 잠깐 크게 띄운다(글귀는 앱이 opacity 0 으로 지운다). */
.pres-card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .35em;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.1s ease;
  /* 카드는 오버레이의 마지막 자식이지만, opacity 트랜지션이 걸린 요소는 자체 stacking context 라
     순서 비교가 미묘하다 — .pres-text(z-index 3)보다 확실히 큰 값을 명시한다(실측 교훈). */
  z-index: 9;
}
.pres-card.on { opacity: 1; }
/* 본문 글귀(.pres-text)와 같은 글꼴 — 카드와 글귀가 같은 판으로 읽히게 */
.pres-card-title,
.pres-card-meta {
  font-family: "Hahmlet", "Diphylleia", "Apple Myungjo", "Nanum Myeongjo",
               "Noto Serif KR", "Gungsuh", "Batang", "Malgun Gothic", serif;
}
.pres-card-title {
  /* 1080p 기준 9.6vw ≈ 184px — TV 거리에서도 한눈에 읽히게 */
  font-size: clamp(44px, 9.6vw, 220px);
  font-weight: 700;
  letter-spacing: .01em;
  color: rgba(250, 244, 232, .94);
  text-shadow: 0 2px 30px rgba(0, 0, 0, .55), 0 1px 6px rgba(0, 0, 0, .4);
  /* 글자 주변만 덮는 부드러운 그늘(spread) — 배경 전체를 어둡게 하지 않는다.
     ⚠ ::before 로 화면 전체를 덮으면 flex 자식 배치가 밀려 제목이 중앙에서 벗어났다(실측). */
  padding: 0 .18em;
  border-radius: .08em;
  background: radial-gradient(ellipse at center,
              rgba(12, 10, 8, .46) 0%, rgba(12, 10, 8, .30) 58%, rgba(12, 10, 8, 0) 100%);
  box-shadow: 0 0 60px 26px rgba(12, 10, 8, .22);
}
.pres-card-meta {
  font-size: clamp(16px, 1.9vw, 42px);
  letter-spacing: .14em;
  color: rgba(247, 240, 226, .45);
  text-shadow: 0 1px 10px rgba(0, 0, 0, .5);
}

/* ---------- 경전 검색 (왼쪽 드로어, 목차 위쪽) ----------
   search-ko.js · search-en.js 인덱스로 모든 경전 본문에서 단어를 찾는다.
   목차와 같은 드로어를 쓴다 — 결과를 누르면 그 장을 열고 그 문단으로 스크롤한다. */
.search-box {
  position: relative;
  display: flex; align-items: center;
  gap: 8px;
  margin: 10px 16px 0;
  padding: 3px 4px 3px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}
.search-box:focus-within { border-color: rgba(200,148,45,.6); background: var(--paper-bright); }
.search-ico { font-size: 15px; color: var(--ink-faint); flex: none; }
#search-input {
  flex: 1 1 auto; min-width: 0;
  font-family: inherit; font-size: 14.5px;
  color: var(--ink);
  background: transparent; border: 0; outline: none;
  padding: 8px 0;
  -webkit-appearance: none;
}
#search-input::placeholder { color: var(--ink-faint); }
/* 브라우저가 type="search" 입력에 붙이는 기본 '지우기' 단추를 지운다 — 우리 ✕ 와 겹쳐 두 개로 보인다. */
#search-input::-webkit-search-cancel-button,
#search-input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
#search-clear {
  flex: none;
  width: 28px; height: 28px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--ink-faint);
  font-family: inherit; font-size: 14px; line-height: 1;
  cursor: pointer;
  display: none; align-items: center; justify-content: center;
}
#search-clear:hover { background: #f2ead9; color: var(--ink); }
.search-box.has-text #search-clear { display: flex; }

.search-summary {
  margin: 8px 18px 2px;
  font-size: 12px; color: var(--ink-faint);
  line-height: 1.5;
}
.search-results { display: none; }
.toc-drawer.searching .search-results { display: block; }
.toc-drawer.searching .toc-body { display: none; }
.search-results {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--line);
  margin-top: 8px;
}
.search-item {
  display: block; width: 100%;
  text-align: left;
  font-family: inherit;
  background: transparent;
  border: 0; border-bottom: 1px solid rgba(230,221,204,.55);
  padding: 10px 18px 11px;
  cursor: pointer;
  color: var(--ink);
}
.search-item:hover, .search-item:focus-visible { background: #f6eedd; outline: none; }
.si-meta {
  display: block;
  font-size: 11px; letter-spacing: .3px;
  color: var(--accent);
  margin-bottom: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.si-text {
  display: block;
  font-size: 13.5px; line-height: 1.65;
  color: var(--ink-soft);
  word-break: keep-all;
}
.si-text.is-head { color: var(--ink); font-weight: 700; }
.si-text em { font-style: normal; background: rgba(243,216,120,.55); color: var(--ink); }
.search-none {
  padding: 22px 18px; font-size: 13px; color: var(--ink-faint); text-align: center;
  line-height: 1.7;
}
/* 검색 결과로 들어온 문단을 잠깐 표시한다 — 어디로 왔는지 보이게.
   ⚠ 형광펜은 글자(<mark class="hl">)에 칠해지므로 문단 배경 애니메이션은 그 위로 보이지 않는다(실측).
     그래서 문단 **왼쪽에 금색 세로 띠**를 덧그린다 — 배경·글자와 겹치지 않고 눈에 바로 띈다. */
.reader .search-hit { position: relative; }
.reader .search-hit::before {
  content: '';
  position: absolute;
  left: -14px; top: 2px; bottom: 2px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent, #9a6b27);
  animation: search-hit 3.2s ease-out 1 forwards;
}
@keyframes search-hit {
  0%   { opacity: 1; box-shadow: 0 0 0 2px rgba(154,107,39,.25); }
  70%  { opacity: .9; box-shadow: 0 0 0 2px rgba(154,107,39,0); }
  100% { opacity: 0; }
}
