/* 모바일 독서 앱. 읽기 모드에서는 본문 외 아무것도 보이지 않는 것이 최우선 목표다.
 *
 * iOS Safari 기준:
 *  - dvh로 주소창 개폐에 따른 높이 흔들림을 잡는다 (vh 폴백 병기).
 *  - notch/home indicator는 env(safe-area-inset-*)로 피한다.
 *  - overscroll-behavior로 당겨서 새로고침을 막는다 — 읽던 위치가 흐트러진다.
 *  - 본문 선택은 iOS 네이티브에 맡기고, 우리 버튼은 선택 근처가 아닌 하단에 고정한다.
 */

:root {
  --font-stack: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', system-ui, 'Malgun Gothic', sans-serif;
  --fs: 18px;          /* settings.js가 덮어쓴다 */
  --lh: 1.85;
  --maxw: 100%;

  --bg: #f7f6f2;
  --fg: #1f2421;
  --muted: #6d7772;
  --line: #e2e0d8;
  --card: #fffefa;
  --green: #256d5a;
  --green-soft: #e7f0ec;
  --danger: #8e3e37;
  --chrome-bg: rgba(255, 254, 250, 0.94);
  --scrim: rgba(20, 26, 23, 0.42);
  --shadow: 0 -8px 30px rgba(20, 26, 23, 0.16);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

[data-theme="sepia"] {
  --bg: #f4ead6; --fg: #3a2f22; --muted: #7d6f5c; --line: #e2d5bd;
  --card: #fbf4e6; --green: #6b5330; --green-soft: #ece0c9;
  --chrome-bg: rgba(251, 244, 230, 0.94);
}

[data-theme="dark"] {
  --bg: #16191a; --fg: #dfe4e2; --muted: #8e9895; --line: #2a2f30;
  --card: #1e2223; --green: #7fc4ab; --green-soft: #21302b; --danger: #d98a82;
  --chrome-bg: rgba(30, 34, 35, 0.94); --scrim: rgba(0, 0, 0, 0.6);
  --shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-stack);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body { font-size: 15px; line-height: 1.6; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

.screen {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ══ 서재 ══════════════════════════════════════════ */

#libraryScreen { padding: calc(var(--safe-t) + 14px) calc(16px + var(--safe-r)) calc(var(--safe-b) + 12px) calc(16px + var(--safe-l)); }
#appUpdate { flex: none; padding: 10px; margin-bottom: 8px; border-radius: 8px; background: var(--green-soft); color: var(--green); }

.lib-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.lib-head h1 { margin: 2px 0 0; font-size: 24px; letter-spacing: -0.4px; }
.lib-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.eyebrow { display: block; font-size: 9px; letter-spacing: 1.4px; color: var(--muted); text-transform: uppercase; }

.icon {
  width: 38px; height: 38px; flex: none; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card); font-size: 16px;
  display: grid; place-items: center;
}
.icon:active { background: var(--green-soft); }
#backupButton.icon {
  width: auto; min-width: 38px; padding: 0 11px; border-radius: 19px;
  font-size: 12px; font-weight: 650; letter-spacing: -0.2px;
}

.library-nav { display: flex; align-items: center; gap: 3px; width: min(100%, 720px);
  margin: 12px 0 4px; padding: 3px; background: var(--card); border: 1px solid var(--line); border-radius: 11px; }
.library-nav > button { flex: none; padding: 8px 7px; border-radius: 8px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.library-nav > button.active { background: var(--green); color: #fff; }

.search { display: flex; align-items: center; flex: 1; min-width: 0; gap: 3px;
  padding: 0 4px 0 8px; border-left: 1px solid var(--line); }
.search.active { background: var(--green-soft); border-radius: 8px; }
.search span { flex: none; color: var(--muted); font-size: 16px; }
.search input { flex: 1; min-width: 0; width: 100%; padding: 7px 0; border: 0; background: none; outline: none; font-size: 13px; }
.search button { flex: none; display: grid; place-items: center; width: 30px; height: 30px;
  padding: 0; border-radius: 7px; font-size: 20px; line-height: 1; color: var(--green); }
.search-cancel { color: var(--muted) !important; }
.search button:hover, .search button:focus-visible { background: var(--green-soft); }

.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 0 84px; }

.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 6px 2px 10px; }
.section-title h2 { margin: 0; font-size: 14px; }
.section-title h2 span { color: var(--muted); font-weight: 400; }
.section-title span { font-size: 11px; color: var(--muted); }

.library-title { align-items: center; }
.book-views { display: flex; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); }
.book-views button { width: 30px; height: 28px; border-radius: 6px; color: var(--muted); font-size: 16px; }
.book-views button[aria-pressed="true"] { background: var(--green); color: #fff; }
.books.gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; }
.books.list { display: grid; gap: 9px; }
.book { min-width: 0; text-align: left; touch-action: pan-y; -webkit-user-select: none; user-select: none; }
.book-open { width: 100%; min-width: 0; padding: 0; text-align: left; }
.book-sort { margin: 0 2px 10px; color: var(--muted); font-size: 11px; }
.series-group { position: relative; min-width: 0; }
.series-group.expanded { grid-column: 1 / -1; padding: 10px; border: 1px solid var(--line);
  border-radius: 14px; background: color-mix(in srgb, var(--green-soft) 42%, var(--card)); }
