:root {
  --bg: #f8f3ec; --surface: #ffffff; --surface-2: #eef0e8; --text: #1f2522; --muted: #5f6a65; --line: #dfe2d6;
  --accent: #7b2f28; --accent-2: #9a4a3c; --gold: #b8892d; --ink: #1f2522; --ok: #2f8a4c; --bad: #b8433a; --change: #b8433a;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(30,50,40,.07);
  --serif: 'Noto Serif CJK TC', 'Noto Serif TC', 'Noto Serif CJK SC', 'Noto Serif SC', 'Songti TC', 'Songti SC', 'PMingLiU', serif;
  color-scheme: light;
}
/* Dark theme: follows the phone unless the user picked Light or Dark (html[data-theme]). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101614; --surface: #19211e; --surface-2: #222c28; --text: #e8ece6; --muted: #9aa69f; --line: #2e3a35;
    --accent: #eea08f; --accent-2: #f3b9aa; --gold: #e2b85c; --ink: #e8ece6; --change: #f08b7e;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101614; --surface: #19211e; --surface-2: #222c28; --text: #e8ece6; --muted: #9aa69f; --line: #2e3a35;
  --accent: #eea08f; --accent-2: #f3b9aa; --gold: #e2b85c; --ink: #e8ece6; --change: #f08b7e;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  display: flex; flex-direction: column; overscroll-behavior-y: none; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: #7b2f28; color: #fff; }
@media (prefers-color-scheme: dark) { :where(:root:not([data-theme="light"])) .topbar { background: #2a1513; } }
:where(:root[data-theme="dark"]) .topbar { background: #2a1513; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .logo { font-family: var(--serif); font-size: 20px; opacity: .85; }
.topbar .hbtn { background: rgba(255,255,255,.14); color: inherit; border: 0; border-radius: 999px; min-width: 34px; height: 32px; padding: 0 9px; font: 600 15px/32px system-ui, sans-serif; cursor: pointer; }
.back { background: none; border: 0; color: inherit; font-size: 30px; line-height: 1; padding: 0 8px 4px 0; cursor: pointer; }
main { flex: 1; overflow-y: auto; padding: 16px 16px calc(110px + env(safe-area-inset-bottom)); max-width: 760px; width: 100%; margin: 0 auto; outline: none; zoom: var(--text-zoom, 1); }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 6px 0 8px; color: var(--muted); text-decoration: none; font-size: 11.5px; min-width: 0; white-space: nowrap; }
.tabs a .ti { font-family: var(--serif); font-size: 22px; line-height: 1.2; }
.tabs a.active { color: var(--accent); font-weight: 600; }
h2 { font-size: 22px; margin: 4px 0 12px; }
h3 { font-size: 17px; margin: 20px 0 6px; }
h4 { font-size: 15px; margin: 14px 0 2px; color: var(--accent); }
p { margin: 8px 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.zh { font-family: var(--serif); }
.accent { color: var(--accent); }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 0 0 14px; border: 1px solid var(--line); }
.card.inset { box-shadow: none; background: var(--surface-2); }
.hero { background: linear-gradient(135deg, #7b2f28, #4a1712); color: #fff; border: 0; }
.hero p { color: #f2dfda; }
.hero .big { font-family: var(--serif); font-size: 44px; line-height: 1; }
.progress { height: 8px; background: rgba(255,255,255,.25); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; background: var(--gold); border-radius: 99px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.list > .card { margin: 0; }
.lvl-head { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 4px 8px; }
.lvl-head h3 { margin: 0; }
.lesson-item, .daily, .reading-row { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; }
.lesson-item .badge { flex: 0 0 52px; height: 52px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center;
  font-family: var(--serif); font-size: 19px; color: var(--accent); }
.lesson-item.done .badge { background: var(--accent); color: var(--surface); }
.lesson-item.here { box-shadow: 0 0 0 2px var(--gold); }
.t { font-weight: 600; }
.s { display: block; font-size: 13px; color: var(--muted); }
.lvl { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--gold); font-weight: 600; }
.daily { border-color: color-mix(in srgb, var(--gold) 45%, var(--line)); }
.about-link { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); margin-top: 18px; }
.about-link > span:first-child { font-size: 22px; color: var(--muted); }
.go { margin-left: auto; font-size: 22px; color: var(--muted); }
.lesson-body ul, .lesson-body ol { padding-left: 22px; }
.lesson-body li { margin: 4px 0; }
.note, .tip { border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.note { background: var(--surface-2); color: var(--muted); }
.tip { background: color-mix(in srgb, var(--gold) 16%, transparent); }
.tip::before { content: '💡 '; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px; padding: 12px 18px; font: inherit; font-weight: 600;
  background: var(--accent); color: #fff; cursor: pointer; text-decoration: none; min-height: 46px; text-align: center; }
@media (prefers-color-scheme: dark) { :where(:root:not([data-theme="light"])) .btn { color: #1f0d0a; } }
:where(:root[data-theme="dark"]) .btn { color: #1f0d0a; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.gold { background: var(--gold); color: #1b1410; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; }
label { display: block; font-size: 14px; font-weight: 600; margin: 12px 0 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); min-height: 46px; }
textarea { resize: vertical; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--surface); color: var(--text); padding: 11px 6px; font: inherit; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--surface); font-weight: 600; }
.help { font-size: 12px; color: var(--muted); margin-top: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }
.chip { display: inline-block; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); font-size: 13px; margin: 2px 4px 2px 0; }
.chips { margin-top: 6px; }
.pill { font-size: 11px; background: var(--gold); color: #1b1410; padding: 2px 8px; border-radius: 99px; font-weight: 600; }

/* Sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 760px; max-height: 85vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 20px 18px calc(24px + env(safe-area-inset-bottom)); position: relative; animation: up .2s ease-out; zoom: var(--text-zoom, 1); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-close { position: absolute; top: 10px; right: 12px; border: 0; background: var(--surface-2); color: var(--text); width: 36px; height: 36px; border-radius: 50%; font-size: 22px; cursor: pointer; }
.web-foot { text-align: center; margin-top: 24px; }

/* Star grid (nine palaces) */
.grid9 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0 6px; }
.grid9 .cell { background: var(--surface-2); border-radius: 12px; padding: 8px 4px 10px; min-height: 92px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; text-align: center; line-height: 1.2; border: 2px solid transparent; font: inherit; color: inherit; cursor: pointer; }
.grid9 .cell.centre { background: color-mix(in srgb, var(--gold) 16%, var(--surface-2)); }
.grid9 .cell.warn { border-color: color-mix(in srgb, var(--bad) 60%, transparent); }
.grid9 .cell.good { border-color: color-mix(in srgb, var(--ok) 55%, transparent); }
.grid9 .dir { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.grid9 .star { font-size: 30px; font-weight: 700; line-height: 1; display: flex; align-items: center; gap: 5px; }
.grid9 .tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; }
.tag { font-size: 10px; font-weight: 600; border-radius: 99px; padding: 1px 6px; background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.tag.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.25); flex: 0 0 auto; }
.dot.s1, .dot.s6, .dot.s8 { background: #f4f4f0; } .dot.s2 { background: #2b2b2b; } .dot.s3 { background: #2e8b6f; } .dot.s4 { background: #5aa05a; }
.dot.s5 { background: #d8b02a; } .dot.s7 { background: #c0392b; } .dot.s9 { background: #7d3c98; }
.year-nav { display: flex; align-items: center; gap: 10px; }
.year-nav .btn { flex: 0 0 auto; min-height: 40px; padding: 8px 14px; }
.year-nav .mid { flex: 1; text-align: center; }
.hero .zh-year { font-family: var(--serif); font-size: 40px; line-height: 1.1; }
.star-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.star-row:first-child { border-top: 0; }
.star-row .num { flex: 0 0 40px; height: 40px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; font-size: 20px; }
.months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.month { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 12px; padding: 8px; font: inherit; font-size: 13px; cursor: pointer; text-align: center; line-height: 1.3; }
.month b { display: block; font-size: 20px; }
.month.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.month.now { background: color-mix(in srgb, var(--gold) 14%, var(--surface)); }

/* Natal chart */
.chart9 .cell { min-height: 104px; gap: 0; }
.chart9 .cell.facing { border-color: var(--gold); }
.chart9 .mw { display: flex; justify-content: space-between; width: 70%; font-size: 18px; font-weight: 700; margin-top: 2px; }
.ms { color: #3d6b4f; } .ws { color: #2f5f8f; }
@media (prefers-color-scheme: dark) { :where(:root:not([data-theme="light"])) .ms { color: #8fd1a6; } :where(:root:not([data-theme="light"])) .ws { color: #8fbbe8; } }
.chart9 .bs { font-size: 28px; font-weight: 700; line-height: 1.05; }
.chart9 .ys { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 3px; }
.chart9 .ys .dot { width: 9px; height: 9px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 8px; align-items: center; }
.legend span { display: inline-flex; gap: 5px; align-items: center; }
details summary { cursor: pointer; color: var(--accent); }

/* Quiz (from I Ching Academy) */
.q-opts { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.q-opts.fig-opts { display: grid; grid-template-columns: 1fr 1fr; }
.q-opts.fig-opts .q-opt { display: grid; place-items: center; padding: 16px; }
.q-opt { text-align: left; padding: 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.q-opt.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, var(--surface)); }
.q-opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--surface)); }
.q-explain { margin-top: 12px; font-size: 14px; }
.q-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; }
.done-note { background: color-mix(in srgb, var(--ok) 14%, transparent); border-radius: 10px; padding: 8px 12px; margin: 0 0 8px; }
.how-to { counter-reset: s; list-style: none; padding: 0; }
.how-to > li { counter-increment: s; position: relative; padding: 2px 0 10px 40px; }
.how-to > li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--surface); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.why { display: block; font-size: 14px; color: var(--muted); margin-top: 4px; }
.lesson-item.locked .t, .lesson-item.locked .s { opacity: .65; }

