/* ── Noscript fallback ── */
.noscript-fallback {
  max-width: 40rem;
  margin: 2rem auto;
  padding: 0 1rem;
  font-family: sans-serif;
}

/* ── Accessibility ── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  z-index: 100;
  font-size: 0.9rem;
  text-decoration: none;
  border-radius: 0 0 var(--radius) 0;
}

.skip-link:focus {
  top: 0;
}

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

/* ── Reset & Base ── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar {
  display: none;
}

:root {
  --bg: #faf8f5;
  --bg-card: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #555;
  --accent: #1e3a5f;
  --accent-light: #2d5480;
  --border: #e0dcd6;
  --verse-num: #6b8aaa;
  --paragraph-mark: #5a7a9a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --max-width: 720px;
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --bg-card: #252540;
  --text: #e0dcd6;
  --text-secondary: #a0a0a0;
  --accent: #8ab4d8;
  --accent-light: #a8cce8;
  --border: #3a3a55;
  --verse-num: #8ab4d8;
  --paragraph-mark: #6a94b8;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* ── Color schemes ── */

[data-color-scheme="terracotta"] {
  --accent: #6b3a2a;
  --accent-light: #8b5e3c;
  --verse-num: #9b8579;
  --paragraph-mark: #b08968;
}
[data-color-scheme="terracotta"][data-theme="dark"] {
  --accent: #c49a6c;
  --accent-light: #d4b08c;
  --verse-num: #c49a6c;
  --paragraph-mark: #b08968;
}

[data-color-scheme="green"] {
  --accent: #1a6b50;
  --accent-light: #2a8b6a;
  --verse-num: #5a9b80;
  --paragraph-mark: #4a8b70;
}
[data-color-scheme="green"][data-theme="dark"] {
  --accent: #5ab896;
  --accent-light: #7acea8;
  --verse-num: #5ab896;
  --paragraph-mark: #4aa886;
}

[data-color-scheme="purple"] {
  --accent: #5a2d82;
  --accent-light: #7a4da2;
  --verse-num: #8a6ab0;
  --paragraph-mark: #7a5aa0;
}
[data-color-scheme="purple"][data-theme="dark"] {
  --accent: #c09ad8;
  --accent-light: #d4b8e8;
  --verse-num: #c09ad8;
  --paragraph-mark: #b08ac8;
}

html {
  font-size: 18px;
  scroll-behavior: smooth;
}

body {
  font-family: "Noto Serif KR", "Batang", serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  min-height: 100dvh;
}

/* ── Header ── */
#sticky-group {
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 20;
}

#sticky-group::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 2rem;
  background: linear-gradient(to bottom, var(--bg), transparent);
  pointer-events: none;
}

#app-header {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  border-bottom: none;
  padding: 0.6rem 1rem;
  max-width: var(--max-width);
  margin: 0 auto;
}

#app-header::after {
  content: "";
  display: block;
  height: 1px;
  margin-top: 0.6rem;
  background: linear-gradient(to right, transparent, var(--border) 20%, var(--border) 80%, transparent);
}


#breadcrumb-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  max-height: 4rem;
  opacity: 1;
  overflow: visible;
  transition: max-height 0.25s ease, opacity 0.2s ease;
}

#app-header.compact #breadcrumb-row {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

#header-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

/* ── Settings ── */
.settings-wrapper {
  position: relative;
}

.settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.2em;
  line-height: 1;
}

.settings-btn:hover {
  color: var(--accent);
}

.settings-popover {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  position: fixed;
  z-index: 25;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  padding: 0.5rem;
  width: 280px;
  white-space: nowrap;
}

/* Container is programmatically focused on pointer-driven open so the first
   button doesn't catch a stray :focus-visible ring (iOS Safari). */
.settings-popover:focus,
.settings-popover:focus-visible {
  outline: none;
}

/* ── Drive sync settings UI ── */

.settings-drive-info-btn {
  background: none;
  border: none;
  margin-left: 0.3em;
  padding: 0;
  cursor: pointer;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  /* Korean glyphs sit higher than Latin x-height middle; nudge the icon up
     to align with the optical center of the surrounding label. */
  transform: translateY(-0.08em);
  line-height: 1;
}
.settings-drive-info-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 50%;
}

.drive-info-icon { width: 1.1em; height: 1.1em; }

.settings-drive-info-row {
  padding: 0.35rem 0 0.25rem 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  white-space: normal;
}
.settings-drive-info-row[hidden] { display: none; }

.settings-drive-info-top {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.settings-drive-info-close {
  margin-left: auto;
  background: none;
  border: none;
  padding: 0 0.1em;
  cursor: pointer;
  color: var(--text);
  opacity: 0.45;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}
.settings-drive-info-close:hover { opacity: 0.8; }

.settings-drive-info-email {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-drive-info-desc {
  font-size: 0.78rem;
  color: var(--text-muted, var(--text));
  opacity: 0.7;
  line-height: 1.55;
  white-space: normal;
}

.settings-drive-diag-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--text);
  opacity: 0.45;
  text-decoration: underline;
  text-underline-offset: 2px;
  align-self: flex-start;
}
.settings-drive-diag-btn:hover { opacity: 0.75; }

/* ── Drive disconnect modal ── */

#drive-disconnect-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 78;
  background: rgba(0, 0, 0, 0.45);
}
#drive-disconnect-scrim:not([hidden]) { display: block; }

#drive-disconnect-modal {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 79;
  width: min(92vw, 360px);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  padding: 1.25rem;
}
#drive-disconnect-modal:not([hidden]) { display: block; }

#drive-disconnect-title { font-size: 1rem; font-weight: 700; margin: 0 0 0.6rem; }
#drive-disconnect-body  { font-size: 0.88rem; margin: 0 0 0.75rem; color: var(--text-secondary); line-height: 1.5; }
#drive-disconnect-file-question { font-size: 0.88rem; margin: 0 0 1rem; color: var(--text); line-height: 1.5; font-weight: 500; }

#drive-disconnect-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }

#drive-disconnect-delete, #drive-disconnect-cancel {
  padding: 0.45rem 0.9rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--text);
}
#drive-disconnect-cancel { color: var(--text-secondary); }

#drive-disconnect-keep {
  padding: 0.45rem 0.9rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.25rem 0;
}

/* Right-align the control group so every row shares a clean right edge. */
.settings-row > :last-child {
  margin-left: auto;
}

.settings-label {
  font-size: 0.92rem;
  color: var(--text);
  min-width: 5em;
}

