:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --brand: #2e5a9e;
  --brand-dark: #1f4279;
  --text: #1b2330;
  --muted: #66707d;
  --line: #e1e6ee;
  --danger: #c0392b;
  --reader-scale: 1; /* 글자 크기 조절 */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Malgun Gothic", "맑은 고딕", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  padding-bottom: calc(72px + var(--safe-bottom));
}

/* 상단바 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.topbar h1 { font-size: 1.25rem; margin: 0; font-weight: 700; }
.font-controls { display: flex; gap: 6px; }
.font-controls button {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.95rem;
  font-weight: 700;
}

main { padding: 16px; max-width: 720px; margin: 0 auto; }

.view { display: none; animation: fade 0.18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.hint { color: var(--muted); line-height: 1.6; font-size: 0.95rem; }
.hint code, code { background: #eef1f6; padding: 1px 6px; border-radius: 5px; font-size: 0.9em; }

/* 큰 버튼 */
.big-btn {
  display: block;
  width: 100%;
  padding: 18px;
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.big-btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.big-btn:active { transform: scale(0.99); }

.small-btn {
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font-size: 0.95rem;
  font-weight: 600;
}
.small-btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.small-btn.danger { color: var(--danger); border-color: #e8c4bf; }

/* 미리보기 */
.preview { margin: 12px 0; }
.preview img { width: 100%; border-radius: 12px; border: 1px solid var(--line); }

/* 진행 표시 */
.progress {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 12px 0;
  font-weight: 600;
}
.spinner {
  width: 22px; height: 22px;
  border: 3px solid #d6deea;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 찾은 항목 */
.detected { margin-top: 16px; }
.detected h2 { font-size: 1.1rem; }
.detected h2 small { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 8px 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--brand);
  background: #eaf1fb;
  color: var(--brand-dark);
  font-weight: 700;
  font-size: 1rem;
}
.chip.hymn { border-color: #b07d2b; background: #fbf3e3; color: #8a5e16; }
.chip.kyodok { border-color: #2e8b6f; background: #e6f5ef; color: #1f6b54; }
.chip .chip-label { cursor: pointer; }
.chip .chip-label:active { transform: scale(0.97); }
.chip .chip-x {
  border: none; background: transparent; color: inherit;
  font-size: 1.25rem; line-height: 1; padding: 0 6px;
  cursor: pointer; opacity: 0.55; font-weight: 700;
}
.chip .chip-x:active { opacity: 1; }
.add-row { display: flex; gap: 8px; margin: 10px 0; }
.add-row input { flex: 1; min-width: 0; }

.raw { margin-top: 14px; }
.raw summary { color: var(--muted); cursor: pointer; }
.raw textarea {
  width: 100%; margin-top: 8px; padding: 10px;
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 0.95rem; font-family: inherit; resize: vertical;
}

/* 검색 */
.search-row { display: flex; gap: 8px; margin: 12px 0; }
.search-row input {
  flex: 1; padding: 14px; font-size: 1.05rem;
  border: 1px solid var(--line); border-radius: 10px;
}

/* 설정 */
.setting-block { margin: 16px 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.file-label {
  display: inline-block; padding: 14px 18px;
  border: 1px solid var(--brand); border-radius: 10px;
  background: #eaf1fb; color: var(--brand-dark); font-weight: 700;
}
.stat { color: var(--muted); font-size: 0.9rem; }
.about { color: var(--muted); font-size: 0.85rem; margin-top: 24px; }

/* 리더(결과) */
.reader {
  position: fixed; inset: 0; z-index: 50;
  background: var(--card); display: flex; flex-direction: column;
}
.reader-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: var(--brand); color: #fff;
}
.reader-head h2 { margin: 0; font-size: 1.15rem; }
.close-btn {
  background: rgba(255, 255, 255, 0.2); color: #fff;
  border: none; border-radius: 8px; width: 38px; height: 38px;
  font-size: 1.1rem; flex: 0 0 auto;
}
.reader-body {
  padding: 20px 18px calc(28px + var(--safe-bottom));
  overflow-y: auto; line-height: 1.9;
  font-size: calc(1.15rem * var(--reader-scale));
}
.reader-body .verse { margin: 0 0 12px; }
.reader-body .vnum {
  color: var(--brand); font-weight: 700; font-size: 0.8em;
  vertical-align: super; margin-right: 4px;
}
.reader-body .ref-title { color: var(--muted); font-size: 0.9em; margin-bottom: 16px; }
.reader-body .stanza { margin: 0 0 18px; white-space: pre-line; }
.reader-body .stanza-num { color: #8a5e16; font-weight: 700; margin-right: 6px; }
.reader-body .stanza.refrain .stanza-num { color: #2e8b6f; }
.reader-body .kyodok-line { margin: 0 0 12px; }
.reader-body .kyodok-mark {
  margin: 4px 0 12px; font-weight: 700; color: #1f6b54;
  text-align: center; letter-spacing: 2px;
}
.reader-body .notfound {
  background: #fbeceb; color: var(--danger);
  padding: 14px; border-radius: 10px; font-size: 0.95rem; line-height: 1.6;
}

/* 하단 탭 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tab {
  flex: 1; border: none; background: none;
  padding: 10px 0 8px; font-size: 1.4rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: 0.72rem; font-weight: 600; }
.tab.active { color: var(--brand); }

/* 토스트 */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #2b2f37; color: #fff;
  padding: 12px 18px; border-radius: 999px;
  font-size: 0.92rem; z-index: 60; max-width: 90%;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
