/* Usui Reiki 四級教學系統 — 黑金主題 + light，手機優先 */
:root {
  --bg: #0b0a08;
  --bg2: #14110c;
  --card: #1b1710;
  --line: #3a3020;
  --gold: #c9a15a;
  --gold2: #e6c98a;
  --green: #7fc9a0;
  --text: #f0e6d2;
  --muted: #a89a80;
  --danger: #d98a5a;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
html[data-theme="light"] {
  --bg: #f6f1e6;
  --bg2: #ede4d2;
  --card: #fffaf0;
  --line: #d8c9a8;
  --gold: #8a6a2f;
  --gold2: #6b4f1d;
  --green: #2e7d5b;
  --text: #2a2318;
  --muted: #6e6250;
  --danger: #a6592b;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  padding-bottom: calc(76px + var(--safe-b));
  overflow-x: hidden;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--gold); }

/* 頂欄 */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(180deg, var(--bg2), var(--bg));
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.brand-seal {
  width: 34px; height: 34px; flex: none;
  border-radius: 9px;
  background: linear-gradient(180deg, var(--gold2), var(--gold));
  color: var(--bg);
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px;
  border: 1px solid var(--gold2);
}
.brand-text { min-width: 0; }
.brand-text b { display: block; color: var(--gold2); font-size: 15px; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { display: block; color: var(--muted); font-size: 11px; }
.icon-btn {
  min-width: 42px; height: 42px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--card); color: var(--gold2);
  font-size: 13px; font-weight: 600;
}
.icon-btn:active { transform: scale(.96); }

/* 主內容 */
main { max-width: 860px; margin: 0 auto; padding: 18px 16px 24px; }
.page { display: none; }
.page.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

h1 { color: var(--gold2); font-size: 24px; margin: 6px 0 4px; }
h2 { color: var(--gold2); font-size: 19px; margin: 22px 0 10px; }
h3 { color: var(--green); font-size: 16px; margin: 16px 0 8px; }
p { margin: 8px 0; }
.lede { color: var(--muted); font-size: 14px; margin: 0 0 18px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin: 12px 0;
}
.card.flat { background: transparent; }

/* 首頁四級卡 */
.level-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.level-card {
  background: linear-gradient(150deg, var(--card), var(--bg2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; position: relative; overflow: hidden;
  cursor: pointer; transition: border-color .15s, transform .15s;
}
.level-card:hover { border-color: var(--gold); }
.level-card:active { transform: scale(.985); }
.level-card::after {
  content: ""; position: absolute; right: -26px; top: -26px;
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--gold) 22%, transparent), transparent 70%);
}
.level-card .lv-no { color: var(--gold); font-size: 12px; letter-spacing: .18em; font-weight: 700; }
.level-card .lv-name { color: var(--gold2); font-size: 19px; font-weight: 700; margin: 4px 0; }
.level-card .lv-sub { color: var(--muted); font-size: 13px; }
.progress-track { height: 6px; border-radius: 6px; background: var(--line); margin-top: 12px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--gold), var(--green)); width: 0; transition: width .3s; }
.lv-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 6px; }

/* 章節列表 */
.mod-list { display: flex; flex-direction: column; gap: 8px; }
.mod-item {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 11px; padding: 12px 14px; cursor: pointer;
}
.mod-item:active { transform: scale(.995); }
.mod-item.read { border-left: 3px solid var(--green); }
.mod-item.marked { border-right: 3px solid var(--gold); }
.mod-no { color: var(--gold); font-size: 12px; font-weight: 700; min-width: 26px; padding-top: 2px; }
.mod-body { flex: 1; min-width: 0; }
.mod-title { font-weight: 600; color: var(--text); }
.mod-sum { color: var(--muted); font-size: 13px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mod-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.tag { font-size: 11px; color: var(--green); border: 1px solid var(--line); border-radius: 20px; padding: 1px 8px; }
.bookmark-btn {
  flex: none; width: 38px; height: 38px; border-radius: 10px;
  background: transparent; border: 1px solid var(--line); color: var(--muted); font-size: 16px;
}
.bookmark-btn.on { color: var(--bg); background: var(--gold); border-color: var(--gold); }

/* 閱讀器 */
.reader-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.back-btn { min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--gold2); }
.reader-title { color: var(--gold2); font-size: 20px; margin: 4px 0 10px; }
.reader-source { color: var(--muted); font-size: 12px; margin-bottom: 16px; }
.points { list-style: none; padding: 0; margin: 12px 0; }
.points li {
  position: relative; padding: 9px 12px 9px 30px; margin: 7px 0;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
}
.points li::before { content: "•"; position: absolute; left: 12px; color: var(--gold); font-weight: 800; }
.reader-nav { display: flex; gap: 8px; margin-top: 22px; }
.reader-nav button { flex: 1; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--gold2); }
.reader-nav button:disabled { opacity: .35; }
.mark-read { background: linear-gradient(180deg, var(--gold2), var(--gold)) !important; color: var(--bg) !important; font-weight: 700; border: none !important; }