/* Section grouping: a divider sits between consecutive sections. */
.settings-section + .settings-section {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.settings-action-btn {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.8em;
  cursor: pointer;
  height: 28px;
  min-width: 3.5em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.settings-action-btn:hover {
  background: var(--accent);
  color: var(--bg-card);
  border-color: var(--accent);
}
[data-theme="dark"] .settings-action-btn:hover {
  color: #1a1a2e;
}

.btn-group {
  display: flex;
}

.btn-group .toolbar-btn {
  border-radius: 0;
}

.btn-group .toolbar-btn + .toolbar-btn {
  border-left: none;
}

.btn-group .toolbar-btn:first-child {
  border-radius: 4px 0 0 4px;
}

.btn-group .toolbar-btn:last-child {
  border-radius: 0 4px 4px 0;
}

.toolbar-btn {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.7em;
  height: 28px;
  min-width: 2.4em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.15s;
}

.toolbar-btn:hover:not(:disabled) {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.toolbar-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.toolbar-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

#breadcrumb {
  font-size: 0.78rem;
  color: var(--text-secondary);
  min-height: 1.2em;
}

#breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

#breadcrumb a:hover {
  text-decoration: underline;
}

#breadcrumb .sep {
  margin: 0 0.3em;
  color: var(--border);
}

/* ── Breadcrumb Division Picker ── */
.bc-division-popover {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 25;
  list-style: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  padding: 0.3rem 0;
  margin-top: 0.3rem;
  min-width: 6rem;
  white-space: nowrap;
}

.bc-division-item {
  display: block;
  padding: 0.35rem 0.8rem;
  font-size: 0.82rem;
  color: var(--text);
  text-decoration: none;
}

.bc-division-item:hover {
  background: var(--accent);
  color: #fff;
}

.bc-division-item.active {
  color: var(--accent);
  font-weight: 700;
}

.title-division-popover {
  left: 50%;
  transform: translateX(-50%);
}

#page-title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  position: relative;
  margin: 0.3rem 0 0.2rem;
}

/* ── Chapter Title Back Button ── */
.title-back-btn {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s;
}

.title-back-btn:active {
  opacity: 0.4;
}

.title-back-icon {
  width: 1.25rem;
  height: 1.25rem;
}

/* ── Chapter Picker ── */
.title-picker-btn {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  line-height: inherit;
}

.title-picker-btn::after {
  content: "";
  display: inline-block;
  width: 0.4em;
  height: 0.4em;
  border-right: 2px solid var(--text-secondary);
  border-bottom: 2px solid var(--text-secondary);
  transform: rotate(45deg);
  margin-left: 0.4em;
  vertical-align: 0.15em;
  transition: transform 0.15s;
}

.title-picker-btn[aria-expanded="true"]::after {
  transform: rotate(-135deg);
  vertical-align: -0.05em;
}

.title-picker-btn:hover {
  color: var(--accent);
}

.title-picker-btn:hover::after {
  border-color: var(--accent);
}

.chapter-popover {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  padding: 0.5rem;
  margin-top: 0.3rem;
  max-height: 60vh;
  overflow-y: auto;
  min-width: 14rem;
}

.popover-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.5rem, 1fr));
  gap: 0.25rem;
}

.popover-prologue {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.25rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--accent);
  border: 1px dashed var(--border);
  border-radius: 4px;
  text-decoration: none;
  aspect-ratio: 1;
}

.popover-item {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  font-size: 0.82rem;
  text-decoration: none;
  color: var(--text);
  border-radius: 4px;
  transition: background 0.1s;
}

.popover-item:hover {
  background: var(--accent);
  color: #fff;
}

.popover-item.current {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* ── Search Bar (Desktop inline) ── */
#search-bar {
  position: relative;
  width: 16rem;
  transition: width 0.2s ease;
}

#search-bar:focus-within {
  width: 22rem;
}

#search-input {
  width: 100%;
  font-family: inherit;
  font-size: 0.85rem;
  /* Reserve space for 44px history toggle (right: 2.6rem) + 44px clear (right: 0.1rem). */
  padding: 0.6rem 5.5rem 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  background: var(--bg-card);
  color: var(--text);
  outline: none;
  line-height: 1.3;
  min-height: 44px;
  box-sizing: border-box;
}

/* Trim padding when one or both action buttons are hidden so text doesn't
   sit beneath empty space. JS keeps the dataset flags in sync with the
   button .hidden state. */
#search-bar[data-clear-hidden="true"] #search-input {
  padding-right: 3rem;
}

#search-bar[data-clear-hidden="true"][data-history-hidden="true"] #search-input {
  padding-right: 0.75rem;
}

#search-input::-webkit-search-cancel-button,
#search-sheet-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

#search-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 15%, transparent);
}

#search-clear,
#search-history-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
}

#search-clear { right: 0.1rem; }
#search-history-toggle { right: 2.6rem; }
#search-bar[data-clear-hidden="true"] #search-history-toggle { right: 0.1rem; }

#search-clear:hover,
#search-history-toggle:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

#search-clear:focus-visible,
#search-history-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent);
}

#search-history-toggle[aria-expanded="true"] {
  color: var(--accent);
}

/* ── Search history panel (shared with sheet variant) ── */
#search-history,
#search-sheet-history {
  list-style: none;
  margin: 0;
  padding: 0.3rem 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--text) 18%, transparent);
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

#search-history {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  right: 0;
  z-index: 50;
}

#search-sheet-history {
  margin: 0 0.8rem 0.5rem;
}

.search-history-item {
  display: flex;
  align-items: stretch;
  min-height: 44px;
}

.search-history-item-select {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 0 0.85rem;
  font: inherit;
  font-size: 0.92rem;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 0;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 44px;
}

.search-history-item-select[aria-selected="true"],
.search-history-item-select:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.search-history-item-select:focus-visible {
  outline: none;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 50%, transparent);
}

.search-history-item-remove {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  margin-right: 0.2rem;
}

.search-history-item-remove:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.search-history-item-remove:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent);
}

.search-history-more,
.search-history-clear {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  background: none;
  border: none;
  text-align: center;
  cursor: pointer;
}

.search-history-more {
  color: var(--accent);
  border-top: 1px dashed var(--border);
}

.search-history-clear {
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

.search-history-more:hover,
.search-history-clear:hover {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.search-history-more:hover { color: var(--accent); }
.search-history-clear:hover { color: var(--accent); }

.search-history-more:focus-visible,
.search-history-clear:focus-visible {
  outline: none;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* ── Search FAB (Mobile only) ── */
#search-fab {
  display: none;
  position: fixed;
  right: 1.2rem;
  z-index: 30;
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.25);
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease, bottom 0.25s ease;
}

#search-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

#search-fab:active {
  transform: scale(0.95);
}

/* Lift FAB above chapter-nav when it scrolls into view */
#search-fab {
  bottom: max(calc(1.5rem + env(safe-area-inset-bottom)), var(--fab-lift-nav, 0px));
}

/* Lift FAB when audio bar is visible */
#audio-bar:not([hidden]) ~ #search-fab {
  bottom: max(calc(5rem + env(safe-area-inset-bottom)), var(--fab-lift-nav, 0px));
}

