:root {
  color-scheme: dark;
  --bg: #070b14;
  --card: #0c1526;
  --text: #f3f6fb;
  --muted: #9aadc4;
  --gold: #f0b429;
  --gold-ink: #1c1404;
  --line: #31445f;
  --ring: #8ea3c2;
  --tick: #c5d4ea;
  --wheel: #101a2e;
  --wheel-mid: #182844;
  --house1: rgba(232, 156, 46, 0.5);
  --sign-a: rgba(255, 255, 255, 0.03);
  --sign-b: rgba(255, 255, 255, 0.07);
  --sky-top: #07111e;
  --sky-horizon: #1c3d68;
  --ground: #141b27;
  --note: #c5d0e0;
  --danger: #ffb4a8;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

html[data-theme="day"] {
  color-scheme: light;
  --bg: #e7eef6;
  --card: #fbfcfe;
  --text: #172033;
  --muted: #52627a;
  --gold: #a86208;
  --gold-ink: #fff8ea;
  --line: #c5d0e0;
  --ring: #5d7290;
  --tick: #314863;
  --wheel: #f4f7fb;
  --wheel-mid: #e7eef7;
  --house1: rgba(214, 140, 32, 0.42);
  --sign-a: rgba(23, 40, 70, 0.03);
  --sign-b: rgba(23, 40, 70, 0.06);
  --sky-top: #8ecbf7;
  --sky-horizon: #3e8fd0;
  --ground: #243044;
  --note: #3d4e66;
  --danger: #9f2d2d;
  --shadow: 0 12px 32px rgba(30, 50, 80, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(240, 180, 41, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "PingFang TC", "Noto Sans TC", "Heiti TC", sans-serif;
  line-height: 1.5;
}

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 12px 18px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: "Songti TC", "PMingLiU", serif;
  font-size: 1.25rem;
  letter-spacing: 0.08em;
}

.tabs, .controls, .seg {
  display: flex;
  align-items: center;
  gap: 8px;
}

.controls { margin-left: auto; }

button, input {
  font: inherit;
  color: var(--text);
}

button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
}

button.on {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--gold-ink);
}

button:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

time {
  font-variant-numeric: tabular-nums;
  min-width: 11rem;
  text-align: right;
  white-space: nowrap;
}

.hint, .nowrap { color: var(--muted); font-size: 0.85rem; }
.nowrap { white-space: nowrap; color: inherit; font-size: inherit; }

main {
  width: min(1040px, calc(100% - 28px));
  margin: 0 auto 48px;
}

h1, h2 {
  text-align: center;
  font-family: "Songti TC", "PMingLiU", serif;
  font-weight: 700;
  letter-spacing: 0.06em;
}

h1 { font-size: 2rem; margin: 28px 0 0; }
h2 { font-size: 1.15rem; margin: 28px 0 12px; }

.lead {
  text-align: center;
  margin: 4px 0;
  color: var(--muted);
}

.lead.strong { color: var(--text); font-weight: 650; }