.series-toggle { position: relative; display: flex; width: 100%; min-width: 0; padding: 0; text-align: left; }
.series-group.expanded > .series-toggle { align-items: center; gap: 10px; }
.series-marker { position: absolute; left: 7px; bottom: 7px; padding: 3px 7px; border-radius: 12px;
  background: rgba(20, 50, 42, 0.88); color: #fff; font-size: 10px; font-weight: 700; }
.series-info { min-width: 0; }
.series-info h3 { margin: 0 0 4px; font-size: 14px; overflow-wrap: anywhere; }
.series-info p { margin: 0; color: var(--muted); font-size: 11px; }
.series-books { display: grid; gap: 12px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.books.gallery .series-books { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.author-results { margin: 2px 0 14px; }
.author-results-title { margin: 0 0 7px; color: var(--muted); font-size: 11px; }
.author-suggestions { display: grid; gap: 7px; }
.author-suggestion { width: 100%; padding: 9px 11px; text-align: left;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.author-suggestion strong, .author-suggestion small { display: block; }
.author-suggestion strong { font-size: 13px; }
.author-suggestion small { margin-top: 2px; color: var(--muted); font-size: 10.5px; }
.author-suggestion.active { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.cover { flex: none; width: 52px; height: 74px; border-radius: 5px; background: linear-gradient(150deg, var(--green), #173f34); display: grid; place-items: center; overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.spine { color: #fff; font-size: 10px; line-height: 1.35; padding: 6px 5px; text-align: center; word-break: keep-all; overflow: hidden; }
.book-info { flex: 1; min-width: 0; }
.book-info h3 { margin: 2px 0 3px; font-size: 15px; line-height: 1.35; overflow-wrap: anywhere; }
.book-info p { margin: 0 0 7px; font-size: 12px; color: var(--muted); }
.book-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 11px; color: var(--muted); }
.badge { background: var(--green-soft); color: var(--green); border-radius: 20px; padding: 1px 8px; }
.resume { color: var(--green); }
.book-accessible { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.books.gallery .book-open { position: relative; display: block; border-radius: 8px; overflow: hidden;
  box-shadow: 0 4px 14px rgba(31, 36, 33, 0.13); }
.books.gallery .book-open:active { transform: scale(0.985); }
.books.gallery .book .cover, .books.gallery .series-toggle .cover { width: 100%; height: auto; aspect-ratio: 2 / 3; border-radius: 8px; }
.books.gallery .book-info, .books.gallery .series-info { display: none; }
.books.gallery .series-group.expanded > .series-toggle .cover { width: 48px; height: 72px; aspect-ratio: auto; }
.books.gallery .series-group.expanded > .series-toggle .series-info { display: block; }
.books.list .book, .books.list .series-toggle { padding: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.books.list .book-open { display: flex; align-items: flex-start; gap: 12px; }
.books.list .book:active, .books.list .series-toggle:active { background: var(--green-soft); }
.books.list .series-toggle { gap: 12px; }
.books.list .series-marker { position: static; align-self: flex-start; order: 3; margin-left: auto;
  background: var(--green-soft); color: var(--green); white-space: nowrap; }
.books.list .series-group.expanded > .series-toggle { padding: 0; border: 0; background: transparent; }
.book-manage-hint { margin-top: 0; }
.book-manage-actions { display: grid; gap: 9px; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-icon { font-size: 34px; opacity: 0.5; }
.empty h2 { font-size: 16px; color: var(--fg); margin: 12px 0 6px; }
.empty p { font-size: 13px; margin: 0 0 14px; line-height: 1.7; }

.hit { display: block; width: 100%; text-align: left; padding: 11px 12px; margin-bottom: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.hit:active { background: var(--green-soft); }
.hit small { display: block; font-size: 10px; color: var(--muted); }
.hit h3 { margin: 3px 0 4px; font-size: 13px; }
.hit p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.6; overflow-wrap: anywhere; }

.note-group { margin-bottom: 16px; }
.note-link { display: block; font-size: 12px; color: var(--green); margin-bottom: 6px; text-align: left; }
.note-card { padding: 11px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; }
.note-open {
  display: block; width: 100%; margin: 0; padding: 0; border: 0;
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: color-mix(in srgb, var(--green) 16%, transparent);
}
.note-card small { display: block; font-size: 10px; color: var(--muted); margin-bottom: 5px; }
.note-card p { margin: 0; font-size: 13.5px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-quote {
  margin: 0 0 7px; padding: 6px 0 6px 10px; border-left: 3px solid var(--green-soft);
  border-left-color: color-mix(in srgb, var(--green) 32%, transparent);
  font-size: 12px; color: var(--muted); line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere;
}
.note-actions { display: flex; gap: 8px; margin-top: 8px; }
.note-actions button { font-size: 11px; color: var(--muted); padding: 3px 0; }
.note-actions .del { color: var(--danger); }

.privacy { margin: 0 2px 8px; font-size: 10.5px; color: var(--muted); line-height: 1.6; }
.privacy strong { color: var(--green); }

.fab-add {
  position: fixed; right: calc(16px + var(--safe-r)); bottom: calc(18px + var(--safe-b));
  padding: 13px 20px; border-radius: 26px; background: var(--green); color: #fff;
  font-size: 14px; font-weight: 600; box-shadow: 0 6px 20px rgba(20, 40, 33, 0.3);
}
.fab-add:active { transform: scale(0.97); }

/* ══ 읽기 모드 — 본문만 ════════════════════════════ */

#readerScreen { position: relative; background: var(--bg); }

#page {
  flex: 1; min-height: 0; overflow: hidden;
  padding: calc(var(--safe-t) + 26px) calc(20px + var(--safe-r)) calc(var(--safe-b) + 26px) calc(20px + var(--safe-l));
  overscroll-behavior: none;
}

#pageFlow {
  height: 100%;
  overflow: hidden;
}

#chapterTitle {
  margin: 0 0 1.4em; font-size: calc(var(--fs) * 1.12); line-height: 1.45;
  font-weight: 650; letter-spacing: -0.2px; word-break: keep-all; overflow-wrap: anywhere;
}

#chapterText, #chapterText p, #pageFlow {
  -webkit-user-select: text; user-select: text;
  -webkit-touch-callout: default;
}

#chapterText {
  font-family: var(--font-stack);
  font-size: var(--fs);
  line-height: var(--lh);
  max-width: var(--maxw);
  /* 한글은 임의 위치에서 끊지 않는다 — 띄어쓰기 단위 줄바꿈이 읽기 편하다. */
  word-break: keep-all;
  overflow-wrap: anywhere;
}

#chapterText p { margin: 0 0 0.95em; text-indent: 0; }
#chapterText p:last-child { margin-bottom: 0; }
#chapterText mark.ann {
  background: #ffd36a;
  color: inherit;
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
#chapterText mark.ann-explain { background: #7fc4ab; color: #10241c; }
#chapterText mark.ann-focus { outline: 2px solid var(--green); outline-offset: 1px; }
[data-theme="dark"] #chapterText mark.ann { background: rgba(255, 196, 72, 0.45); color: inherit; }
[data-theme="dark"] #chapterText mark.ann-explain { background: rgba(127, 196, 171, 0.45); color: inherit; }
[data-theme="sepia"] #chapterText mark.ann { background: #e8c15a; }

/* 쪽 높이 측정용. display:none 이면 scrollHeight 가 0 이라 [hidden] 을 덮어쓴다. */
#pageMeasure {
  position: absolute;
  left: -9999px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
  font-family: var(--font-stack);
  font-size: var(--fs);
  line-height: var(--lh);
  word-break: keep-all;
  overflow-wrap: anywhere;
}
#pageMeasure[hidden] { display: block !important; }
#pageMeasure h1 {
  margin: 0 0 1.4em; font-size: calc(var(--fs) * 1.12); line-height: 1.45;
  font-weight: 650; letter-spacing: -0.2px; word-break: keep-all; overflow-wrap: anywhere;
}
#pageMeasure p { margin: 0 0 0.95em; text-indent: 0; }
#pageMeasure p:last-child { margin-bottom: 0; }

.chapter-end {
  text-align: center; color: var(--muted); font-size: 12px; margin: 2.4em 0 0; letter-spacing: 2px;
}

#progressLine { position: absolute; top: 0; left: 0; right: 0; height: 2px; background: transparent; z-index: 5; }
#progressFill { display: block; height: 100%; width: 0; background: var(--green); transition: width 0.12s linear; }

/* 탭하면 나타나는 최소 크롬 */
.chrome {
  position: absolute; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 9px calc(12px + var(--safe-r)) 9px calc(12px + var(--safe-l));
  background: var(--chrome-bg);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  animation: chromeIn 0.16s ease-out;
}
#topBar { top: 0; padding-top: calc(9px + var(--safe-t)); border-bottom: 1px solid var(--line); }
#bottomBar { bottom: 0; padding-bottom: calc(9px + var(--safe-b)); border-top: 1px solid var(--line); }
@keyframes chromeIn { from { opacity: 0; } to { opacity: 1; } }

.chrome-btn { padding: 7px 11px; border-radius: 9px; font-size: 13px; color: var(--green); background: var(--green-soft); flex: none; }
.chrome-btn:disabled { opacity: 0.38; }
.chrome-btn.icon-btn { min-width: 36px; padding: 7px 8px; text-align: center; font-size: 13px; }
.chrome-title { flex: 1; min-width: 0; text-align: center; font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 400px) {
  .chrome { gap: 4px; padding-left: calc(6px + var(--safe-l)); padding-right: calc(6px + var(--safe-r)); }
  .chrome-btn.icon-btn { min-width: 32px; padding-left: 5px; padding-right: 5px; font-size: 11.5px; }
  #exitReader { padding-left: 8px; padding-right: 8px; }
}

/* 선택 시 하단 고정 액션 바 */
.selbar {
  position: absolute; left: 0; right: 0; z-index: 30;
  bottom: calc(var(--safe-b) + 0px);
  display: flex; gap: 8px; padding: 10px calc(14px + var(--safe-r)) 10px calc(14px + var(--safe-l));
  background: var(--chrome-bg);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  animation: selUp 0.15s ease-out;
}
@keyframes selUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.selbar button {
  flex: 1; padding: 12px 4px; border-radius: 11px;
  background: var(--green); color: #fff; font-size: 14px; font-weight: 600;
}
.selbar button:active { transform: scale(0.97); }

/* ══ 바텀 시트 ════════════════════════════════════ */

#scrim { position: fixed; inset: 0; z-index: 40; background: var(--scrim); animation: fade 0.18s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-height: 86vh; max-height: 86dvh;
  display: flex; flex-direction: column;
  background: var(--card); border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  animation: sheetUp 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.grip { width: 38px; height: 4px; border-radius: 3px; background: var(--line); margin: 8px auto 2px; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 16px 10px; flex: none; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 15px; }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 16px calc(20px + var(--safe-b)); }

.disclaimer {
  margin: 0 0 12px; padding: 8px 11px; border-radius: 9px;
  background: var(--green-soft); color: var(--green); font-size: 11.5px; line-height: 1.55;
}
.sheet .quote {
  margin: 0 0 13px; padding: 8px 0 8px 11px;
  border-left: 3px solid color-mix(in srgb, var(--green) 34%, transparent);
  font-size: 12.5px; color: var(--muted); line-height: 1.75;
  white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 108px; overflow-y: auto;
}
.answer { font-size: 14.5px; line-height: 1.85; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 14px; }
.answer.loading { color: var(--muted); }

.field { margin-bottom: 13px; }
.cloud-backup h3 { font-size: 16px; margin: 0 0 10px; }
.cloud-backup .rows { flex-wrap: wrap; margin-bottom: 12px; }
.cloud-backup .backup-option { margin: 12px 0; }
.cloud-backup .cloud-error { color: var(--danger); }
.cloud-backup select { min-width: 0; }
.cloud-backup input { font-size: 16px; }
.field label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.field textarea, .field input, .field select {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); outline: none; font-size: 15px;
}
.field textarea { resize: none; line-height: 1.7; min-height: 92px; }
.field textarea:focus, .field input:focus, .field select:focus { border-color: var(--green); }
.hint { font-size: 11px; color: var(--muted); line-height: 1.65; margin: 0 0 12px; }
.hint strong { color: var(--fg); }

.rows { display: flex; gap: 8px; }
.review-item { padding: 14px 0; border-bottom: 1px solid var(--line); }
.review-item h3 { margin: 0 0 6px; font-size: 15px; }
.review-item p, .review-question p { white-space: pre-wrap; overflow-wrap: anywhere; }
.review-item .rows { flex-wrap: wrap; }
.review-item .btn { flex: 0 1 auto; font-size: 12px; padding: 9px; }
.review-question { margin: 16px 0; padding: 14px; border-radius: 10px; background: var(--green-soft); }
.review-return { position: fixed; bottom: calc(18px + var(--safe-b)); left: 50%; transform: translateX(-50%); z-index: 22;
  padding: 12px 18px; border-radius: 24px; background: var(--green); color: var(--card); font-size: 13px; white-space: nowrap; }
/* 백그라운드 분석 진행 표시 — 본문을 가리지 않게 오른쪽 위에 작게. 상단 바가 열리면 그 아래로 비킨다. */
.analysis-pill { position: absolute; top: calc(8px + var(--safe-t)); right: calc(10px + var(--safe-r)); z-index: 21;
  display: inline-flex; align-items: center; gap: 6px; max-width: calc(100% - 90px); padding: 6px 11px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--chrome-bg); color: var(--green); font-size: 11.5px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; box-shadow: 0 2px 10px rgba(20, 26, 23, 0.12);
  -webkit-backdrop-filter: saturate(180%) blur(14px); backdrop-filter: saturate(180%) blur(14px); }