/* ── Install guide modal ── */
#install-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.45);
}
#install-scrim:not([hidden]) {
  display: block;
}
#install-modal {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 61;
  width: min(92vw, 420px);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-card);
  color: var(--text);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  padding: 1.25rem 1.25rem 1rem;
}
#install-modal:not([hidden]) {
  display: block;
}
#install-modal-title {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  font-weight: 700;
}
#install-modal-close {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  background: transparent;
  border: 0;
  color: var(--text-secondary);
  font-size: 1.6rem;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#install-modal-close:hover { color: var(--text); }
#install-modal-body p { margin: 0.5rem 0; line-height: 1.6; }
#install-modal-body ol { padding-left: 1.3rem; margin: 0.5rem 0; }
#install-modal-body ol li { margin: 0.35rem 0; line-height: 1.6; }
#install-modal-body .install-figure {
  margin: 0.75rem 0;
  text-align: center;
}
#install-modal-body .install-figure img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
}
#install-modal-body .install-figure figcaption {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.3rem;
}

/* ── Install guide screenshot slider ── */
.install-slider-wrap {
  margin: 0.75rem -1.25rem 0;
  overflow: hidden;
  border-top: 1px solid var(--border);
}
.install-slider-track {
  display: flex;
  transition: transform 0.32s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  will-change: transform;
  touch-action: pan-y;
  cursor: grab;
}
.install-slider-track:active {
  cursor: grabbing;
}
.install-slide {
  flex: 0 0 100%;
  overflow: hidden;
}
.install-slide img {
  width: 100%;
  height: 300px;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.install-dots {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 0.65rem 1.25rem 0;
}
.install-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
  border: 0;
  padding: 0;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  flex-shrink: 0;
}
.install-dot.active {
  background: var(--accent);
  transform: scale(1.25);
}
.install-step-caption {
  text-align: center;
  padding: 0.4rem 1.25rem 0.25rem;
  font-size: 0.9rem;
  line-height: 1.55;
  min-height: 2.8em;
  color: var(--text);
}
.install-bookmark-notice {
  margin: 0.75rem 1.25rem 0;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--text-muted, #666);
  background: var(--surface-alt, #f5f5f5);
}
[data-theme="dark"] .install-bookmark-notice {
  color: var(--text-muted, #aaa);
  background: var(--surface-alt, #2a2a2a);
}
#install-modal-body .install-cta {
  display: inline-block;
  margin-top: 0.75rem;
  min-height: 44px;
  padding: 0.55rem 1.1rem;
  background: var(--accent);
  /* Light mode: --accent #1e3a5f is dark → white text = ~12:1. */
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}
/* Dark mode: --accent #8ab4d8 is light → use dark text for AA contrast. */
[data-theme="dark"] #install-modal-body .install-cta {
  color: #1a1a2e;
}
#install-modal-body .install-cta--end {
  display: block;
  margin-left: auto;
}
#install-modal-body .install-cta:hover { opacity: 0.9; }
#install-modal-body .install-cta[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}
#install-modal-body .install-note {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.75rem;
}
.install-never-show-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}
.install-never-show-row input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}
.install-never-show-row label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
#install-modal-body kbd {
  display: inline-block;
  padding: 0.05rem 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85em;
  font-family: inherit;
}

/* ── Search Bottom Sheet (Mobile only) ── */
#search-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  /* Block touch panning on the scrim — without this iOS Safari can rubber-band
     the body even though body is position:fixed, especially while the compact
     modal is small and most of the viewport is scrim. */
  touch-action: none;
}

#search-scrim:not([hidden]) {
  display: block;
  animation: bm-scrim-in 0.25s ease both;
}

#search-sheet {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: none;
  position: fixed;
  /* Float on all four sides — the same 12px breathing room compact already
     uses, so expanded reads as a card, not a flush bottom sheet. */
  bottom: 0.75rem;
  left: 0.75rem;
  right: 0.75rem;
  z-index: 50;
  background: var(--bg);
  background-clip: padding-box;
  /* All four corners rounded — both states float as cards with margins. */
  border-radius: 16px;
  /* Omnidirectional shadow suits the floating card on all four sides. */
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
  flex-direction: column;
  height: 55vh;
  max-height: 80vh;
  padding-bottom: env(safe-area-inset-bottom);
  transition:
    height 220ms cubic-bezier(0.4, 0, 0.2, 1),
    bottom 220ms cubic-bezier(0.4, 0, 0.2, 1),
    left 220ms cubic-bezier(0.4, 0, 0.2, 1),
    right 220ms cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 220ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Compact state: only input bar + chips visible, sized to sit above keyboard.
   Fixed px so compact↔expanded `height` transition can interpolate.
   left/right margins are inherited from the base rule (already 0.75rem); the
   bottom is applied via JS in adjustSheetForKeyboard (keyboardOffset + 12). */
#search-sheet[data-state="compact"] {
  /* Add the safe-area inset so it doesn't eat the chip row. With
     box-sizing:border-box the base `padding-bottom: env(safe-area-inset-bottom)`
     subtracts from the fixed height, and on devices with a home indicator the
     value stays >0 even while the keyboard is up (it tracks the layout viewport,
     not the visual one). */
  height: calc(6.4rem + env(safe-area-inset-bottom));
  /* Omnidirectional shadow so the modal reads as a floating card. The base
     rule's negative-Y shadow only suits the bottom-attached expanded state. */
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
}

/* The handle normally provides top breathing room above the input bar; add
   matching padding when it's hidden so the input doesn't kiss the sheet edge. */
#search-sheet[data-state="compact"] #search-sheet-bar {
  padding-top: 0.8rem;
}

#search-sheet[data-state="compact"] #search-sheet-handle,
#search-sheet[data-state="compact"] #search-sheet-results {
  display: none;
}

/* Grow the compact sheet when the history panel opens so the list is visible
   without forcing a state-machine round-trip into expanded mode. */
#search-sheet[data-state="compact"]:has(#search-sheet-history:not([hidden])) {
  height: auto;
  max-height: min(70vh, 28rem);
}

#search-sheet:not([hidden]) {
  display: flex;
  animation: bm-drawer-in-up 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

#search-sheet-handle {
  display: flex;
  justify-content: center;
  padding: 0.5rem 0 0.3rem;
  cursor: grab;
  touch-action: none;
}

#search-sheet-handle span {
  width: 2.2rem;
  height: 0.22rem;
  background: var(--border);
  border-radius: 2px;
}

#search-sheet-bar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0 0.5rem 0.6rem 0.8rem;
}

#search-sheet-input-wrap {
  position: relative;
  flex: 1;
}

#search-sheet-close {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  border-radius: 50%;
  padding: 0;
  transition: color 0.15s, background 0.15s;
}

#search-sheet-close:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

#search-sheet-close:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent);
}

