:root {
  --bg: #1d1a16; --card: #2a251f; --ink: #f2ead9; --muted: #a99d88; --line: #4a4136;
  --gold: #e0b44c; --teal: #2fb8ac; --red: #e5534b; --purple: #b07cf0; --green: #5cc46a; --blue: #5aa8ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif; }
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.hidden { display: none !important; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 17px; display: flex; gap: 8px; align-items: center; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: var(--gold); color: var(--bg); }
.who { font-size: 12px; min-width: 0; color: var(--muted); display: flex; gap: 8px; align-items: center; }
main { max-width: 820px; margin: 0 auto; padding: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
h1 { font-size: 22px; margin: 0 0 8px; } h2 { font-size: 17px; margin: 0 0 10px; } h4 { margin: 12px 0 4px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
input, select { display: block; width: 100%; margin-top: 3px; padding: 8px; border-radius: 6px; border: 1px solid var(--line); background: #191612; color: var(--ink); font-size: 15px; }
.row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.row.tight { align-items: center; gap: 4px; flex-wrap: nowrap; } .row.tight select { width: auto; flex: 1; }
.grow { flex: 1; min-width: 160px; margin-bottom: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
label.check { display: flex; gap: 8px; align-items: center; color: var(--ink); }
label.check input { width: auto; margin: 0; }
button { padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); background: #3a332a; color: var(--ink); font-size: 14px; cursor: pointer; }
button.primary { background: var(--gold); color: #1d1a16; border-color: var(--gold); font-weight: 600; }
button.danger { color: var(--red); }
button:disabled { opacity: .5; cursor: default; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 1 0 auto; white-space: nowrap; } .tab.active { background: var(--ink); color: var(--bg); }
.small { font-size: 12px; } .muted { color: var(--muted); }
.foot { text-align: center; padding: 18px 12px 28px; }

/* Nine-palace grid */
.qm { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 6px 0 10px; }
.cell { position: relative; background: #211d18; border: 1px solid var(--line); border-radius: 6px; padding: 6px 6px 5px; min-height: 132px; display: flex; flex-direction: column; gap: 2px; }
.toprow { display: flex; justify-content: space-between; align-items: center; min-height: 16px; }
.toprow .pn { font-size: 10px; color: var(--muted); }
.cell .god { font-weight: 600; } .cell .en { font-size: 10px; color: var(--muted); font-weight: 400; }
.toprow .marks { display: flex; gap: 3px; }
.mk { font-size: 11px; padding: 0 3px; border-radius: 3px; border: 1px solid var(--muted); }
.mk.horse { border-color: var(--gold); color: var(--gold); }
.cell .star { color: #e9d9b6; }
.cell .door.pressured { color: var(--red); font-weight: 700; }
.stems { display: flex; justify-content: space-between; align-items: flex-end; margin-top: auto; }
.plate { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.plate .lbl { font-size: 9px; color: var(--muted); }
.stemrow { display: flex; gap: 3px; }
.stem { display: flex; flex-direction: column; align-items: center; }
.stem .st { font-size: 9px; color: var(--muted); min-height: 11px; letter-spacing: -1px; }
.stem .g { font-size: 18px; line-height: 1.1; padding: 0 3px; border: 2px solid transparent; border-radius: 4px; }
.stem.x .g { color: var(--purple); } .stem.m .g { color: var(--green); } .stem.xm .g { color: var(--blue); }
.stem.day .g { border-color: var(--gold); } .stem.hour .g { border-color: var(--teal); }
.stem.day.hour .g { border-color: var(--gold); box-shadow: 0 0 0 2px var(--teal); }
.hid { font-size: 12px; color: var(--muted); } .hid b { color: var(--ink); font-weight: 400; }
.cell.center { justify-content: center; align-items: center; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 11px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; background: var(--c); }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; margin-top: 10px; }
.meta dt { color: var(--muted); } .meta dd { margin: 0; }
.reading { white-space: normal; margin-top: 10px; } .reading p { margin: 0 0 10px; }
.disclaimer { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 8px; font-size: 12px; color: var(--muted); }
.err { color: var(--red); }
.hist { border-top: 1px solid var(--line); padding: 8px 0; } .hist summary { cursor: pointer; }
@media (max-width: 420px) { .stem .g { font-size: 16px; } .cell { min-height: 124px; padding: 5px 4px; } }
@media (max-width: 420px) { .who span { display: none; } }

/* Bazi */
h3 { font-size: 15px; margin: 16px 0 6px; }
.wx.wood { color: #5cc46a; } .wx.fire { color: #e5534b; } .wx.earth { color: #c9a26b; } .wx.metal { color: #e8e2d0; } .wx.water { color: #5aa8ff; }
table.bz { width: 100%; border-collapse: collapse; text-align: center; table-layout: fixed; }
table.bz th, table.bz td { border-bottom: 1px solid var(--line); padding: 4px 2px; vertical-align: top; }
table.bz tr > th:first-child { width: 44px; font-size: 11px; color: var(--muted); font-weight: 400; text-align: left; }
table.bz tr.big td { font-size: 28px; line-height: 1.2; }
table.bz tr.gods td, table.bz tr.small td { font-size: 12px; }
table.bz .dm { color: var(--gold); font-weight: 700; }
table.bz .hs { font-size: 14px; white-space: nowrap; } table.bz .hs .small { font-size: 10px; color: var(--muted); }
table.bz .mk { font-size: 10px; vertical-align: super; margin-left: 2px; }
.wxbars { display: flex; flex-direction: column; gap: 3px; margin: 4px 0 8px; }
.wxbar { display: grid; grid-template-columns: 18px 1fr 22px; gap: 6px; align-items: center; font-size: 13px; }
.wxbar .bar { height: 8px; background: #191612; border-radius: 4px; overflow: hidden; }
.wxbar .bar i { display: block; height: 100%; }
.bar i.wood { background: #5cc46a; } .bar i.fire { background: #e5534b; } .bar i.earth { background: #c9a26b; } .bar i.metal { background: #e8e2d0; } .bar i.water { background: #5aa8ff; }
.strength { margin: 4px 0; }
.luck { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
.lp { flex: 0 0 64px; text-align: center; background: #211d18; border: 1px solid var(--line); border-radius: 6px; padding: 4px 2px; }
.lp.cur { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.lp .gz { font-size: 20px; line-height: 1.15; margin: 2px 0; }
table.ln { width: 100%; border-collapse: collapse; font-size: 12px; text-align: center; }
table.ln th { color: var(--muted); font-weight: 400; } table.ln td, table.ln th { border-bottom: 1px solid var(--line); padding: 3px 2px; }
table.ln tr.cur td { color: var(--gold); }

/* Admin */
ul.plain { list-style: none; padding: 0; margin: 8px 0 0; }
ul.plain li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); word-break: break-all; }
ul.plain li button, table.signins button { padding: 4px 10px; font-size: 12px; white-space: nowrap; flex-shrink: 0; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 3px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.ok { border-color: var(--green); color: var(--green); } .tag.no { border-color: var(--red); color: var(--red); }
table.signins { width: 100%; border-collapse: collapse; font-size: 12px; }
table.signins th, table.signins td { text-align: left; padding: 4px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.signins td:first-child { word-break: break-all; } table.signins td:last-child { white-space: nowrap; }
table.signins td:last-child button { margin-top: 4px; display: block; }
table.signins th { color: var(--muted); font-weight: 400; }

/* Zi Wei board: 4x4, palaces on the edge, chart info in the middle */
.zw { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, auto); gap: 3px; margin: 6px 0 10px; }
.zc { background: #211d18; border: 1px solid var(--line); border-radius: 5px; padding: 4px; min-height: 128px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.zc.soul { border-color: var(--gold); } .zc.dec { box-shadow: inset 0 0 0 2px var(--teal); }
.zc.soul.dec { border-color: var(--gold); box-shadow: inset 0 0 0 2px var(--teal); }
.zcenter { grid-column: 2 / 4; grid-row: 2 / 4; border: 1px solid var(--line); border-radius: 5px; padding: 8px; display: flex; flex-direction: column; gap: 4px; justify-content: center; text-align: center; font-size: 13px; }
.zmain, .zminor { display: flex; flex-wrap: wrap; gap: 0 4px; }
.zs { white-space: nowrap; } .zs.major { font-size: 15px; font-weight: 600; color: #f0c674; } .zs.minor { font-size: 12px; color: #e9d9b6; }
.zs .br { font-size: 9px; color: var(--muted); font-weight: 400; margin-left: 1px; }
.mut { font-size: 10px; padding: 0 2px; border-radius: 3px; color: #1d1a16; font-weight: 700; margin-left: 1px; }
.mut.lu { background: var(--green); } .mut.quan { background: var(--purple); } .mut.ke { background: var(--blue); } .mut.ji { background: var(--red); }
.zadj { font-size: 10px; color: var(--muted); line-height: 1.25; }
.zfoot { margin-top: auto; display: flex; justify-content: space-between; align-items: flex-end; line-height: 1.2; }
.zname { text-align: right; font-size: 13px; } .zname .mk { margin-right: 2px; font-size: 10px; } .mk.yr { border-color: var(--teal); color: var(--teal); }
@media (max-width: 520px) { .zs.major { font-size: 13px; } .zs.minor { font-size: 11px; } .zadj { display: none; } .zc { min-height: 112px; padding: 3px; } .zname { font-size: 12px; } .zcenter { font-size: 12px; padding: 4px; } }
.zname, .zfoot .small { white-space: nowrap; } .zfoot { gap: 2px; }
@media (max-width: 520px) { .zfoot .small { font-size: 10px; } .zname { font-size: 11px; } .zname .small { font-size: 10px; } }

/* Sign-in buttons, offline bar, iPhone app */
.signins { display: flex; flex-direction: column; gap: 10px; max-width: 320px; }
.signins button { padding: 11px 14px; font-size: 16px; }
button.apple { background: #fff; color: #000; border-color: #fff; font-weight: 600; }
.offlineBar { display: none; background: #5a4a1f; color: var(--ink); text-align: center; padding: 6px; }
html.offline .offlineBar { display: block; }
button.share { margin-top: 10px; }
html.native header.top { padding-top: calc(env(safe-area-inset-top) + 8px); }
html.native .foot { padding-bottom: calc(env(safe-area-inset-bottom) + 8px); }
