/* ===== README 디자인 토큰 ===== */
:root {
  --bg: #0e1a2b;
  --bg-elevated: #13233a;
  --border: #23324a;
  --text-title: #f4f2ea;
  --text-body: #c3cede;
  --text-muted: #7a8aa3;
  --nav-label: #6b7c96;
  --nav-item: #8fa3bf;
  --nav-dim: #4a5975;
  --nav-active-bg: #1a2c47;
  --nav-active-text: #f4f2ea;
  --accent: #4a6fa5;
  --accent-soft: #2c4468;

  --font-sans: -apple-system, "Pretendard", "Noto Sans KR", "Segoe UI", sans-serif;
  --radius: 8px;
  --transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
  --reading-font-size: 16px;
  --topbar-row-height: 77px;
  --topbar-logo-height: 30px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ios-pwa-safe-top: 54px;
}

html.ios-pwa {
  --safe-top: var(--ios-pwa-safe-top);
  --safe-top: max(env(safe-area-inset-top, 0px), var(--ios-pwa-safe-top));
  overscroll-behavior-x: none;
  touch-action: pan-y pinch-zoom;
}

[data-fontsize="sm"] { --reading-font-size: 14px; }
[data-fontsize="lg"] { --reading-font-size: 18px; }

[data-theme="light"] {
  --bg: #f7f5ef;
  --bg-elevated: #ffffff;
  --border: #e2ded1;
  --text-title: #1f2a1a;
  --text-body: #3c4a35;
  --text-muted: #7c8a72;
  --nav-label: #8a8574;
  --nav-item: #5c6b52;
  --nav-dim: #b3ac98;
  --nav-active-bg: #e9e4d3;
  --nav-active-text: #1f2a1a;
  --accent: #5c7a49;
  --accent-soft: #dfe6d2;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-body);
  font-family: var(--font-sans);
  transition: var(--transition);
  min-height: 100dvh;
  overflow-x: hidden;
}

body {
  padding-top: calc(var(--safe-top) + var(--topbar-row-height));
  padding-bottom: var(--safe-bottom);
  transition: padding-top 0.2s ease, var(--transition);
}

body.topbar-logo-visible {
  padding-top: calc(var(--safe-top) + var(--topbar-row-height) + var(--topbar-logo-height));
}

body { line-height: 1.7; }

a { color: inherit; }

/* ===== 상단 바 (공통) ===== */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 24;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: var(--safe-top) 32px 0;
  border-bottom: 0.5px solid var(--border);
  transition: var(--transition);
  flex-shrink: 0;
  background: var(--bg);
}

.topbar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 0;
  overflow: hidden;
  transform: translateY(-6px);
  color: var(--text-title);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  text-decoration: none;
  transition: height 0.2s ease, opacity 0.18s ease, transform 0.18s ease, color 0.25s ease;
}

.topbar.logo-visible .topbar-logo {
  height: var(--topbar-logo-height);
  opacity: 0.92;
  transform: translateY(0);
  pointer-events: auto;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--topbar-row-height);
}

.topbar.compact {
  padding-left: 20px;
  padding-right: 20px;
}

.topbar.compact .brand {
  display: none;
}

.topbar.compact #bookmarkBtn span + span,
.topbar.compact #memoToggleBtn span + span,
.topbar.compact #fontSizeBtn span + span,
.topbar.compact .mode-toggle span:last-child {
  display: none;
}

.compact-title {
  display: none;
  font-size: 13px;
  color: var(--text-title);
  font-weight: 500;
  line-height: 1.45;
}

.topbar.compact .compact-title { display: inline; }

.topbar-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  position: relative;
  z-index: 2;
}

.topbar .brand {
  font-size: 14px;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 0.5px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 6px 14px;
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.icon-toggle, .mode-toggle, #memoModalClose {
  display: inline-flex;
  align-items: center;
}

.icon-toggle svg, .mode-toggle svg, .menu-btn svg, #memoModalClose svg {
  display: block;
}

.inline-star {
  display: inline-flex;
  align-items: center;
  margin-right: 6px;
  color: var(--accent);
}

.mode-toggle:hover { border-color: var(--accent); color: var(--text-title); }

