:root {
  --bg: #000000;
  --fg: #e8e8e8;
  --muted: #8a8a8a;
  --accent: #4a9eff;
  --accent-dim: color-mix(in srgb, var(--accent) 28%, transparent);
  --border: #222;
  --panel: #0a0a0a;
  --font-size: 17px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: var(--font-size);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
  overflow: hidden;
}
body { height: 100dvh; max-height: 100dvh; }
#app {
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, select, input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0;
}
button {
  cursor: pointer;
  padding: 8px 12px;
  color: var(--accent);
  border-color: var(--accent);
  background: var(--bg);
}
button:active { opacity: 0.75; }
button.active, button[aria-pressed="true"] {
  background: var(--accent);
  color: #000;
}
button.ghost {
  border-color: var(--border);
  color: var(--muted);
}
button.ghost.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}
select {
  padding: 8px 10px;
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg);
  appearance: none;
  -webkit-appearance: none;
}
a { color: var(--accent); text-decoration: none; }
input[type="password"], input[type="text"] {
  padding: 10px 12px;
  border-color: var(--border);
  background: #050505;
  width: 100%;
}

/* —— chrome —— */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(0,0,0,0.94);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + var(--safe-t)) 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.topbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.topbar h1 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 500;
  flex: 1;
}
.pd-note {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.pd-note strong { color: var(--fg); font-weight: 500; }
.vault-chip {
  font-size: 11px;
  padding: 6px 8px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
}
.tabs button {
  flex: 1;
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  color: var(--muted);
  padding: 10px;
}
.tabs button:last-child { border-right: none; }
.tabs button.active {
  color: #000;
  background: var(--accent);
}

.book-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 0 calc(24px + var(--safe-b));
}
.book-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #111;
  color: var(--fg);
  cursor: pointer;
  background: transparent;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
  border-radius: 0;
}
.book-item:active { background: var(--accent-dim); }
.book-item .id {
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.08em;
  min-width: 3.2em;
}
.book-item .name { flex: 1; padding: 0 12px; }
.book-item .chs { color: var(--muted); font-size: 12px; }

