:root {
  --bg: #f5f7fb; --card: #fff; --text: #1f2937; --sub: #6b7280; --line: #e5e7eb;
  --primary: #1e3a8a; --ok: #16a34a; --ng: #dc2626; --warn: #d97706;
}
[data-theme="dark"] {
  --bg: #0f172a; --card: #1e293b; --text: #e5e7eb; --sub: #94a3b8; --line: #334155;
  --primary: #60a5fa;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg); color: var(--text); padding-bottom: env(safe-area-inset-bottom); }
header { display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.header-left { display: flex; align-items: center; gap: 8px; }
header h1 { font-size: 18px; margin: 0; cursor: pointer; user-select: none; }
.icon-btn { background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1; color: var(--text); }
.icon-btn:active { background: var(--line); }
button, .btn, .choice, .icon-btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
main { max-width: 640px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 16px; margin: 0 0 10px; line-height: 1.4; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin: 10px 0; }
.stats div { background: var(--bg); border-radius: 8px; padding: 8px 2px; }
.stats b { display: block; font-size: 18px; }
.stats span { font-size: 11px; color: var(--sub); }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.bar > i { display: block; height: 100%; background: var(--primary); transition: width .3s; }
.btn { display: block; width: 100%; padding: 14px; border: none; border-radius: 10px; font-size: 16px;
  font-weight: 600; background: var(--primary); color: #fff; cursor: pointer; margin-top: 8px; }
[data-theme="dark"] .btn { color: #0f172a; }
.btn.secondary { background: var(--line); color: var(--text); }
.btn:disabled { opacity: .4; }
.meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--sub); margin-bottom: 6px; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 6px; color: #fff; margin-right: 6px; }
.dir-forward { background: #2563eb; } .dir-reverse { background: #7c3aed; }
.dir-caution { background: #d97706; } .dir-number { background: #0891b2; }
.round { background: var(--ng); }
.question { font-size: 17px; font-weight: 600; line-height: 1.5; margin: 12px 0 16px; }
.choice { display: block; width: 100%; text-align: left; padding: 14px; margin-bottom: 10px; font-size: 15px;
  border: 2px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); cursor: pointer; }
.choice .n { font-weight: 700; margin-right: 8px; color: var(--sub); }
.choice.correct { border-color: var(--ok); background: rgba(22,163,74,.12); }
.choice.wrong { border-color: var(--ng); background: rgba(220,38,38,.12); }
.choice:disabled { cursor: default; }
.feedback { border-left: 4px solid var(--ok); padding: 10px 12px; background: var(--bg); border-radius: 6px; margin-top: 6px; }
.feedback.ng { border-color: var(--ng); }
.feedback .title { font-weight: 700; margin-bottom: 6px; }
.feedback .src { font-size: 12px; color: var(--sub); margin-top: 6px; }
ul.result { list-style: none; padding: 0; margin: 0; }
ul.result li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; display: flex; justify-content: space-between; gap: 8px; }
.ok { color: var(--ok); font-weight: 700; } .ng { color: var(--ng); font-weight: 700; }
.muted { color: var(--sub); font-size: 13px; }

/* PWA 설치 권장 배너 */
.pwa-banner { background: var(--card); border: 1.5px solid var(--primary); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
[data-theme="dark"] .pwa-banner { background: rgba(96, 165, 250, 0.08); }
.pwa-banner-title { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.pwa-banner-desc { font-size: 13px; color: var(--sub); line-height: 1.5; margin: 0 0 12px; }
.pwa-banner-desc b { color: var(--text); }
.pwa-banner-btn { margin-top: 0; padding: 12px; font-size: 14px; }

/* PWA 설치 안내 모달 */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65); display: flex;
  align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.modal-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; max-width: 420px; width: 100%; box-shadow: 0 12px 32px rgba(0,0,0,0.35); }
.modal-card h3 { margin: 0 0 8px; font-size: 17px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-header h3 { margin: 0; }
.modal-close-btn { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--sub); padding: 4px; line-height: 1; border-radius: 6px; }
.modal-close-btn:active { background: var(--line); }
.modal-steps { margin: 12px 0 16px; padding-left: 20px; font-size: 14px; line-height: 1.6; }
.modal-steps li { margin-bottom: 8px; }
.modal-note { font-size: 12px; color: var(--sub); background: var(--bg); padding: 10px 12px;
  border-radius: 8px; margin-bottom: 16px; line-height: 1.4; }

/* 챕터 카드 및 진입 안내 */
.chapter-card { cursor: pointer; transition: transform .12s, border-color .12s; }
.chapter-card:active { transform: scale(0.99); }
.chapter-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.chapter-card-header h2 { margin: 0; }
.chapter-enter-badge { font-size: 12px; font-weight: 700; color: var(--primary); background: rgba(30, 58, 138, 0.08);
  padding: 4px 8px; border-radius: 6px; white-space: nowrap; }
[data-theme="dark"] .chapter-enter-badge { background: rgba(96, 165, 250, 0.15); }
.chapter-enter-badge.in-progress { background: rgba(22, 163, 74, 0.15); color: var(--ok); border: 1px solid var(--ok); }

/* 탭 네비게이션 */
.tabs { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 14px; gap: 4px; }
.tab-btn { flex: 1; padding: 10px 6px; border: none; background: none; border-radius: 8px; font-size: 14px; font-weight: 700; color: var(--sub); cursor: pointer; text-align: center; }
.tab-btn.active { background: var(--primary); color: #fff; }
[data-theme="dark"] .tab-btn.active { color: #0f172a; }

/* 암기 카드 */
.memorize-card { min-height: 200px; display: flex; flex-direction: column; justify-content: space-between; }
.memorize-topic { font-size: 13px; font-weight: 700; color: var(--primary); margin-bottom: 10px; }
.memorize-key { font-size: 19px; font-weight: 700; line-height: 1.6; margin-bottom: 16px; word-break: keep-all; }
.memorize-source { font-size: 12px; color: var(--sub); margin-bottom: 16px; }
.memorize-btn { margin-top: auto; padding: 16px; font-size: 17px; font-weight: 700; }

/* 통계 탭 */
.weak-list { list-style: none; padding: 0; margin: 0; }
.weak-item { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; }

/* 마크다운 렌더링 스타일 (비교표, 제목, 리스트) */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 12px 0 16px; border: 1px solid var(--line); border-radius: 10px; }
.md-table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: left; min-width: 320px; }
.md-table th, .md-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); line-height: 1.4; }
.md-table th:last-child, .md-table td:last-child { border-right: none; }
.md-table th { background: var(--bg); font-weight: 700; color: var(--primary); white-space: nowrap; }
.md-table tr:last-child td { border-bottom: none; }
[data-theme="dark"] .md-table tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }
[data-theme="light"] .md-table tr:nth-child(even) td { background: rgba(0, 0, 0, 0.02); }
.md-p { margin: 8px 0; font-size: 14px; line-height: 1.6; word-break: keep-all; }
.md-li { font-size: 14px; line-height: 1.6; margin-left: 18px; margin-bottom: 4px; word-break: keep-all; }
.md-h3 { font-size: 16px; font-weight: 700; margin: 10px 0 6px; color: var(--text); }
.card-content { margin-bottom: 16px; }



