:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f3;
  --text: #16181d;
  --text-2: #5b616e;
  --text-3: #979ca8;
  --line: #e5e7eb;
  --accent: #d6453d;
  --accent-soft: #fdeceb;
  --shadow: 0 1px 2px rgba(16, 20, 30, .04), 0 10px 30px -14px rgba(16, 20, 30, .14);
  --radius: 18px;
  --wood: #2f9e5a;
  --fire: #e0564b;
  --earth: #b07b2a;
  --metal: #c39a2b;
  --water: #2f80ed;
  --font-ui: "Inter", "Noto Sans SC", -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-han: "Noto Serif SC", "Songti SC", "STSong", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #171a1f;
    --surface-2: #1d2127;
    --surface-3: #252a32;
    --text: #eceef2;
    --text-2: #a4aab6;
    --text-3: #6b7280;
    --line: #262b33;
    --accent: #f0655b;
    --accent-soft: #3a1f1d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -14px rgba(0, 0, 0, .7);
    --wood: #5ccf85;
    --fire: #ff7b6e;
    --earth: #d9a659;
    --metal: #e6c35a;
    --water: #6aa8ff;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
}
.hidden { display: none !important; }
.muted { color: var(--text-3); font-size: 13px; }

.wx-wood { color: var(--wood); }
.wx-fire { color: var(--fire); }
.wx-earth { color: var(--earth); }
.wx-metal { color: var(--metal); }
.wx-water { color: var(--water); }

/* 顶栏：品牌 · 此刻干支 · 时钟 */
.topbar {
  flex: none;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font-family: var(--font-han); font-weight: 700; font-size: 19px;
}
.brand-name { font-weight: 600; font-size: 16px; letter-spacing: .02em; white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--text-3); padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; }
.now { display: flex; align-items: baseline; gap: 14px; justify-self: center; }
.now .n-gz { font-family: var(--font-han); font-size: 22px; font-weight: 700; line-height: 1; }
.now .n-t { font-size: 11px; color: var(--text-3); margin-right: 3px; font-family: var(--font-ui); }
.now .n-meta { font-size: 12px; color: var(--text-3); padding-left: 14px; border-left: 1px solid var(--line); }
.now .n-meta b { color: var(--text-2); font-weight: 600; font-family: var(--font-han); }
.clock { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.clock-time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 17px; letter-spacing: .04em; }
.clock-date { font-size: 11.5px; color: var(--text-3); }

