:root {
  --bg: #f6f4ef;
  --panel: #fff;
  --text: #292723;
  --muted: #6e6a63;
  --line: #ded9cf;
  --purple: #534ab7;
  --purple-soft: #eeedfe;
  --teal: #0f6e56;
  --teal-soft: #e1f5ee;
  --amber: #854f0b;
  --amber-soft: #faeeda;
  --red: #a32d2d;
  --red-soft: #fcebeb;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: clip;
  font: 14px/1.6 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 3vw;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: 0.02em; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 12px; }
.seal {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(145deg, #4f45b6, #352d82);
  color: #f7e8c3;
  box-shadow: 0 2px 8px rgba(53, 45, 130, 0.22);
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 20px;
  font-weight: 600;
}
.topbar nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar a { color: var(--muted); text-decoration: none; font-size: 13px; padding: 5px 8px; border-radius: 7px; }
.topbar a:hover { color: var(--purple); background: var(--purple-soft); }
.nav-mode-btn {
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 5px 9px;
  border-radius: 7px;
  cursor: pointer;
}
.nav-mode-btn:hover,
.nav-mode-btn.active {
  color: var(--purple);
  background: var(--purple-soft);
}
.nav-mode-btn.active {
  font-weight: 600;
}
.footer-links {
  margin-left: 8px;
}
.footer-links a {
  color: var(--purple);
  text-decoration: none;
  margin: 0 4px;
}
.footer-links a:hover {
  text-decoration: underline;
}
.legal-doc {
  max-width: 860px;
  margin: 24px auto;
}
.legal-doc h3 {
  font-size: 16px;
  margin: 20px 0 8px;
  color: var(--text);
}
.legal-doc p,
.legal-doc li {
  color: var(--text);
  line-height: 1.75;
}
.nav-mobile-pill {
  background: #f2f0fa;
  color: var(--purple) !important;
  font-weight: 500;
}

.shell { max-width: 1520px; margin: auto; padding: 18px 2.6vw 60px; }
.notice {
  border-left: 3px solid var(--amber);
  background: var(--amber-soft);
  padding: 10px 16px;
  margin-bottom: 18px;
  color: #633806;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  min-width: 0;
  max-width: 100%;
}
#results, #calibratePanel, #aiPanel, #diffPanel, #hehunPanel, #timelineSection, #cases {
  scroll-margin-top: 88px;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.section-head h2 { font-size: 19px; margin: 0; font-weight: 500; }
.eyebrow {
  margin: 0 0 3px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--purple);
  font-size: 11px;
}
.tag {
  display: inline-flex;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--purple-soft);
  color: #3c3489;
  font-size: 12px;
}
.mono { font-family: ui-monospace, monospace; }

.grid { display: grid; gap: 13px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.form-row-gap { margin-top: 13px; }

.lunar-fields {
  margin-top: 12px;
  padding: 13px 14px;
  border: 1px dashed var(--purple);
  border-radius: 10px;
  background: #faf9ff;
}
.lunar-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 10px;
  font-size: 12px;
}
.inline-check { margin: 0; font-size: 13px; }
.inline-check[hidden] { display: none; }

.dst-banner {
  margin-top: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid #d99b43;
  border-left: 4px solid var(--amber);
  background: var(--amber-soft);
  color: #633806;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
}
.dst-banner[hidden], .lunar-fields[hidden], .ai-msg-footer[hidden] { display: none; }
.dst-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.boundary-banner {
  margin-top: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid #9d96e3;
  border-left: 4px solid var(--purple);
  background: var(--purple-soft);
  color: #31297a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
}
.boundary-banner[hidden], .calibrate-panel[hidden], .timeline-section[hidden] { display: none; }

label { display: grid; gap: 5px; font-size: 12px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #534ab733;
  border-color: var(--purple);
}
textarea { resize: vertical; }
.wide { margin-top: 14px; }

.checks, .checkline { display: flex; gap: 18px; align-items: center; margin: 14px 0; }
.checks label, .checkline { display: flex; align-items: center; gap: 6px; color: var(--text); }
.checks input, .checkline input { width: auto; }