/* 搜尋 */
.search-box { width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 11px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.search-box:focus { outline: none; border-color: var(--gold); }
.hit { border-left: 3px solid var(--gold); cursor: pointer; }
mark { background: color-mix(in srgb, var(--gold) 35%, transparent); color: var(--text); border-radius: 3px; padding: 0 2px; }
.empty { color: var(--muted); text-align: center; padding: 40px 12px; }

/* 設定 */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: none; }
.set-row .k { font-weight: 600; }
.set-row .v { color: var(--muted); font-size: 13px; }
.switch { min-width: 56px; height: 34px; border-radius: 20px; border: 1px solid var(--line); background: var(--bg2); color: var(--muted); font-size: 12px; }
.switch.on { background: var(--gold); color: var(--bg); border-color: var(--gold); font-weight: 700; }

/* 底部 Tab */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: linear-gradient(180deg, var(--bg2), var(--bg));
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
}
.tab {
  min-height: 62px; border: none; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px;
}
.tab .ti { font-size: 17px; font-weight: 700; color: var(--muted); }
.tab.active { color: var(--gold2); }
.tab.active .ti { color: var(--gold); }

/* 神聖本源 BGM 膠囊 */
.bgm-pill {
  position: fixed; right: 14px; bottom: calc(78px + var(--safe-b)); z-index: 45;
  min-height: 38px; padding: 0 14px; border-radius: 20px;
  background: linear-gradient(180deg, var(--gold2), var(--gold));
  color: var(--bg); border: 1px solid var(--gold2);
  font-size: 12px; font-weight: 700;
  box-shadow: 0 4px 16px rgba(0,0,0,.35);
}
.bgm-pill.off { background: var(--card); color: var(--muted); border-color: var(--line); }

/* 免責 gate */
.gate {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.82);
  display: grid; place-items: center; padding: 20px;
}
.gate-card {
  max-width: 520px; width: 100%; background: var(--card);
  border: 1px solid var(--gold); border-radius: 18px; padding: 24px;
  box-shadow: 0 18px 60px rgba(0,0,0,.5);
}
.gate-card h2 { margin-top: 0; }
.gate-card p { color: var(--muted); font-size: 14px; }
.gate-accept {
  width: 100%; min-height: 48px; margin-top: 12px; border: none; border-radius: 11px;
  background: linear-gradient(180deg, var(--gold2), var(--gold)); color: var(--bg);
  font-weight: 800; font-size: 15px;
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translateX(-50%);
  z-index: 90; background: var(--gold); color: var(--bg);
  padding: 9px 18px; border-radius: 20px; font-size: 13px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; }

.offline-chip { font-size: 11px; color: var(--danger); border: 1px solid var(--danger); border-radius: 20px; padding: 1px 8px; display: none; }
body.offline .offline-chip { display: inline-block; }

@media (max-width: 390px) {
  h1 { font-size: 21px; }
  .brand-text b { font-size: 13px; }
  .lv-name { font-size: 17px; }
  main { padding: 14px 12px 20px; }
  .card { padding: 13px; }
  .points li { font-size: 14px; padding-left: 26px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
