* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --font-scale: 1;
  --primary: #7c5c3e;
  --primary-light: #a07850;
  --accent: #c87941;
  --bg: #f5ede0;
  --card-bg: #fdf6ec;
  --text: #3b2412;
  --text-muted: #9e7a5a;
  --done-color: #4a7c3f;
  --border: #e0cdb8;
  --panel-bg: #faf4ea;
  --player-bg: #f0e6d8;
  --quote-bg: #ede3d4;
  --done-bg: #eef4e8;
  --cal-day-bg: #ede3d4;
  --nav-bg: #fdf6ec;
  --modal-bg: #fdf6ec;
  --radius: 12px;
  --header-h: 120px;
  --tab-h: 48px;
  --nav-h: 56px;
}

[data-theme="dark"] {
  --primary: #c8956a;
  --primary-light: #e0b080;
  --accent: #d4891a;
  --bg: #1c1208;
  --card-bg: #2a1e10;
  --text: #e0c9a8;
  --text-muted: #806848;
  --done-color: #6a9a4a;
  --border: #3a2a18;
  --panel-bg: #2e1c0a;
  --player-bg: #2a1e10;
  --quote-bg: #3a2410;
  --done-bg: #1e2a15;
  --cal-day-bg: #2a2010;
  --nav-bg: #2a1e10;
  --modal-bg: #2a1e10;
}

html, body {
  height: 100%;
  font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── 화면 전환 ── */
.screen { display: none; height: 100vh; flex-direction: column; }
.screen.active { display: flex; }

/* ── 목록 화면 ── */
.app-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  padding: 20px 20px 16px;
  flex-shrink: 0;
}
.app-header h1 { font-size: 22px; font-weight: 500; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
.header-sub { font-size: 13px; opacity: 0.8; margin-top: 2px; }

#progress-bar-wrap {
  margin-top: 12px;
  background: rgba(255,255,255,0.25);
  border-radius: 99px;
  height: 8px;
  position: relative;
}
#progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.4s ease;
  width: 0%;
}
#progress-text {
  position: absolute;
  right: 0;
  top: -20px;
  font-size: 12px;
  opacity: 0.9;
}

.chapter-grid {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: start;
}

.chapter-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 12px;
  cursor: pointer;
  border: 2px solid transparent;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
}
.chapter-card:active { transform: scale(0.97); }
.chapter-card.done {
  border-color: var(--done-color);
  background: var(--done-bg);
}
.chapter-card .ch-id {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.chapter-card .ch-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
}
.chapter-card .done-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 16px;
}

/* ── 읽기 화면 ── */
.reader-header {
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 12px;
  height: 52px;
  flex-shrink: 0;
  gap: 8px;
}
.reader-header span {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
}
.done-btn {
  background: var(--accent);
  border: none;
  color: white;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  flex-shrink: 0;
}
.done-btn.done {
  background: var(--done-color);
}