#search-sheet-input {
  width: 100%;
  font-family: inherit;
  font-size: 0.95rem;
  /* Reserve 96px for history toggle (44) + clear (44) + 8px breathing room. */
  padding: 0.7rem 6rem 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: var(--bg-card);
  color: var(--text);
  outline: none;
  line-height: 1.4;
  min-height: 48px;
  box-sizing: border-box;
}

#search-sheet-input-wrap[data-clear-hidden="true"] #search-sheet-input {
  padding-right: 3.25rem;
}

#search-sheet-input-wrap[data-clear-hidden="true"][data-history-hidden="true"] #search-sheet-input {
  padding-right: 0.85rem;
}

#search-sheet-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 15%, transparent);
}

#search-sheet-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

#search-sheet-clear,
#search-sheet-history-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
}

#search-sheet-clear { right: 0.25rem; }
#search-sheet-history-toggle { right: 3rem; }
#search-sheet-input-wrap[data-clear-hidden="true"] #search-sheet-history-toggle { right: 0.25rem; }

#search-sheet-clear:hover,
#search-sheet-history-toggle:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

#search-sheet-clear:focus-visible,
#search-sheet-history-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent);
}

#search-sheet-history-toggle[aria-expanded="true"] {
  color: var(--accent);
}

#search-sheet-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.4rem;
  padding: 0 0.8rem 0.55rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

#search-sheet-chips::-webkit-scrollbar {
  display: none;
}

.search-chip {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 0.82rem;
  line-height: 1.2;
  padding: 0.35rem 0.7rem;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.search-chip:hover {
  border-color: var(--accent);
}

.search-chip:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}

.search-notice {
  margin: 0 0 0.6rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--text);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}

#search-sheet-results {
  flex: 1;
  overflow-y: auto;
  padding: 0 1rem 1rem;
  -webkit-overflow-scrolling: touch;
  /* Don't let inner scrolling chain to the body when the user reaches the
     top/bottom of the result list. */
  overscroll-behavior: contain;
}

/* ── Search Results ── */
.search-count {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 0.8rem;
}


.search-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.search-results {
  list-style: none;
}

.search-result-item {
  border-bottom: 1px solid var(--border);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item a {
  display: block;
  padding: 0.6rem 0;
  text-decoration: none;
  color: var(--text);
  transition: background 0.1s;
}

.search-result-item a:hover {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.search-result-ref {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.15rem;
}

.search-result-text {
  display: block;
  font-family: "Noto Serif KR", serif;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

/* ── Search Highlight ── */
mark.search-highlight {
  background: rgba(255, 200, 50, 0.35);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

[data-theme="dark"] mark.search-highlight {
  background: rgba(196, 154, 108, 0.3);
}

.verse-highlight {
  background: rgba(107, 58, 42, 0.08) !important;
  border-radius: 5px;
  padding: 0.1em 0.15em;
}

/* In a run of consecutive highlighted verses, flatten the corners that abut
   another highlighted verse so the run reads as a single block.
   Inline verses (default) stack horizontally → flatten left/right edges.
   Block verses (poetry) stack vertically   → flatten top/bottom edges. */
.verse-highlight.verse-highlight-join-prev {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.verse-highlight.verse-highlight-join-next {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.verse.verse-poetry.verse-highlight.verse-highlight-join-prev {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-bottom-left-radius: 5px;
  border-bottom-right-radius: 5px;
}
.verse.verse-poetry.verse-highlight.verse-highlight-join-next {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}
.verse.verse-poetry.verse-highlight.verse-highlight-join-prev.verse-highlight-join-next {
  border-radius: 0;
}

[data-theme="dark"] .verse-highlight {
  background: rgba(196, 154, 108, 0.12) !important;
}

/* ── Search Pagination ── */
.search-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1rem;
}

.search-pagination a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.88rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background 0.15s;
}

.search-pagination a:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.search-page-info {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* ── Main ── */
#app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1rem 1rem;
}

/* ── Resume Banner ── */
#resume-banner-slot {
  position: relative;
  z-index: 10; /* above #app-header::before gradient (z-index: 9) */
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1rem;
}

.resume-banner {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: flex;
  align-items: center;
  background: var(--accent);
  border-radius: var(--radius);
  overflow: hidden;
  transition: opacity 0.15s;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.resume-banner-link {
  flex: 1;
  padding: 0.7rem 1rem;
  color: #fff;
  text-decoration: none;
  font-size: 0.9rem;
  text-align: center;
}

.resume-banner-link:hover {
  opacity: 0.85;
}

.resume-banner-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  border: none;
  border-left: 1px solid rgba(255, 255, 255, 0.3);
  background: transparent;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.7rem 0;
  flex-shrink: 0;
}

.resume-banner-close:hover {
  background: rgba(0, 0, 0, 0.15);
}

/* ── Book List ── */
.division {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  margin-bottom: 1.8rem;
}

.division-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-bottom: 0.4rem;
  border-bottom: none;
  background-image: linear-gradient(to right, transparent, var(--accent) 15%, var(--accent) 85%, transparent);
  background-repeat: no-repeat;
  background-position: bottom;
  background-size: 100% 1px;
  margin-bottom: 0.6rem;
  cursor: pointer;
  list-style: none;
}

.division-title::-webkit-details-marker {
  display: none;
}

.division-title::after {
  content: "";
  display: inline-block;
  width: 0.45em;
  height: 0.45em;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(45deg);
  margin-left: 0.5em;
  vertical-align: 0.1em;
  transition: transform 0.2s;
}

.division[open] > .division-title::after {
  transform: rotate(-135deg);
  vertical-align: -0.1em;
}

.ot-subcategory {
  margin-bottom: 1rem;
}

.ot-subcategory-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 0.8rem 0 0.4rem;
  padding-left: 0.2rem;
}

.book-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
  gap: 0.4rem;
}

.book-list a {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  padding: 0.5rem 0.7rem;
  word-break: keep-all;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-size: 0.88rem;
  transition: background 0.15s;
}

.book-list a:hover,
.book-list a:focus-visible {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Chapter Grid ── */
.chapter-grid {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.2rem, 1fr));
  gap: 0.4rem;
  margin-top: 0.8rem;
}

.chapter-grid a {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-size: 0.9rem;
  transition: background 0.15s;
}

.chapter-grid a:hover,
.chapter-grid a:focus-visible {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.prologue-link {
  grid-column: 1 / -1;
  aspect-ratio: auto !important;
  padding: 0.5rem;
  font-size: 0.85rem;
  color: var(--accent) !important;
  border-style: solid !important;
}

.prologue-link:hover,
.prologue-link:focus-visible {
  color: #fff !important;
}

/* ── Chapter View (verses) ── */
.chapter-text {
  font-size: 1rem;
  line-height: 2;
}

.verse {
  display: inline;
}

.verse.verse-poetry {
  display: block;
  padding-left: 2rem;
}

.verse.verse-poetry .verse-num {
  display: inline-block;
  box-sizing: border-box;
  margin-left: -2rem;
  width: 2rem;
  text-align: left;
  margin-right: 0;
}

.verse.verse-poetry .hanging-quote {
  margin-left: -0.4em;
}

.verse.verse-poetry .hanging-quote--single {
  margin-left: -0.2em;
}

.verse-num {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--verse-num);
  vertical-align: super;
  margin-right: 0.15em;
  user-select: none;
}