/* Lesson pictures */
.diagram { margin: 14px 0; }
.dg-svg { display: block; width: 100%; max-width: 340px; margin: 8px auto 0; }
.dg-street { fill: var(--surface-2); }
.dg-house { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.dg-door { fill: var(--gold); }
.dg-arrow { stroke: var(--accent); stroke-width: 2.5; fill: none; }
.dg-arrow.muted-stroke { stroke: var(--muted); }
.dg-head { fill: var(--accent); } .dg-head-muted { fill: var(--muted); }
.dg-label { font: 600 14px system-ui, sans-serif; fill: var(--text); }
.dg-small { font: 12px system-ui, sans-serif; fill: var(--muted); }
.dg-el { font: 600 13px system-ui, sans-serif; fill: #fff; }
.dg-animal { font: 26px var(--serif); fill: var(--text); }
.grid9 .tri { font-size: 30px; line-height: 1.1; }
.ring-s { fill: var(--surface-2); stroke: var(--surface); stroke-width: 1.5; }
.ring-s.on { fill: var(--accent); }
.ring-zh { font: 16px var(--serif); fill: var(--text); }
.ring-zh.on { fill: #fff; }
.ring-edge { stroke: var(--gold); stroke-width: 2; }
input[type=range] { padding: 0; min-height: 36px; border: 0; background: none; accent-color: var(--accent); }
.lq { padding: 6px 0 12px; border-top: 1px solid var(--line); }
.lq:first-of-type { border-top: 0; }
.tri-svg { width: 38px; height: auto; fill: var(--ink); margin: 4px 0 2px; }

/* ---------- Compass (luopan) ---------- */
.lp-wrap { max-width: 420px; margin: 0 auto 12px; }
.lp-svg { width: 100%; height: auto; display: block; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.lp-svg.dragging { cursor: grabbing; }
#lp-dial { transform-origin: 200px 200px; transition: transform .25s ease-out; }
.lp-svg.dragging #lp-dial { transition: none; }
.lp-rim { fill: #2a1d16; }
.lp-tick { stroke: #e9dcc6; stroke-width: .6; } .lp-tick5 { stroke: #f4e9d6; stroke-width: 1.2; }
.lp-deg { font: 600 9px system-ui, sans-serif; fill: #f4e9d6; }
.lp-m { fill: #f4e9d6; } .lp-m.on { fill: #e8c77a; }
.lp-mzh { font: 17px var(--serif); fill: #2a1d16; } .lp-mzh.yang { fill: #b0281e; }
.lp-p { fill: #e9dcc6; } .lp-p.on { fill: #d9b45f; }
.lp-tri rect { fill: #2a1d16; }
.lp-dirs { fill: #f4e9d6; }
.lp-dir { font: 600 12px system-ui, sans-serif; fill: #2a1d16; }
.lp-edge { stroke: #7b2f28; stroke-width: 1.6; } .lp-medge { stroke: #b9a688; stroke-width: .7; }
.lp-line { fill: none; stroke: #7b2f28; stroke-width: 1; }
.lp-pool { fill: #2a1d16; } .lp-pool-in { fill: #f8f3ea; stroke: #b9a688; }
.lp-north { fill: #c0392b; } .lp-south { fill: #8a8f98; } .lp-pin { fill: #2a1d16; }
.lp-cross { stroke: #e0261b; stroke-width: 1.6; pointer-events: none; } .lp-cross.thin { stroke-width: .8; opacity: .7; }
.lp-mark { fill: #e0261b; pointer-events: none; }
.lp-read { text-align: center; }
#lp-deg { font-size: 40px; font-weight: 700; color: var(--accent); line-height: 1.1; }
.lp-btns .btn { flex: 1; }
.lp-fine { margin-top: 10px; align-items: center; }
.lp-fine input { flex: 1; text-align: center; font-size: 18px; }
.lp-fine .btn { flex: 0 0 auto; min-width: 64px; }
@media (prefers-reduced-motion: reduce) { #lp-dial { transition: none; } }

/* ---------- Pictures of lessons 7–16 ---------- */
.timeline { display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; margin: 8px 0; }
.tl { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: 6px 0; font: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; }
.tl b { font-size: 18px; } .tl span { font-size: 9px; color: var(--muted); }
.tl.yuan { margin-left: 6px; }
.tl.now { background: color-mix(in srgb, var(--gold) 18%, var(--surface)); }
.tl.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.star-cards { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; margin: 8px 0; }
.sc { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 10px; padding: 8px 0; font: 700 16px system-ui, sans-serif; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sc.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.sc.tm-ruling, .sc.tm-coming { background: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.sc.tm-five { background: color-mix(in srgb, var(--bad) 10%, var(--surface)); }
.star-card { margin-top: 6px; }
.kua9 .cell { min-height: 78px; } .kua9 .t { font-family: var(--serif); font-size: 18px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 10px 0 0; }
label.check input { width: auto; min-height: 0; }
.remedy-pic { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 12px 0; }
.rp-box { width: 120px; min-height: 90px; border-radius: 12px; background: var(--surface-2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; padding: 6px; border: 2px solid transparent; }
.rp-box.on { border-color: color-mix(in srgb, var(--ok) 55%, transparent); } .rp-box.off { opacity: .55; }
.rp-star, .rp-el { font-size: 26px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.rp-arrow { font-size: 26px; color: var(--accent); min-width: 20px; }
.lesson-item.locked { opacity: .75; }
.lesson-body ol { padding-left: 22px; }
