:root {
  color-scheme: light;
  --ink: #1d2732;
  --muted: #596672;
  --line: #dce3e8;
  --soft: #f4f7f8;
  --paper: #fff;
  --accent: #256b68;
  --accent-soft: #e5f1ef;
  --pending: #80552d;
  --pending-soft: #fbf3e8;
}
* { box-sizing: border-box; letter-spacing: 0; }
[hidden] { display: none !important; }
body { margin: 0; background: #edf1f3; color: var(--ink); font: 14px/1.6 system-ui, "Microsoft YaHei", sans-serif; }
.app-shell { width: calc(100% - 15.625vw); max-width: 1320px; min-height: 100vh; margin: 0 auto; border-inline: 1px solid var(--line); background: #fbfcfd; }
a { color: var(--accent); text-decoration: none; }
button, input { font: inherit; }
button, .mode, summary { cursor: pointer; }
button { min-height: 42px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 4px; background: var(--paper); color: var(--ink); }
button:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
button:disabled { cursor: not-allowed; opacity: .6; }
.primary { border-color: var(--accent); background: var(--accent); color: white; font-weight: 650; }
.primary:hover:not(:disabled) { background: #1b5553; color: white; }
:focus-visible { outline: 3px solid #318b85; outline-offset: 3px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 23px; }
h2 { margin-bottom: 14px; font-size: 17px; }
h3 { font-size: 15px; }
small { font-size: 12px; font-weight: 400; color: var(--muted); }
.topnav { min-height: 58px; display: flex; align-items: center; gap: 24px; padding: 0 22px; border-bottom: 1px solid var(--line); background: var(--paper); }
.brand { color: var(--ink); font-size: 19px; font-weight: 750; white-space: nowrap; }
.topnav nav { display: flex; flex: 1; align-self: stretch; gap: 6px; }
.topnav nav a, .nav-placeholder { display: flex; align-items: center; padding: 16px 10px; color: var(--muted); border-bottom: 2px solid transparent; font-size: 13px; white-space: nowrap; }
.topnav nav a[aria-current] { color: var(--accent); border-color: var(--accent); font-weight: 650; }
.nav-placeholder { cursor: default; }
.account { display: flex; align-items: center; gap: 8px; }
.account button { min-height: 36px; padding: 6px 10px; border-radius: 2px; font-size: 12px; white-space: nowrap; }
.account button:disabled { opacity: 1; cursor: not-allowed; }
.account small { margin-left: 4px; font-size: 10px; }
.login { color: #fff; background: var(--accent); border-color: var(--accent); }
.login small { color: #fff; }
.rule-badge { color: var(--pending); font-size: 12px; }
.workspace { max-width: 1100px; margin: auto; padding: 22px 22px 48px; }
.toolbar, .panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.toolbar { margin-bottom: 14px; }
.toolbar h1 { font-size: 21px; }
.toolbar > span, .panel-head > span { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.toolbar .rule-badge { color: var(--pending); }
.method-row { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 14px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.method { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 2px; background: var(--paper); font-size: 12px; }
.method.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 650; }
.method:disabled { color: var(--muted); opacity: 1; }
.main-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(260px, .7fr); gap: 14px; align-items: start; }
.panel { min-width: 0; padding: 16px; border: 1px solid var(--line); background: var(--paper); }
.panel-head { margin-bottom: 14px; }
.panel-head h2 { margin: 0; }
.main-grid .panel-head h2 { font-size: 16px; }
.sidebar { display: grid; gap: 14px; min-width: 0; }
.side-card { padding: 14px; border: 1px solid var(--line); background: var(--paper); }
.side-card h2 { margin-bottom: 9px; font-size: 14px; }
.side-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
.side-card p + p { margin-top: 10px; }
fieldset { min-width: 0; padding: 0; margin: 0; border: 0; }
.section-block { padding: 14px 0; border-top: 1px solid #edf0f2; }
.section-block:first-child { padding-top: 0; border-top: 0; }
.section-block > legend { float: left; width: 100%; padding: 0; margin-bottom: 10px; font-weight: 650; }
.section-block > legend + * { clear: both; }
legend small { margin-left: 8px; }
.mode-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.mode { position: relative; display: flex; min-height: 46px; }
.mode input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.mode span { display: flex; flex: 1; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px; padding: 8px 5px; border: 1px solid var(--line); text-align: center; font-size: 13px; }
.mode input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.mode input:focus-visible + span { outline: 3px solid #318b85; outline-offset: 2px; }
.mode input:disabled + span { background: var(--soft); color: var(--muted); cursor: not-allowed; }
.mode small { display: block; width: 100%; font-size: 11px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.subject-fields > fieldset { grid-column: 1 / -1; }
.field-label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.radio-row { display: flex; flex-wrap: wrap; gap: 14px; min-height: 42px; align-items: center; }
.radio-row label { display: inline-flex; align-items: center; gap: 5px; min-height: 36px; }
input[type="radio"], input[type="checkbox"] { accent-color: var(--accent); width: 17px; height: 17px; margin: 0; }
input[type="number"], input[type="date"], #related-people-fields input[type="text"], #related-people-fields select { min-width: 0; width: 100%; min-height: 42px; padding: 8px; border: 1px solid var(--line); border-radius: 3px; color: var(--ink); background: white; }
.related-person .two-col { margin-bottom: 10px; }
#related-people-data { overflow-wrap: anywhere; }
#related-people-data > div { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(0, 3fr); }
#related-people-data dd { min-width: 0; white-space: pre-line; }
#personal-position-form .radio-row label { min-width: 0; max-width: 100%; }
#personal-position-form .radio-row input { flex-shrink: 0; }
#personal-position-data > div { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(0, 3fr); }
#personal-position-data dt, #personal-position-data dd { min-width: 0; overflow-wrap: anywhere; }
#personal-position-data dd { white-space: pre-line; }
#designated-war-form select { min-width: 0; width: 100%; min-height: 42px; padding: 8px; border: 1px solid var(--line); border-radius: 3px; color: var(--ink); background: white; }
@media (max-width: 540px) {
  #related-people-data > div { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  #personal-position-data > div { grid-template-columns: minmax(0, 1fr); gap: 8px; }
}
input:disabled { background: var(--soft); color: var(--muted); }
.datetime-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, .75fr); gap: 10px; align-items: end; }
.calendar-row { display: grid; grid-template-columns: 1fr 1fr; max-width: 150px; gap: 6px; margin-bottom: 12px; }
.calendar-row .mode { min-height: 36px; }
.date-values, .time-values { display: grid; gap: 8px; }
.date-values { grid-template-columns: minmax(0, 1.35fr) repeat(2, minmax(0, 1fr)); }
.time-values { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.leap-row { display: flex; justify-content: space-between; align-items: center; max-width: 150px; min-height: 40px; margin-top: 12px; padding: 8px 10px; background: var(--soft); border: 1px solid var(--line); }
.hint { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.time-note { margin: 10px 0 0; }
.form-footer { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; padding-top: 16px; border-top: 1px solid var(--line); }
#casting-info-dialog { width: min(460px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 24px; border: 1px solid var(--line); border-radius: 4px; background: var(--paper); color: var(--ink); }
#casting-info-dialog::backdrop { background: #292d2f69; }
#casting-info-dialog p, #casting-info-missing { color: var(--muted); overflow-wrap: anywhere; }
#casting-info-missing { max-height: 35vh; overflow-y: auto; padding-left: 22px; }
.casting-info-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; }
#casting-info-dialog .primary { min-width: 0; min-height: 42px; padding: 8px 16px; }
#chart-history { margin-bottom: 16px; }
#chart-history-list { margin: 0; padding: 0 0 12px; list-style: none; }
#chart-history-list li + li { border-top: 1px solid var(--line); }
#chart-history-list a { display: block; padding: 10px 0; overflow-wrap: anywhere; }
#chart-history-list time { display: block; color: var(--muted); font-size: 12px; }
#chart-history-list .history-reading-state { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); }
#chart-history-list .history-reading-state[data-state="completed"] { color: #286346; font-weight: 600; }
#chart-history-list .history-reading-state[data-state="failed"] { color: #a13e35; }
.steps { padding: 0; margin: 0 0 18px; list-style: none; }
.steps li { position: relative; display: flex; align-items: flex-start; gap: 10px; min-height: 66px; padding-top: 4px; font-size: 13px; }
.steps li:last-child { min-height: 54px; }
.steps li strong, .steps li small { display: block; }
.steps li small { margin-top: 3px; font-size: 11px; }
.steps li:not(:last-child)::after { content: ""; position: absolute; left: 13px; top: 30px; bottom: -4px; border-left: 1px solid var(--line); }
.dot { display: grid; place-items: center; width: 28px; height: 28px; flex-shrink: 0; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); background: white; z-index: 1; }
[aria-current="step"] .dot { color: white; border-color: var(--accent); background: var(--accent); }
.status-box { padding: 12px; background: var(--soft); margin: 0; font-size: 12px; }
.status-box > div, .data-list > div { display: flex; justify-content: space-between; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.status-box > div:last-child { border: 0; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
.status-box dd { color: var(--accent); text-align: right; }
.data-list { margin-bottom: 24px; }
#supplementary-data { margin-bottom: 0; }
#supplementary-data > div { display: grid; grid-template-columns: 7em minmax(0, 1fr); }
#supplementary-data dd { min-width: 0; white-space: pre-line; }
#branch-data { margin-bottom: 0; }
#branch-data > div { display: grid; grid-template-columns: 2em minmax(0, 1fr); }
#branch-data dd { min-width: 0; white-space: pre-line; }
#spouse-pattern-data > div { display: grid; grid-template-columns: 10em minmax(0, 1fr); }
#spouse-pattern-data dd { min-width: 0; white-space: pre-line; }
.notice, .error { padding: 12px 14px; font-size: 13px; overflow-wrap: anywhere; }
.notice { color: var(--pending); background: var(--pending-soft); border-left: 3px solid #bd905c; }
.sidebar-notice { margin: 12px 0 0; padding: 10px; font-size: 12px; }
.error { color: #9e2929; background: #fff0f0; border-left: 3px solid #b33c3c; }
#loading { margin: 16px 0 0; text-align: center; color: var(--accent); }
.result-actions { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.empty { text-align: center; padding: 60px 16px; }
.empty p { color: var(--muted); }
.result-section { padding: 22px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.result-section .panel-head h2 { flex-shrink: 0; white-space: nowrap; }
#chart-id { min-width: 0; overflow-wrap: anywhere; }
.metadata { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin: 0; }
.metadata dt { font-size: 12px; margin-bottom: 4px; }
.metadata dd { font-weight: 550; }
.result-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 28px; }
.lessons { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; direction: rtl; }
.lesson { direction: ltr; text-align: center; background: var(--soft); padding: 12px 4px; }
.lesson h3 { font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 10px; }
.lesson p { margin: 0; font-size: 24px; line-height: 1.8; }
.transmissions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.transmission { min-width: 0; text-align: center; padding: 12px 4px; background: var(--accent-soft); }
.transmission span { display: block; color: var(--accent); font-size: 12px; }
.transmission strong { display: block; font-size: 26px; margin-top: 14px; font-weight: 550; }
.transmission-meta { margin: 10px 0 0; font-size: 12px; }
.transmission-meta > div { display: grid; grid-template-columns: 2em minmax(0, 1fr); gap: 6px; text-align: left; }
.transmission-meta dt { white-space: nowrap; }
.transmission-meta dd { min-width: 0; color: var(--ink); text-align: right; overflow-wrap: anywhere; }
.plate { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(105px, auto)); max-width: 650px; margin: 18px auto 0; gap: 5px; }
.palace { padding: 10px 4px; text-align: center; border: 1px solid var(--line); background: var(--paper); min-width: 0; overflow-wrap: anywhere; }
.palace small, .palace span { display: block; font-size: 12px; }
.palace strong { display: block; font-weight: 550; font-size: 22px; color: var(--accent); }
.plate-center { grid-area: 2 / 2 / 4 / 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; background: var(--soft); padding: 10px; }
.plate-center small { overflow-wrap: anywhere; }
.evidence { margin-top: 24px; border-top: 1px solid var(--line); }
summary { padding: 16px 0; color: var(--accent); font-weight: 600; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.7 ui-monospace, monospace; background: var(--soft); padding: 14px; }
.warnings { padding-left: 22px; color: var(--pending); overflow-wrap: anywhere; }
#review-issues li, #derivation-steps li { margin: 10px 0; overflow-wrap: anywhere; }
#review-issues small { display: block; }
#derivation-steps { padding-left: 24px; }
.skip-link { position: absolute; left: 12px; top: -60px; background: white; padding: 8px; z-index: 5; }
.skip-link:focus { top: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 1100px) {
  .topnav { gap: 16px; }
  .nav-placeholder, .wallet { display: none; }
}
@media (max-width: 800px) {
  .app-shell { width: 100%; border-inline: 0; }
  .topnav { gap: 16px; padding: 0 16px; flex-wrap: wrap; }
  .topnav nav { justify-content: flex-end; gap: 0; }
  .topnav nav a { padding: 16px 8px; font-size: 13px; }
  .workspace { padding: 20px 14px 40px; }
  .main-grid, .result-grid { grid-template-columns: 1fr; gap: 16px; }
  .panel { padding: 16px; }
  .metadata { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-section .panel-head { flex-direction: column; align-items: stretch; gap: 6px; }
  .plate { grid-template-rows: repeat(4, minmax(100px, auto)); }
}
@media (max-width: 540px) {
  #spouse-pattern-data > div { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .topnav { column-gap: 12px; }
  .topnav .brand { order: 0; }
  .account { order: 1; margin-left: auto; }
  .topnav nav { order: 2; flex-basis: 100%; justify-content: flex-start; }
  .topnav nav a { padding: 10px 12px; }
  .topnav > .brand, .account { margin-top: 12px; }
  .datetime-grid { grid-template-columns: 1fr; gap: 12px; }
}
@media (max-width: 400px) {
  #supplementary-data > div { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .two-col { grid-template-columns: 1fr; gap: 12px; }
  .leap-row { max-width: none; }
  .brand { font-size: 17px; }
  .plate { gap: 3px; }
  .palace small, .palace span { font-size: 11px; }
  .plate-center { padding: 6px; font-size: 13px; }
}