.verse-num::before {
  content: attr(data-v);
}

.paragraph-break {
  display: block;
  margin-top: 0.9em;
}

.hemistich-break {
  display: block;
}

.stanza-break {
  display: block;
  margin-top: 1.5em;
}

.pilcrow {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  color: var(--paragraph-mark);
  margin-right: 0.2em;
  user-select: none;
}

/* Dual numbering (alt_ref) */
.alt-ref {
  font-size: 0.6rem;
  color: var(--accent-light);
  margin-left: 0.1em;
}

.dual-numbering-note {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 0.8rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Cross-chapter reference */
.verse-cross-ref {
  padding: 0 0.1em;
}

.cross-ref-tag {
  font-size: 0.85em;
  color: var(--accent-light);
}

/* ── Prologue ── */
.prologue-text {
  font-size: 0.95rem;
  line-height: 2;
}

.prologue-text p {
  text-indent: 1em;
  margin-bottom: 1em;
}

/* ── Chapter Navigation ── */
.chapter-nav {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2rem;
  padding-top: 1rem;
}

.chapter-nav a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.88rem;
  padding: 0.4rem 0.8rem;
  border: none;
  border-radius: var(--radius);
  transition: background 0.15s;
}

.chapter-nav a:hover {
  background: var(--accent);
  color: #fff;
}

.chapter-nav .placeholder {
  width: 4rem;
}

/* ── Settings about row ── */
.color-swatches {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--swatch-color);
  border: 2px solid transparent;
  outline: 2px solid transparent;
  outline-offset: 1px;
  cursor: pointer;
  transition: transform 0.1s, outline-color 0.15s;
  padding: 0;
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch[aria-pressed="true"] {
  outline-color: var(--text);
}

.cache-clear-btn {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  color: #c0392b;
  background: none;
  border: 1px solid #e6a9a4;
  border-radius: 4px;
  padding: 0 0.8em;
  height: 28px;
  min-width: 3.5em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3em;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.warn-icon {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
}

.cache-clear-btn:hover {
  background: #c0392b;
  color: #fff;
  border-color: #c0392b;
}

[data-theme="dark"] .cache-clear-btn {
  color: #e88;
  border-color: #844;
}

[data-theme="dark"] .cache-clear-btn:hover {
  background: #a33;
  color: #fff;
  border-color: #a33;
}

.settings-about {
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  font-size: 0.65rem;
  color: var(--text-secondary);
  white-space: normal;
  line-height: 1.4;
  text-align: center;
  font-family: sans-serif;
}

.settings-about a {
  color: var(--accent);
  text-decoration: none;
}

.settings-about a:hover {
  text-decoration: underline;
}

.github-icon {
  vertical-align: middle;
  fill: currentColor;
  margin-bottom: 1px;
}

/* ── Audio Bar ── */
#audio-bar {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  position: sticky;
  bottom: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 50%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: none;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0.5rem 1.25rem max(0.75rem, env(safe-area-inset-bottom, 0px));
}

#audio-bar::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border) 20%, var(--border) 80%, transparent);
}

#audio-bar[hidden] {
  display: none;
}

.audio-player {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Play/pause button — CSS icons, no unicode glyphs */
.audio-play-btn {
  flex-shrink: 0;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.audio-play-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.audio-play-btn:active {
  transform: scale(0.96);
}

/* Play triangle */
.audio-icon-play {
  display: block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0.4rem 0 0.4rem 0.7rem;
  border-color: transparent transparent transparent var(--bg);
  margin-left: 0.15rem;
}

/* Pause bars */
.audio-icon-pause {
  display: flex;
  gap: 0.18rem;
}

.audio-icon-pause::before,
.audio-icon-pause::after {
  content: "";
  display: block;
  width: 0.22rem;
  height: 0.7rem;
  background: var(--bg);
  border-radius: 1px;
}

/* Loading spinner */
.audio-icon-loading {
  display: block;
  width: 0.85rem;
  height: 0.85rem;
  border: 0.13rem solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--bg);
  border-radius: 50%;
  animation: audio-spin 0.7s linear infinite;
}

@keyframes audio-spin {
  to { transform: rotate(360deg); }
}

/* Progress bar */
.audio-progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.audio-progress {
  --fill: 0%;
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--border) var(--fill));
  border-radius: 1.5px;
  outline: none;
  cursor: pointer;
  transition: height 0.15s ease;
}

.audio-progress:hover {
  height: 5px;
}

.audio-progress::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
  cursor: pointer;
  transition: box-shadow 0.15s ease;
}

.audio-progress:hover::-webkit-slider-thumb {
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 25%, transparent);
}

.audio-progress::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
  cursor: pointer;
}

.audio-progress::-moz-range-track {
  height: 3px;
  background: transparent;
  border: none;
}

.audio-time {
  font-size: 0.68rem;
  color: var(--text-secondary);
  min-width: 6.5em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.audio-speed-btn {
  flex-shrink: 0;
  width: 3rem;
  text-align: center;
  padding: 0.15rem 0;
  border: 1px solid var(--border);
  border-radius: 0.3rem;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.audio-speed-btn:hover {
  color: var(--text);
  border-color: var(--text-secondary);
}

/* Unavailable message */
.audio-unavailable {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding: 0.15rem 0;
}

.audio-unavailable-icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  background: currentColor;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 18v-6a9 9 0 0 1 18 0v6'/%3E%3Cpath d='M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 18v-6a9 9 0 0 1 18 0v6'/%3E%3Cpath d='M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  vertical-align: -0.15em;
}

/* ── Loading / Error ── */
.loading {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.error {
  text-align: center;
  padding: 3rem 1rem;
  color: #a33;
  font-size: 0.9rem;
}

/* ── Focus ── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Responsive ── */

/* Mobile: hide inline search, show FAB */
@media (max-width: 768px) {
  #search-bar {
    display: none;
  }

  #search-fab {
    display: flex;
  }

  /* Extra top margin so FAB (3.2rem) fits in the gap above chapter-nav */
  .chapter-nav {
    margin-top: 4.5rem;
  }
}

/* Desktop: hide FAB and bottom sheet */
@media (min-width: 769px) {
  #search-fab {
    display: none !important;
  }

  #search-scrim,
  #search-sheet {
    display: none !important;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 16px;
  }

  .book-list {
    grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
  }

  .book-list a {
    font-size: 0.82rem;
    padding: 0.4rem 0.4rem;
  }

  .chapter-grid {
    grid-template-columns: repeat(auto-fill, minmax(2.8rem, 1fr));
  }
}

