: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: 'Songti SC', 'Noto Serif CJK SC', 'SimSun', serif;
  --sans: -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; }
.seal { flex-shrink: 0; background: var(--accent); color: white; width: 42px; height: 46px; display: grid; place-content: center; font-size: 17px; letter-spacing: 0; border-radius: 3px; }
.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: none; }
.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; }
.period-age { font-size: 11px; color: var(--green); white-space: nowrap; }
.active-period .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: var(--green); border-color: var(--green); }
.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; }
.chief { color: var(--accent); }
.stems { white-space: nowrap; }
.guest { font-family: inherit; font-size: 12px; color: var(--muted); margin-left: 4px; }
.stem-label { font-family: var(--sans); font-size: 10px; color: var(--muted); margin-right: 5px; }
.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; }
.center-symbol { display: grid; place-content: center; flex: 1; text-align: center; gap: 10px; }
.center-symbol strong { font-family: var(--serif); font-weight: 500; letter-spacing: 6px; font-size: 27px; padding-left: 6px; color: var(--muted); }
.center-symbol p { font-size: 11px; color: var(--muted); margin: 0; line-height: 1.8; }
.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; }
.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; }
  .seal { width: 38px; height: 42px; }
  .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; }
  .stem-label { display: none; }
  .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-symbol { gap: 7px; }
  .center-symbol strong { font-size: 24px; letter-spacing: 3px; padding-left: 3px; }
  .center-symbol p { font-size: 10px; }
  .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; }
}