.checks.system-tracks {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 12px;
  align-items: stretch;
}
.system-track-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 13px;
  background: #fbfaf7;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.track-card-div {
  background: #faf9ff;
  border-color: #dcd6f7;
}
.track-pill {
  display: inline-flex;
  align-self: flex-start;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}
.track-pill-natal { background: #ebe7dc; color: #4b4335; }
.track-pill-div { background: var(--purple-soft); color: var(--purple); }
.track-pill-meihua { background: #efeafe; color: #3c3489; }
.track-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
}

.meihua-quick-bar {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid #d5d0f2;
  border-left: 4px solid var(--purple);
  border-radius: 10px;
  background: #faf9ff;
}
.meihua-quick-bar[hidden], .mh-quick-inputs[hidden] { display: none; }
.meihua-quick-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  flex-wrap: wrap;
}
.meihua-quick-title {
  display: flex;
  align-items: center;
  gap: 8px 10px;
  flex-wrap: wrap;
}
.mh-quick-modes {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.mh-method-select-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.mh-method-select-wrap select { width: auto; padding: 5px 10px; }
.mh-quick-inputs {
  margin-top: 10px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.mh-input-grow { flex: 1 1 260px; }
.mh-time-notice {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.5;
}
.mh-time-notice.is-warn {
  padding: 6px 10px;
  border-radius: 7px;
  background: var(--amber-soft);
  border: 1px solid #e7c288;
  color: #633806;
}

.config { border-top: 1px solid var(--line); padding: 11px 0; }
.config summary { cursor: pointer; font-weight: 500; }
.config .grid { margin-top: 13px; }

.actions { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); border-radius: 8px; padding: 8px 15px; cursor: pointer; font: inherit; }
.btn.primary { background: var(--purple); color: #fff; border-color: var(--purple); }
.btn.ghost { background: #fff; color: var(--purple); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.muted { color: var(--muted); }
.errors { border-color: #e24b4a; background: var(--red-soft); color: #791f1f; }

.tabs {
  display: flex;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 5px;
  margin-bottom: 14px;
  overflow: auto;
  min-width: 0;
  max-width: 100%;
}
.tabs button {
  border: 0;
  background: transparent;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tabs button:hover {
  color: var(--purple);
  background: #f7f6fd;
}
.tabs button.active {
  color: #fff;
  background: var(--purple);
  font-weight: 600;
}

.research-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(290px, 0.78fr); gap: 18px; align-items: start; }
.research-grid.companion-grid {
  grid-template-columns: minmax(0, 1.52fr) minmax(360px, 1fr);
}
.research-grid.is-wide-companion {
  grid-template-columns: minmax(0, 1fr);
}
.side-stack, .chart-panel { min-width: 0; max-width: 100%; }
.companion-sidebar {
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 2px;
}
.research-grid.is-wide-companion .companion-sidebar {
  position: static;
  max-height: none;
  overflow: visible;
}

.prewrap { white-space: pre-wrap; word-break: break-word; color: var(--muted); font-size: 12px; max-height: 360px; overflow: auto; }
pre { white-space: pre-wrap; word-break: break-word; font: 12px/1.6 ui-monospace, monospace; max-height: 420px; overflow: auto; }

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-width: 100%;
  max-height: 560px;
  -webkit-overflow-scrolling: touch;
}
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 8px; vertical-align: top; word-break: break-word; }
th { position: sticky; top: 0; background: #f6f4ef; }

.empty { padding: 28px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); }
footer { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 12px; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 24px; max-width: 520px; width: 90vw; }
dialog::backdrop { background: #0006; }
dialog h2 { margin-top: 0; font-weight: 500; }
dialog label { margin: 12px 0; }

.view-switch { display: inline-flex; background: #f1efe8; border-radius: 9px; padding: 3px; margin-bottom: 18px; }
.view-switch button { border: 0; background: transparent; color: var(--muted); padding: 7px 16px; border-radius: 7px; cursor: pointer; }
.view-switch button.active { background: #fff; color: var(--purple); font-weight: 500; }

.guide-hero { border-left: 3px solid var(--purple); padding: 2px 0 2px 16px; margin-bottom: 18px; }
.guide-hero h3 { font-size: 16px; line-height: 1.75; font-weight: 500; margin: 4px 0 8px; }
.guide-hero p:last-child { color: var(--muted); margin: 0; }
.guide-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.guide-facts > div { background: var(--purple-soft); border-radius: 10px; padding: 12px; }
.guide-facts span { display: block; color: var(--muted); font-size: 11px; }
.guide-facts strong { display: block; margin-top: 4px; font-size: 16px; font-weight: 500; color: #3c3489; }
.guide-grid { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 12px; }
.guide-card { border: 1px solid var(--line); border-radius: 11px; padding: 16px; }
.guide-card h3 { font-size: 14px; font-weight: 500; margin: 0 0 10px; }
.guide-card p { color: var(--muted); }
.reading-path { margin: 0; padding-left: 22px; }
.reading-path li { margin: 10px 0; padding-left: 4px; }

.glossary { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.glossary summary, .config summary, details.panel > summary { cursor: pointer; color: var(--purple); }
.glossary dl > div { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.glossary dd { margin: 0; color: var(--muted); font-size: 12px; }
details.panel > summary { font-weight: 500; }
details.panel[open] > summary { margin-bottom: 12px; }

.sr-copy-buffer {
  position: fixed;
  left: -9999px;
  opacity: 0;
  pointer-events: none;
}

/* ── Studio Input Modes, Compact Summary Bar & Advanced Drawer ── */
.studio-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.workspace-compact-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
  padding: 4px 2px;
}
.workspace-compact-bar[hidden], #workspaceFormWrap[hidden], .div-nianming-hint[hidden], .adv-cfg-group[hidden] {
  display: none;
}
.compact-summary-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}
.compact-seal-dot {
  display: inline-flex;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--purple);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
.compact-summary-text {
  font-size: 14px;
  color: var(--text);
}
.compact-summary-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.intent-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.intent-tab {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fbfaf7;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.intent-tab strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.intent-tab span {
  font-size: 11.5px;
  color: var(--muted);
}
.intent-tab:hover {
  border-color: #b7b0e8;
  background: #faf9ff;
}
.intent-tab.active {
  border-color: var(--purple);
  background: #f4f2ff;
  box-shadow: 0 2px 8px rgba(83, 74, 183, 0.1);
}
.intent-tab.active strong {
  color: var(--purple);
}
.intent-tab-hecan {
  background: #fdf9f9;
  border-color: #e6d2d8;
}
.intent-tab-hecan:hover {
  border-color: #c27ba0;
  background: #fdf4f7;
}

.studio-blocks {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.studio-form.is-div-first .block-divination {
  order: -1;
}
.studio-form.is-div-first .block-natal {
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #fcfbf9;
}
.div-nianming-hint {
  margin-bottom: 10px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 7px;
  background: #f4f2ec;
}
.question-field {
  margin-top: 0;
}
.divination-clock-wrap[hidden] {
  display: none;
}
.divination-fields {
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #faf9ff;
  border: 1px solid #dcd6f7;
}
.divination-fields[hidden] {
  display: none;
}
.divination-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 18px;
}

.geo-solar-row {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.75fr) minmax(0, 1.3fr);
  gap: 13px;
  align-items: end;
  margin-top: 12px;
}
.geo-true-solar-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-bottom: 4px;
}
.geo-true-solar-wrap .checkline {
  margin: 0;
}

.advanced-config-drawer {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  background: #fcfbf9;
  margin-top: 4px;
}
.advanced-config-drawer > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
}
.adv-summary-sub {
  font-weight: 400;
  font-size: 12px;
  margin-left: 8px;
}
.advanced-config-body {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.adv-cfg-group {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.adv-cfg-group h4 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--purple);
  font-weight: 600;
}
.adv-checks-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 8px;
}
.btn-lg {
  padding: 9px 22px;
  font-weight: 600;
}
.studio-submit-bar {
  padding-top: 6px;
}