.icon-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 0.5px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.icon-toggle:hover { border-color: var(--accent); color: var(--text-title); }
.icon-toggle.active { background: var(--nav-active-bg); color: var(--nav-active-text); border-color: var(--accent); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

@media (max-width: 560px) {
  .topbar-actions {
    justify-content: flex-end;
  }
}

/* 상단 액션 버튼은 화면 크기와 관계없이 아이콘만 표시 */
.icon-toggle span + span { display: none; }
.mode-toggle span:last-child { display: none; }

/* ===== 랜딩 페이지 ===== */
.hero {
  flex: 1;
  min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - var(--topbar-row-height));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 22px;
  padding: 48px 24px;
}

.hero h1 {
  font-size: 52px;
  font-weight: 500;
  color: var(--text-title);
  margin: 0;
  letter-spacing: -0.01em;
}

.hero .tagline {
  font-size: 17px;
  color: var(--text-body);
  max-width: 440px;
  margin: 0;
}

.hero-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 28px;
}

.hero .cta {
  background: var(--nav-active-bg);
  color: var(--text-title);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 34px;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.hero .cta:hover { border-color: var(--accent); }

.hero .cta-secondary {
  background: transparent;
  color: var(--text-body);
}

.review-start-panel {
  width: min(440px, 100%);
  margin-top: -4px;
  padding: 16px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg-elevated) 82%, transparent);
  text-align: left;
}

.review-start-panel[hidden] {
  display: none;
}

.review-start-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-title);
  font-size: 13px;
  font-weight: 600;
}

.review-name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.review-name-row input,
.review-name-row button {
  height: 42px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-title);
  font: inherit;
}

.review-name-row input {
  min-width: 0;
  padding: 0 12px;
}

.review-name-row button {
  padding: 0 14px;
  cursor: pointer;
  color: var(--text-title);
  background: var(--nav-active-bg);
}

.review-start-panel p {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.55;
}

.app-home[hidden] {
  display: none;
}

body.home-screen {
  min-height: 100dvh;
}

body.home-screen .reader-layout,
body.home-screen .progress-row,
body.home-screen .selection-toolbar,
body.home-screen .highlight-popover,
body.home-screen .verse-memo-modal {
  display: none;
}

body.home-screen .topbar-main {
  visibility: hidden;
}

body.home-screen #bookmarkBtn,
body.home-screen #memoToggleBtn {
  display: none;
}

body.home-screen .topbar-actions {
  min-width: 44px;
}

/* ===== 리더 화면 ===== */
.reader-layout {
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - var(--topbar-row-height));
  min-width: 0;
  width: 100%;
}

body.sidebar-collapsed .sidebar {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
  overflow: hidden;
}

body.sidebar-collapsed .progress-row { left: 0; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  position: fixed;
  top: var(--topbar-row-height);
  bottom: 0;
  padding: 28px 20px;
  border-right: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: width 0.2s ease, padding 0.2s ease, border-color 0.2s ease, var(--transition);
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  z-index: 18;
}

body.topbar-logo-visible .sidebar {
  top: calc(var(--topbar-row-height) + var(--topbar-logo-height));
}

.nav-divider {
  height: 0.5px;
  background: var(--border);
  margin: 12px 0;
}

.sidebar .nav-label {
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--nav-label);
  margin: 18px 0 4px;
}

.sidebar .nav-label:first-child {
  margin-top: 0;
}

.sidebar .nav-item {
  font-size: 14px;
  color: var(--nav-item);
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  min-width: 0;
}