.footer-pd {
  padding: 16px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* —— reader —— */
.reader-top {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(0,0,0,0.96);
  border-bottom: 1px solid var(--border);
  padding: calc(8px + var(--safe-t)) 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.reader-top .nav {
  display: flex;
  align-items: center;
  gap: 6px;
}
.reader-top .title {
  flex: 1;
  text-align: center;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  width: 40px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 16px;
  flex-shrink: 0;
}
.slider-label { min-width: 4.5em; color: var(--accent); }

/* —— chapter roller (iOS compass / flat drum) —— */
.ch-roller {
  position: relative;
  height: 44px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  touch-action: pan-x;
  mask-image: linear-gradient(90deg, transparent 0%, #000 12%, #000 88%, transparent 100%);
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 12%, #000 88%, transparent 100%);
}
.ch-roller::-webkit-scrollbar { display: none; }
.roller-track {
  display: flex;
  align-items: center;
  height: 100%;
  gap: 0;
  width: max-content;
}
.roller-item {
  flex: 0 0 48px;
  width: 48px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  letter-spacing: 0.04em;
  scroll-snap-align: center;
  display: grid;
  place-items: center;
  transition: opacity 0.12s ease, transform 0.12s ease, color 0.12s ease;
  -webkit-user-select: none;
  user-select: none;
}
.roller-item.selected {
  color: var(--accent);
  font-weight: 600;
}
.roller-center {
  pointer-events: none;
  position: absolute;
  left: 50%;
  top: 4px;
  bottom: 4px;
  width: 48px;
  transform: translateX(-50%);
  border-left: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-right: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.roller-fade { display: none; }
.roller-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  min-height: 16px;
}
.vault-status {
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.vault-status.muted { color: var(--muted); }

.reader-body {
  flex: 1;
  min-height: 0; /* allow flex child to scroll instead of growing the page */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px calc(80px + var(--safe-b));
  font-size: var(--font-size);
  overscroll-behavior: contain;
}
.chapter-block {
  margin-bottom: 28px;
  scroll-margin-top: 160px;
}
.chapter-head {
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.verse {
  display: grid;
  grid-template-columns: 2.4em 1fr;
  gap: 8px;
  padding: 4px 4px;
  margin: 0 -4px;
  border-radius: 0;
}
.verse .n {
  color: var(--muted);
  font-size: 0.75em;
  text-align: right;
  padding-top: 0.35em;
  user-select: none;
}
.verse .t { word-wrap: break-word; }
.verse.underlined .t {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
.verse.tap-target { cursor: pointer; }
.verse.tap-target:active { background: var(--accent-dim); }
.unavailable {
  color: var(--muted);
  padding: 24px 8px;
  text-align: center;
  border: 1px dashed var(--border);
}

/* —— tools FAB —— */
.fab {
  position: fixed;
  right: 14px;
  bottom: calc(18px + var(--safe-b));
  z-index: 50;
  width: 52px;
  height: 52px;
  border-radius: 0;
  border: 1px solid var(--accent);
  background: #000;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.08em;
  box-shadow: 0 0 0 4px rgba(0,0,0,0.6);
}
.tools-panel {
  position: fixed;
  right: 14px;
  bottom: calc(78px + var(--safe-b));
  z-index: 50;
  width: min(300px, calc(100vw - 28px));
  background: #000;
  border: 1px solid var(--accent);
  padding: 12px;
  display: none;
  flex-direction: column;
  gap: 10px;
  max-height: min(70vh, 520px);
  overflow: auto;
}
.tools-panel.open { display: flex; }
.tools-panel h3 {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.tools-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tools-row button { flex: 1; min-width: 72px; font-size: 12px; padding: 10px 8px; }
.tools-hint {
  margin: 0;
  font-size: 10px;
  color: var(--muted);
  line-height: 1.4;
}
.tools-panel label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}
.tools-panel input[type="range"] { width: 100%; accent-color: var(--accent); }
.tools-panel input[type="color"] {
  width: 100%;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  background: #000;
}
.mode-banner {
  position: fixed;
  left: 12px;
  right: 76px;
  bottom: calc(24px + var(--safe-b));
  z-index: 45;
  background: var(--accent);
  color: #000;
  padding: 10px 12px;
  font-size: 12px;
  letter-spacing: 0.04em;
  display: none;
}
.mode-banner.show { display: block; }

.version-select { flex: 0 0 auto; font-size: 11px; padding: 6px 8px; min-width: 72px; max-width: 160px; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* —— modal / library —— */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: end center;
  padding: 12px;
  padding-bottom: calc(12px + var(--safe-b));
}
.modal-root[hidden] { display: none !important; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.72);
}
.modal {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  background: #000;
  border: 1px solid var(--accent);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: min(80vh, 640px);
  overflow: auto;
}
.modal-wide { width: min(520px, 100%); }
.modal h3 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.modal h4.lib-section {
  margin: 8px 0 0;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}
.modal-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}
.modal-error {
  margin: 0;
  font-size: 12px;
  color: #ff6b6b;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}
.modal label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
}
.lib-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  max-height: 200px;
  overflow: auto;
}
.lib-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid #151515;
  border-radius: 0;
  padding: 10px 12px;
  color: var(--fg);
  background: transparent;
}
.lib-item:last-child { border-bottom: none; }
.lib-item:active { background: var(--accent-dim); }
.lib-label { font-size: 13px; color: var(--fg); }
.lib-meta { font-size: 10px; color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-b));
  transform: translateX(-50%) translateY(12px);
  z-index: 90;
  background: var(--accent);
  color: #000;
  padding: 10px 14px;
  font-size: 12px;
  letter-spacing: 0.03em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: min(90vw, 360px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