/* ── Launch Screen ── */

#launch-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #1a1a2e;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  will-change: opacity;
}

#launch-screen svg {
  width: 30vmin;
  aspect-ratio: 494 / 671;
  will-change: transform, opacity;
}

#launch-screen.fade-out {
  animation: launch-screen-out 2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

#launch-screen.fade-out svg {
  animation: launch-screen-out 2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes launch-screen-out {
  to { opacity: 0; }
}

/* launch-cross-out is no longer used, kept launch-screen-out for both */

@media (prefers-reduced-motion: reduce) {
  #launch-screen.fade-out,
  #launch-screen.fade-out svg {
    animation: none;
    opacity: 0;
  }
}

/* ── SW Update Toast ── */

#sw-update-toast {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem 1rem;
  max-width: calc(100vw - 2rem);
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: 0.9rem;
  animation: toast-in 0.3s ease-out;
}

#sw-update-toast > span {
  white-space: nowrap;
}

#sw-update-release-link {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

#sw-update-btn {
  padding: 0.35rem 0.75rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(1rem); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Search Reference Match Card ── */
.ref-match-item {
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--border) !important;
}

.search-result-ref-card {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: flex !important;
  flex-direction: column;
  padding: 1rem !important;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease !important;
}

.search-result-ref-card:hover {
  background: var(--accent) !important;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.search-result-ref-card:hover .search-result-ref-label,
.search-result-ref-card:hover .search-result-ref-title {
  color: #fff !important;
}

.search-result-ref-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.search-result-ref-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

/* ═══════════════════════════════════════════════
   BOOKMARK FEATURE
   ═══════════════════════════════════════════════ */

/* ── Header bookmark button ── */

.title-bookmark-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 2.2rem;
  height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 0.15s;
  padding: 0;
}

.title-bookmark-btn:hover,
.title-bookmark-btn.has-bookmark {
  color: var(--accent);
}


/* ── Verse selection mode ── */

body.verse-select-active {
  user-select: none;
}

body.verse-select-active #audio-bar {
  display: none;
}

body.verse-select-active #search-fab {
  display: none !important;
}


body.verse-select-active .verse[data-vref] {
  cursor: pointer;
  padding: 0.1em 0.15em;
  transition: background 0.1s;
}

body.verse-select-active .verse[data-vref]:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: 5px;
}

/* Poetry verses use a 2rem left gutter for the verse-num (margin-left: -2rem).
   The shorthand padding above would shrink that gutter and push the number
   off-screen, so restore it here. */
body.verse-select-active .verse.verse-poetry[data-vref] {
  padding-left: 2rem;
}

.verse.verse-selected {
  background: color-mix(in srgb, var(--accent) 20%, transparent) !important;
  border-radius: 5px;
}

/* In a run of consecutive selected verses, flatten the corners that abut
   another selected verse so the run reads as a single highlighted block.
   Inline verses (default) stack horizontally → flatten left/right edges.
   Block verses (poetry) stack vertically   → flatten top/bottom edges. */
.verse.verse-selected.verse-selected-join-prev {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.verse.verse-selected.verse-selected-join-next {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.verse.verse-poetry.verse-selected.verse-selected-join-prev {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-bottom-left-radius: 5px;
  border-bottom-right-radius: 5px;
}
.verse.verse-poetry.verse-selected.verse-selected-join-next {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}
.verse.verse-poetry.verse-selected.verse-selected-join-prev.verse-selected-join-next {
  border-radius: 0;
}

/* ── Verse selection action bar ── */

#verse-select-bar {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 35;
  background: color-mix(in srgb, var(--bg) 50%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: none;
  padding: 0.65rem 1rem max(0.75rem, env(safe-area-inset-bottom));
  align-items: center;
  gap: 0.75rem;
}

#verse-select-bar::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border) 20%, var(--border) 80%, transparent);
}

#verse-select-bar:not([hidden]) {
  display: flex;
}

#verse-select-count {
  flex: 1;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

#verse-select-bookmark-btn {
  padding: 0.45rem 1.1rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.15s;
}

#verse-select-bookmark-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

#verse-select-cancel-btn {
  padding: 0.45rem 0.8rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s;
}

#verse-select-cancel-btn:hover {
  background: var(--border);
}

/* ── Bookmark drawer (right-side panel) ── */

#bookmark-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.4);
}

#bookmark-scrim:not([hidden]) {
  display: block;
  animation: bm-scrim-in 0.25s ease both;
}

@keyframes bm-scrim-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Bookmark drawer (mobile: bottom sheet) ── */
#bookmark-drawer {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 70vh;
  max-height: 85vh;
  z-index: 71;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
  flex-direction: column;
  overflow: hidden;
}

#bookmark-drawer:not([hidden]):not(.drawer-closing) {
  display: flex;
  animation: bm-drawer-in-up 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

#bookmark-drawer.drawer-closing {
  display: flex;
  animation: bm-drawer-out-down 0.22s ease-in both;
  pointer-events: none;
}

@keyframes bm-drawer-in-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

@keyframes bm-drawer-out-down {
  from { transform: translateY(0); }
  to   { transform: translateY(100%); }
}

/* ── Bookmark drawer (desktop: right side panel) ── */
@media (min-width: 769px) {
  #bookmark-drawer {
    top: 2.5vh;
    right: 0;
    bottom: auto;
    left: auto;
    width: min(360px, 90vw);
    height: 95vh;
    max-height: none;
    border-radius: 16px 0 0 16px;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
  }

  #bookmark-drawer:not([hidden]):not(.drawer-closing) {
    animation-name: bm-drawer-in-right;
  }

  #bookmark-drawer.drawer-closing {
    animation-name: bm-drawer-out-right;
  }

  @keyframes bm-drawer-in-right {
    from { transform: translateX(100%); }
    to   { transform: translateX(0); }
  }

  @keyframes bm-drawer-out-right {
    from { transform: translateX(0); }
    to   { transform: translateX(100%); }
  }

  #bookmark-drawer-header {
    padding-top: 0.9rem;
  }
}

#bookmark-drawer-handle {
  display: flex;
  justify-content: center;
  padding: 0.5rem 0 0.3rem;
  cursor: grab;
  touch-action: none;
  flex-shrink: 0;
}

#bookmark-drawer-handle span {
  width: 2.2rem;
  height: 0.22rem;
  background: var(--border);
  border-radius: 2px;
}

/* Hide drag handle on desktop (must come after the base style above) */
@media (min-width: 769px) {
  #bookmark-drawer-handle {
    display: none;
  }
}

#bookmark-drawer-resize {
  display: none;
}

@media (min-width: 769px) {
  #bookmark-drawer-resize {
    display: flex;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: calc(0.22rem + 0.5rem * 2);
    cursor: ew-resize;
    align-items: center;
    justify-content: center;
    touch-action: none;
    z-index: 1;
  }

  #bookmark-drawer-resize::after {
    content: '';
    width: 0.22rem;
    height: 2.2rem;
    background: var(--border);
    border-radius: 2px;
    transition: background 0.15s;
  }

  #bookmark-drawer-resize:hover::after {
    background: var(--accent);
  }
}

