:root {
  --bg: #f7f7f9;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8a8a8e;
  --line: #e2e2e6;
  --accent: #33549e;
  --accent-soft: rgba(51, 84, 158, 0.1);
  --bar: rgba(247, 247, 249, 0.92);
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  --bible-size: 19px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111216;
    --card: #1c1d22;
    --text: #ececf0;
    --muted: #8e8e96;
    --line: #2c2d33;
    --accent: #8aa8ec;
    --accent-soft: rgba(138, 168, 236, 0.14);
    --bar: rgba(17, 18, 22, 0.92);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* 상단 바 */
#bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  padding: env(safe-area-inset-top) 8px 0;
  height: calc(48px + env(safe-area-inset-top));
  background: var(--bar);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-bottom: 0.5px solid var(--line);
}
#title {
  flex: 1; margin: 0; font-size: 17px; font-weight: 600; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar-btn {
  min-width: 44px; height: 44px; border: 0; background: none;
  color: var(--accent); font-size: 17px; padding: 0 8px;
}
#back { font-size: 32px; line-height: 1; padding-bottom: 4px; visibility: hidden; }
#back.show { visibility: visible; }
#bar-tools { display: flex; min-width: 44px; justify-content: flex-end; }

/* 하단 탭 */
#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bar);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 0.5px solid var(--line);
}
#tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 6px 0 4px; font-size: 11px; color: var(--muted);
}
#tabs a.on { color: var(--accent); }
.ti { font-size: 22px; line-height: 1.2; }

#view {
  padding: calc(48px + env(safe-area-inset-top)) 0 calc(56px + env(safe-area-inset-bottom));
  min-height: 100%;
}

/* 공통 */
.pad { padding: 16px; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); line-height: 1.6; }
.btn {
  display: inline-block; border: 0; border-radius: 12px; padding: 12px 18px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 16px;
}
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn:disabled { opacity: 0.4; }

/* 구약/신약 선택 */
.seg {
  display: flex; margin: 12px 16px; padding: 2px; border-radius: 9px;
  background: var(--line);
}
.seg button {
  flex: 1; border: 0; background: none; padding: 7px 0; border-radius: 7px; font-size: 14px;
}
.seg button.on { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* 목록 */
.list { margin: 0 16px 16px; background: var(--card); border-radius: 12px; overflow: hidden; }
.list a, .list .row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 0.5px solid var(--line); font-size: 17px;
}
.list a:last-child { border-bottom: 0; }
.list .sub { color: var(--muted); font-size: 14px; }
.list a::after { content: "›"; color: var(--muted); margin-left: 8px; font-size: 20px; }
.list a .sub { margin-left: auto; }
.resume { color: var(--accent); }

/* 장 번호 */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 10px; padding: 16px;
}
.grid a, .grid button {
  border: 0; width: 100%;
  display: flex; align-items: center; justify-content: center; height: 50px;
  border-radius: 10px; background: var(--accent-soft); font-size: 18px;
  font-variant-numeric: tabular-nums;
}

/* 권·장 선택창 (본문 제목을 누르면 아래에서 올라옴) */
#title.tappable { cursor: pointer; color: var(--accent); }
#picker { position: fixed; inset: 0; z-index: 20; }
#picker .backdrop {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35);
  opacity: 0; transition: opacity .2s;
}
#picker .sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  top: calc(env(safe-area-inset-top) + 56px);
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 14px 14px 0 0;
  transform: translateY(100%); transition: transform .25s ease-out;
}
#picker.open .backdrop { opacity: 1; }
#picker.open .sheet { transform: none; }
.sheet-head {
  display: flex; align-items: center; padding: 4px 8px;
  border-bottom: 0.5px solid var(--line);
}
.sheet-head h2 { flex: 1; margin: 0; text-align: center; font-size: 17px; font-weight: 600; }
.sheet-head .bar-btn { min-width: 64px; }
.sheet-head .bar-btn[data-act=close] { text-align: right; }
.sheet-head .bar-btn[hidden] { display: block; visibility: hidden; }
.sheet-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom);
}
.bookgrid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 4px 16px 16px;
}
.bookgrid button {
  border: 0; border-radius: 10px; background: var(--card); padding: 12px 4px;
  font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bookgrid button.cur, .grid button.cur { background: var(--accent); color: #fff; }

/* 본문 */
.reader { padding: 12px 18px 24px; font-size: var(--bible-size); }
.reader .h { color: var(--accent); font-weight: 600; font-size: 0.85em; margin: 18px 0 6px; }
.reader .v { display: flex; gap: 8px; margin: 0 0 10px; line-height: 1.65; }
.reader .n {
  flex: 0 0 auto; min-width: 1.6em; text-align: right; color: var(--muted);
  font-size: 0.68em; padding-top: 0.45em; font-variant-numeric: tabular-nums;
}
.reader .t { flex: 1; word-break: keep-all; overflow-wrap: anywhere; }
.chapnav { display: flex; justify-content: space-between; gap: 12px; margin-top: 28px; }

/* 찬송가 번호판 */
.display {
  text-align: center; font-size: 52px; font-weight: 700; height: 72px; line-height: 72px;
  font-variant-numeric: tabular-nums; margin-top: 8px;
}
.display.placeholder { color: var(--muted); opacity: 0.5; font-size: 30px; font-weight: 500; }
.warn { text-align: center; color: #d33; font-size: 13px; height: 18px; }
.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  padding: 8px 32px; max-width: 420px; margin: 0 auto;
}
.keypad button {
  height: 60px; border: 0; border-radius: 14px; background: var(--card);
  font-size: 26px; font-weight: 500; box-shadow: 0 0.5px 1px rgba(0,0,0,.08);
}
.keypad button:active { background: var(--line); }
.keypad .go { background: var(--accent); color: #fff; font-size: 19px; font-weight: 700; }
.keypad .go:disabled { opacity: 0.4; }
.recent { padding: 16px 20px; }
.recent .label { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.chips a {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 18px;
  background: var(--accent-soft); color: var(--accent); font-size: 15px;
}

/* 악보 */
.score {
  position: fixed; left: 0; right: 0;
  top: calc(48px + env(safe-area-inset-top));
  bottom: calc(56px + env(safe-area-inset-bottom) + 52px);
  overflow: auto; background: #fff; -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}
.score img { display: block; width: 100%; height: auto; margin: 0 auto; }
.scorenav {
  position: fixed; left: 0; right: 0; height: 52px;
  bottom: calc(56px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: space-between; padding: 0 12px;
  background: var(--bar); border-top: 0.5px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.scorenav .pos { color: var(--muted); font-size: 14px; }
.scorenav button { border: 0; background: none; color: var(--accent); font-size: 16px; padding: 10px; }
.scorenav button:disabled { color: var(--muted); opacity: 0.5; }

/* 자료 가져오기 */
.stat { display: flex; justify-content: space-between; }
.progress { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin: 12px 0 6px; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.note { color: var(--muted); font-size: 14px; line-height: 1.6; }
.note b { color: var(--text); }

/* 악보 화면에서 올라오는 번호판 */
.sheet-body.padsheet { padding-top: 8px; }