#topBar:not([hidden]) ~ .analysis-pill { top: calc(60px + var(--safe-t)); }
.analysis-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--green); animation: jobPulse 1.2s ease-in-out infinite; }
@keyframes jobPulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .analysis-dot { animation: none; } }
.job-status { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; background: var(--green-soft); color: var(--green);
  font-size: 12px; line-height: 1.6; }
.conversation-turn { padding: 12px 0; border-bottom: 1px solid var(--line); }
.conversation-user { margin: 0 0 8px; color: var(--green); font-size: 13px; }
.conversation-ai { margin: 0 0 10px; white-space: pre-wrap; line-height: 1.75; }
.conversation-evidence { flex-wrap: wrap; }
.conversation-evidence .btn { flex: 0 1 auto; padding: 8px; font-size: 11.5px; }
.conversation-follow { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; color: var(--muted); font-size: 11px; }
.conversation-follow button { text-align: left; color: var(--green); line-height: 1.5; }
.conversation-payload { max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
  padding: 12px; border-radius: 9px; background: var(--green-soft); font-size: 11px; line-height: 1.5; }
.character-summary { margin: 0 0 16px; padding: 12px; border-radius: 10px; background: var(--green-soft); line-height: 1.65; }
.character-section-title { margin: 18px 0 8px; color: var(--green); font-size: 14px; }
.character-list, .relationship-list { display: grid; gap: 9px; }
.character-card, .relationship-card { padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--card); }
.character-card h4 { margin: 0 0 5px; font-size: 15px; }
.character-card p, .relationship-card p { margin: 4px 0; white-space: pre-wrap; }
.character-alias { color: var(--green); font-size: 11px; }
.relationship-names { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.relationship-names span { color: var(--muted); }
.person-focus { margin: 0 0 16px; padding: 14px; border: 1px solid var(--green); border-radius: 14px; background: var(--card);
  overflow-wrap: anywhere; }
.person-focus p { margin: 4px 0; white-space: pre-wrap; }
.person-focus-label { color: var(--muted); font-size: 11px; }
.person-focus-name { margin: 2px 0 6px; color: var(--green); font-size: 19px; line-height: 1.35; }
.person-focus-heading { margin: 14px 0 8px; font-size: 13.5px; }
.person-relations { display: grid; gap: 8px; }
.person-relation { padding: 10px; background: var(--bg); }
.person-focus-searching { color: var(--green); font-size: 13px; }
.person-focus-missing { font-weight: 600; }
.person-focus-status { margin: 10px 0 0; padding: 8px 10px; border-radius: 9px; background: var(--green-soft); color: var(--green); }
.person-focus .rows { margin-top: 12px; }
.relationship-graph { position: relative; margin: 14px 0; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.graph-toolbar { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 8px; }
.graph-toolbar label { display: grid; gap: 4px; flex: 1; min-width: 150px; font-size: 12px; }
.graph-toolbar select { width: 100%; max-width: 100%; min-height: 40px; padding: 7px; border: 1px solid var(--line); border-radius: 8px; color: var(--fg); background: var(--bg); }
.graph-controls { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; justify-content: flex-end; }
.graph-controls button, .graph-toolbar > button, .graph-detail > button { min-width: 40px; min-height: 40px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--fg); padding: 7px 10px; }
.graph-toolbar > button { color: var(--green); border-color: var(--green); font-weight: 700; }
.graph-layers { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 8px; font-size: 13px; }
.graph-layers label { display: flex; align-items: center; gap: 5px; min-height: 32px; cursor: pointer; }
.graph-layers input { width: 18px; height: 18px; accent-color: var(--green); }
.graph-status { min-height: 2.5em; margin: 8px 0; line-height: 1.5; }
.graph-status strong { color: var(--fg); }
.graph-legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 10px 0; }
.graph-legend span { display: inline-flex; align-items: center; gap: 4px; }
.graph-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.graph-canvas { display: block; width: 100%; height: clamp(380px, 60vh, 740px); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; touch-action: none; user-select: none; cursor: grab; }
.graph-canvas:active { cursor: grabbing; }
.graph-node, .graph-edge { cursor: pointer; transition: opacity .15s; }
.graph-node rect { fill: var(--card); stroke: var(--green); stroke-width: 2; }
.graph-node.isolated rect { stroke: var(--muted); stroke-dasharray: 5 3; }
.graph-node text { fill: var(--fg); font-size: 24px; font-weight: 650; }
.graph-radial .graph-node text { font-size: 21px; }
.graph-radial .graph-node.major text { font-size: 25px; font-weight: 750; }
.graph-radial .graph-node.center text { font-size: 28px; }
.graph-radial .graph-node.major rect { stroke-width: 3; fill: var(--green-soft); }
.graph-radial .graph-node.center rect { stroke-width: 5; }
.graph-radial .graph-node.minor rect { stroke: var(--muted); stroke-dasharray: 5 4; }
.graph-node .graph-node-subtitle { fill: var(--muted); font-size: 13px; font-weight: 400; }
.graph-radial .graph-node text.graph-node-subtitle { font-size: 13px; font-weight: 400; }
.graph-edge-line { fill: none; stroke-width: 2.5; }
.graph-radial .graph-edge.primary .graph-edge-line { stroke-width: 3; opacity: .85; }
.graph-radial .graph-edge.extra .graph-edge-line { stroke-width: 1.6; opacity: .22; }
.graph-radial .graph-edge.highlighted .graph-edge-line, .graph-radial .graph-edge.selected .graph-edge-line, .graph-radial .graph-edge:focus .graph-edge-line { stroke-width: 4; opacity: 1; }
.graph-hide-extra .graph-edge.extra { display: none; }
.graph-edge.perceived .graph-edge-line { stroke-dasharray: 7 5; }
.graph-edge-hit { fill: none; stroke: transparent; stroke-width: 24; }
.graph-edge.selected .graph-edge-line { stroke-width: 4; }
.graph-node.selected rect, .graph-node:focus rect { stroke-width: 4; fill: var(--green-soft); }
.graph-edge:focus .graph-edge-line { stroke-width: 4; }
.graph-node.dimmed, .graph-edge.dimmed { opacity: .16; }
.graph-radial .graph-node.dimmed { opacity: .5; }
.graph-detail { margin-top: 12px; padding: 12px; border-radius: 10px; border: 1px solid var(--line); }
.graph-detail h4 { margin: 0 0 7px; }
.graph-detail p { line-height: 1.65; }
.graph-detail .relationship-card + .relationship-card { margin-top: 12px; }
.graph-detail > button { margin: 0 5px 10px 0; font-size: 12px; }
.graph-fullscreen { position: fixed; inset: 0; z-index: 10000; height: 100dvh; background: var(--bg); padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
.graph-fullscreen .relationship-graph { display: flex; flex-direction: column; height: 100%; margin: 0; border: 0; border-radius: 0; padding: 10px 12px; overflow: hidden; }
.graph-fullscreen [data-graph-view] { flex: 1; min-height: 100px; display: flex; }
.graph-fullscreen .graph-canvas { height: 100%; min-height: 0; flex: 1; }
.graph-fullscreen .graph-status { min-height: 0; margin: 5px 0; }
.graph-fullscreen .graph-help { margin: 5px 0 0; font-size: 11px; }
.graph-fullscreen .graph-detail { position: absolute; right: 18px; bottom: 36px; width: min(360px, calc(100% - 36px)); max-height: 38%; overflow: auto; margin: 0; background: var(--card); box-shadow: 0 5px 28px #0004; z-index: 1; }
.graph-fullscreen .graph-detail[hidden] { display: none; }
@media (min-width: 700px) {
  .graph-fullscreen .graph-toolbar { position: absolute; top: 10px; left: 12px; width: min(420px, 45%); }
  .graph-fullscreen .graph-layers { justify-content: flex-end; margin-left: 46%; }
  .graph-fullscreen .graph-controls { margin-left: 46%; }
  .graph-fullscreen .graph-status { margin-top: 10px; }
}
@media (max-height: 500px) {
  .graph-fullscreen .relationship-graph { padding: 5px 8px; }
  .graph-fullscreen .graph-layers { margin-top: 0; }
  .graph-fullscreen .graph-controls { margin-top: 0; }
  .graph-fullscreen .graph-help { display: none; }
}
.character-directory { margin: 14px 0; }
.character-directory > summary { cursor: pointer; color: var(--green); padding: 8px 0; font-size: 14px; font-weight: 600; }
.epub-figure { margin: 16px 0; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.epub-figure img { display: block; max-width: 100%; height: auto; margin: auto; }
.epub-figure figcaption { margin-top: 8px; color: var(--muted); font-size: 12px; }
.character-evidence details { margin-top: 7px; }
.character-evidence summary { color: var(--green); font-size: 11px; cursor: pointer; }
.character-evidence blockquote { margin: 7px 0 0; }
.character-actions { position: sticky; bottom: 0; margin-top: 16px; padding: 10px 0 2px; background: var(--bg); }
.character-add { margin-top: 18px; }
.character-add .rows { align-items: stretch; }
.character-add input { flex: 1 1 150px; min-width: 0; }
.character-add .btn { flex: 0 0 auto; padding-left: 14px; padding-right: 14px; }
.research-options { margin: 0 0 14px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 12px; }
.research-cache { margin: 0 0 12px; }
.research-cache .btn { padding: 8px 12px; font-size: 12px; }
.research-cache .hint { margin: 6px 0; }
.research-options summary, .research-report summary, .research-citation summary { color: var(--green); cursor: pointer; }
.research-options label { display: block; margin: 12px 0 5px; }
.research-options textarea { width: 100%; font-size: 12px; }
.research-report { margin: 0 0 14px; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 11px; font-size: 12px; }
.research-report p { margin: 0 0 7px; }
.research-report ul { padding-left: 18px; }
.research-report li { margin: 7px 0; overflow-wrap: anywhere; }
.research-report small { display: block; color: var(--muted); font-size: 10px; }
.research-report a, .research-citation a { color: var(--green); }
.verification-badge { display: inline-block; margin: 7px 0 0; padding: 3px 7px; border-radius: 7px; font-size: 10px; background: var(--bg); color: var(--muted); }
.verification-badge.institutional { background: var(--green-soft); color: var(--green); }
.research-citation { margin-top: 7px; font-size: 11px; }
.summary-overview { margin: 0 0 16px; padding: 12px; border-radius: 10px; background: var(--green-soft); line-height: 1.7; }
.summary-list { display: grid; gap: 9px; }
.summary-card { padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--card); }
.summary-card h4 { margin: 0 0 6px; font-size: 14px; }
.summary-card p { margin: 0; line-height: 1.65; white-space: pre-wrap; }
.summary-questions { margin: 0; padding: 12px 12px 12px 30px; border-radius: 11px; background: var(--card); }
.summary-questions li { margin: 5px 0; line-height: 1.55; }
.error-message { padding: 12px; border-radius: 10px; background: var(--danger-soft, #fbe9e7); color: var(--danger); }
.drafts-button { flex: none; align-self: flex-start; padding: 8px 12px; border-radius: 9px; background: var(--green-soft); color: var(--green); font-size: 12px; }
.selbar { flex-wrap: wrap; }
.selbar button { white-space: nowrap; }
#sheetBody .rows:has(#reviewNote) { flex-wrap: wrap; }
#reviewNote { flex-basis: 100%; }
.backup-option { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.backup-option input { width: auto; }
.btn { flex: 1; padding: 13px; border-radius: 11px; font-size: 14.5px; font-weight: 600; background: var(--green); color: #fff; }
.btn:disabled { opacity: 0.45; }
.btn.ghost { background: var(--bg); color: var(--fg); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); }

.toc-list { display: flex; flex-direction: column; gap: 2px; }
.toc-list button { text-align: left; padding: 11px 10px; border-radius: 9px; font-size: 13.5px; line-height: 1.5; word-break: keep-all; overflow-wrap: anywhere; }
.toc-list button:active { background: var(--green-soft); }
.toc-list button.current { background: var(--green-soft); color: var(--green); font-weight: 600; }
.toc-list small { color: var(--muted); font-size: 11px; margin-right: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { padding: 9px 13px; border-radius: 20px; border: 1px solid var(--line); background: var(--bg); font-size: 13px; }
.chip.active { background: var(--green); border-color: var(--green); color: #fff; }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 42px; height: 42px; flex: none; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); font-size: 18px; }
.stepper output { flex: 1; text-align: center; font-size: 14px; color: var(--muted); }

.preview {
  margin-top: 12px; padding: 13px; border-radius: 11px; border: 1px solid var(--line); background: var(--bg);
  font-family: var(--font-stack); font-size: var(--fs); line-height: var(--lh); word-break: keep-all;
}

.state-line { font-size: 12px; color: var(--muted); margin: 0 0 12px; line-height: 1.6; }
.state-line strong { color: var(--green); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 78px); z-index: 70;
  max-width: calc(100vw - 40px);
  padding: 11px 16px; border-radius: 12px; font-size: 13px; line-height: 1.5;
  background: #23282a; color: #fff; box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
  animation: toastIn 0.18s ease-out; word-break: keep-all;
}
#toast.error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

[hidden] { display: none !important; }

/* 서재 부가 — 책 삭제, 장 기록 점 */
.book { cursor: pointer; }
.book-del {
  align-self: flex-start;
  flex: none;
  white-space: nowrap;
  font-size: 11px;
  color: var(--danger);
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.book-del:active { background: var(--green-soft); }
.note-card[data-open],
.note-card[data-note-id],
.note-card[data-expl-id] { cursor: pointer; }
.note-del {
  align-self: flex-start;
  flex: none;
  white-space: nowrap;
  font-size: 11px;
  color: var(--danger);
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.note-actions .note-del { padding: 5px 8px; }
.note-del:active { background: var(--green-soft); }
.chrome-btn.has-notes { position: relative; }
.chrome-btn.has-notes::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}