#bookmark-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 0.75rem 0.3rem 1rem;
  flex-shrink: 0;
}

#bookmark-drawer-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0;
}

#bookmark-drawer-close {
  width: 2rem;
  height: 2rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.15s;
  padding: 0;
}

#bookmark-drawer-close:hover {
  color: var(--text);
}

#bookmark-drawer-toolbar {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem max(0.75rem, env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
  justify-content: flex-end;
  align-items: center;
  position: relative;
}

#bookmark-drawer-toolbar::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border) 20%, var(--border) 80%, transparent);
}

#bm-overflow-panel:not([hidden]) {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  padding-left: 0.4rem;
  margin-left: 0.15rem;
  border-left: 1px solid var(--border);
}

/* Mobile: toolbar moves below the list */
@media (max-width: 768px) {
  #bookmark-drawer-toolbar {
    order: 1;
  }

  #bookmark-drawer-toolbar::after {
    top: 0;
    bottom: auto;
  }
}

.bm-toolbar-btn {
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 0.15s, background 0.15s;
}

.bm-toolbar-btn:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.bm-toolbar-btn:disabled {
  color: var(--text-secondary);
  opacity: 0.35;
  cursor: default;
  background: none;
}


.bm-new-folder-form {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  width: 100%;
  padding: 0.3rem 0;
}

.bm-new-folder-input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 0.82rem;
  padding: 0.28rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.bm-new-folder-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(30, 58, 95, 0.1);
}

[data-theme="dark"] .bm-new-folder-input:focus {
  box-shadow: 0 0 0 2px rgba(138, 180, 216, 0.15);
}

#bookmark-drawer-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.4rem 0;
  margin: 0;
  list-style: none;
}

/* ── Bookmark tree items ── */

.bm-folder,
.bm-bookmark {
  list-style: none;
}

.bm-folder-row,
.bm-bookmark-row {
  display: flex;
  align-items: center;
  padding: 0.3rem 0.75rem;
  gap: 0.4rem;
  transition: background 0.1s;
}

.bm-row-content {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
}

/* Mobile-only swipe-to-reveal panel; shown on viewports ≤768px (see ADR-010). */
.bm-row-actions-mobile {
  display: none;
}

.bm-folder-row:hover,
.bm-bookmark-row:hover {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.bm-bookmark-row.bm-active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: var(--radius);
  margin-right: 0.5rem;
}

.bm-bookmark-row.bm-active .bm-bookmark-type-icon {
  color: var(--accent);
}

.bm-bookmark-row.bm-active .bm-bookmark-label {
  color: var(--accent);
  font-weight: 600;
}

.bm-folder-toggle {
  width: 1.4rem;
  height: 1.4rem;
  flex-shrink: 0;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.bm-folder-name {
  flex: 1;
  font-size: 0.88rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bm-folder-children {
  padding-left: 1.8rem;
  margin: 0;
  list-style: none;
}


.bm-folder[aria-expanded="false"] > .bm-folder-children {
  display: none;
}

.bm-bookmark-link {
  flex: 1;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.bm-bookmark-type-icon {
  flex-shrink: 0;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  width: 1.4rem;
  justify-content: center;
}

.bm-bookmark-label {
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bm-bookmark-ref {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.bm-item-actions {
  display: flex;
  gap: 0.2rem;
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.bm-folder-row:hover .bm-item-actions,
.bm-bookmark-row:hover .bm-item-actions,
.bm-folder-row:focus-within .bm-item-actions,
.bm-bookmark-row:focus-within .bm-item-actions {
  opacity: 1;
}

.bm-action-btn {
  font-family: inherit;
  font-size: 0.7rem;
  padding: 0.18rem 0.4rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}

.bm-action-btn:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.bm-delete-btn:hover {
  background: #c0392b;
  border-color: #c0392b;
  color: #fff;
}

.bm-empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.88rem;
}

/* ── Save bookmark modal ── */

#bm-save-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 72;
  background: rgba(0, 0, 0, 0.45);
}

#bm-save-scrim:not([hidden]) {
  display: block;
}

#bm-save-modal {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 73;
  width: min(92vw, 420px);
  overflow: visible;
  background: var(--bg-card);
  color: var(--text);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  padding: 1.25rem 1.25rem 1rem;
}

#bm-save-modal:not([hidden]) {
  display: block;
}

#bm-save-title {
  margin: 0 2rem 0.85rem 0;
  font-size: 1.05rem;
  font-weight: 700;
}

#bm-save-close {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  background: transparent;
  border: 0;
  color: var(--text-secondary);
  font-size: 1.6rem;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#bm-save-close:hover {
  color: var(--text);
}

.bm-form-field {
  margin-bottom: 0.85rem;
}

.bm-form-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.bm-form-input,
.bm-form-textarea,
.bm-form-select {
  width: 100%;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  outline: none;
  box-sizing: border-box;
}

/* Folder picker (replaces <select> so each row can use the same SVG as the tree) */
.bm-folder-combobox {
  position: relative;
  width: 100%;
}

.bm-folder-combobox-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  outline: none;
  box-sizing: border-box;
  text-align: left;
  cursor: pointer;
  min-height: 2.2rem;
}

.bm-folder-combobox-btn-icon,
.bm-folder-combobox-option-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  color: var(--accent);
}

.bm-folder-combobox-btn-label,
.bm-folder-combobox-option-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bm-folder-combobox-chevron {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-left: auto;
  padding-left: 0.25rem;
}

.bm-folder-combobox-list {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: 100%;
  margin: 0.2rem 0 0 0;
  padding: 0.25rem 0;
  list-style: none;
  max-height: 12rem;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 0.4rem 1rem rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
}

.bm-folder-combobox-option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}

.bm-folder-combobox-option:hover,
.bm-folder-combobox-option[aria-selected="true"] {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.bm-folder-combobox-new {
  list-style: none;
  margin-top: 0.25rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}

.bm-folder-combobox-new-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.4rem 0.6rem;
  font-family: inherit;
  font-size: 0.9rem;
  background: transparent;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
}

.bm-folder-combobox-new-btn:hover,
.bm-folder-combobox-new-btn:focus {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  outline: none;
}

.bm-form-input:focus,
.bm-form-textarea:focus,
.bm-form-select:focus,
.bm-folder-combobox-btn:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(30, 58, 95, 0.12);
}

[data-theme="dark"] .bm-form-input:focus,
[data-theme="dark"] .bm-form-textarea:focus,
[data-theme="dark"] .bm-form-select:focus,
[data-theme="dark"] .bm-folder-combobox-btn:focus {
  box-shadow: 0 0 0 2px rgba(138, 180, 216, 0.18);
}