/* 起课工具条 */
.castbar {
  flex: none;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.segmented { display: flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: 10px; }
.seg {
  border: 0; background: transparent; color: var(--text-2);
  padding: 6px 14px; border-radius: 8px; font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s;
}
.seg.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.mode-panel { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.castbar input, .castbar select {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 10px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.castbar input:focus, .castbar select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#number-input { width: 110px; }
.gz-field { display: inline-flex; align-items: center; gap: 5px; }
.gz-field > span { font-size: 11px; color: var(--text-3); letter-spacing: .08em; }
.gz-field select { padding: 6px 8px; font-family: var(--font-han); font-weight: 600; }
.number-preview { font-family: var(--font-han); font-size: 18px; font-weight: 700; min-width: 44px; }
.hint { font-size: 12.5px; color: var(--text-3); }
.ming-field { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; padding-left: 14px; border-left: 1px solid var(--line); }
.ming-field > span { font-size: 11px; color: var(--text-3); letter-spacing: .08em; }
.ming-field input { width: 76px; }
.cast-actions { display: flex; align-items: center; gap: 12px; }
.chip.ming { border-color: color-mix(in srgb, var(--water) 50%, var(--line)); }
.cell .c-ming { position: absolute; left: 8px; bottom: 5px; font-size: 10px; color: var(--water); font-weight: 600; letter-spacing: .04em; }
.btn-primary {
  border: 0; cursor: pointer; font: inherit; font-weight: 600; font-size: 14px;
  color: #fff; background: var(--accent);
  padding: 8px 26px; border-radius: 10px;
  box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--accent) 80%, transparent);
  transition: transform .1s, filter .15s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: translateY(1px); }
.error { color: var(--accent); font-size: 13px; }

/* 课盘：占满剩余视口 */
.result {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 10px;
  width: 100%; max-width: 1360px; margin: 0 auto; padding: 10px 24px 14px;
}
.result.empty { visibility: hidden; }
.result-head { flex: none; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; row-gap: 8px; }
.result-head .chips { flex: 1; min-width: 0; }
.ss-box {
  flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 4px 14px;
  padding: 6px 14px; border: 1px dashed var(--text-3); border-radius: 12px;
}
.ss-box .ss, .ss-list .ss { background: transparent; padding: 0; font-size: 13px; color: var(--text-2); gap: 0; }
.ss-box .ss .s-zhi, .ss-list .ss .s-zhi { font-size: 16px; }
.keti { display: flex; align-items: baseline; gap: 8px; padding-right: 22px; border-right: 1px solid var(--line); }
.keti-label { font-size: 11px; color: var(--text-3); letter-spacing: .16em; }
.keti-name { font-family: var(--font-han); font-size: 30px; font-weight: 700; color: var(--accent); line-height: 1; white-space: nowrap; }
.keti-name small { font-size: 15px; font-weight: 600; color: var(--text-2); margin-left: 10px; }
.result-pillars { display: flex; gap: 16px; }
.rp { display: flex; align-items: baseline; gap: 3px; }
.rp .rp-t { font-size: 11px; color: var(--text-3); letter-spacing: .1em; }
.rp .rp-gz { font-family: var(--font-han); font-size: 24px; font-weight: 700; line-height: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: baseline; gap: 6px; min-height: 28px; line-height: 1.4;
  padding: 4px 11px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums;
}
.chip b { color: var(--text); font-weight: 600; font-size: 13px; }
.chip span { white-space: nowrap; }
.chip.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip.accent b { color: var(--accent); }
.chip.kong { border-style: dashed; border-color: var(--text-3); }
.chip.kong b { color: var(--text-2); }

/* 空亡角标：天盘神空亡、下神空亡 */
.kong-badge {
  font-style: normal; font-family: var(--font-ui); font-weight: 600;
  font-size: 9px; line-height: 1; padding: 2px 3px; border-radius: 4px;
  border: 1px dashed var(--text-3); color: var(--text-2);
  vertical-align: top; margin-left: 3px;
}

.result-grid {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: auto minmax(360px, 1fr); gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
  min-height: 0;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h3 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .14em; color: var(--text-2); }

/* 天地盘：4×4 方盘，边长由 JS 取容器宽高较小者 */
.board-card { display: flex; flex-direction: column; }
.board-wrap { flex: 1; min-height: 0; display: grid; place-items: center; }
.board {
  display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr);
  gap: 8px; width: 560px; height: 560px;
}
.cell {
  position: relative; border-radius: 14px;
  background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 4px; min-width: 0;
}
.cell .c-jiang { font-size: 12px; color: var(--text-2); letter-spacing: .08em; }
.cell .c-main { display: flex; align-items: baseline; gap: 4px; }
.cell .c-dun { font-family: var(--font-han); font-size: 15px; color: var(--text-3); width: 14px; text-align: right; }
.c-dun.kong, .t-dun.kong, .k-dun.kong { color: var(--accent); font-family: var(--font-ui); font-weight: 600; }
.cell .c-tian { font-family: var(--font-han); font-size: 38px; font-weight: 700; line-height: 1; }
.cell.kong .c-tian { opacity: .6; }
.cell.kong .c-main { position: relative; }
.cell.kong .c-main .kong-badge { position: absolute; left: 100%; top: 0; }
.cell .c-di { position: absolute; right: 9px; top: 7px; font-size: 11px; color: var(--text-3); font-family: var(--font-han); }
/* 落空之神：加框 */
.luo { box-shadow: 0 0 0 1.5px currentColor; border-radius: 4px; padding: 0 2px; }
.cell.in-chuan { background: var(--accent-soft); }
.cell.in-chuan .c-jiang { color: var(--accent); }
.cell.center {
  grid-column: 2 / 4; grid-row: 2 / 4;
  background: transparent; box-shadow: inset 0 0 0 1px var(--line);
  gap: 8px;
}
.cell.center .c-day { font-family: var(--font-han); font-size: 40px; font-weight: 700; line-height: 1; }
.cell.center .c-day small { font-family: var(--font-ui); font-size: 13px; color: var(--text-3); font-weight: 500; margin-left: 6px; }
.cell.center .c-sub { font-size: 12.5px; color: var(--text-2); text-align: center; line-height: 1.7; }
.cell.center .c-sub b { font-family: var(--font-han); font-weight: 600; color: var(--text); }
/* 小方盘时缩字 */
.board.small { gap: 6px; }
.board.small .cell { gap: 2px; padding: 6px 2px; }
.board.small .cell .c-tian { font-size: 30px; }
.board.small .cell .c-jiang { font-size: 11px; }
.board.small .cell .c-dun { font-size: 13px; width: 12px; }
.board.small .cell.center .c-day { font-size: 30px; }
.board.small .cell.center .c-sub { font-size: 11.5px; line-height: 1.5; }

