:root {
  color-scheme: light;
  --bg: #edf1ef; --surface: #f8faf9; --surface-2: #e5ece9;
  --text: #16272c; --muted: #52676a; --subtle: #65797b;
  --brand: #16272c; --on-brand: #fff; --accent: #a43d35;
  --line: #bdcbc7; --focus: #2f7165; --danger: #9c302a;
  font-family: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
html { min-width: 280px; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); background: var(--bg); line-height: 1.45; }
body.dark { color-scheme: dark; --bg:#101a1d; --surface:#19282b; --surface-2:#223438; --text:#e4efed; --muted:#afbfbc; --subtle:#9bb0ad; --brand:#081214; --on-brand:#f7fbfa; --accent:#c7665d; --line:#3d5356; --focus:#75b9ab; --danger:#ef8078; }
button, input, select { font: inherit; }
button { min-height: 44px; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.skip-link { position: fixed; z-index: 50; top: 8px; left: 8px; padding: 9px 13px; color: var(--text); background: var(--surface); border-radius: 7px; transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }
.app-header { position: sticky; z-index: 20; top: 0; display: flex; align-items: center; justify-content: space-between; min-height: 62px; padding: 9px max(16px, env(safe-area-inset-left)); color: var(--on-brand); background: var(--brand); border-bottom: 1px solid color-mix(in srgb,var(--on-brand) 18%,transparent); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { font-size: 20px; letter-spacing: .03em; }
.brand-seal { display:grid; place-items:center; width:38px; height:38px; border:1px solid color-mix(in srgb,var(--on-brand) 65%,transparent); border-radius:7px; font:24px/1 KaiTi,STKaiti,serif; }
.header-button { padding:0 13px; color:var(--on-brand); background:transparent; border:1px solid color-mix(in srgb,var(--on-brand) 45%,transparent); border-radius:7px; }
main { width:min(790px,100%); margin:0 auto; padding:22px 20px calc(90px + env(safe-area-inset-bottom)); }
.screen { display:none; }
.screen.active { display:block; }

.time-row { display:flex; align-items:end; gap:10px; padding-bottom:16px; border-bottom:1px solid var(--line); }
.time-row label { display:grid; flex:1; gap:5px; }
.time-row span, .field span, .section-title p { color:var(--muted); font-size:13px; }
.time-row input, .field input, .settings-sheet select { min-height:46px; padding:9px 12px; color:var(--text); background:var(--surface); border:1px solid var(--line); border-radius:8px; }
.time-row button, .empty-state button, .result-toolbar button, .panel-heading button { padding:0 14px; color:var(--text); background:var(--surface); border:1px solid var(--line); border-radius:8px; }
.field { display:grid; gap:6px; margin:19px 0; }
.field input { width:100%; }
.field input::placeholder { color:var(--subtle); }

.line-stage { background:var(--surface); border:1px solid var(--line); border-radius:10px; overflow:hidden; }
.line-row { display:grid; grid-template-columns:54px minmax(95px,1fr) minmax(110px,auto); align-items:center; gap:12px; width:100%; min-height:58px; padding:8px 17px; color:var(--text); background:transparent; border:0; border-bottom:1px solid var(--line); text-align:left; }
.line-row:hover { background:var(--surface-2); }
.line-row .position { color:var(--muted); font-size:14px; }
.line-row .choice { justify-self:end; color:var(--muted); font-size:14px; }
.line-row .choice em { margin-right:6px; color:var(--accent); font-style:normal; font-weight:800; }
.stage-footer { display:flex; justify-content:flex-end; padding:11px 17px; }
.stage-footer strong { color:var(--muted); font-size:14px; }
.primary-action { width:100%; margin-top:14px; padding:11px 18px; color:var(--on-brand); background:var(--brand); border:0; border-radius:8px; font-weight:700; }
.validation { min-height:22px; margin:6px 0 0; color:var(--danger); font-weight:600; }

.yao-glyph { display:flex; align-items:center; justify-content:center; gap:12px; width:72px; height:16px; margin-inline:auto; }
.yao-glyph .stroke { display:block; height:3px; background:currentColor; border-radius:1px; }
.yao-glyph.yang .stroke { width:72px; }
.yao-glyph.yin .stroke { width:30px; }
.line-row.empty .yao-glyph { opacity:.32; }
.line-row.empty .yao-glyph .stroke { background:repeating-linear-gradient(90deg,currentColor 0 5px,transparent 5px 9px); }

.empty-state { display:grid; justify-items:center; padding:48px 18px; color:var(--muted); text-align:center; }
.empty-state h2 { margin:0; color:var(--text); }
.empty-state p { margin:6px 0 16px; }
.result-card { background:var(--surface); border:1px solid var(--line); border-radius:10px; overflow:hidden; }
.result-toolbar { padding:9px 12px; background:var(--surface-2); border-bottom:1px solid var(--line); }
.result-toolbar button { min-height:38px; background:var(--surface); }
.result-header { padding:18px 20px; color:var(--on-brand); background:var(--brand); }
.result-header p { margin:0 0 7px; overflow-wrap:anywhere; color:color-mix(in srgb,var(--on-brand) 77%,transparent); font-size:14px; }
.result-header div { color:color-mix(in srgb,var(--on-brand) 82%,transparent); font-size:14px; }
.result-header h2 { margin:6px 0 0; font-size:18px; line-height:1.5; }
.hex-titles { display:grid; grid-template-columns:1fr auto 1fr; align-items:center; gap:12px; padding:15px 20px; border-bottom:1px solid var(--line); }
.hex-titles > div { display:grid; }
.hex-titles > div:last-child { text-align:right; }
.hex-titles span, .hex-titles small { color:var(--muted); font-size:12px; }
.hex-titles strong { font-size:19px; }
.hex-titles i { color:var(--accent); font-family:KaiTi,STKaiti,serif; font-style:normal; font-size:20px; }
.chart-head, .chart-line { display:grid; grid-template-columns:minmax(195px,1.55fr) 88px 38px minmax(155px,1.25fr) 88px; align-items:center; }
.chart-head { padding:8px 14px; color:var(--muted); background:var(--surface-2); font-size:12px; }
.chart-head span:not(:first-child) { text-align:center; }
.chart-line { min-height:58px; padding:7px 14px; border-bottom:1px solid var(--line); }
.chart-line:last-child { border-bottom:0; }
.line-meta { display:flex; align-items:center; gap:7px; min-width:0; font-size:13px; font-weight:600; }
.line-meta.changed { justify-content:flex-end; text-align:right; }
.spirit { flex:0 0 30px; color:var(--muted); font-weight:400; }
.meta-text { min-width:0; overflow-wrap:anywhere; }
.hidden-spirit { display:block; color:var(--accent); font-size:11px; font-weight:500; }
.motion-mark { color:var(--accent); font-size:18px; font-weight:800; text-align:center; }
.role-marker { display:inline-grid; place-items:center; flex:0 0 24px; width:24px; height:24px; color:var(--accent); border:1px solid currentColor; border-radius:50%; font-style:normal; font-size:11px; font-weight:700; }
.line-label { display:none; }
.result-actions { display:flex; justify-content:flex-end; gap:8px; padding:13px 14px; background:var(--surface-2); }
.result-actions button { padding:0 14px; color:var(--text); background:var(--surface); border:1px solid var(--line); border-radius:7px; }
.result-actions .accent { color:#fff; background:var(--accent); border-color:var(--accent); }

.section-title { margin-bottom:14px; }
.section-title p, .section-title h2 { margin:0; }
.section-title h2 { font-size:24px; }
.record-tabs { display:grid; grid-template-columns:1fr 1fr; margin-bottom:14px; padding:4px; background:var(--surface-2); border-radius:9px; }
.record-tabs button { color:var(--muted); background:transparent; border:0; border-radius:7px; }
.record-tabs button[aria-selected="true"] { color:var(--text); background:var(--surface); font-weight:700; }
.panel-heading { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:10px; }
.panel-heading h3, .panel-heading p { margin:0; }
.panel-heading h3 { font-size:18px; }
.panel-heading p { color:var(--muted); font-size:12px; }
.panel-heading button { min-height:38px; }
.record-list { display:grid; gap:8px; }
.record-item { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:13px 15px; background:var(--surface); border:1px solid var(--line); border-radius:9px; }
.record-item > div { min-width:0; }
.record-item h3 { margin:0; overflow-wrap:anywhere; font-size:15px; }
.record-item p { margin:3px 0 0; color:var(--muted); font-size:12px; }
.record-item .item-actions { display:flex; gap:6px; }
.record-item button { min-height:38px; padding:0 11px; color:var(--text); background:var(--surface-2); border:1px solid var(--line); border-radius:7px; }
.record-item .delete-button { color:var(--danger); }
.loading-row, .error-state { padding:24px; color:var(--muted); background:var(--surface); border:1px solid var(--line); border-radius:9px; text-align:center; }
.error-state { color:var(--danger); }
.error-state button { display:block; margin:10px auto 0; padding:0 14px; color:var(--text); background:var(--surface-2); border:1px solid var(--line); border-radius:7px; }
.settings-sheet { background:var(--surface); border:1px solid var(--line); border-radius:9px; }
.settings-sheet > div, .setting-control { display:grid; grid-template-columns:minmax(120px,.65fr) 1fr; gap:3px 16px; padding:15px 16px; border-bottom:1px solid var(--line); }
.settings-sheet > div > span { grid-row:1 / span 2; color:var(--muted); }
.settings-sheet small, .setting-control small { color:var(--muted); }
.setting-control { display:flex; align-items:center; justify-content:space-between; cursor:pointer; }
.setting-control > span { display:grid; }
.setting-control select { min-width:105px; }
.setting-control input { width:48px; height:28px; accent-color:var(--focus); }
.setting-control:last-child { border-bottom:0; }

.bottom-nav { position:fixed; z-index:30; right:0; bottom:0; left:0; display:grid; grid-template-columns:repeat(3,1fr); min-height:65px; padding:4px max(8px,env(safe-area-inset-right)) max(4px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left)); background:var(--surface); border-top:1px solid var(--line); }
.bottom-nav button { display:grid; place-items:center; align-content:center; gap:1px; color:var(--muted); background:transparent; border:0; border-radius:7px; font-size:12px; }
.bottom-nav button span { font-size:19px; line-height:1; }
.bottom-nav button.active { color:var(--text); background:var(--surface-2); font-weight:700; }
.line-dialog { width:min(410px,calc(100% - 28px)); max-height:calc(100vh - 40px); padding:0; color:var(--text); background:var(--surface); border:1px solid var(--line); border-radius:10px; }
.line-dialog::backdrop { background:rgb(5 13 15 / .62); }
.line-dialog header { display:flex; align-items:center; justify-content:space-between; padding:13px 15px; border-bottom:1px solid var(--line); }
.line-dialog header > div { display:grid; }
.line-dialog header span { color:var(--muted); font-size:12px; }
.line-dialog header button { width:44px; padding:0; color:var(--text); background:transparent; border:0; font-size:23px; }
.line-options { display:grid; grid-template-columns:1fr; gap:7px; max-height:calc(100vh - 150px); padding:10px; overflow:auto; }
.line-option { position:relative; display:grid; grid-template-columns:65px 1fr auto; align-items:center; gap:12px; min-height:64px; padding:9px 13px; color:var(--text); background:var(--surface-2); border:1px solid var(--line); border-radius:8px; text-align:left; }
.line-option:hover { border-color:var(--focus); }
.line-option small { color:var(--muted); }
.line-option em { color:var(--accent); font-style:normal; font-size:18px; font-weight:800; }
.toast { position:fixed; z-index:60; left:50%; bottom:calc(78px + env(safe-area-inset-bottom)); max-width:calc(100% - 32px); padding:10px 15px; color:var(--on-brand); background:var(--brand); border-radius:7px; opacity:0; pointer-events:none; transform:translate(-50%,10px); transition:opacity .18s ease,transform .18s ease; }
.toast.show { opacity:1; transform:translate(-50%,0); }

@media (min-width:850px) {
  .bottom-nav { top:62px; right:auto; bottom:0; left:0; width:82px; grid-template-columns:1fr; grid-template-rows:repeat(3,70px); align-content:start; padding:14px 7px; border-top:0; border-right:1px solid var(--line); }
  main { padding-left:102px; }
  .toast { bottom:22px; }
}
@media (max-width:650px) {
  main { padding:15px 12px calc(84px + env(safe-area-inset-bottom)); }
  .time-row { align-items:end; }
  .line-row { grid-template-columns:44px minmax(80px,1fr) auto; gap:7px; padding-inline:12px; }
  .line-row .choice { font-size:13px; }
  .result-header { padding:16px 14px; }
  .result-header h2 { font-size:16px; }
  .hex-titles { padding:13px 14px; }
  .hex-titles strong { font-size:17px; }
  .chart-head { display:none; }
  .chart-line { grid-template-columns:minmax(0,1fr) 30px minmax(0,1fr); grid-template-areas:"original motion changed"; gap:7px; min-height:82px; padding:11px 10px; }
  .original-side { grid-area:original; }
  .motion-mark { grid-area:motion; }
  .changed-side { grid-area:changed; }
  .line-side { display:grid; gap:8px; min-width:0; }
  .line-side .line-meta { align-items:flex-start; font-size:12px; }
  .line-side.changed .line-meta { justify-content:flex-start; text-align:left; }
  .line-side .yao-glyph { margin-inline:0; }
  .line-side.changed .yao-glyph { margin-left:auto; }
  .line-side.changed .line-meta { flex-direction:row-reverse; justify-content:flex-start; }
  .line-side.changed .meta-text { text-align:right; }
  .line-label { display:inline; margin-right:3px; color:var(--muted); font-weight:400; }
  .spirit { flex-basis:28px; }
  .hidden-spirit { font-size:10px; }
  .result-actions { display:grid; grid-template-columns:1fr 1fr; }
  .result-actions .accent { grid-column:1 / -1; }
  .settings-sheet > div { grid-template-columns:1fr; }
  .settings-sheet > div > span { grid-row:auto; }
}
@media (max-width:390px) {
  .time-row input { width:100%; font-size:14px; }
  .time-row button { padding-inline:11px; }
  .yao-glyph { width:62px; gap:10px; }
  .yao-glyph.yang .stroke { width:62px; }
  .yao-glyph.yin .stroke { width:26px; }
  .chart-line { grid-template-columns:minmax(0,1fr) 26px minmax(0,1fr); padding-inline:8px; }
  .line-meta { gap:4px; }
  .role-marker { flex-basis:22px; width:22px; height:22px; }
  .record-item { align-items:flex-start; }
  .record-item .item-actions { display:grid; }
}
@media (prefers-reduced-motion:reduce) { *,*::before,*::after { transition:none !important; scroll-behavior:auto !important; } }
