/* 경전함 웹: 안드로이드 앱과 같은 '고요한 밤' (먹빛 남색 바탕에 금빛 한 점, 낮에는 미색 종이에 남먹색) */
@font-face { font-family: 'Gowun Batang'; font-weight: 400; font-display: swap; src: url(fonts/gowun-batang-regular.woff2) format('woff2'); }
@font-face { font-family: 'Gowun Batang'; font-weight: 700; font-display: swap; src: url(fonts/gowun-batang-bold.woff2) format('woff2'); }
:root {
  --primary: #8C6A2E;
  --on-primary: #FFFFFF;
  --primary-container: #EFE3C9;
  --on-primary-container: #2E2108;
  --bg: #F6F4EF;
  --surface-low: #F1EEE7;
  --surface: #ECE8E0;
  --surface-high: #E2DDD3;
  --text: #1E2230;
  --muted: #6B675F;
  --outline: #C9C3B7;
  --line: #DDD8CD;
  --serif: 'Gowun Batang', 'Nanum Myeongjo', 'AppleMyungjo', serif;
  --fs: 1;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #D4AE6A;
    --on-primary: #2A1E08;
    --primary-container: #3A3122;
    --on-primary-container: #F1DDB3;
    --bg: #15171C;
    --surface-low: #1A1D23;
    --surface: #1F222A;
    --surface-high: #2D313B;
    --text: #E9E4D8;
    --muted: #9A958A;
    --outline: #4A4E58;
    --line: #2A2D35;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  word-break: keep-all; /* 한국어는 낱말 단위로 줄을 바꾼다 */
  overflow-wrap: anywhere;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--primary); }
.loading { padding: 40px 16px; text-align: center; color: var(--muted); }

.page { max-width: 760px; margin: 0 auto; padding: 16px 16px 120px; }
h1, h2, .serif { font-family: var(--serif); }
h1.title { font-size: 24px; margin: 8px 0 12px; }
h2.section { font-size: 21px; margin: 24px 0 12px; }
.ico svg { width: 24px; height: 24px; display: block; }
.btn svg { width: 20px; height: 20px; vertical-align: -4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* 카드와 버튼 */
.card {
  display: block; width: 100%; text-align: left;
  background: var(--surface); border: 0; border-radius: 16px;
  padding: 18px 20px; margin: 0 0 12px;
}
.card.outlined { background: transparent; border: 1px solid var(--outline); }
.card.verse { background: var(--surface); border-radius: 20px; padding: 20px 20px 8px; }
.card.verse .label { color: var(--primary); font-size: 14px; }
.card.verse .text { font-family: var(--serif); font-size: 18px; line-height: 1.85; }
.row { display: flex; align-items: center; gap: 8px; }
.row .grow { flex: 1; min-width: 0; }
.btn {
  border: 1px solid var(--outline); background: transparent; border-radius: 999px;
  padding: 8px 16px; font-size: 15px;
}
.btn.filled { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.text { border: 0; color: var(--primary); padding: 8px 10px; }
.btn[disabled] { opacity: .4; cursor: default; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--outline); background: transparent; border-radius: 10px; padding: 6px 14px; }
.chip.on { background: var(--surface-high); border-color: var(--surface-high); font-weight: 600; }

/* 아래 탭 */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--bg); border-top: 0.5px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs[hidden] { display: none; }
.tabs a {
  flex: 1; max-width: 190px; text-align: center; text-decoration: none; color: var(--muted);
  padding: 8px 0 10px; font-size: 13px;
}
.tabs a .ico { display: flex; justify-content: center; padding: 4px 0; margin: 0 auto 2px; width: 64px; border-radius: 16px; }
.tabs a.on { color: var(--primary); font-weight: 600; }
.tabs a.on .ico { background: var(--primary-container); }