.sky-wrap, .wheel-wrap {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sky-wrap { margin-top: 14px; }

svg { display: block; width: 100%; height: auto; }

.note, .foot, .headline, .legend {
  text-align: center;
  color: var(--note);
}

.headline { margin: 14px 0 0; font-size: 1.05rem; }
.headline strong {
  display: block;
  color: var(--gold);
  font-size: 1.35rem;
  letter-spacing: 0.04em;
}
.foot { margin-top: 8px; color: var(--muted); font-size: 0.92rem; }

.stars { fill: #fff; }
html[data-theme="day"] .stars { display: none; }

.sky-sign, .axis-tag { fill: var(--text); font-size: 18px; }
.ground-label { font-size: 20px; }
.ground-label.rise { fill: #ffcc66; font-weight: 700; }
.ground-label.set { fill: #d5deea; }
html[data-theme="day"] .ground-label.set { fill: #d7e4f4; }
.compass { fill: #d7e2f1; font-size: 15px; }
.ecliptic { fill: none; stroke: url(#ecliptic); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.equator { fill: none; stroke: rgba(215, 226, 242, 0.85); stroke-width: 1.6; stroke-dasharray: 2 7; stroke-linecap: round; }
html[data-theme="day"] .equator { stroke: rgba(255, 255, 255, 0.9); }
.horizon { stroke: rgba(255, 255, 255, 0.78); stroke-width: 1.5; }

.ring { fill: none; stroke: var(--ring); stroke-width: 1.2; }
.disk { fill: var(--wheel); }
.mid { fill: var(--wheel-mid); }
.sign-a { fill: var(--sign-a); }
.sign-b { fill: var(--sign-b); }
.house1 { fill: var(--house1); }
.cusp { stroke: var(--tick); stroke-width: 1; opacity: 0.75; }
.axis { stroke: var(--gold); stroke-width: 1.7; }
.horizon-axis { stroke: var(--text); stroke-width: 1.5; opacity: 0.8; }
.tick { stroke: var(--tick); stroke-width: 1; }
.sign-label, .house-num, .cap, .body-label {
  fill: var(--text);
  font-size: 15px;
  text-anchor: middle;
  dominant-baseline: middle;
}
.body-label {
  font-weight: 700;
  paint-order: stroke;
  stroke: var(--wheel);
  stroke-width: 4px;
}
.house-num { fill: var(--muted); font-size: 13px; }
.cap { font-size: 14px; font-weight: 700; }
.cap.gold { fill: var(--gold); }
.sun-ray { stroke: var(--gold); stroke-width: 1.6; }
.sun-core { fill: #f0b429; stroke: #fff6df; stroke-width: 1.5; }

.asp-0 { stroke: #e6b325; color: #e6b325; }
.asp-60 { stroke: #3cb8a0; color: #3cb8a0; }
.asp-90 { stroke: #e05a4f; color: #e05a4f; }
.asp-120 { stroke: #5b8def; color: #5b8def; }
.asp-180 { stroke: #d45d8c; color: #d45d8c; }
.aspect { fill: none; stroke-width: 1.15; opacity: 0.7; }

.dob {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin: 8px 0 18px;
}

.dob label { color: var(--muted); }

input[type="date"], input[type="time"] {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

.bi {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.85fr);
  gap: 18px;
  align-items: start;
}

.legend { display: flex; justify-content: center; gap: 14px; font-weight: 700; }

.side {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 8px 12px 16px;
  max-height: calc(100vh - 96px);
  overflow: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 0.86rem; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 6px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
h3 { margin: 14px 0 6px; font-size: 1rem; }
.side h4 { margin: 12px 0 4px; font-size: 0.92rem; }
.level-lead { color: var(--muted); font-size: 0.82rem; margin: 0 0 8px; line-height: 1.45; }
.level-list { margin: 0; padding-left: 1.15em; font-size: 0.84rem; line-height: 1.5; }
.level-list li { margin: 0 0 6px; }
.src { display: none; }
#panel-natal.show-src .src { display: inline; color: var(--muted); }
.src-bar { display: flex; justify-content: flex-end; margin: 0 0 8px; }
.read-col { min-width: 0; }
.pri { color: var(--gold); font-weight: 700; margin-right: 4px; }
.good { color: #1f8a70; font-weight: 700; margin-right: 2px; }
.bad { color: #c2412d; font-weight: 700; margin: 0 2px; }
html[data-theme="night"] .good { color: #3ecfb0; }
html[data-theme="night"] .bad { color: #ff8d7d; }
.flat { color: var(--muted); font-weight: 700; }
.year-panel { margin-top: 8px; }
.house-now { margin-top: 4px; }
.house-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.hcell {
  border-radius: 14px;
  padding: 10px 12px 12px;
  min-height: 96px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.hcell.good { background: color-mix(in srgb, #1f8a70 34%, var(--card)); }
.hcell.bad { background: color-mix(in srgb, #c2412d 36%, var(--card)); }
.hcell.mixed { background: color-mix(in srgb, var(--gold) 28%, var(--card)); }
.hcell.empty { opacity: 0.72; }
.hcell header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.92rem;
}
.hcell header b { font-size: 1.15rem; }
.hcell header span { color: var(--muted); }
.hcell header em { margin-left: auto; font-style: normal; font-weight: 700; }
.hcell.good header em { color: #1f8a70; }
.hcell.bad header em { color: #c2412d; }
html[data-theme="night"] .hcell.good header em { color: #8ef0d4; }
html[data-theme="night"] .hcell.bad header em { color: #ffb0a4; }
.hcell p { margin: 6px 0 0; font-size: 0.86rem; line-height: 1.45; }
.year-chart {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 12px 12px 16px;
}
.year-meta, .year-focus { margin: 4px 0 8px; color: var(--muted); font-size: 0.86rem; }
.year-focus b { color: var(--text); }
.year-chart svg { width: 100%; height: auto; display: block; touch-action: none; }
.year-chart .axis { stroke: var(--line); stroke-width: 1; }
.year-chart .zero { stroke: var(--gold); stroke-width: 1.4; stroke-dasharray: 4 4; }
.year-chart .today { stroke: var(--text); stroke-width: 1.2; opacity: 0.7; }
.year-chart .label { fill: var(--muted); font-size: 12px; }
.year-chart .num { font-variant-numeric: tabular-nums; }
.year-legend, .year-scores {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
  padding: 0;
  list-style: none;
}
.year-legend button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
}
.year-legend button.on {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}
.year-legend button.off { opacity: 0.38; }
.year-legend i, .year-scores i, .year-table i {
  display: inline-block;
  width: 14px;
  height: 4px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: middle;
}
.year-scores li { font-size: 0.86rem; }
.year-table i { width: 10px; }
.year-table td, .year-table th { white-space: normal; }
.year-table tr.off { opacity: 0.4; }
.retro { color: var(--gold); fill: var(--gold); font-size: 0.8em; }
.error { color: var(--danger); margin: 0; width: 100%; text-align: center; }

#loading {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  font-family: "Songti TC", "PMingLiU", serif;
  font-size: 1.4rem;
  letter-spacing: 0.08em;
}

#loading[hidden] { display: none; }

@media (max-width: 860px) {
  .controls { margin-left: 0; width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  time { min-width: 0; flex-basis: 100%; text-align: left; }
  .bi { grid-template-columns: 1fr; }
  .side { max-height: none; }
  .house-grid { gap: 6px; }
  .hcell { min-height: 0; padding: 8px; }
  .hcell p { font-size: 0.75rem; }
  h1 { font-size: 1.6rem; }
  .headline strong { font-size: 1.12rem; }
}