/* 右栏：三传 / 四课 / 神煞 */
.side-card { display: flex; flex-direction: column; overflow: hidden; }
.chuan { display: grid; grid-template-columns: auto auto auto auto; column-gap: 18px; align-items: center; justify-content: start; margin-bottom: 10px; }
.chuan > div { padding: 6px 0; }
.chuan .t-ord { font-size: 11px; color: var(--text-3); letter-spacing: .12em; }
.chuan .t-qin { color: var(--text-2); font-size: 14px; min-width: 2em; }
.chuan .t-main { display: flex; align-items: baseline; gap: 4px; }
.chuan .t-dun { font-family: var(--font-han); font-size: 17px; color: var(--text-3); width: 16px; text-align: right; }
.chuan .t-zhi { font-family: var(--font-han); font-size: 28px; font-weight: 700; line-height: 1; }
.chuan .t-jiang { color: var(--text-2); font-size: 14px; min-width: 2em; }
.chuan .t-row { grid-column: 1 / -1; height: 1px; background: var(--line); padding: 0; }

.ke { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.ke-col { position: relative; border-radius: 14px; background: var(--surface-2); padding: 8px 6px 8px; text-align: center; }
.ke-col.fa { background: var(--accent-soft); }
.ke-col .k-ord { font-size: 11px; color: var(--text-3); letter-spacing: .12em; }
.ke-col .k-jiang { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.ke-col.fa .k-jiang { color: var(--accent); }
.ke-col .k-main { display: flex; align-items: baseline; justify-content: center; gap: 3px; margin-top: 3px; }
.ke-col .k-dun { font-family: var(--font-han); font-size: 14px; color: var(--text-3); width: 14px; text-align: right; }
.ke-col .k-shang { font-family: var(--font-han); font-size: 28px; font-weight: 700; line-height: 1; }
.ke-col .k-main { position: relative; }
.ke-col .k-main .kong-badge { position: absolute; left: calc(50% + 16px); top: 0; }
.ke-col .k-sep { width: 22px; height: 1px; background: var(--line); margin: 5px auto; }
.ke-col .k-xia { font-family: var(--font-han); font-size: 28px; font-weight: 700; line-height: 1; }
.ke-col .k-rel {
  position: absolute; top: 7px; right: 7px;
  font-size: 10px; line-height: 1; padding: 3px 5px; border-radius: 6px;
  background: var(--surface-3); color: var(--text-2);
}
.ke-col.fa .k-rel { background: var(--accent); color: #fff; }

.shensha { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 90px; overflow: auto; }
.ss-tabs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; margin-bottom: 6px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.ss-tab { border: 0; background: transparent; font: inherit; font-size: 12.5px; color: var(--text-3); padding: 4px 9px; border-radius: 8px; cursor: pointer; }
.ss-tab.active { background: var(--surface-3); color: var(--text); font-weight: 600; }
.ss-tabs .link { margin-left: auto; }
.link { font-size: 12px; color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* 全部神煞页 */
.ss-page { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 18px 24px 60px; display: grid; gap: 16px; }
.ss-page .result-head { margin-bottom: 4px; }
.ss-tools { display: flex; gap: 10px; align-items: center; }
.ss-tools input { font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 7px 12px; width: 260px; outline: none; }
.ss-tools input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ss-section { padding: 14px 18px; }
.ss-section .card-head { margin-bottom: 8px; }
.ss-table { width: 100%; border-collapse: collapse; }
.ss-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: baseline; }
.ss-table tr:last-child td { border-bottom: 0; }
.ss-table .n { width: 84px; color: var(--text); font-weight: 600; white-space: nowrap; }
.ss-table .z { width: 44px; font-family: var(--font-han); font-size: 20px; font-weight: 700; }
.ss-table .b { color: var(--text-3); font-size: 12px; }
.ss-table tr.hit td { background: var(--accent-soft); }
.ss-empty { color: var(--text-3); padding: 40px; text-align: center; }
.ss-group { display: flex; gap: 10px; align-items: flex-start; }
.ss-title { flex: none; width: 44px; font-size: 11px; color: var(--text-3); letter-spacing: .12em; padding-top: 5px; }
.ss-title span { display: block; font-size: 10px; letter-spacing: 0; color: var(--text-3); opacity: .7; }
.ss-list { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.ss {
  display: inline-flex; align-items: baseline; gap: 4px;
  padding: 3px 7px; border-radius: 8px; background: var(--surface-2);
  font-size: 11.5px; color: var(--text-2); cursor: default; white-space: nowrap;
}
.ss:hover { background: var(--surface-3); }
.ss .s-zhi { font-family: var(--font-han); font-size: 15px; font-weight: 700; }

.note { flex: none; padding-top: 8px; }
.note summary { cursor: pointer; font-size: 12px; color: var(--text-3); font-weight: 600; letter-spacing: .14em; }
.note pre { margin: 6px 0 0; white-space: pre-wrap; font-family: var(--font-ui); font-size: 12px; color: var(--text-2); line-height: 1.55; max-height: 96px; overflow: auto; }

/* 窄屏：恢复纵向滚动 */
@media (max-width: 900px) {
  html, body { height: auto; }
  .topbar { grid-template-columns: 1fr auto; padding: 10px 14px; }
  .now { display: none; }
  .castbar { padding: 10px 14px; }
  .mode-panel { flex-basis: 100%; }
  .cast-actions { margin-left: 0; width: 100%; }
  .cast-actions .btn-primary { width: 100%; }
  .error { order: 2; }
  .result { padding: 12px 12px 40px; }
  .result-grid { grid-template-columns: 1fr; }
  .board { width: 100% !important; height: auto !important; aspect-ratio: 1 / 1; }
  .keti { border-right: 0; padding-right: 0; }
  .card { padding: 14px; }
  .brand-sub { display: none; }
  .result-head { gap: 12px; }
  .result-pillars { gap: 12px; flex-wrap: wrap; }
  .rp .rp-gz { font-size: 20px; white-space: nowrap; }
  .cell { gap: 2px; padding: 6px 2px; }
  .cell .c-jiang { font-size: 11px; letter-spacing: 0; }
  .cell .c-tian { font-size: 28px; }
  .cell .c-dun { font-size: 12px; width: 11px; }
  .cell .c-di { top: 4px; right: 5px; font-size: 10px; }
  .cell.center .c-day { font-size: 28px; }
  .cell.center .c-sub { font-size: 11px; line-height: 1.5; }
  .chuan { column-gap: 12px; }
  .ke-col .k-ord { text-align: left; padding-left: 4px; }
  .ke-col .k-rel { top: 5px; right: 5px; font-size: 9px; padding: 2px 4px; }
  .chuan .t-zhi { font-size: 28px; }
}

/* 《六壬金针》课例页 */
.jz-page { max-width: 1000px; }
.jz-intro { margin: -6px 0 4px; font-size: 12.5px; }
.ss-tools select { font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; }
.jz { padding: 10px 0 12px; border-bottom: 1px solid var(--line); }
.jz:last-child { border-bottom: 0; }
.jz-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.jz-no { font-size: 11px; color: var(--text-3); min-width: 22px; }
.jz-page { font-size: 11px; color: var(--text-3); padding: 2px 6px; border: 1px solid var(--line); border-radius: 999px; }
.jz-title { font-weight: 600; font-size: 14px; flex: 1; min-width: 200px; }
.btn-mini { font-size: 12px; color: var(--accent); text-decoration: none; padding: 3px 9px; border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 8px; white-space: nowrap; }
.btn-mini:hover { background: var(--accent-soft); }
.jz-row { font-size: 13px; color: var(--text-2); line-height: 1.9; }
.jz-row b { font-family: var(--font-han); font-size: 15px; }
.jz-k { display: inline-block; width: 36px; font-size: 11px; color: var(--text-3); letter-spacing: .12em; }
.jz-keti { color: var(--accent); }
.jz-v { font-weight: 600; }
.jz-v.ok { color: var(--wood); }
.jz-v.fixed { color: var(--metal); }
.jz-v.skip { color: var(--accent); }
.jz-v.muted { color: var(--text-3); }
.jz-note { margin-left: 8px; font-size: 12px; color: var(--text-3); }
.jz-text { margin-top: 4px; }
.jz-text summary { cursor: pointer; font-size: 12px; color: var(--text-3); }
.jz-text p { margin: 6px 0 0; font-size: 13px; line-height: 1.75; color: var(--text-2); }
.topbar .link.nav { justify-self: end; margin-right: 14px; }
