:root {
  color-scheme: light;
  --paper: #f5f2e9;
  --surface: #fffdf7;
  --ink: #28372d;
  --muted: #657064;
  --line: #deded0;
  --accent: #86612c;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); line-height: 1.7; }
.page { width: min(100% - 40px, 1040px); margin: 0 auto; padding: 64px 0 28px; }
.hero { margin-bottom: 40px; }
.eyebrow { color: var(--accent); font-size: .75rem; font-weight: 650; letter-spacing: .13em; }
h1, h2, p { margin: 0; }
h1 { margin: 16px 0 12px; font-family: "Songti SC", SimSun, serif; font-size: clamp(2rem, 6vw, 3.6rem); font-weight: 500; letter-spacing: .08em; }
h2 { font-size: 1.25rem; font-weight: 550; }
.hero > p { margin-bottom: 20px; color: var(--muted); }
.badge { display: inline-block; border: 1px solid var(--line); border-radius: 100px; padding: 5px 13px; color: var(--muted); font-size: .78rem; }
.panel { margin-bottom: 24px; padding: 30px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 8px 28px #28372d04; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 26px; }
.section-heading h2 { margin-top: 4px; }
.fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
label { display: grid; gap: 9px; font-size: .85rem; font-weight: 550; }
input, select, button { font: inherit; }
input, select { width: 100%; min-width: 0; min-height: 48px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #a77b36; outline-offset: 4px; }
.field-note { margin-top: 16px; color: var(--muted); font-size: .8rem; }
.primary-button { display: flex; justify-content: space-between; gap: 50px; margin-top: 24px; padding: 12px 22px; border: 0; border-radius: 8px; background: var(--ink); color: var(--surface); }
.primary-button:hover { background: #3d5142; }
.ai-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 24px 0 12px; }
.ai-actions .ai-link { width: fit-content; max-width: 100%; margin-top: 0; text-decoration: none; }
#ai-prompt { box-sizing: border-box; width: 100%; margin: 12px 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; line-height: 1.7; resize: vertical; }
.text-button { padding: 8px 0; border: 0; background: none; color: var(--accent); font-size: .85rem; white-space: nowrap; }
.text-button:hover { text-decoration: underline; }
.error { margin-top: 14px; color: #a12c29; }
.summary { margin-bottom: 20px; color: var(--muted); font-size: .9rem; }
.summary + .summary { margin-top: -10px; }
h3 { margin: 16px 0 10px; font-size: .95rem; font-weight: 600; }
h3 > span { margin-left: 8px; color: var(--muted); font-size: .75rem; font-weight: 400; }
.view-switch { display: flex; gap: 8px; margin: 20px 0; }
.view-switch button { padding: 8px 24px; border: 1px solid var(--line); border-radius: 100px; color: var(--muted); background: transparent; }
.view-switch [aria-pressed="true"] { color: var(--surface); background: var(--ink); border-color: var(--ink); }
.flow-controls { margin-bottom: 24px; padding: 18px; background: #f5f4ec; border: 1px solid var(--line); border-radius: 10px; }
.timeline { display: flex; gap: 8px; overflow-x: auto; padding: 5px 4px 12px; scroll-padding: 4px; }
.timeline-card { display: flex; flex: 0 0 102px; flex-direction: column; align-items: center; gap: 4px; padding: 12px 8px; border: 1px solid transparent; border-radius: 8px; color: var(--ink); background: var(--surface); }
.timeline-card:hover { border-color: var(--accent); }
.timeline-card[aria-pressed="true"] { border-color: var(--accent); background: #efe3c7; box-shadow: inset 0 -3px var(--accent); }
.timeline-label { font-size: .85rem; }
.timeline-symbols { font-family: "Songti SC", SimSun, serif; font-size: 1.5rem; font-weight: 500; letter-spacing: .08em; }
.timeline-subtitle { color: var(--muted); font-size: .7rem; }
.table-hint { margin-bottom: 12px; }
.element-legend { display: inline-block; margin-left: 12px; }
[data-element="木"] { color: #267151; }
[data-element="火"] { color: #b13f36; }
[data-element="土"] { color: #7a6744; }
[data-element="金"] { color: #8c6000; }
[data-element="水"] { color: #206893; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; min-width: 580px; border-collapse: collapse; text-align: center; }
th, td { padding: 15px 12px; border-bottom: 1px solid var(--line); }
thead th { background: #eeeee3; font-size: .85rem; font-weight: 550; }
tbody th { color: var(--muted); font-size: .85rem; font-weight: 400; white-space: nowrap; }
tbody td { font-size: .9rem; }
tr[data-field="ganZhi"] td { font-family: "Songti SC", SimSun, serif; font-size: 1.9rem; letter-spacing: .15em; white-space: nowrap; }
tr[data-field="stem"] td, tr[data-field="branch"] td { font-family: "Songti SC", SimSun, serif; font-size: 1.6rem; }
tr[data-field="hiddenStems"] td, tr[data-field="branchGods"] td { line-height: 1.9; }
tbody tr:nth-child(even) { background: #f8f7f0; }
.field-button { padding: 6px 0; border: 0; color: var(--muted); background: none; font-size: .8rem; white-space: nowrap; }
.field-button:hover { color: var(--accent); text-decoration: underline; }
.relations { margin-top: 22px; }
.relations ul { padding-left: 20px; color: var(--muted); font-size: .85rem; }
.reading-summary { margin: 18px 0; color: var(--muted); font-size: .9rem; }
details { border-top: 1px solid var(--line); padding: 16px 0; }
summary { cursor: pointer; font-size: .95rem; }
.glossary { font-size: .85rem; }
.glossary dt { margin-top: 14px; font-weight: 650; color: var(--ink); }
.glossary dd { margin: 3px 0 0; color: var(--muted); }
dialog { width: min(100% - 32px, 620px); max-height: 85vh; padding: 26px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: var(--surface); }
dialog::backdrop { background: #17271bd0; }
dialog > p { font-size: .9rem; }
.current-values { padding: 14px 14px 14px 32px; border-radius: 8px; background: var(--paper); font-size: .85rem; }
.checkbox-label { display: flex; align-items: center; gap: 10px; width: fit-content; margin-top: 18px; font-weight: 400; }
.checkbox-label input { width: 18px; min-height: 18px; height: 18px; margin: 0; accent-color: var(--ink); }
.numerology-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 20px; }
.number-card { min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: 10px; background: #f8f7f0; }
.number-card h3 { margin-top: 0; }
.number-card h4 { margin: 8px 0 14px; font-size: 1rem; font-weight: 550; }
.number-card > p { color: var(--muted); font-size: .85rem; }
.number-value { display: block; color: var(--accent); font-family: Georgia, serif; font-size: 3.2rem; font-weight: 400; line-height: 1.2; }
.number-steps { padding-left: 20px; font-size: .78rem; color: var(--muted); overflow-wrap: anywhere; }
.number-rules { margin-top: 20px; padding-bottom: 0; }
.palace-section { grid-column: 1 / -1; min-width: 0; padding-top: 12px; border-top: 1px solid var(--line); }
.palace-layout { display: grid; grid-template-columns: minmax(0, 330px) minmax(0, 1fr); gap: 28px; align-items: start; margin-top: 22px; }
.palace-map { position: relative; width: 100%; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 12px; background: #f8f7f0; }
#palace-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.palace-connection { stroke: #47877a; stroke-width: 5; stroke-linecap: round; fill: none; }
.palace-connection.unavailable { stroke: #a88a54; stroke-dasharray: 8 10; }
.palace-digits { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.palace-number { position: relative; display: grid; place-items: center; min-width: 0; padding: 0; border: 0; border-radius: 8px; color: var(--ink); background: transparent; }
.palace-number[aria-pressed="true"] { background: #86612c0c; }
.palace-symbol { display: grid; position: relative; place-items: center; width: 62px; height: 62px; }
.palace-ring { position: absolute; border: 2px solid; border-radius: 50%; }
.palace-digit { position: relative; font-family: Georgia, serif; font-size: 1.8rem; font-weight: 500; }
.missing-digit .palace-digit { color: var(--muted); font-size: 1.5rem; }
.palace-count { position: absolute; top: calc(50% + 32px); left: 50%; transform: translateX(-50%); width: max-content; padding: 0 4px; border-radius: 4px; background: #f8f7f0; text-align: center; color: var(--muted); font-size: .65rem; line-height: 1.2; }
.palace-legend { margin-top: 16px; text-align: center; font-size: .72rem; }
.palace-legend [data-source="birth"], .palace-ring[data-source="birth"] { color: #26715c; }
.palace-legend [data-source="intermediate"], .palace-ring[data-source="intermediate"] { color: #946623; }
.palace-legend [data-source="lifePath"], .palace-ring[data-source="lifePath"] { color: #705685; }
.palace-legend [data-source="zodiac"], .palace-ring[data-source="zodiac"] { color: #276c90; }
.palace-source { min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: 10px; }
.palace-source h4 { margin: 0; font-size: 1.1rem; font-weight: 550; }
.palace-source .field-note { margin-top: 10px; }
.palace-source ul { padding-left: 20px; margin-bottom: 0; color: var(--muted); font-size: .82rem; }
.palace-source li + li { margin-top: 6px; }
.palace-lines-heading { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px 16px; margin-top: 26px; }
.palace-lines-heading .checkbox-label { margin: 0; font-size: .78rem; }
.palace-line-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.palace-line-card { display: flex; min-width: 0; flex-direction: column; align-items: center; gap: 6px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #f8f7f0; color: var(--ink); }
.palace-line-card:hover, .palace-line-card[aria-pressed="true"] { border-color: var(--accent); background: #f1ead9; }
.palace-line-card strong { font-size: .85rem; font-weight: 550; }
.palace-line-card > span { font-size: .7rem; color: var(--muted); }
.palace-line-card .line-status { color: #26715c; }
.palace-line-card.inactive .line-status { color: var(--muted); }
.line-miniature { display: block; width: min(100%, 128px); aspect-ratio: 1; }
.line-miniature .palace-connection { stroke-width: 7; }
.mini-digit { font: 30px system-ui, sans-serif; fill: #b5bdb1; }
.mini-digit.required { fill: #26715c; font-weight: 650; }
.mini-digit.required.not-present { fill: #946623; }
.palace-line-detail { margin-top: 18px; padding: 16px 18px; border-left: 3px solid #47877a; background: #f8f7f0; }
.palace-line-detail h4 { margin: 0 0 8px; font-size: .95rem; font-weight: 550; }
.palace-line-detail p { font-size: .85rem; color: var(--muted); }
.analysis-controls { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; margin: 24px 0; }
.analysis-controls label { width: min(100%, 350px); }
.analysis-controls .badge { max-width: 100%; overflow-wrap: anywhere; }
.analysis-focus-summary { margin: 16px 0; padding: 16px 18px; border-left: 3px solid var(--accent); background: #f1ead9; font-size: .95rem; }
.analysis-panels { display: grid; gap: 18px; margin: 24px 0; min-width: 0; }
.analysis-card { min-width: 0; padding: 22px; border: 1px solid var(--line); border-radius: 12px; background: #f8f7f0; }
.analysis-card:first-child { border-color: var(--accent); }
.analysis-card h3 { margin-top: 0; }
.analysis-result { margin: 12px 0; font-size: 1.1rem; color: var(--ink); }
.analysis-copy { margin: 12px 0; color: var(--muted); font-size: .85rem; }
.analysis-list { margin: 14px 0; padding-left: 22px; color: var(--muted); font-size: .85rem; }
.analysis-list li + li { margin-top: 7px; }
.analysis-source { margin-top: 18px; font-size: .72rem; color: var(--muted); overflow-wrap: anywhere; }
.analysis-table { margin-top: 16px; }
.analysis-table table { min-width: 500px; }
.analysis-table td { font-size: .8rem; }
.analysis-notice { margin-bottom: 20px; padding: 18px; border: 1px solid #c7ab74; border-radius: 10px; background: #f1ead9; }
.analysis-notice h3 { margin-top: 0; }
#analysis-luck { margin-top: 16px; }
tbody tr:last-child > * { border-bottom: 0; }
.notes { padding: 10px 4px; color: var(--muted); }
.notes h2 { margin-bottom: 10px; font-size: .9rem; color: var(--ink); }
.notes p { margin-bottom: 8px; font-size: .82rem; }
footer { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: .75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }
@media (max-width: 680px) {
  .page { width: min(100% - 28px, 1040px); padding-top: 36px; }
  .hero { margin-bottom: 28px; }
  .panel { padding: 20px; }
  .fields { grid-template-columns: 1fr; }
  .numerology-grid { grid-template-columns: 1fr; }
  .palace-layout { grid-template-columns: 1fr; gap: 20px; }
  .palace-map { max-width: 330px; margin: 0 auto; }
  .palace-line-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .palace-source { padding: 16px; }
  .palace-symbol { width: 52px; height: 52px; }
  .palace-count { top: calc(50% + 27px); }
  .palace-line-card { padding: 10px 6px; }
  .analysis-card { padding: 16px; }
  .primary-button { width: 100%; }
  table[data-view="natal"] { min-width: 0; table-layout: fixed; }
  table[data-view="natal"] th, table[data-view="natal"] td { padding: 12px 3px; font-size: .7rem; }
  table[data-view="natal"] .field-button { font-size: .66rem; white-space: normal; }
  table[data-view="natal"] tr[data-field="ganZhi"] td { font-size: clamp(1.1rem, 5vw, 1.4rem); letter-spacing: .06em; }
  table[data-view="natal"] tr[data-field="stem"] td, table[data-view="natal"] tr[data-field="branch"] td { font-size: 1.25rem; }
}
