:root {
  --paper: #f6f4ee;
  --card: #fffefa;
  --ink: #243c38;
  --muted: #65736b;
  --line: #dedfd3;
  --accent: #a84332;
  --green: #2e6257;
  --soft: #e7eee8;
  --red-soft: #f7e9df;
  --focus: #986b30;
  --scroll-thumb: #96a497;
  --scroll-hover: #65736b;
  --scroll-active: #243c38;
  --serif: var(--preferred-kai), 'Songti SC', 'Noto Serif CJK SC', 'SimSun', serif;
  --sans: var(--preferred-kai), -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  font-size: 14px;
  color-scheme: light;
  scrollbar-color: var(--scroll-thumb) var(--paper);
  scrollbar-width: auto;
}

* { box-sizing: border-box; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: var(--paper); }
*::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border: 2px solid var(--paper); border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: var(--scroll-hover); }
*::-webkit-scrollbar-thumb:active { background: var(--scroll-active); }
body { margin: 0; }
button, input, select { font: inherit; }
button, a, input, select, summary { -webkit-tap-highlight-color: transparent; }
button, summary { touch-action: manipulation; cursor: pointer; }
button { color: var(--ink); }
button:disabled { cursor: default; opacity: .45; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
a { color: inherit; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
button:active:not(:disabled) { filter: brightness(.94); }
/* Hidden result/error regions must override their component display rules. */
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.site-header {
  min-height: 96px; max-width: 1280px; margin: auto; display: flex; align-items: center;
  justify-content: space-between; gap: 16px; padding: 16px 40px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; font-family: var(--serif); font-size: 23px; font-weight: bold; text-decoration: none; letter-spacing: 3px; }
.brand small { display: block; font-size: 11px; font-weight: normal; letter-spacing: 2px; color: var(--muted); margin-top: 6px; }
.brand-logo { flex-shrink: 0; display: block; width: 42px; height: 42px; }
.local-tag { font-size: 12px; color: var(--muted); white-space: nowrap; }
.local-tag i { display: inline-block; background: var(--green); width: 6px; height: 6px; border-radius: 50%; margin-right: 7px; }
.workspace { max-width: 1280px; margin: 0 auto; display: grid; grid-template-columns: 254px minmax(0,1fr); gap: 46px; padding: 40px; }
.controls { padding-top: 4px; min-width: 0; }
.settings-summary { display: none; }
.section-kicker { font-size: 11px; color: var(--muted); letter-spacing: 2px; }
.controls h1 { font-family: var(--serif); font-size: 35px; line-height: 1.55; font-weight: 500; letter-spacing: 4px; margin: 16px 0; }
.intro { color: var(--muted); font-size: 13px; line-height: 1.9; margin-bottom: 29px; }
label, legend { display: block; font-size: 12px; margin: 0 0 9px; color: var(--muted); }
input, select { width: 100%; min-width: 0; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--ink); min-height: 46px; font-size: 16px; }
input[type=date], input[type=time] { appearance: none; -webkit-appearance: none; }
input::-webkit-date-and-time-value { text-align: left; }
input[aria-invalid=true] { border-color: var(--accent); }
input[type=radio] { width: auto; min-height: 0; position: absolute; opacity: 0; }
fieldset { border: 0; padding: 0; margin: 21px 0 0; min-width: 0; }
legend { padding: 0; }
.input-pair { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; margin-top: 18px; }
.input-pair > div { min-width: 0; }
.segmented { display: flex; background: var(--soft); border-radius: 7px; padding: 4px; gap: 3px; }
.segmented label { margin: 0; flex: 1; position: relative; cursor: pointer; }
.segmented span { display: grid; min-height: 44px; place-content: center; border-radius: 5px; padding: 9px 2px; font-size: 13px; }
.segmented input:checked + span { background: var(--card); color: var(--green); box-shadow: 0 1px 4px #293d3314; font-weight: 600; }
.segmented input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }
.field-hint { color: var(--muted); font-size: 11px; line-height: 1.8; margin: 9px 0 17px; }
.primary { border: 0; border-radius: 6px; background: var(--ink); color: var(--card); width: 100%; min-height: 48px; padding: 14px 16px; display: flex; justify-content: space-between; font-size: 14px; letter-spacing: 1px; }
.error { border-left: 3px solid var(--accent); padding: 8px 10px; background: var(--red-soft); color: var(--accent); font-size: 12px; line-height: 1.8; }
.control-footer { font-size: 11px; color: var(--muted); line-height: 1.9; margin-top: 24px; }
.control-footer a { display: inline-flex; align-items: center; min-height: 44px; }
.result { min-width: 0; }
.result-heading { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.result-heading > div { min-width: 0; }
.result-heading h2 { font-family: var(--serif); font-weight: 500; font-size: 30px; letter-spacing: 3px; margin: 12px 0 8px; scroll-margin-top: 24px; }
.result-heading h2:focus { outline: none; }
.result-heading p { font-size: 12px; color: var(--muted); margin: 0; line-height: 1.8; overflow-wrap: anywhere; }
.edition { font-size: 10px; letter-spacing: 1px; border: 1px solid var(--line); color: var(--muted); border-radius: 3px; padding: 6px 9px; white-space: nowrap; }
.pillars { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); margin-top: 25px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 17px 0; }
.pillar { text-align: center; border-right: 1px solid var(--line); }
.pillar:last-child { border-right: 0; }
.pillar span { display: block; font-size: 11px; color: var(--muted); letter-spacing: 3px; }
.pillar strong { display: block; font-family: var(--serif); font-weight: 500; font-size: 25px; letter-spacing: 7px; margin: 7px 0 0; padding-left: 7px; }
.meta { display: flex; gap: 5px 20px; flex-wrap: wrap; font-size: 11px; color: var(--muted); line-height: 1.9; margin: 12px 0 22px; }
.meta b { color: var(--ink); font-weight: 500; }
.year-panel { border-top: 1px solid var(--line); padding: 18px 0 10px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.year-panel strong { display: block; margin-top: 7px; font-weight: 500; font-size: 17px; line-height: 1.7; }
.year-controls { display: flex; align-items: center; gap: 7px; }
.year-controls input { width: 88px; text-align: center; background: var(--card); padding: 8px 4px; font-variant-numeric: tabular-nums; }
.year-controls button { width: 44px; height: 46px; border: 1px solid var(--line); background: var(--card); border-radius: 6px; font-size: 19px; }
.year-controls span { font-size: 11px; color: var(--muted); white-space: nowrap; }
.year-error { flex-basis: 100%; margin: 0; }
.board-legend { display: flex; gap: 14px; margin: 14px 0 9px; font-size: 11px; color: var(--muted); align-items: center; }
.board-legend span:last-child { margin-left: auto; }
.board-legend i { display: inline-block; width: 7px; height: 7px; margin-right: 5px; }
.legend-current { background: var(--accent); }
.legend-period { background: var(--green); }
.board-hint { display: block; font-size: 12px; color: var(--muted); line-height: 1.8; margin: 8px 0; }
.board { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); border: 1px solid #b8c1b2; border-radius: 8px; overflow: hidden; background: var(--card); box-shadow: 0 8px 28px #243c3806; }
.palace { position: relative; min-width: 0; min-height: 208px; padding: 14px 16px; display: flex; flex-direction: column; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); transition: background .2s; }
.palace:nth-child(3n) { border-right: 0; }
.palace:nth-child(n+7) { border-bottom: 0; }
.palace.active-period { background: var(--soft); }
.palace.current-palace { box-shadow: inset 0 0 0 2px var(--accent); }
.palace-top { display: flex; justify-content: space-between; gap: 6px; align-items: center; flex-wrap: wrap; }
.palace-title { font-size: 11px; color: var(--muted); letter-spacing: 1px; }
.center-gender { margin-left: 6px; color: var(--ink); font-weight: 600; }
.period-age { font-size: 11px; color: var(--green); white-space: nowrap; }
.period-age.current-period-age { font-weight: 600; }
.symbols { padding: 14px 0 12px; }
.god-row { font-size: 18px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 2px; margin-bottom: 7px; }
.marks { display: flex; gap: 3px; flex-wrap: wrap; }
.mark { font-size: 10px; border: 1px solid var(--line); border-radius: 2px; padding: 1px 3px; color: var(--muted); }
.mark.body { color: #8b6528; border-color: #8b6528; }
.symbol-row { display: flex; justify-content: space-between; gap: 2px; align-items: baseline; font-family: var(--serif); font-size: 22px; line-height: 1.6; }
.symbol-row > span { flex-shrink: 0; }
.star-name, .door-name { font-size: 19px; white-space: nowrap; }
.auspicious, .meta b.auspicious { color: var(--accent); }
.stems { white-space: nowrap; }
.guest { font-family: inherit; font-size: 12px; color: var(--muted); margin-left: 4px; }
.branch-slots { display: flex; gap: 5px; margin-top: auto; }
.branch-slot { display: flex; align-items: center; justify-content: space-between; gap: 3px; flex: 1; min-width: 0; min-height: 44px; border: 1px solid var(--line); border-radius: 4px; padding: 6px 5px; background: transparent; text-align: left; font-size: 11px; }
.branch-slot:disabled { opacity: 1; }
.slot-branch { font-size: 14px; }
.slot-age { font-size: 12px; color: var(--green); white-space: nowrap; }
.slot-house { display: none; }
.branch-slot.selected { background: var(--accent); color: white; border-color: var(--accent); }
.branch-slot.selected .slot-age, .branch-slot.selected .slot-house { color: white; }
.branch-slot:focus-visible, .period-button:focus-visible { outline-offset: -4px; }
/* Birth details stay with the chart when the nine-palace board is captured. */
.center-birth { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 5px; padding-top: 4px; }
.center-date { display: grid; grid-template-columns: 26px minmax(0,1fr); gap: 6px; font-size: 13px; line-height: 1.6; }
.center-date-label { font-size: 11px; color: var(--muted); }
.center-solar time { font-variant-numeric: tabular-nums; }
.center-clock { white-space: nowrap; }
.center-lunar-year, .center-lunar-date { display: inline-block; white-space: nowrap; }
.center-pillars { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 4px; text-align: center; border-block: 1px solid var(--line); padding: 6px 0; margin-top: 0; }
.center-pillar { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.center-pillar-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.center-pillar-value { font-family: var(--serif); font-size: 22px; line-height: 1.3; }
.center-footer { display: grid; grid-template-columns: minmax(0,1.2fr) minmax(0,1fr); align-items: stretch; gap: 3px 10px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.center-terms { display: flex; flex-direction: column; justify-content: space-between; gap: 2px; }
.center-term-name { color: var(--ink); margin-right: 4px; }
.center-term time { font-family: var(--preferred-kai), Arial, sans-serif; font-variant-numeric: tabular-nums; }
.center-term time span, .center-notes span { display: inline-block; }
.center-notes { display: flex; flex-direction: column; justify-content: space-between; justify-self: end; max-width: 100%; text-align: left; }
.center-notes p { margin: 0; }
.center-day-rule { grid-column: 1 / -1; margin: 0; display: grid; grid-template-columns: minmax(0,1.2fr) minmax(0,1fr); gap: 10px; text-align: center; white-space: nowrap; }
.center-earth-note { display: flex; flex-wrap: wrap; justify-content: flex-start; column-gap: 4px; }

.section-title { display: flex; justify-content: space-between; align-items: center; margin: 25px 0 12px; gap: 12px; }
.section-title h3 { font-size: 14px; font-weight: 500; margin: 0; scroll-margin-top: 20px; }
.section-title small { color: var(--muted); font-size: 11px; margin-left: 9px; font-weight: normal; }
.section-title > span { font-size: 11px; color: var(--muted); }
.periods { display: grid; grid-template-columns: repeat(9,minmax(0,1fr)); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.period-button { background: transparent; border: 0; border-right: 1px solid var(--line); padding: 12px 3px; font-size: 11px; line-height: 1.8; }
.period-button:last-child { border: 0; }
.period-button strong { display: block; font-size: 12px; font-weight: 500; white-space: nowrap; }
.period-button.selected { background: var(--green); color: white; }
.annual-list { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 7px; }
.year-card { background: var(--card); border: 1px solid var(--line); border-radius: 5px; padding: 10px 8px; text-align: left; font-size: 11px; line-height: 1.8; }
.year-card strong { font-size: 14px; margin-right: 6px; font-weight: 500; }
.year-card span, .year-card small { color: var(--muted); }
.year-card small { display: block; font-size: 11px; }
.year-card.selected { border-color: var(--accent); background: var(--red-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.status-notes { border-top: 1px solid var(--line); margin-top: 23px; padding-top: 10px; color: var(--muted); font-size: 11px; line-height: 1.8; }
.status-notes p { margin: 6px 0; }
.reference-tools { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; align-items: start; margin-top: 20px; }
.lookup-tools { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; align-items: start; margin-top: 12px; }
.lookup-tools > .lookup-entry { width: 100%; }
.lookup-entry[aria-expanded="true"]::after { content: '−'; }
.lookup-panel { grid-column: 1 / -1; width: 100%; margin-top: 0; }
.lookup-controls { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; max-width: 390px; }
#lookup-qi .lookup-controls { grid-template-columns: repeat(3,minmax(0,1fr)); max-width: 600px; }
.lookup-controls label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.lookup-controls select { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--card); color: var(--ink); font: inherit; font-size: 16px; }
.lookup-reading h3 { margin: 18px 0 12px; font-family: var(--serif); font-size: 21px; font-weight: 500; }
.lookup-meanings { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 24px; }
.lookup-meanings section { min-width: 0; border-top: 1px solid var(--line); padding-top: 12px; }
.lookup-meanings h4 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin: 0; font-size: 15px; font-weight: 600; }
.lookup-meanings h4 span { color: var(--muted); font-size: 12px; font-weight: 400; }
.lookup-meanings p { margin: 9px 0 0; font-size: 13px; line-height: 1.9; }
.qi-general, .qi-context, .qi-boundary { display: block; }
.qi-context, .qi-boundary { margin-top: 8px; }
.qi-boundary { color: var(--muted); font-size: 12px; }
.lookup-status { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.8; }
@media (max-width: 600px) {
 .lookup-tools { grid-template-columns: repeat(2,minmax(0,1fr)); }
 .lookup-meanings { grid-template-columns: 1fr; gap: 18px; }
}
.palace-reference { min-width: 0; }
.reference-tools .reference-toggle { width: 100%; height: 100%; }
.reference-tools .reference-content { width: calc(200% + 12px); }
#palace-analysis > .reference-content { margin-left: calc(-100% - 12px); }
@media (max-width: 600px) { .reference-tools .reference-toggle { flex-wrap: wrap; gap: 4px 8px; padding: 9px 10px; } .reference-tools .reference-toggle span { order: 1; width: 100%; } }
.reference-toggle { display: flex; align-items: center; gap: 12px; width: fit-content; min-height: 44px; padding: 9px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); font-weight: 600; list-style: none; }
.reference-toggle span { color: var(--muted); font-size: 12px; font-weight: normal; }
.reference-toggle::-webkit-details-marker, .palace-guide > summary::-webkit-details-marker { display: none; }
.reference-toggle::after, .palace-guide > summary::after { content: '+'; margin-left: auto; color: var(--green); font-size: 18px; }
.palace-reference[open] > .reference-toggle::after, .palace-guide[open] > summary::after { content: '−'; }
.reference-content { margin-top: 14px; }
.reference-intro, .reference-footnote { color: var(--muted); font-size: 12px; line-height: 1.8; margin: 12px 0; }
.reference-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; align-items: start; }
.palace-guide { min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 6px; }
.palace-guide > summary { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 12px 14px; list-style: none; }
.palace-guide > summary b { font-family: var(--serif); font-size: 17px; flex-shrink: 0; }
.palace-guide > summary span { font-size: 12px; color: var(--muted); line-height: 1.6; }
.palace-guide[open] > summary { border-bottom: 1px solid var(--line); }
.guide-content { padding: 0 14px 12px; font-size: 13px; line-height: 1.85; overflow-wrap: anywhere; }
.guide-content p { margin: 12px 0; }
.guide-content ul { margin: 12px 0; padding-left: 18px; }
.guide-content li + li { margin-top: 7px; }
.guide-content .guide-tip { color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; margin-bottom: 0; font-size: 12px; }
@media (hover: hover) { .reference-toggle:hover, .palace-guide > summary:hover { background: var(--soft); } }
@media (max-width: 600px) { .reference-grid { grid-template-columns: minmax(0,1fr); } }
.page-footer a { display: inline-flex; align-items: center; min-height: 44px; }
.page-footer { max-width: 1200px; border-top: 1px solid var(--line); padding: 22px 0; margin: 10px auto 0; display: flex; justify-content: space-between; gap: 15px; font-size: 11px; color: var(--muted); line-height: 1.8; }
.board-frame { position: relative; margin: 48px 38px; }
.house-ring { position: absolute; inset: 0; pointer-events: none; }
.house-name { position: absolute; font-size: 18px; font-weight: 650; color: var(--ink); white-space: nowrap; line-height: 1.6; }
.house-name:is([data-branch="巳"],[data-branch="午"],[data-branch="未"]) { bottom: calc(100% + 12px); transform: translateX(-50%); }
.house-name:is([data-branch="丑"],[data-branch="子"],[data-branch="亥"]) { top: calc(100% + 12px); transform: translateX(-50%); }
.house-name:is([data-branch="巳"],[data-branch="丑"]) { left: 16.666667%; }
.house-name:is([data-branch="午"],[data-branch="子"]) { left: 50%; }
.house-name:is([data-branch="未"],[data-branch="亥"]) { left: 83.333333%; }
.house-name:is([data-branch="辰"],[data-branch="卯"],[data-branch="寅"]) { right: calc(100% + 8px); writing-mode: vertical-rl; letter-spacing: 3px; transform: translateY(-50%); }
.house-name:is([data-branch="申"],[data-branch="酉"],[data-branch="戌"]) { left: calc(100% + 8px); writing-mode: vertical-rl; letter-spacing: 3px; transform: translateY(-50%); }
.house-name:is([data-branch="辰"],[data-branch="申"]) { top: 16.666667%; }
.house-name:is([data-branch="卯"],[data-branch="酉"]) { top: 50%; }
.house-name:is([data-branch="寅"],[data-branch="戌"]) { top: 83.333333%; }
.help-page { max-width: 800px; margin: 32px auto; padding: 24px; font-size: 15px; line-height: 1.9; }
.help-page > a { display: inline-flex; min-height: 44px; align-items: center; }
.help-page h1, .help-page h2 { font-family: var(--serif); font-weight: 500; }
.help-page h1 { font-size: clamp(24px,5vw,32px); }
.help-page h2 { font-size: 22px; margin-top: 32px; }
@media (hover: hover) {
  .primary:hover { background: var(--green); }
  .year-controls button:hover:not(:disabled), .branch-slot:hover:not(:disabled):not(.selected), .period-button:hover:not(.selected), .year-card:hover:not(.selected) { background: var(--soft); }
  .settings-summary:hover, .segmented label:hover { color: var(--green); }
}
@media (min-width: 1500px) {
  .workspace { gap: 60px; grid-template-columns: 270px minmax(0,1fr); }
}
@media (max-width: 1050px) {
  .workspace { padding: 28px; gap: 26px; grid-template-columns: 222px minmax(0,1fr); }
  .palace { padding: 12px 10px; }
  .branch-slot { flex-wrap: wrap; }
  .periods { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .period-button { border-bottom: 1px solid var(--line); }
  .period-button:nth-child(3n) { border-right: 0; }
  .period-button:nth-child(n+7) { border-bottom: 0; }
  .page-footer { margin-inline: 28px; }
}
@media (max-width: 900px) {
  .site-header { min-height: 78px; padding: 16px 24px; }
  .brand { font-size: 21px; }
  .workspace { display: block; padding: 20px 24px 28px; max-width: 768px; }
  .controls { padding: 0; }
  .chart-settings { border-bottom: 1px solid var(--line); }
  .settings-summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 56px; list-style: none; padding: 8px 0; }
  .settings-summary::-webkit-details-marker { display: none; }
  .settings-summary b { font-weight: 500; font-size: 14px; }
  .settings-summary small { display: block; font-size: 12px; line-height: 1.8; color: var(--muted); margin-top: 5px; }
  .settings-toggle { display: flex; align-items: center; gap: 8px; color: var(--green); white-space: nowrap; font-size: 12px; }
  .chart-settings[open] .when-closed, .chart-settings:not([open]) .when-open { display: none; }
  .chart-settings[open] .settings-toggle > span:last-child { transform: rotate(180deg); }
  .chart-settings[open] .settings-summary small { display: none; }
  .settings-content { padding: 12px 0 20px; }
  .controls h1 { font-size: 26px; margin: 8px 0; line-height: 1.5; letter-spacing: 2px; }
  .controls h1 br, .intro br { display: none; }
  .intro { margin: 8px 0 20px; }
  .controls form { display: grid; grid-template-columns: minmax(0,1fr); }
  .input-pair { margin-top: 16px; }
  .controls fieldset { margin-top: 18px; }
  .controls form .field-hint { margin: 9px 0 8px; }
  .primary { margin-top: 10px; }
  .control-footer { display: none; }
  .result { margin-top: 24px; }
  .result-heading h2 { font-size: 27px; }
  .pillars { margin-top: 18px; padding: 14px 0; }
  .meta { gap: 4px 12px; margin-bottom: 14px; }
  .year-panel strong { font-size: 16px; }
  .year-controls { margin-left: auto; }
  .period-button { padding: 10px 8px; font-size: 12px; }
  .period-button strong { font-size: 13px; }
  .annual-list { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .page-footer { margin: 0 24px; padding: 18px 0; }
}
@media (max-width: 600px) {
  .site-header { padding: 14px 16px; }
  .brand { font-size: 20px; gap: 10px; letter-spacing: 2px; }
  .brand small { letter-spacing: 1px; font-size: 10px; }
  .brand-logo { width: 38px; height: 38px; }
  .local-tag { font-size: 11px; }
  .local-tag > span { display: none; }
  .workspace { padding: 12px 16px 24px; }
  .result-heading h2 { font-size: 24px; letter-spacing: 2px; }
  .edition { font-size: 10px; padding: 5px 6px; letter-spacing: 0; }
  .year-panel { display: block; }
  .year-panel strong { font-size: 15px; }
  .year-controls { margin-top: 12px; width: fit-content; }
  .year-error { margin-top: 10px; }
  .board-legend { font-size: 10px; gap: 10px; }
  .board-hint { display: block; font-size: 11px; color: var(--muted); line-height: 1.7; margin: 0 0 10px; }
  .board-frame { margin: 0; }
  .house-ring { display: none; }
  .palace { padding: 10px 6px 8px; min-height: 224px; }
  .palace-top { display: block; line-height: 1.7; }
  .palace-title { display: block; font-size: 11px; letter-spacing: 0; }
  .period-age { display: block; font-size: 10px; }
  .symbols { padding: 9px 0 10px; }
  .god-row { font-size: 16px; margin-bottom: 6px; }
  .mark { font-size: 9px; padding: 1px 2px; }
  .marks { gap: 2px; }
  .symbol-row { font-size: 21px; gap: 0; }
  .star-name, .door-name { font-size: 18px; }
  .guest { font-size: 10px; margin-left: 1px; }
  .branch-slots { flex-wrap: nowrap; gap: 3px; }
  .branch-slot { flex-direction: column; flex-wrap: nowrap; justify-content: center; gap: 3px; min-height: 66px; padding: 5px 1px; text-align: center; }
  .slot-branch { font-size: 13px; line-height: 1.2; }
  .slot-house { display: block; font-size: 10px; line-height: 1.4; color: var(--muted); white-space: nowrap; }
  .slot-age { font-size: 11px; line-height: 1.4; }
  .center-birth { gap: 3px; padding-top: 3px; }
  .center-date { display: flex; flex-direction: column; gap: 0; text-align: center; font-size: 11px; line-height: 1.35; }
  .center-date-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .center-clock, .center-lunar-year { display: block; }
  .center-pillars { gap: 1px; padding: 4px 0; }
  .center-pillar-label { font-size: 10px; }
  .center-pillar-value { font-size: 16px; line-height: 1.25; writing-mode: vertical-rl; align-self: center; letter-spacing: 2px; }
  .center-footer { grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 4px; font-size: 10px; line-height: 1.25; }
  .center-day-rule { grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 4px; }
  .center-term-name { display: block; margin-right: 0; }
  .center-term time span { display: block; white-space: nowrap; }
  .section-title small, .section-title > span { font-size: 10px; }
  .year-card { padding: 10px 6px; }
  .year-card strong { margin-right: 4px; }
  .page-footer { margin-inline: 16px; flex-direction: column; gap: 4px; font-size: 10px; padding-bottom: max(18px,env(safe-area-inset-bottom)); }
  .help-page { margin: 8px auto; padding: 16px; }
}
@media (max-width: 360px) {
  .workspace { padding-inline: 12px; }
  .site-header { padding-inline: 12px; }
  .brand { font-size: 18px; }
  .local-tag { font-size: 10px; }
  .star-name, .door-name { font-size: 16px; }
  .symbol-row { font-size: 19px; }
  .palace { padding-inline: 5px; }
  .god-row { font-size: 15px; }
  .mark { padding-inline: 1px; font-size: 8px; }
  .year-card strong, .year-card span { display: block; }
  .year-card strong { margin: 0; }
}
@supports (padding: max(0px)) {
  body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
}
/* Override all component transitions when the user requests reduced motion. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  :root { scrollbar-color: auto; }
  .palace.current-palace, .year-card.selected { outline: 2px solid Highlight; outline-offset: -3px; }
  .branch-slot.selected, .period-button.selected { outline: 2px solid Highlight; outline-offset: -3px; }
}

/* 地支负责另立太极，岁数仍负责流年，避免一次点击改变两个选择。 */
.slot-branch, .slot-age { border: 0; border-radius: 3px; background: transparent; color: inherit; padding: 4px 2px; min-height: 32px; }
.slot-branch { min-width: 28px; }
.slot-age { color: var(--green); }
.slot-branch[aria-pressed=true] { outline: 2px solid var(--accent); outline-offset: -2px; font-weight: bold; }
.slot-branch:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.taiji-label { color: var(--accent); font-size: 13px; font-weight: 600; letter-spacing: 0; }
.branch-slot.selected { background: var(--red-soft); color: var(--ink); }
.branch-slot.selected .slot-age { color: var(--accent); font-weight: 600; }
.branch-slot.selected .slot-house { color: var(--muted); }
@media (max-width: 600px) {
 .slot-branch, .slot-age { width: 100%; min-width: 0; min-height: 36px; }
 .slot-house { width: 100%; }
 .slot-house .taiji-label { display: block; font-size: 10px; white-space: normal; overflow-wrap: anywhere; text-spacing-trim: space-all; line-height: 1.5; }
}

/* 刑墓跟随各自的干，寄干独立标注；窄屏允许寄干换行，避免压住门星。 */
.mark { font-size: 13px; }
.symbol-row > .stems { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 1px 3px; flex-shrink: 1; }
.stem-token { display: inline-flex; align-items: baseline; white-space: nowrap; }
.stem-token.guest { font-size: inherit; align-items: center; }
.stem-flags { font: 11px/1.2 var(--sans); color: var(--accent); margin-right: 1px; transform: translateY(4px); }
.door-pressure { font: 11px/1.2 var(--sans); color: var(--accent); margin-left: 2px; }
@media (max-width: 600px) {
 .mark { font-size: 11px; }
 .stem-flags, .door-pressure { font-size: 9px; }
 .symbol-row > .stems { column-gap: 1px; }
}

.period-ages { display: flex; align-items: center; gap: 5px; }
.transferred-period { border: 1px solid currentColor; border-radius: 3px; padding: 1px 3px; }
.stem-token.guest > .stem-value { display: inline-flex; align-items: center; justify-content: center; font-size: .8em; width: 1.25em; height: 1.25em; border: 1px solid currentColor; border-radius: 3px; padding: 0; line-height: 1; }
@media (max-width: 600px) {
 .period-ages { gap: 1px; }
 .period-ages.has-transfer .period-age { font-size: 9px; }
 .transferred-period { padding: 1px 0; }
}

@media (max-width: 600px) {
 .year-controls { width: 100%; margin-left: 0; }
 .year-controls input { flex: 1; width: auto; }
 .year-controls button { flex: 0 0 44px; }
 .reference-tools > details > .reference-toggle, .lookup-tools > .lookup-entry { min-height: 64px; }
 .lookup-tools > .lookup-entry { font-size: 15px; }
 #lookup-qi .lookup-controls { grid-template-columns: repeat(2,minmax(0,1fr)); max-width: none; }
 #lookup-qi .lookup-controls > label:last-child { grid-column: 1 / -1; }
 .lookup-meanings p, .guide-content { font-size: 14px; }
 .reference-intro, .reference-footnote { font-size: 13px; }
}

/* Keyword headings stay with their own reading, including on narrow screens. */
.lookup-panel:not(#lookup-qi) .lookup-meanings h4 { display: block; line-height: 1.7; overflow-wrap: anywhere; }
.lookup-panel:not(#lookup-qi) .lookup-meanings h4 span { color: var(--ink); font-size: inherit; font-weight: 500; }
.lookup-panel:not(#lookup-qi) .lookup-meanings p, .lookup-special { font-size: 14px; line-height: 1.9; overflow-wrap: anywhere; }

@supports (grid-template-rows: subgrid) {
 @media (min-width: 601px) {
  .lookup-panel:not(#lookup-qi) .lookup-meanings { grid-template-rows: auto auto; row-gap: 0; }
  .lookup-panel:not(#lookup-qi) .lookup-meanings section { display: grid; grid-template-rows: subgrid; grid-row: span 2; }
 }
}

/* Keep heaven, earth and synthesis readable as three successive passages. */
#lookup-qi .lookup-meanings { align-items: start; }
#lookup-qi .lookup-meanings h4 { min-height: 27px; line-height: 1.8; }
#lookup-qi .qi-person-layer { margin-top: 16px; overflow-wrap: anywhere; }
#lookup-qi .qi-person-layer:first-child { margin-top: 10px; }
#lookup-qi .qi-person-layer h5 { margin: 0; font-size: 14px; line-height: 1.8; font-weight: 500; }
#lookup-qi .qi-person-layer h5 b { font-weight: 600; }
#lookup-qi .lookup-meanings p { font-size: 14px; line-height: 1.9; }
#lookup-qi .qi-person-layer p { margin-top: 6px; }
#lookup-qi .qi-person-combined { padding: 12px; border-radius: 6px; background: var(--soft); }

/* Mobile trial: retain the chart geometry and desktop presentation. */
@media (max-width: 600px) {
  .site-header { min-height: 68px; padding-block: 10px; }
  .settings-content { padding-top: 6px; padding-bottom: 16px; }
  .controls h1 { font-size: 23px; margin-block: 6px; }
  .intro { margin-bottom: 14px; font-size: 12px; }
  .controls fieldset { margin-top: 14px; }
  .result { margin-top: 20px; }
  .pillars { margin-top: 14px; padding-block: 12px; }
  .board-frame { margin-inline: -4px; }
  .year-controls input { font-weight: 600; font-variant-numeric: tabular-nums; }
  .year-controls button { background: var(--soft); border-color: #cbd8cf; }
  .period-button { padding-block: 11px; }
  .year-card { padding-block: 12px; }
  .reference-tools, .lookup-tools { gap: 10px; }
  .reference-tools .reference-content { width: calc(200% + 10px); }
  #palace-analysis > .reference-content { margin-left: calc(-100% - 10px); }
  .reference-toggle { border-radius: 8px; }
  .reference-tools > details > .reference-toggle { min-height: 68px; }
  .lookup-tools > .lookup-entry { min-height: 54px; padding: 12px; }
  .palace-reference[open] > .reference-toggle,
  .lookup-entry[aria-expanded="true"] { background: var(--soft); border-color: var(--green); color: var(--green); }
  .lookup-panel { padding: 14px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
  .lookup-panel .reference-intro { margin-top: 0; }
  .lookup-controls { max-width: none; gap: 10px; }
  .lookup-controls label { margin-bottom: 0; }
  .lookup-controls select { min-height: 48px; background: var(--paper); }
  .lookup-reading h3 { font-size: 20px; line-height: 1.65; margin-block: 20px 12px; }
  .lookup-meanings { gap: 22px; }
  .lookup-panel .lookup-meanings h4 { font-size: 15px; }
  .lookup-panel:not(#lookup-qi) .lookup-meanings p,
  #lookup-qi .lookup-meanings p, .guide-content { font-size: 15px; line-height: 1.9; }
  #lookup-qi .qi-person-layer { margin-top: 20px; }
  #lookup-qi .qi-person-layer h5 { font-size: 15px; line-height: 1.8; }
  #lookup-qi .qi-person-combined { padding: 12px; border-left: 3px solid var(--green); }
  .palace-guide > summary { min-height: 58px; }
  .palace-guide[open] > summary { background: var(--soft); border-radius: 6px 6px 0 0; }
  .guide-content li + li { margin-top: 12px; }
}

/* Align the two term rows with their notes even when the center cell is narrow. */
@media (min-width: 601px) {
 .center-footer { grid-template-columns: minmax(0,1fr) clamp(40px,calc(100% - 104px),80px); gap: 3px 4px; align-items: start; }
 .center-terms, .center-notes { display: contents; }
 .center-term { grid-column: 1; display: grid; grid-template-columns: 2em minmax(0,72px); justify-content: center; align-items: baseline; gap: 4px; min-width: 0; }
 .center-term:first-child { grid-row: 1; }
 .center-term:last-child { grid-row: 2; }
 .center-term-name { margin-right: 0; white-space: nowrap; }
 .center-term time { display: flex; flex-wrap: wrap; justify-content: space-between; column-gap: 4px; min-width: 0; }
 .center-notes > p { grid-column: 2; justify-self: center; max-width: 100%; text-align: center; }
 .center-earth-note { grid-row: 1; justify-content: center; }
 .center-notes > p:last-child { grid-row: 2; }
 .center-notes span { max-width: 100%; }
 .center-day-rule { grid-row: 3; grid-template-columns: minmax(0,1fr) clamp(40px,calc(100% - 104px),80px); gap: 4px; }
}

/* Keep mobile center details in short rows instead of two stretched columns. */
@media (max-width: 600px) {
 .center-footer { display: flex; flex-direction: column; gap: 5px; }
 .center-terms { gap: 3px; }
 .center-term { display: flex; align-items: baseline; gap: 4px; }
 .center-term-name { flex: 0 0 2em; }
 .center-term time { display: flex; flex: 1; flex-wrap: wrap; justify-content: space-between; column-gap: 3px; min-width: 0; }
 .center-term time span { display: inline-block; }
 .center-notes { align-self: stretch; max-width: none; gap: 3px; text-align: center; border-top: 1px solid var(--line); padding-top: 5px; }
 .center-earth-note { justify-content: center; }
 .center-day-rule { gap: 3px; padding-top: 2px; }
}

/* Synthesis is scoped below the existing reference tools. */
.synthesis-panel { margin-top: 20px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.synthesis-panel > summary { display: flex; align-items: center; gap: 14px; cursor: pointer; padding: 18px 20px; font-weight: 600; }
.synthesis-panel > summary::after { content: '+'; margin-left: auto; }
.synthesis-panel[open] > summary::after { content: '−'; }
.synthesis-panel > summary small { font-size: 12px; font-weight: 400; color: var(--muted); }
.synthesis-panel > summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.synthesis-body { padding: 4px 22px 24px; }
.synthesis-controls { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; }
.synthesis-topics { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; margin-bottom: 6px; }
.synthesis-topics button { min-height: 44px; padding: 10px 8px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--soft); font: inherit; font-weight: 600; cursor: pointer; }
.synthesis-topics button[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #fff; }
.synthesis-topics button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.synthesis-controls label { font-size: 12px; color: var(--muted); margin: 0; }
.synthesis-controls select { display: block; margin-top: 6px; width: 100%; min-width: 0; min-height: 44px; }
.synthesis-controls select:disabled { opacity: 1; color: var(--muted); background: var(--soft); cursor: default; }
#synthesis-status:empty { display: none; }
#synthesis-status { color: var(--accent); line-height: 1.7; }
.synthesis-heading h3 { font-size: 22px; line-height: 1.5; margin: 26px 0 6px; }
.synthesis-heading p { font-size: 12px; color: var(--muted); margin: 0 0 18px; }
.synthesis-facts { border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.synthesis-facts h4 { margin: 0 0 12px; font-size: 16px; }
.synthesis-facts dl { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px 18px; margin: 0; }
.synthesis-fact { min-width: 0; font-size: 13px; line-height: 1.7; }
.synthesis-fact dt { color: var(--muted); }
.synthesis-fact dd { margin: 0; overflow-wrap: anywhere; }
.synthesis-relation { margin: 18px 0 24px; background: var(--soft); border-left: 3px solid var(--green); padding: 13px 16px; }
.synthesis-relation strong { font-size: 17px; line-height: 1.7; }
.synthesis-relation p { font-size: 13px; line-height: 1.6; margin: 6px 0 0; color: var(--muted); }
.synthesis-article { max-width: 840px; margin: auto; }
.synthesis-article h4 { font-size: 17px; line-height: 1.6; margin: 24px 0 10px; }
.synthesis-article p { font-size: 15px; line-height: 2; margin: 0 0 10px; overflow-wrap: anywhere; }
.synthesis-basis { color: #8b5d3b; font-size: .9em; }
.synthesis-article .synthesis-keywords { border-top: 1px solid var(--line); padding-top: 16px; color: #8b6528; font-size: 13px; }
@media(max-width:600px) {
 .synthesis-panel > summary { padding: 16px 14px; gap: 8px; flex-wrap: wrap; }
 .synthesis-panel > summary small { font-size: 11px; }
 .synthesis-body { padding: 0 12px 20px; }
 .synthesis-controls { grid-template-columns: minmax(0,1fr); gap: 12px; }
 .synthesis-controls select { font-size: 16px; }
 .synthesis-heading h3 { font-size: 20px; }
 .synthesis-facts { padding: 12px; }
 .synthesis-facts dl { column-gap: 10px; }
}

/* Life articles keep the established board geometry and type scale. */
.life-article{max-width:900px;margin-inline:auto}.life-nav,.life-house-index{display:flex;flex-wrap:wrap;gap:8px;margin:18px 0}.life-nav a,.life-house-index a{display:block;text-decoration:none;color:var(--ink);padding:7px 12px;border:1px solid var(--line);border-radius:6px;background:#faf9f5;font-size:14px;line-height:1.5}.life-nav a:focus-visible,.life-house-index a:focus-visible{outline:2px solid #32655a;outline-offset:2px}.life-section{padding-top:18px;margin-top:26px;border-top:1px solid var(--line);scroll-margin-top:20px}.life-section>h4{font-size:21px;margin:4px 0 18px}.life-house,.life-period{margin:24px 0;padding-top:16px;border-top:1px solid var(--line);scroll-margin-top:20px}.life-article h5{font-size:18px;margin:6px 0 14px}.life-facts summary{cursor:pointer;color:#52635e;font-size:13px;line-height:1.9;overflow-wrap:anywhere}.life-facts .synthesis-facts{margin-top:12px}.life-note,.life-period-position,.life-period-facts{color:#61706a;font-size:13px!important;line-height:1.9!important}.life-period{padding:16px;border:1px solid var(--line);border-radius:8px}.life-period.is-current{border-color:#74978a;background:#f5f8f4}#life-summary{background:#f6f5ef;border:1px solid var(--line);border-radius:8px;padding:20px}#life-summary p:last-child{margin-bottom:0}
@media(max-width:600px){.life-nav{gap:6px}.life-nav a,.life-house-index a{padding:7px 10px}.life-section>h4{font-size:19px}.life-article h5{font-size:17px}.life-period,#life-summary{padding:14px}.life-facts .synthesis-facts{padding:10px}}