/* 읽기 화면 */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 4px; padding: 8px 8px;
  max-width: 760px; margin: 0 auto;
}
.topbar h1 { font-size: 23px; margin: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .icon { border: 0; background: transparent; color: var(--text); padding: 8px; border-radius: 50%; display: flex; }
.topbar .icon svg { width: 24px; height: 24px; }
.topbar select { background: transparent; color: var(--muted); border: 0; font-size: 14px; max-width: 120px; }
.segment { display: flex; border: 1px solid var(--outline); border-radius: 999px; overflow: hidden; margin: 4px 0 16px; }
.segment button { flex: 1; border: 0; background: transparent; padding: 10px 0; }
.segment button + button { border-left: 1px solid var(--outline); }
.segment button.on { background: var(--surface-high); font-weight: 600; }

.passage {
  display: flex; gap: 0; padding: 8px 8px 8px 0; margin: 0 0 14px;
  border-radius: 12px; cursor: pointer; scroll-margin-top: 72px;
}
.passage.playing { background: var(--primary-container); }
.passage .num { width: 32px; flex: none; font-size: 12px; color: var(--muted); padding-top: 4px; text-align: center; }
.passage .num .star { color: var(--primary); display: block; }
.passage .body { flex: 1; min-width: 0; }
.passage .head { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.reader { font-size: calc(17px * var(--fs)); }
.reader .plain, .reader .recite, .reader .mantra, .reader .hanja { font-family: var(--serif); }
.reader .plain { line-height: 1.85; }
.reader .recite { font-size: 1.08em; line-height: 2; }
.reader .mantra { font-size: 1.12em; line-height: 1.9; }
.reader .hanja { font-size: 1.12em; letter-spacing: .06em; line-height: 1.9; }
.reader .eumdok { font-size: .88em; color: var(--muted); white-space: pre-line; }
.reader .pre { white-space: pre-line; }

.fab svg { width: 22px; height: 22px; }
.fab {
  position: fixed; right: max(16px, calc(50% - 364px)); bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 6;
  background: var(--primary); color: var(--on-primary); display: flex; align-items: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 15px 24px; font-size: 16px; font-weight: 700;
  box-shadow: 0 3px 10px rgba(0,0,0,.25);
}
.playbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; background: var(--surface);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.playbar .inner { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: 8px; }
.playbar .progress { position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--line); }
.playbar .progress i { display: block; height: 100%; background: var(--primary); }
.playbar .now { font-family: var(--serif); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn.tonal { background: var(--primary-container); color: var(--on-primary-container); border-color: transparent; display: flex; align-items: center; gap: 4px; }
.btn.tonal svg { width: 18px; height: 18px; }

/* 아래에서 올라오는 창 */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 88vh; overflow-y: auto; background: var(--surface-low);
  border-radius: 24px 24px 0 0; padding: 8px 24px calc(28px + env(safe-area-inset-bottom));
  max-width: 760px; margin: 0 auto;
}
.sheet .grip { width: 36px; height: 4px; border-radius: 2px; background: var(--outline); margin: 6px auto 16px; }
.sheet .hanja { font-size: 19px; line-height: 1.8; }
.sheet .eumdok { color: var(--muted); font-size: 15px; }
.sheet .plain { font-size: 17px; line-height: 1.8; }
.sheet h3 { color: var(--primary); font-size: 15px; margin: 18px 0 6px; }
.sheet .term { background: var(--surface); border-radius: 12px; padding: 14px; margin-top: 10px; }
.sheet .stack > * + * { margin-top: 10px; }
.sheet section + section { margin-top: 20px; }

/* 검색 */
.search-box {
  width: 100%; padding: 14px 16px; font-size: 17px; border-radius: 12px;
  border: 2px solid var(--outline); background: transparent; color: var(--text);
}
.search-box:focus { outline: none; border-color: var(--primary); }
.hit .where { color: var(--primary); font-size: 13px; }
mark { background: var(--primary-container); color: var(--on-primary-container); border-radius: 3px; }

/* 수행 */
.bead {
  display: block; width: 220px; height: 220px; margin: 8px auto 12px; border-radius: 50%;
  border: 0; background: var(--primary-container); color: var(--on-primary-container);
  user-select: none; touch-action: manipulation;
}
.bead .n { font-size: 64px; font-weight: 300; line-height: 1.1; display: block; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.calendar .dow { font-size: 12px; color: var(--muted); }
.calendar button {
  width: 38px; height: 38px; margin: 0 auto; border-radius: 50%; border: 0; background: transparent; font-size: 14px;
}
.calendar button.done { background: var(--primary); color: var(--on-primary); }
.calendar button.sel:not(.done) { background: var(--surface-high); }
.calendar button.today { font-weight: 700; }

/* 사경 */
.trace-wrap { position: relative; background: var(--surface-low); border-radius: 16px; overflow: hidden; height: calc(100vh - 230px); min-height: 320px; }
.trace-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; }
.trace-head .segment { flex: 1; margin: 0; }
.trace-page { font-size: 14px; white-space: nowrap; }
.trace-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.trace-ink { touch-action: none; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: 14px;
}
.notice { background: var(--primary-container); color: var(--on-primary-container); border-radius: 16px; padding: 16px; }

/* 공식 채널 독송 영상 (유튜브 플레이어 그대로) */
.video {
  position: sticky; top: 52px; z-index: 4; background: var(--surface);
  max-width: 760px; margin: 0 auto 12px; padding-bottom: 10px; border-radius: 0 0 16px 16px;
}
.video .frame { aspect-ratio: 16 / 9; background: #000; }
.video iframe { width: 100%; height: 100%; border: 0; display: block; }
.topbar .btn { white-space: nowrap; padding: 8px 6px; }
.topbar h1 { min-width: 0; flex: 0 1 auto; }
.topbar select { max-width: 76px; }

/* 홈: 매일 독송 세 개, 경전 줄 목록, 게송 버튼 */
.home-head { margin: 20px 2px 18px; }
.home-head h1 { font-size: 30px; margin: 0; line-height: 1.3; }
.resume { display: flex; align-items: center; gap: 10px; padding: 12px 18px; color: inherit; text-decoration: none;
  border: 1px solid color-mix(in srgb, var(--primary) 60%, transparent); border-radius: 999px; margin: 12px 0 0; }
.resume svg { width: 18px; height: 18px; color: var(--primary); flex: none; }
.resume .grow { font-family: var(--serif); font-size: 17px; }
.resume .at { color: var(--primary); font-size: 13px; }
h2.group { font-family: inherit; font-size: 14px; font-weight: 500; color: var(--muted); margin: 28px 2px 8px; }
.daily { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.daily .card { margin: 0; padding: 18px 4px; text-align: center; color: inherit; text-decoration: none; }
.daily .card b { display: block; font-family: var(--serif); font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rows a { display: flex; align-items: center; padding: 15px 2px; color: inherit; text-decoration: none; font-family: var(--serif); font-size: 18px; }
.rows a .small { font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", Roboto, sans-serif; }
.rows a + a { border-top: 0.5px solid var(--line); }
.chips a.pill { color: inherit; text-decoration: none; background: var(--surface); border-radius: 999px; padding: 9px 16px; font-family: var(--serif); font-size: 16px; }
.rows a .grow, .resume .grow { flex: 1; min-width: 0; }

/* 좌선 타이머 */
.card.sit { padding: 20px; }
.sit-left { font-family: var(--serif); font-size: 56px; font-weight: 700; text-align: center; line-height: 1.2; margin: 4px 0 12px; }
.sit-track { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-bottom: 12px; }
.sit-track i { display: block; height: 100%; background: var(--primary); }

/* 불교 재일 */
.holy-next { color: var(--primary); font-size: 14px; margin-top: 2px; }
.calendar button { position: relative; }
.calendar button.holy::after { content: ''; position: absolute; left: 50%; bottom: 3px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--primary); }
.calendar button.holy.major::after { width: 6px; height: 6px; margin-left: -3px; }
.calendar button.done.holy::after { background: var(--on-primary); }