.sidebar .nav-item-text {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar .nav-item:hover { background: var(--bg-elevated); }

.sidebar .nav-item.active {
  background: var(--nav-active-bg);
  color: var(--nav-active-text);
  font-weight: 500;
}

.sidebar .nav-item.dim { color: var(--nav-dim); }

.reading-pane {
  flex: 1;
  padding: 40px 56px 80px;
  max-width: 720px;
  margin: 0 auto;
  min-height: calc(100vh - 77px);
  min-width: 0;
  width: 100%;
  overflow-y: visible;
  overflow-x: hidden;
}

.reading-pane > .chapter-label,
.reading-pane > h2 {
  display: none;
}

.chapter-section {
  scroll-margin-top: 28px;
  padding-bottom: 56px;
}

.chapter-section + .chapter-section {
  padding-top: 30px;
  border-top: 0.5px solid var(--border);
}

.reading-pane .chapter-label {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.reading-pane h2 {
  font-size: 26px;
  font-weight: 500;
  color: var(--text-title);
  margin: 0 0 20px;
}

.reading-pane p {
  font-size: var(--reading-font-size);
  color: var(--text-body);
  line-height: 1.95;
  margin: 0 0 18px;
}

.chapter-body p {
  font-size: var(--reading-font-size);
  color: var(--text-body);
  line-height: 1.95;
  margin: 0 0 18px;
  max-width: 100%;
}

.chapter-body p.section-marker {
  margin: 36px 0 14px;
  padding-top: 20px;
  border-top: 0.5px solid var(--border);
}

.chapter-body h3 {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-title);
  margin: 32px 0 16px;
  padding-top: 20px;
  border-top: 0.5px solid var(--border);
}

.chapter-body h3:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.chapter-body p.section-marker + h3,
.chapter-body h3.after-section-marker {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.chapter-body strong {
  color: var(--text-title);
  font-weight: 500;
}

.chapter-body em {
  color: var(--text-muted);
  font-style: italic;
}

.chapter-body blockquote {
  margin: 0 0 22px;
  padding: 4px 0 4px 18px;
  border-left: 2px solid var(--accent);
  color: var(--text-body);
}

.chapter-body blockquote p { margin: 0 0 10px; }
.chapter-body blockquote p:last-child { margin-bottom: 0; }

.chapter-body blockquote.qa-dialogue {
  margin: 4px 0 30px;
  padding: 0;
  border-left: none;
}

.chapter-body blockquote.qa-dialogue p {
  font-size: var(--reading-font-size);
  line-height: 1.85;
}

.chapter-body blockquote.qa-dialogue p.qa-question {
  width: fit-content;
  max-width: min(86%, 520px);
  margin: 0 0 24px auto;
  padding: 13px 16px;
  border: 0.5px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 18px 18px 4px 18px;
  background: color-mix(in srgb, var(--bg-elevated) 86%, var(--accent-soft));
  color: var(--text-title);
  line-height: 1.75;
}

.chapter-body blockquote.qa-dialogue p.qa-answer,
.chapter-body blockquote.qa-dialogue p.qa-continuation {
  margin: 0 0 12px;
  padding-left: 0;
}

.chapter-body blockquote.qa-dialogue p.qa-continuation {
  margin-top: -4px;
}

.chapter-body blockquote.code-console {
  position: relative;
  margin: 8px 0 28px;
  padding: 44px 22px 20px;
  border-left: none;
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: #111312;
  color: #e8ece7;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.18);
  overflow-x: auto;
}

.chapter-body blockquote.code-console p {
  margin: 0 0 9px;
  color: #e8ece7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: calc(var(--reading-font-size) - 2px);
  line-height: 1.72;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chapter-body blockquote.code-console p:last-child { margin-bottom: 0; }

.chapter-body blockquote.code-console strong,
.chapter-body blockquote.code-console em {
  color: inherit;
  font-style: normal;
  font-weight: 500;
}

.chapter-body blockquote.code-console .tok-comment { color: #858b88; }
.chapter-body blockquote.code-console .tok-keyword { color: #8ca8ff; }
.chapter-body blockquote.code-console .tok-function { color: #f2d35c; font-weight: 600; }
.chapter-body blockquote.code-console .tok-string { color: #66d982; }
.chapter-body blockquote.code-console .tok-constant { color: #c9a6ff; }

.code-console-title {
  position: absolute;
  top: 14px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 16px;
  color: rgba(232, 236, 231, 0.54);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  letter-spacing: 0;
}

.console-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(232, 236, 231, 0.32);
}

.console-dot:nth-child(1) { background: #e26868; }
.console-dot:nth-child(2) { background: #ddb85a; }
.console-dot:nth-child(3) { background: #78bd74; }
.console-label {
  margin-left: 6px;
  color: rgba(232, 236, 231, 0.58);
}

.memo-panel {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 24px;
  padding: 16px;
  background: var(--bg-elevated);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
}

.memo-panel.open { display: flex; }

.memo-panel-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.memo-panel textarea {
  width: 100%;
  min-height: 90px;
  resize: vertical;
  background: transparent;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-body);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.7;
  padding: 10px 12px;
  transition: var(--transition);
}

.memo-panel textarea:focus { outline: none; border-color: var(--accent); }

.memo-status {
  font-size: 12px;
  color: var(--text-muted);
  min-height: 14px;
}

.memo-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.memo-modal.open { display: flex; }

.memo-modal-box {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
}

.memo-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 0.5px solid var(--border);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-title);
}

.memo-modal-head button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
}

#memoModalList {
  padding: 12px 20px 20px;
  overflow-y: auto;
}

.admin-export-row {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 2px 0 10px;
}

.admin-export-btn {
  height: 32px;
  padding: 0 12px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
}

.admin-export-btn:hover {
  border-color: var(--accent);
  color: var(--text-title);
}

.memo-entry {
  padding: 12px 0;
  border-bottom: 0.5px solid var(--border);
  cursor: pointer;
}

.memo-entry:last-child { border-bottom: none; }

.memo-entry-title {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-title);
  margin-bottom: 4px;
}

.memo-entry-reviewer {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border: 0.5px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.memo-entry-missing {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border: 0.5px solid rgba(192, 85, 74, 0.5);
  border-radius: 999px;
  color: #c98278;
  font-size: 12px;
  font-weight: 600;
}

.memo-entry-title svg {
  flex: 0 0 auto;
  color: #d6b83f;
}

.memo-entry-bookmark-icon {
  display: inline-flex;
  align-items: center;
  color: var(--accent);
}

.memo-entry-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-left: auto;
  border: 0.5px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.memo-entry-delete:hover {
  border-color: rgba(192, 85, 74, 0.5);
  color: #c98278;
}

.memo-entry-delete svg {
  width: 13px;
  height: 13px;
}

.memo-entry-quote {
  font-size: 13px;
  color: var(--text-body);
  line-height: 1.6;
  margin-bottom: 5px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.memo-entry-text {
  font-size: 13px;
  color: var(--text-muted);
  white-space: pre-wrap;
  line-height: 1.6;
}

/* ===== 텍스트 선택 하이라이트 ===== */
.chapter-section mark.hl {
  display: inline;
  line-height: inherit;
  vertical-align: baseline;
  border-radius: 3px;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: inherit;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.chapter-section mark.hl-yellow { background: rgba(242, 210, 75, 0.4); }
.chapter-section mark.hl-green  { background: rgba(127, 191, 127, 0.35); }
.chapter-section mark.hl-blue   { background: rgba(111, 168, 220, 0.35); }
.chapter-section mark.hl-pink   { background: rgba(226, 154, 192, 0.35); }
.chapter-section mark.hl-favorite { background: rgba(242, 210, 75, 0.18); }

.chapter-section mark.hl.has-note::after {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  margin-left: 3px;
  vertical-align: super;
  opacity: 0.6;
}

.bookmark-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin: 0 2px 0 4px;
  color: var(--accent);
  vertical-align: -3px;
  cursor: pointer;
}

.bookmark-marker svg {
  width: 16px;
  height: 16px;
}

.bookmark-popover {
  display: none;
  position: fixed;
  z-index: 58;
  padding: 5px;
  border: 0.5px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
}

.bookmark-popover.open { display: flex; }

.bookmark-delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.bookmark-delete-btn:hover {
  background: var(--nav-active-bg);
  color: #c98278;
}

.bookmark-delete-btn svg {
  width: 15px;
  height: 15px;
}

.selection-toolbar, .highlight-popover {
  display: none;
  position: fixed;
  z-index: 50;
  background: var(--bg-elevated);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  padding: 8px;
  transition: var(--transition);
}

.selection-toolbar.open, .highlight-popover.open { display: flex; }

.selection-toolbar {
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  align-items: center;
  gap: 6px;
}

.selection-toolbar.open {
  animation: toolbar-rise 0.16s ease;
}

@keyframes toolbar-rise {
  from { transform: translate(-50%, 6px); opacity: 0.6; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

.hl-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
  cursor: pointer;
  padding: 0;
}

.toolbar-divider {
  width: 0.5px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: transparent;
  border: none;
  color: var(--text-body);
  cursor: pointer;
  border-radius: 6px;
}

.toolbar-btn:hover { background: var(--nav-active-bg); }
.save-btn {
  width: 34px;
  height: 34px;
  border: 0.5px solid var(--border);
  color: var(--text-title);
}

.verse-memo-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, 0.42);
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.verse-memo-modal.open { display: flex; }

.verse-memo-box {
  width: min(460px, 100%);
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.34);
  padding: 14px;
}

.verse-memo-head,
.verse-memo-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.verse-memo-head {
  color: var(--text-title);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 10px;
}

.verse-memo-quote {
  max-height: 96px;
  overflow-y: auto;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.65;
  padding: 10px 12px;
  border-left: 2px solid var(--accent);
  background: color-mix(in srgb, var(--bg-elevated) 72%, transparent);
  border-radius: 8px;
  margin-bottom: 10px;
}

.verse-memo-box textarea {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  background: transparent;
  border: 0.5px solid var(--border);
  border-radius: 8px;
  color: var(--text-body);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.65;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.verse-memo-box textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.highlight-popover {
  flex-direction: column;
  gap: 10px;
  width: 220px;
}

.highlight-popover-colors {
  display: flex;
  gap: 8px;
  align-items: center;
}

.highlight-popover textarea {
  width: 100%;
  min-height: 60px;
  resize: vertical;
  background: transparent;
  border: 0.5px solid var(--border);
  border-radius: 6px;
  color: var(--text-body);
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 8px 10px;
  box-sizing: border-box;
}

.highlight-popover textarea:focus { outline: none; border-color: var(--accent); }

.highlight-popover-actions {
  display: flex;
  justify-content: space-between;
}

.bookmark-filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
  margin-bottom: 2px;
  border-bottom: 0.5px solid var(--border);
}

.bookmark-filter-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 28px;
  padding: 0 10px;
  border: 0.5px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.bookmark-filter-btn.active {
  color: var(--text-title);
  background: var(--nav-active-bg);
  border-color: var(--accent);
}

.filter-dot,
.memo-color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
  flex: 0 0 auto;
}

.memo-color-dot {
  width: 8px;
  height: 8px;
}

.filter-yellow { background: #f2d24b; }
.filter-green { background: #7fbf7f; }
.filter-blue { background: #6fa8dc; }
.filter-pink { background: #e29ac0; }

.toolbar-btn-text {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
}

.toolbar-btn-text:hover { color: var(--text-title); }
.toolbar-btn-text.danger:hover { color: #c0554a; }

/* ===== 읽기 설정 ===== */
.settings-modal {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 31;
  width: min(380px, 92vw);
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 16px);
  border-left: 0.5px solid var(--border);
  background: var(--bg);
  box-shadow: -10px 0 34px rgba(0, 0, 0, 0.26);
  transform: translateX(100%);
  pointer-events: none;
  transition: transform 0.25s ease, background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.settings-modal.open {
  transform: translateX(0);
  pointer-events: auto;
}

.settings-box {
  width: 100%;
  height: 100%;
  max-height: none;
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-body);
  box-shadow: none;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 0.5px solid var(--border);
  color: var(--text-title);
  font-size: 15px;
  font-weight: 600;
}

.settings-head button {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.settings-section {
  padding: 14px 16px;
  border-bottom: 0.5px solid var(--border);
}

.settings-label {
  margin-bottom: 9px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.segmented-control button,
.settings-action {
  min-height: 36px;
  border: 0.5px solid var(--border);
  border-radius: 7px;
  background: transparent;
  color: var(--text-body);
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
}

.segmented-control button.active,
.settings-action:hover {
  border-color: var(--accent);
  background: var(--nav-active-bg);
  color: var(--text-title);
}

.settings-action {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-bottom: 8px;
}

.settings-action:disabled {
  cursor: wait;
  opacity: 0.72;
}

.settings-help {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.55;
}

.settings-version {
  padding: 11px 16px 14px;
  color: var(--text-muted);
  font-size: 11px;
}

.app-update-banner {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 22px);
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  max-width: calc(100vw - 32px);
  min-width: 288px;
  padding: 12px 12px 12px 16px;
  border: 1px solid color-mix(in srgb, var(--accent) 54%, var(--border));
  border-radius: 18px;
  background: color-mix(in srgb, var(--bg-elevated) 96%, black);
  color: var(--text-title);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.42), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  transform: translateX(-50%);
  backdrop-filter: blur(16px) saturate(1.2);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
}

.app-update-banner::before {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

.app-update-banner span {
  min-width: 0;
  flex: 1 1 auto;
}

.app-update-banner button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 16px;
  border: 1px solid color-mix(in srgb, var(--accent) 72%, var(--text-title));
  border-radius: 999px;
  background: var(--accent);
  color: var(--text-title);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
}

.progress-row {
  position: fixed;
  left: 240px;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: block;
  height: 3px;
  pointer-events: none;
  opacity: 0.72;
}

.progress-track {
  width: 100%;
  height: 100%;
  border-radius: 0;
  background: color-mix(in srgb, var(--border) 76%, transparent);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.15s ease;
}

.review-badge {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 28;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
  backdrop-filter: blur(10px);
}

@media (max-width: 860px) and (display-mode: standalone) {
  :root {
    --safe-top: var(--ios-pwa-safe-top);
    --safe-top: max(env(safe-area-inset-top, 0px), var(--ios-pwa-safe-top));
  }
}

/* ===== 모바일 메뉴 버튼 (기본 숨김) ===== */
.menu-btn {
  display: flex;
  background: transparent;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 20;
}

body.settings-open .overlay { display: block; }

/* ===== 반응형: 태블릿/모바일 ===== */
@media (max-width: 860px) {
  :root {
    --topbar-row-height: 56px;
    --topbar-logo-height: 32px;
  }
  .topbar {
    padding: var(--safe-top) 14px 0;
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
  }
  .topbar-logo {
    font-size: 16px;
    letter-spacing: 0.09em;
  }
  .topbar-row {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) max-content;
    align-items: center;
    min-height: var(--topbar-row-height);
    column-gap: 8px;
    padding-right: 0;
  }
  .topbar .brand { display: none; }
  .compact-title {
    display: inline;
    font-size: 12px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    grid-column: 2;
  }
  .topbar-main {
    display: contents;
  }
  .topbar-actions {
    position: relative;
    top: auto;
    right: auto;
    transform: none;
    grid-column: 3;
    align-self: center;
    gap: 4px;
    padding-top: 0;
    min-width: max-content;
    max-width: none;
    white-space: nowrap;
  }
  .menu-btn { grid-column: 1; }
  .menu-btn,
  .icon-toggle,
  .mode-toggle {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    padding: 0;
    justify-content: center;
    border-radius: 8px;
  }
  .mode-toggle span:last-child { display: none; }
  .settings-modal {
    width: min(340px, 86vw);
    padding: calc(var(--safe-top) + 14px) 14px calc(var(--safe-bottom) + 18px);
  }
  .app-update-banner {
    width: min(420px, calc(100vw - 32px));
    bottom: calc(var(--safe-bottom) + 26px);
    padding: 13px 12px 13px 16px;
    border-radius: 20px;
  }
  .hero h1 { font-size: 38px; }
  .hero .tagline { font-size: 15px; }
  .reading-pane {
    flex-basis: 100%;
    padding: 28px 20px 64px;
    max-width: 100%;
    width: 100%;
  }
  .chapter-body,
  .chapter-body p,
  .chapter-body blockquote {
    max-width: 100%;
    overflow-wrap: break-word;
  }
  .reading-pane h2 { font-size: 22px; }
  .chapter-section { padding-bottom: 46px; }
  .chapter-section + .chapter-section { padding-top: 24px; }
  .progress-row { left: 0; height: 2px; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    padding: calc(var(--safe-top) + 22px) 20px calc(var(--safe-bottom) + 28px);
    max-height: none;
    z-index: 30;
    background: var(--bg);
    transform: translateX(-100%);
    transition: transform 0.25s ease, background 0.25s ease;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.2);
  }

  .sidebar.open { transform: translateX(0); }

  body.topbar-logo-visible .sidebar {
    top: 0;
    max-height: none;
  }

  body.sidebar-collapsed .sidebar {
    width: 240px;
    padding: calc(var(--safe-top) + 22px) 20px calc(var(--safe-bottom) + 28px);
    border-right: 0.5px solid var(--border);
    overflow-y: auto;
  }

  body.menu-open .overlay,
  body.settings-open .overlay { display: block; }
}

@media (max-width: 480px) {
  :root {
    --topbar-row-height: 54px;
    --topbar-logo-height: 30px;
  }
  .hero h1 { font-size: 30px; }
  .hero .cta { width: 100%; }
  .hero-actions { width: 100%; }
  .review-name-row { grid-template-columns: 1fr; }
  .reading-pane { padding: 22px 16px 58px; }
  .topbar { gap: 6px; }
  .topbar-logo { font-size: 16px; }
  .topbar-row {
    grid-template-columns: 34px minmax(0, 1fr) max-content;
    column-gap: 6px;
  }
  .topbar-actions { gap: 3px; }
  .menu-btn,
  .icon-toggle,
  .mode-toggle {
    flex-basis: 34px;
    width: 34px;
    height: 34px;
    padding: 0;
    justify-content: center;
    border-radius: 7px;
  }
  .compact-title {
    font-size: 12px;
    line-height: 1.35;
  }
  .memo-modal-box { max-height: 86vh; }
}