/* ── 탭 ── */
.tab-bar {
  display: flex;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tab {
  flex: 1;
  border: none;
  background: none;
  padding: 12px 4px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

.reader-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.tab-panel {
  display: none;
  height: 100%;
  overflow-y: auto;
  padding: 24px 20px 80px;
  background: var(--panel-bg);
  word-break: keep-all;
}
.tab-panel.active { display: block; }

/* 읽기 본문 타이포그래피 */
.body-para {
  font-size: calc(16px * var(--font-scale));
  line-height: 2.1;
  color: var(--text);
  margin-bottom: 1.4em;
  letter-spacing: 0.01em;
  padding-left: 36px;
}
.body-section {
  position: relative;
  padding-left: 36px;
  font-size: calc(16px * var(--font-scale));
  line-height: 2.1;
  color: var(--text);
  margin: 1.8em 0 1.2em;
  letter-spacing: 0.01em;
}
.section-num {
  position: absolute;
  left: 0;
  top: 5px;
  width: 24px;
  height: 24px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.body-quote {
  border-left: 3px solid var(--primary-light);
  margin: 1em 0;
  padding: 10px 14px;
  background: var(--quote-bg);
  border-radius: 0 8px 8px 0;
  font-size: calc(15px * var(--font-scale));
  line-height: 1.9;
  color: var(--text);
  font-style: normal;
}

/* ── 핵심카드 탭 ── */
.summary-card {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  border-radius: var(--radius);
  padding: 24px 20px;
  margin-bottom: 20px;
  box-shadow: 0 4px 16px rgba(26,35,126,0.25);
}
.card-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
}
.card-summary {
  font-size: 16px;
  line-height: 2.1;
  color: var(--text);
  white-space: pre-wrap;
}
.speech-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

/* ── 이전/다음 네비 ── */
.reader-nav {
  display: flex;
  background: var(--nav-bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.nav-btn {
  flex: 1;
  padding: 14px;
  background: none;
  border: none;
  font-size: 14px;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
}
.nav-btn:first-child { border-right: 1px solid var(--border); }
.nav-btn:disabled { color: var(--text-muted); }


/* ── 성경 구절 링크 ── */
.verse-ref {
  color: var(--primary-light);
  text-decoration: underline;
  text-decoration-style: dotted;
  cursor: pointer;
  border-radius: 3px;
  padding: 0 1px;
}
.verse-ref:active { background: rgba(26,35,126,0.12); }

/* ── 성경 구절 팝업 ── */
.verse-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.verse-modal.hidden { display: none; }
.verse-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
}
.verse-modal-box {
  position: relative;
  background: var(--modal-bg);
  border-radius: 16px 16px 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 560px;
  max-height: 55vh;
  overflow-y: auto;
  z-index: 1;
}
.verse-modal-ref {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
  letter-spacing: 0.03em;
}
.verse-modal-text {
  font-size: 15px;
  line-height: 1.9;
  color: var(--text);
  white-space: pre-wrap;
  word-break: keep-all;
  margin-bottom: 20px;
}
.verse-modal-close {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* ── 하단 광고 배너 ── */
.ad-banner {
  flex-shrink: 0;
  background: var(--nav-bg);
  border-top: 1px solid var(--border);
  padding: 0;
  user-select: none;
}
.ad-row {
  display: flex;
  align-items: center;
}
.ad-viewport {
  flex: 1;
  overflow: hidden;
}
.ad-track {
  display: flex;
  width: 200%;
  touch-action: pan-y;
  height: 52px;
  will-change: transform;
}
.ad-slide {
  width: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 52px;
  text-decoration: none;
  color: var(--text);
  box-sizing: border-box;
}
.ad-slide:active { background: rgba(26,35,126,0.05); }
.ad-icon { font-size: 18px; flex-shrink: 0; }
.ad-text { flex: 1; font-size: 13px; line-height: 1.4; }
.ad-text strong { color: var(--primary); }
.ad-nav-btn {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-muted);
  padding: 0 10px;
  height: 52px;
  cursor: pointer;
  flex-shrink: 0;
}
.ad-nav-btn:active { color: var(--primary); }
.ad-dots {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 0 0 7px;
}
.ad-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ccc;
  transition: background 0.3s;
}
.ad-dot.active { background: var(--primary); }

/* ── 리더 플로팅 녹음 버튼 ── */
.fab-record {
  position: absolute;
  bottom: 110px;
  right: 16px;
  transition: bottom 0.2s ease;
  height: 40px;
  padding: 0 16px;
  border-radius: 20px;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(26,35,126,0.35);
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
}
.fab-record:active { transform: scale(0.93); }
.fab-record.bar-visible { bottom: 185px; }
.fab-record.recording {
  background: #c62828;
  animation: pulse-red 1.2s ease-in-out infinite;
}

/* ── 리더 녹음 바 ── */
.reader-rec-bar {
  position: absolute;
  bottom: 56px;
  left: 0; right: 0;
  background: var(--nav-bg);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 9;
}
.reader-rec-bar.hidden { display: none; }
.reader-rec-left {
  flex-shrink: 0;
}
.reader-rec-timer {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #c62828;
  letter-spacing: 0.05em;
}
.reader-rec-center {
  flex: 1;
  min-width: 0;
}
.reader-player {
  margin: 0;
  background: var(--player-bg);
}
.reader-rec-right {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.reader-stop-btn {
  padding: 4px 10px;
  background: #c62828;
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 4px;
}
.reader-share-btn {
  padding: 7px 12px;
  background: #0088cc;
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.reader-discard-btn {
  padding: 7px 10px;
  background: none;
  border: 1px solid #ccc;
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

/* ── 녹음 바 ── */
.recorder-bar {
  flex-shrink: 0;
  background: var(--nav-bg);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.recorder-timer {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  letter-spacing: 0.05em;
}
.record-btn {
  width: 100%;
  padding: 13px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}
.record-btn.recording {
  background: #c62828;
  animation: pulse-red 1.2s ease-in-out infinite;
}
@keyframes pulse-red {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}
.recorder-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.recorder-actions audio {
  width: 100%;
  border-radius: 8px;
}
.custom-player {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--player-bg);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.play-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.player-progress-wrap {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  cursor: pointer;
  position: relative;
}
.player-progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  width: 0%;
  transition: width 0.1s linear;
}
.player-time {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  font-weight: 600;
  flex-shrink: 0;
}
.share-btn {
  width: 100%;
  padding: 12px;
  background: #0088cc;
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.discard-btn {
  width: 100%;
  padding: 10px;
  background: none;
  border: 1px solid #ccc;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

/* ── 출석표 버튼 & 헤더 ── */
.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.attendance-btn {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.streak-bar {
  font-size: 12px;
  font-weight: 600;
  color: #ffe082;
  margin-top: 6px;
  display: none;
}

/* ── 출석표 화면 ── */
.attendance-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.attendance-summary {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}
.att-stat {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 10px 16px;
  flex: 1;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.att-stat strong {
  display: block;
  font-size: 22px;
  color: var(--primary);
  margin-top: 2px;
}
.attendance-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}
.month-nav-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--primary);
  cursor: pointer;
  padding: 4px 10px;
}
.month-nav-btn:disabled { color: #ccc; cursor: default; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 16px;
}
.cal-header {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 0;
  font-weight: 600;
}
.cal-day {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  background: var(--cal-day-bg);
  position: relative;
}
.cal-day.blank { background: transparent; cursor: default; }
.cal-day.future { opacity: 0.35; cursor: default; }
.cal-day.studied {
  background: var(--primary);
  color: white;
}
.cal-day.today {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.cal-date { font-size: 12px; line-height: 1; }
.cal-count {
  font-size: 10px;
  font-weight: 700;
  margin-top: 2px;
  background: rgba(255,255,255,0.25);
  border-radius: 4px;
  padding: 0 3px;
}
.cal-day:not(.studied) .cal-count { color: var(--primary); background: rgba(26,35,126,0.1); }

.attendance-detail {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.att-detail-title {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  border-bottom: 1px solid var(--border);
}
.att-detail-item {
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.att-ch-id {
  color: var(--text-muted);
  font-size: 12px;
  flex-shrink: 0;
}
.att-ch-title {
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

/* ── 글자 크기 버튼 ── */
.font-size-btn {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  font-size: 12px;
  font-weight: 700;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
  line-height: 1;
}
.font-size-btn:active { background: rgba(255,255,255,0.3); }
.font-size-btn sup { font-size: 9px; }

/* ── 다크모드 토글 ── */
.theme-toggle-btn {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  font-size: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.theme-toggle-btn:active { background: rgba(255,255,255,0.3); }

/* 스크롤바 */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