.bm-form-textarea {
  resize: vertical;
  min-height: 4rem;
}

.bm-form-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.bm-btn-primary {
  padding: 0.5rem 1.1rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.15s;
}

.bm-btn-primary:hover {
  opacity: 0.88;
}

.bm-btn-secondary {
  padding: 0.5rem 1.1rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s;
}

.bm-btn-secondary:hover {
  background: var(--border);
}

/* ── New folder modal (stacks above save modal) ── */

#bm-new-folder-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 76;
  background: rgba(0, 0, 0, 0.45);
}

#bm-new-folder-scrim:not([hidden]) {
  display: block;
}

#bm-new-folder-modal {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 77;
  width: min(92vw, 360px);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  padding: 1.25rem 1.25rem 1rem;
}

#bm-new-folder-modal:not([hidden]) {
  display: block;
}

#bm-new-folder-title {
  margin: 0 2rem 0.85rem 0;
  font-size: 1.05rem;
  font-weight: 700;
}

#bm-new-folder-close {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  background: transparent;
  border: 0;
  color: var(--text-secondary);
  font-size: 1.6rem;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#bm-new-folder-close:hover {
  color: var(--text);
}

/* ── Merge confirmation modal ── */

#bm-merge-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 74;
  background: rgba(0, 0, 0, 0.45);
}

#bm-merge-scrim:not([hidden]) {
  display: block;
}

#bm-merge-modal {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 75;
  width: min(92vw, 360px);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  padding: 1.25rem;
}

#bm-merge-modal:not([hidden]) {
  display: block;
}

#bm-merge-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 0.6rem;
}

#bm-merge-body {
  font-size: 0.88rem;
  margin: 0 0 1rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.bm-merge-desc {
  margin: 0 0 0.75rem;
}

.bm-merge-radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.25rem;
}

.bm-merge-radio {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text);
}

.bm-merge-radio:hover {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.bm-merge-radio input[type="radio"] {
  accent-color: var(--accent);
  flex-shrink: 0;
}

#bm-merge-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#bm-merge-yes {
  padding: 0.45rem 0.9rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}

#bm-merge-no {
  padding: 0.45rem 0.9rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--text);
}

#bm-merge-cancel {
  padding: 0.45rem 0.9rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--text-secondary);
}

/* ── Import bookmarks modal ── */

#bm-import-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 76;
  background: rgba(0, 0, 0, 0.45);
}

#bm-import-scrim:not([hidden]) {
  display: block;
}

#bm-import-modal {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 77;
  width: min(92vw, 360px);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  padding: 1.25rem;
}

#bm-import-modal:not([hidden]) {
  display: block;
}

#bm-import-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 0.6rem;
}

#bm-import-body {
  font-size: 0.88rem;
  margin: 0 0 1rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

#bm-import-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#bm-import-merge {
  padding: 0.45rem 0.9rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

#bm-import-merge:hover {
  opacity: 0.88;
}

#bm-import-overwrite,
#bm-import-cancel {
  padding: 0.45rem 0.9rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
}

#bm-import-overwrite:hover,
#bm-import-cancel:hover {
  background: color-mix(in srgb, var(--text) 6%, transparent);
}

/* ── Drag & drop ── */

.bm-folder-row,
.bm-bookmark-row {
  cursor: grab;
  touch-action: none;
}

.bm-folder-row:active,
.bm-bookmark-row:active {
  cursor: grabbing;
}

.bm-folder-row button,
.bm-folder-row a,
.bm-bookmark-row button,
.bm-bookmark-row a {
  cursor: pointer;
  touch-action: auto;
}

.bm-folder.bm-dragging > .bm-folder-row,
.bm-bookmark.bm-dragging > .bm-bookmark-row {
  opacity: 0.3;
}

.bm-drag-ghost {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.88;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

.bm-folder.drag-over-before > .bm-folder-row,
.bm-bookmark.drag-over-before > .bm-bookmark-row {
  box-shadow: inset 0 2px 0 var(--accent);
}

.bm-folder.drag-over-after > .bm-folder-row,
.bm-bookmark.drag-over-after > .bm-bookmark-row {
  box-shadow: inset 0 -2px 0 var(--accent);
}

.bm-folder.drag-over-into > .bm-folder-row {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: var(--radius);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ── Mobile: swipe-to-reveal bookmark actions (ADR-010, 2026-05-03) ──
   On touch viewports, hover-revealed action buttons stick open after the first
   tap (iOS Safari treats first tap as :hover), forcing a double-tap to reach
   edit/delete. Replace with swipe-left or long-press to reveal a slide-out
   action panel; single tap navigates as expected. */
@media (max-width: 768px) {
  .bm-folder-row .bm-item-actions,
  .bm-bookmark-row .bm-item-actions {
    display: none;
  }

  .bm-folder-row,
  .bm-bookmark-row {
    position: relative;
    overflow: hidden;
    padding: 0;
  }

  .bm-row-content {
    padding: 0.3rem 0.75rem;
    background: var(--bg);
    position: relative;
    z-index: 0;
    min-height: 44px;
    box-sizing: border-box;
  }

  .bm-bookmark-row.bm-active {
    background: transparent;
    margin-right: 0;
    border-radius: 0;
  }

  .bm-bookmark-row.bm-active .bm-row-content {
    background: color-mix(in srgb, var(--accent) 12%, var(--bg));
  }

  .bm-folder-row:hover,
  .bm-bookmark-row:hover {
    background: transparent;
  }

  /* Action panel slides in from the right and overlays the content;
     the row text stays in place per the mobile UX request. */
  .bm-row-actions-mobile {
    display: flex;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 140px;
    z-index: 1;
    transform: translateX(100%);
    transition: transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
  }

  .bm-bookmark-row.bm-swiped .bm-row-actions-mobile,
  .bm-folder-row.bm-swiped .bm-row-actions-mobile {
    transform: translateX(0);
  }

  /* Disable the snap-back transition while the finger is dragging the row. */
  .bm-bookmark-row.bm-swiping .bm-row-actions-mobile,
  .bm-folder-row.bm-swiping .bm-row-actions-mobile {
    transition: none;
  }

  .bm-mobile-action-btn {
    flex: 1;
    border: none;
    font-family: inherit;
    font-size: 0.85rem;
    color: #fff;
    cursor: pointer;
    padding: 0;
    min-height: 44px;
    touch-action: manipulation;
  }

  .bm-mobile-edit-btn {
    background: var(--accent);
  }

  .bm-mobile-delete-btn {
    background: #c0392b;
  }
}

/* ── Reduced motion ── */

@media (prefers-reduced-motion: reduce) {
  #bookmark-drawer {
    transition: none;
  }
  #bookmark-drawer:not([hidden]):not(.drawer-closing),
  #bookmark-drawer.drawer-closing {
    animation: none;
  }
  .bm-row-actions-mobile {
    transition: none;
  }
}
