/* ==========================================================================
   科学命理 Algorithmic Destiny — local UI
   An imperial-editorial system: warm paper, ink-black text, and a single
   imperial-gold accent — the palette of a woodblock almanac. Headings are set
   in a majestic serif (Fraunces for Latin, a subset Noto Serif SC for 中文,
   both self-hosted so the look is identical offline and on any machine); body
   stays in a clean sans. The five element hues are the only other chroma.
   Light and dark are authored together; every pairing is checked to WCAG AA.
   ========================================================================== */

/* --- self-hosted heading faces (served from /fonts, work fully offline) --- */
@font-face {
  font-family: "Fraunces";
  src: url("/fonts/fraunces.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  /* Noto Serif SC, subset to the UI's heading glyphs. unicode-range confines it
     to CJK so Latin in a mixed heading (四柱 Four Pillars) still uses Fraunces. */
  font-family: "Noto Serif SC Head";
  src: url("/fonts/noto-serif-sc-heading.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+2E80-9FFF, U+3000-303F, U+3400-4DBF, U+F900-FAFF, U+FF00-FFEF;
}

:root {
  color-scheme: light dark;

  /* surfaces & text — warm stone neutrals that sit well beside gold */
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-2: #f4f1ea;
  --fg: #1c1917;
  --fg-muted: #57534e;
  --fg-subtle: #7c756c;
  --border: #e8e2d8;
  --border-strong: #d8cfc0;

  /* interaction — ink primary, imperial gold accent */
  --ink: #1c1917;
  --on-ink: #faf8f4;
  --accent: #9a6a12;            /* gold-700, AA on white for text & icons */
  --accent-strong: #7a5210;     /* pressed / deep gold */
  --on-accent: #ffffff;
  --accent-soft: #f7efdd;       /* pale gold wash */
  --gold-line: linear-gradient(90deg, #c99a3b 0%, #a16207 55%, #7a5210 100%);
  --danger: #b3261e;
  --danger-soft: #fdf0ee;

  /* favorability semaphore 喜忌 — the fortune-teller's convention, kept exactly:
     GOOD 喜用 is red, NORMAL 平和 is green, BAD 忌神/无 is black. This is a
     separate axis from the five-element identity hues below and never overrides
     them. */
  --verdict-good: #c0271f;        --verdict-good-bg: #fbe4e0;   /* 喜用 red */
  --verdict-normal: #15803d;      --verdict-normal-bg: #dcf3e2; /* 平和 green */
  --verdict-bad: #1c1917;         --verdict-bad-bg: #ece9e4;    /* 忌神/无 black */

  /* five elements 五行 — the canonical distinct colours: 木青 火赤 土黄 金白 水黑→蓝.
     Base tokens are the readable text colour; -bg is the pastel tile fill. Earth
     and metal are kept genuinely apart (yellow vs steel) rather than two browns. */
  --wood: #15803d;  --wood-bg: #dcf3e2;
  --fire: #dc2626;  --fire-bg: #fbe3e0;
  --earth: #a16207; --earth-bg: #f7edcf;
  --metal: #5b6b7f; --metal-bg: #e9ecf1;
  --water: #2563eb; --water-bg: #dde7fb;

  /* elevation — a single warm-shadow scale, so depth reads as one material */
  --shadow-sm: 0 1px 2px rgba(41, 33, 20, 0.05), 0 1px 3px rgba(41, 33, 20, 0.04);
  --shadow-md: 0 6px 16px -6px rgba(41, 33, 20, 0.12), 0 2px 6px -2px rgba(41, 33, 20, 0.06);
  --shadow-lg: 0 28px 64px -16px rgba(41, 33, 20, 0.24), 0 8px 20px -8px rgba(41, 33, 20, 0.12);

  /* spacing — a 4px rhythm, used in tiers: 1–2 inside a component,
     3–4 between components, 5–6 between sections, 7–8 between regions */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;
  --r-sm: 7px; --r-md: 11px; --r-lg: 16px;

  /* type scale — one ladder every size in the app steps onto, so nothing is
     "nearly the same" as something else. 16px is held for inputs and body:
     below it iOS zooms the field on focus. */
  --fs-2xs: 11px;   /* dense chart glyph labels only */
  --fs-xs:  12px;   /* meta, captions, tags */
  --fs-sm:  13px;   /* secondary text, table headers */
  --fs-md:  14px;   /* dense body, table cells */
  --fs-base:15px;   /* body */
  --fs-lg:  18px;   /* sub-heading */
  --fs-xl:  22px;   /* section heading */
  --fs-2xl: 28px;   /* page verdict */
  --fs-3xl: 36px;

  --lh-tight: 1.2;
  --lh-snug: 1.45;
  --lh-body: 1.65;

  /* the longest comfortable measure for running prose (~68 characters) */
  --measure: 68ch;

  --font: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  /* Majestic heading stack: Fraunces (Latin display) → subset Noto Serif SC for
     中文 → installed serif fallbacks. Used through --display; --serif aliases it
     so every existing reference upgrades to the new face. */
  --display: "Fraunces", "Noto Serif SC Head", "Source Han Serif SC",
    "Noto Serif CJK SC", "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --serif: var(--display);
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;

  /* the display optical + weight settings that make headings read as majestic */
  --display-vary: "opsz" 144;

  --dur: 180ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110d;
    --surface: #1c1813;
    --surface-2: #251f18;
    --fg: #f4ede1;
    --fg-muted: #b3a897;
    --fg-subtle: #8f8474;
    --border: #302921;
    --border-strong: #493f33;

    --ink: #f4ede1;
    --on-ink: #14110d;
    /* the dark accent is a LIGHT gold, so what sits on it must be dark */
    --accent: #e0b45e;
    --accent-strong: #efc978;
    --on-accent: #241a08;
    --accent-soft: #2b2113;
    --gold-line: linear-gradient(90deg, #efc978 0%, #d9a94e 55%, #a97e34 100%);
    --danger: #f2897f;
    --danger-soft: #2c1613;

    --wood: #5fd48c;  --wood-bg: #15321f;
    --fire: #f87171;  --fire-bg: #3a1a1d;
    --earth: #e0b45e; --earth-bg: #352a0f;
    --metal: #aab6c6; --metal-bg: #262d37;
    --water: #7aa5f5; --water-bg: #16243f;

    /* semaphore on dark: pure black is invisible, so BAD becomes a muted dark
       neutral (still reads as negative), GOOD a legible red, NORMAL a legible green */
    --verdict-good: #f28b82;   --verdict-good-bg: #3a1a1d;
    --verdict-normal: #5fd48c; --verdict-normal-bg: #15321f;
    --verdict-bad: #a29a8d;    --verdict-bad-bg: #242019;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 6px 16px -6px rgba(0, 0, 0, 0.55), 0 2px 6px -2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 28px 64px -16px rgba(0, 0, 0, 0.7), 0 8px 20px -8px rgba(0, 0, 0, 0.5);
  }
}

/* --------------------------------------------------------------------------
   base
   -------------------------------------------------------------------------- */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-4) var(--sp-8);
}

@media (min-width: 768px) {
  .wrap { padding: var(--sp-6) var(--sp-5) var(--sp-8); }
}

[hidden] { display: none !important; }

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: var(--on-ink);
  padding: var(--sp-3) var(--sp-4);
  border-radius: 0 0 var(--r-sm) 0;
  z-index: 100;
}
.skip:focus { left: 0; }

:where(a, button, input, select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* --------------------------------------------------------------------------
   header
   -------------------------------------------------------------------------- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sp-2) var(--sp-4);
  padding-bottom: var(--sp-4);
  margin-bottom: var(--sp-6);
  position: relative;
  border-bottom: 1px solid var(--border);
}
/* a fine imperial-gold rule under the masthead — the one flourish up top */
.masthead::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 88px;
  height: 2px;
  background: var(--gold-line);
  border-radius: 2px;
}

.masthead h1 {
  margin: 0;
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
/* brush "命" mark — nudged to sit optically level with the wordmark's baseline */
.wm-logo {
  width: 1.6em;
  height: 1.6em;
  align-self: center;
  flex: none;
  transform: translateY(0.06em);
}
.wm-brand {
  font-family: var(--display);
  font-variation-settings: var(--display-vary);
  font-size: var(--fs-2xl);
  font-weight: 640;
  letter-spacing: 0.005em;
  color: var(--fg);
}
.wm-sep {
  color: var(--accent);
  font-weight: 400;
  font-family: var(--display);
  font-variation-settings: var(--display-vary);
}
.wm-sub {
  font-family: var(--display);
  font-variation-settings: var(--display-vary);
  font-size: var(--fs-lg);
  font-weight: 460;
  letter-spacing: 0.02em;
  color: var(--fg-muted);
}

/* language switcher — segmented, two states, both always visible */
.lang {
  display: inline-flex;
  margin-left: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface);
}
.lang-btn {
  min-height: 36px;
  padding: 6px 14px;
  font-size: var(--fs-md);
  font-weight: 600;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
}
.lang-btn + .lang-btn { border-left: 1px solid var(--border-strong); }
.lang-btn:hover { background: var(--surface-2); color: var(--fg); }
.lang-btn[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }
.lang-btn:focus-visible { outline-offset: -2px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  background: var(--surface);
  white-space: nowrap;
}
@media (max-width: 560px) {
  .lang { margin-left: 0; }
  .chip { flex-basis: 100%; }
}

.dot { width: 7px; height: 7px; border-radius: 99px; background: var(--fg-subtle); flex: none; }
.dot.on { background: var(--wood); }
.dot.off { background: var(--danger); }

/* --------------------------------------------------------------------------
   cards & headings
   -------------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5) var(--sp-4);
  margin-bottom: var(--sp-5);   /* one section rhythm, not a component gap */
  box-shadow: var(--shadow-sm);
}
@media (min-width: 768px) {
  .card { padding: var(--sp-6); }
}

/* Section title. These are the landmarks of the report, so they read as
   majestic titles — set in the display serif, with a short gold rule beneath
   that marks each section like a chapter head. */
h2 {
  position: relative;
  margin: 0 0 var(--sp-5);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border);
  font-family: var(--display);
  font-variation-settings: var(--display-vary);
  font-size: var(--fs-xl);
  font-weight: 600;
  line-height: var(--lh-tight);
  letter-spacing: 0;
  color: var(--fg);
}
h2::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 44px;
  height: 2px;
  background: var(--gold-line);
  border-radius: 2px;
}
h2 .cn {
  margin-left: var(--sp-2);
  font-family: var(--font);
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--fg-subtle);
}

h3 {
  margin: 0 0 var(--sp-2);
  font-family: var(--display);
  font-variation-settings: var(--display-vary);
  font-size: var(--fs-lg);
  font-weight: 560;
  line-height: var(--lh-snug);
  letter-spacing: 0;
}

.hint {
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  margin: var(--sp-3) 0 0;
  max-width: var(--measure);
}

/* Running prose keeps a readable measure; tables and grids stay full width. */
.prose p { max-width: var(--measure); }

/* --------------------------------------------------------------------------
   form
   -------------------------------------------------------------------------- */

fieldset { border: 0; padding: 0; margin: 0 0 var(--sp-4); }

/* the standalone 历法 selector sits above 出生时间 as its own labelled choice;
   the group is named by its legend, so the control keeps a screen-reader-only label */
.cal-fieldset select { max-width: 240px; }

/* --- 八字反查 (reverse lookup) --------------------------------------------- */
.bazi-rev { display: grid; gap: var(--sp-3); }
.bazi-rev-main input {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
}
.bazi-rev-range {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-3);
}
.bazi-rev-range > div { flex: 0 1 120px; }
.bazi-rev-range #bazi-lookup { flex: none; }

.bazi-results { margin-top: var(--sp-1); }
.bazi-msg {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: 0 0 var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--fg-muted);
}
.bazi-msg.is-error { color: var(--danger); }

.bazi-cands {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--sp-2);
}
.bazi-cand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.bazi-cand:hover { background: var(--surface-2); }
.bazi-cand:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.bazi-cand input { width: 18px; height: 18px; flex: none; min-height: 0; accent-color: var(--accent); }
.bazi-cand-time {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}
.bazi-cand-gz {
  margin-left: auto;
  font-family: var(--display);
  font-size: var(--fs-base);
  letter-spacing: 0.08em;
  color: var(--fg-muted);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
legend {
  padding: 0;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--fg-muted);
  margin-bottom: var(--sp-3);
}

.grid {
  display: grid;
  gap: var(--sp-3) var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--fg-muted);
  margin-bottom: var(--sp-1);
}
label .req { color: var(--danger); margin-left: 2px; }

input, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  transition: border-color var(--dur) var(--ease);
}
input:hover, select:hover { border-color: var(--fg-subtle); }
select { cursor: pointer; }

.field-help { display: block; font-size: var(--fs-xs); color: var(--fg-subtle); margin-top: var(--sp-1); }
.field-error { display: block; font-size: var(--fs-xs); color: var(--danger); margin-top: var(--sp-1); font-weight: 500; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); }

details.advanced { margin-bottom: var(--sp-4); }
details.advanced > summary {
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--fg-muted);
  padding: var(--sp-2) 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  list-style: none;
}
details.advanced > summary::-webkit-details-marker { display: none; }
details.advanced > summary .caret { transition: transform var(--dur) var(--ease); flex: none; }
details.advanced[open] > summary .caret { transform: rotate(90deg); }

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  padding-top: var(--sp-2);
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: 10px 20px;
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn-primary {
  background: var(--ink);
  color: var(--on-ink);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn-primary:active:not(:disabled) { transform: translateY(0); box-shadow: var(--shadow-sm); }
.btn-secondary {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
@media (prefers-reduced-motion: reduce) {
  .btn-primary:hover:not(:disabled), .btn-primary:active:not(:disabled) { transform: none; }
}

.spinner {
  width: 15px; height: 15px; flex: none;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 99px;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status { font-size: var(--fs-sm); color: var(--fg-muted); }

/* --------------------------------------------------------------------------
   saved people list
   -------------------------------------------------------------------------- */

/* --- saved-people picker: a full-screen page for choosing a stored 命主 ----
   Opened from the 出生资料 box. It reads as its own page — a fixed header with
   the title + close, a pinned search field, the scrolling list, and paging
   pinned to the bottom — so it works the same on a phone or a wide screen. */
.picker {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: picker-fade var(--dur) var(--ease);
}
.picker[hidden] { display: none; }
body.picker-open { overflow: hidden; }   /* lock the page behind the picker */

.picker-panel {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: min(760px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  animation: picker-rise 240ms var(--ease);
}

.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.picker-head h2 {
  margin: 0;
  border: 0;
  padding: 0;
  font-size: var(--fs-xl);
}
.picker-head h2::after { display: none; }
.picker-close {
  flex: none;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--fg-subtle);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.picker-close:hover { background: var(--surface-2); color: var(--fg); }

.picker-search {
  position: relative;
  display: flex;
  align-items: center;
  padding: var(--sp-4) var(--sp-5) var(--sp-3);
}
.picker-search svg {
  position: absolute;
  left: calc(var(--sp-5) + 12px);
  color: var(--fg-subtle);
  pointer-events: none;
}
.picker-search input {
  width: 100%;
  min-height: 44px;
  padding-left: 40px;
  font-size: var(--fs-md);
}

.picker-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--sp-5) var(--sp-4);
}
.picker-empty {
  margin: 0;
  padding: var(--sp-6) var(--sp-2);
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  text-align: center;
}
.picker-empty[hidden] { display: none; }

.picker .saved-pager {
  margin: 0;
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
}
.picker .saved-pager[hidden] { display: none; }

@keyframes picker-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes picker-rise {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .picker, .picker-panel { animation: none; }
}
.saved-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}
.saved-count { font-size: var(--fs-sm); color: var(--fg-muted); font-variant-numeric: tabular-nums; min-width: 8ch; text-align: center; }
.saved-pager .btn-ghost { min-height: 40px; padding: 0 var(--sp-4); }
.saved-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.saved-item {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.saved-item.is-editing {
  border-color: var(--accent, var(--fg-subtle));
  box-shadow: inset 3px 0 0 var(--accent, var(--fg-subtle));
}
.saved-read {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border: 0;
  border-radius: 0;
  text-align: left;
  cursor: pointer;
  min-width: 0;
}
.saved-read:hover { background: var(--surface-2); }
.saved-name { font-size: var(--fs-base); font-weight: 600; color: var(--fg); }
.saved-meta { font-size: var(--fs-xs); color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.saved-actions { display: flex; flex: none; }
.saved-edit,
.saved-del {
  flex: none;
  min-height: 44px;
  padding: 0 var(--sp-3);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  color: var(--fg-subtle);
  cursor: pointer;
  font: inherit;
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.saved-edit:hover { background: var(--surface-2); color: var(--fg); }
.saved-del { width: 44px; padding: 0; justify-content: center; }
.saved-del:hover { background: var(--danger-soft); color: var(--danger); }

.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--fg); }

/* --------------------------------------------------------------------------
   神煞 cross-reference table
   -------------------------------------------------------------------------- */

/* The report cover exists only on paper — print.css reveals it. */
.print-cover { display: none; }

/* --------------------------------------------------------------------------
   核心格局 — verdict, strategy chain, derived indices
   -------------------------------------------------------------------------- */

.pf-verdict {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin: 0 0 var(--sp-4);
}
.pf-big {
  font-family: var(--display);
  font-variation-settings: var(--display-vary);
  font-size: var(--fs-2xl);
  font-weight: 600;
  letter-spacing: 0;
  line-height: var(--lh-tight);
  color: var(--fg);
}
.pf-dm, .pf-soul {
  font-size: var(--fs-sm);
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg-muted);
}

.pf-note {
  margin: calc(var(--sp-4) * -1) 0 var(--sp-4);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  color: var(--fg-muted);
  max-width: var(--measure);
}
.pf-steps { list-style: none; margin: 0 0 var(--sp-3); padding: 0; display: grid; gap: var(--sp-2); }
.pf-step { display: flex; gap: var(--sp-3); align-items: flex-start; line-height: 1.6; }
.pf-num {
  flex: none;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 999px;
  background: var(--ink); color: var(--on-ink);
  font-size: var(--fs-xs); font-weight: 700;
  margin-top: 2px;
}
.pf-guards-head {
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--danger);
  margin: var(--sp-4) 0 var(--sp-2);
}
.pf-guards { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.pf-guard { display: flex; gap: var(--sp-3); align-items: flex-start; line-height: 1.6; color: var(--fg-muted); }
.pf-warn {
  flex: none;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 999px;
  background: var(--danger-soft); color: var(--danger);
  font-size: var(--fs-sm); font-weight: 700;
  margin-top: 2px;
}
.pf-sub { font-size: var(--fs-md); margin: var(--sp-5) 0 var(--sp-3); color: var(--fg-muted); }

.scores { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.score-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); }
.score-name { font-size: var(--fs-md); font-weight: 600; }
.score-val { font-size: var(--fs-lg); font-weight: 700; font-variant-numeric: tabular-nums; }
.score-val small { font-size: var(--fs-2xs); font-weight: 400; color: var(--fg-subtle); }
.score .track {
  height: 8px;
  margin: 6px 0 4px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
.score .fill { height: 100%; border-radius: 999px; }
.band-hi { background: var(--wood); }
.band-mid { background: var(--earth); }
.band-lo { background: var(--metal); }
.score-basis { font-size: var(--fs-xs); color: var(--fg-subtle); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   五行 per-element cards
   -------------------------------------------------------------------------- */

.el-cards {
  display: grid;
  gap: var(--sp-3);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-top: var(--sp-4);
}
.el-card {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  background: var(--surface);
}
.el-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.el-glyph {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  font-size: 16px; font-weight: 700;
}
.el-card.el-wood .el-glyph { background: var(--wood-bg); color: var(--wood); }
.el-card.el-fire .el-glyph { background: var(--fire-bg); color: var(--fire); }
.el-card.el-earth .el-glyph { background: var(--earth-bg); color: var(--earth); }
.el-card.el-metal .el-glyph { background: var(--metal-bg); color: var(--metal); }
.el-card.el-water .el-glyph { background: var(--water-bg); color: var(--water); }
.el-name { font-size: var(--fs-md); font-weight: 600; }
.el-pct { margin-top: var(--sp-2); font-size: var(--fs-xl); font-weight: 700; font-variant-numeric: tabular-nums; }

.tag {
  font-size: var(--fs-2xs);
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg-muted);
  white-space: nowrap;
}
/* magnitude tags (偏旺/偏弱/平和/缺) — kept neutral except where they carry a
   good/bad meaning, so the red/green/black semaphore stays unambiguous */
.tag-strong { background: var(--surface-2); color: var(--fg-muted); border-color: var(--border); }
.tag-weak { background: var(--surface-2); color: var(--fg-muted); border-color: var(--border); }
.tag-even { background: var(--verdict-normal-bg); color: var(--verdict-normal); border-color: transparent; }   /* 平和 → 绿 */
.tag-absent { background: var(--verdict-bad-bg); color: var(--verdict-bad); border-color: transparent; }       /* 缺/无 → 黑 */

/* favorability 喜忌 semaphore: 喜用 red, 闲神 green, 忌神 black */
.tag-favourable { background: var(--verdict-good-bg); color: var(--verdict-good); border-color: transparent; }
.tag-neutral { background: var(--verdict-normal-bg); color: var(--verdict-normal); border-color: transparent; }
.tag-unfavourable { background: var(--verdict-bad-bg); color: var(--verdict-bad); border-color: transparent; }

/* --------------------------------------------------------------------------
   layered report block — narrative for the subject, 命理依据 for the practitioner
   -------------------------------------------------------------------------- */

#report { margin-top: var(--sp-5); }
.rb { margin-bottom: var(--sp-6); }
.rb > h3 {
  font-size: var(--fs-lg);
  font-weight: 650;
  margin: 0 0 var(--sp-3);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border);
}
.rb-say > :first-child { margin-top: 0; }
.rb-pending {
  color: var(--fg-subtle);
  font-size: var(--fs-md);
  font-style: italic;
}

/* the practitioner's layer: present, but visually subordinate to the reading */
.rb-basis {
  margin-top: var(--sp-4);
  border-left: 2px solid var(--border-strong);
  padding: var(--sp-1) 0 var(--sp-1) var(--sp-4);
}
.rb-basis > summary {
  cursor: pointer;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--fg-subtle);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
}
.rb-basis > summary::-webkit-details-marker { display: none; }
.rb-basis > summary::before {
  content: "";
  width: 0; height: 0;
  border-left: 4px solid currentColor;
  border-top: 3.5px solid transparent;
  border-bottom: 3.5px solid transparent;
  transition: transform var(--dur) var(--ease);
}
.rb-basis[open] > summary::before { transform: rotate(90deg); }
.rb-basis > summary:hover { color: var(--fg); }
.rb-basis .prose p {
  font-size: var(--fs-md);
  color: var(--fg-muted);
  margin: var(--sp-2) 0 0;
}

.ss-summary { margin: 0 0 var(--sp-3); font-size: var(--fs-sm); color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.shensha { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.shensha th, .shensha td {
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.shensha thead th {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--fg-muted);
  white-space: nowrap;
}
.shensha tbody tr:last-child td { border-bottom: 0; }
.shensha .ss-name { font-weight: 600; color: var(--fg); white-space: nowrap; }
.shensha .ss-mean { color: var(--fg-muted); min-width: 12ch; }
.shensha .muted { color: var(--fg-subtle); font-size: var(--fs-sm); }
/* rows present in BOTH systems are the actual cross-references — tint them */
.shensha tr.ss-both { background: var(--accent-soft, var(--surface-2)); }
.shensha tr.ss-both .ss-name { color: var(--accent, var(--fg)); }
.ss-hit {
  display: inline-block;
  margin: 0 4px 4px 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.shensha tr.ss-both .ss-hit { background: var(--surface); }

/* on narrow screens the edit button drops its text label to stay tappable */
@media (max-width: 460px) {
  .saved-edit span { display: none; }
  .saved-edit { width: 44px; padding: 0; justify-content: center; }
}

.alert {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--fg);
  font-size: var(--fs-md);
  margin-bottom: var(--sp-4);
}
.alert svg { flex: none; color: var(--danger); margin-top: 2px; }

/* --------------------------------------------------------------------------
   pillars — 排盘 grid as an editorial table
   Columns read 时 · 日 · 月 · 年. Element-tinted glyph tiles; the day pillar
   is banded as the reference column.
   -------------------------------------------------------------------------- */

.paipan {
  width: 100%;
  min-width: 460px;
  /* `separate` (not `collapse`) so the corner cells can carry a border-radius.
     Each edge is drawn on a single side already, so spacing 0 keeps the same
     crisp single-line grid — the borders don't double up. */
  border-collapse: separate;
  border-spacing: 0;
  text-align: center;
  table-layout: fixed;
}

/* leftmost label column is narrow; the four pillars share the rest evenly */
.paipan .corner { width: 3.6rem; }
.paipan thead th,
.paipan tbody td { width: calc((100% - 3.6rem) / var(--paipan-cols, 4)); }

/* full hairline grid with an outer frame:
   - vertical rule left of every pillar column
   - top and bottom edges span the whole table width (label column included)
   - a rule under the header and between rows, also spanning the label column */
.paipan thead th,
.paipan tbody td { border-left: 1px solid var(--border); }

/* top edge */
.paipan thead th,
.paipan thead .corner { border-top: 1px solid var(--border-strong); }

/* header underline + inter-row rules, full width */
.paipan thead th,
.paipan thead .corner { border-bottom: 1px solid var(--border-strong); }
.paipan tbody tr:not(:last-child) th,
.paipan tbody tr:not(:last-child) td { border-bottom: 1px solid var(--border); }

/* bottom edge */
.paipan tbody tr:last-child th,
.paipan tbody tr:last-child td { border-bottom: 1px solid var(--border-strong); }

/* left edge (outside the label column) and right edge (outside 年柱) */
.paipan thead .corner,
.paipan tbody th { border-left: 1px solid var(--border-strong); }
.paipan thead th:last-child,
.paipan tbody td:last-child { border-right: 1px solid var(--border-strong); }

/* rounded outer corners — each corner cell rounds where its two frame edges meet */
.paipan thead .corner { border-top-left-radius: var(--r-md); }
.paipan thead th:last-child { border-top-right-radius: var(--r-md); }
.paipan tbody tr:last-child th { border-bottom-left-radius: var(--r-md); }
.paipan tbody tr:last-child td:last-child { border-bottom-right-radius: var(--r-md); }

/* --- header ---------------------------------------------------------------- */
.paipan thead th {
  padding: var(--sp-2) var(--sp-1) var(--sp-3);
  vertical-align: top;
}
.paipan .col-name {
  display: block;
  font-size: var(--fs-base);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--fg);
}
.paipan .col-tag {
  display: inline-block;
  margin-top: 6px;
  padding: 1px 8px;
  border-radius: 99px;
  font-size: var(--fs-2xs);
  line-height: 1.5;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: var(--accent);
  color: var(--on-ink);
}
.paipan .col-tag-muted { background: var(--surface-2); color: var(--fg-subtle); }
/* a same-height, same-width spacer so every column name aligns */
.paipan .col-tag-ghost { visibility: hidden; }

/* --- row labels ------------------------------------------------------------ */
.paipan tbody th {
  padding: var(--sp-2) var(--sp-3) var(--sp-2) 0;
  text-align: right;
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  white-space: nowrap;
  color: var(--fg-subtle);
  vertical-align: middle;
}

.paipan tbody td {
  padding: var(--sp-2) var(--sp-1);
  vertical-align: middle;
}

/* --- the day column: an accent band that sits inside the grid -------------- */
.paipan .is-day { background: var(--day-bg, var(--accent-soft)); }

/* --- 主星 / 副星 stars ----------------------------------------------------- */
.paipan .star { font-size: var(--fs-sm); font-weight: 500; color: var(--fg-muted); }
.paipan .star-self {
  font-size: var(--fs-base);
  font-weight: 700;
  color: var(--accent);
}

/* --- 天干 / 地支 element tiles --------------------------------------------- */
.paipan .row-tile td { padding: var(--sp-1); }
.paipan .tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.9rem;
  height: 2.9rem;
  border-radius: var(--r-md);
  font-size: var(--fs-2xl);
  font-weight: 600;
  line-height: 1;
  transition: transform var(--dur) var(--ease);
}
.paipan .tile.el-wood  { background: var(--wood-bg);  color: var(--wood); }
.paipan .tile.el-fire  { background: var(--fire-bg);  color: var(--fire); }
.paipan .tile.el-earth { background: var(--earth-bg); color: var(--earth); }
.paipan .tile.el-metal { background: var(--metal-bg); color: var(--metal); }
.paipan .tile.el-water { background: var(--water-bg); color: var(--water); }

/* gentle lift on hover, whole column (desktop pointers only) */
@media (hover: hover) {
  .paipan tbody td:hover .tile { transform: translateY(-2px); }
}

/* --- 藏干 / 副星 stacks ---------------------------------------------------- */
.paipan .stk { display: block; line-height: 1.6; }
.paipan .hide-stem { font-size: var(--fs-base); font-weight: 500; }
.paipan .sub { font-size: var(--fs-xs); color: var(--fg-muted); }
/* 神煞 — one small tag per symbolic star landing on the pillar */
.paipan .ss-tag {
  display: inline-block;
  font-size: var(--fs-xs);
  line-height: 1.5;
  color: var(--fg-muted);
  cursor: help;
}

/* --- 星运 / 空亡 / 纳音 meta ----------------------------------------------- */
.paipan .meta { font-size: var(--fs-sm); color: var(--fg-muted); }
.paipan .nayin { font-size: var(--fs-xs); }
.paipan .muted { color: var(--fg-subtle); }



@media (prefers-reduced-motion: reduce) {
  .paipan .tile { transition: none; }
}

/* --------------------------------------------------------------------------
   紫微斗数 命盘 — traditional square 12-palace chart
   -------------------------------------------------------------------------- */

.zw-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  grid-template-rows: repeat(4, minmax(118px, auto));
  gap: 0;
  min-width: 620px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  overflow: hidden;
}

.zw-palace {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border: 1px solid var(--border);
  min-width: 0;
}
.zw-palace.is-soul { background: var(--accent-soft); }
.zw-palace.is-body { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent); }

.zw-stars { display: flex; flex-direction: column; gap: 3px; }
.zw-majors { display: flex; flex-wrap: wrap; gap: 3px 6px; }
.zw-minors, .zw-misc { display: flex; flex-wrap: wrap; gap: 2px 5px; }

.zw-star { display: inline-flex; align-items: baseline; white-space: nowrap; }
.zw-major { font-size: 16px; font-weight: 600; color: var(--fg); }
.zw-minor { font-size: var(--fs-xs); color: var(--fg-muted); }
.zw-misc  { font-size: var(--fs-2xs); color: var(--fg-subtle); }
.zw-empty { color: var(--fg-subtle); }

.zw-br { font-size: var(--fs-2xs); color: var(--fg-subtle); margin-left: 1px; }
.zw-mu {
  font-size: var(--fs-2xs); font-weight: 700; line-height: 1;
  padding: 1px 3px; border-radius: 3px; margin-left: 2px;
  color: var(--on-ink); background: var(--fg-subtle);
}
.zw-mu.mu-lu   { background: var(--wood); }
.zw-mu.mu-quan { background: var(--fire); }
.zw-mu.mu-ke   { background: var(--water); }
.zw-mu.mu-ji   { background: var(--fg-muted); }

.zw-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-1);
  padding-top: var(--sp-1);
  border-top: 1px solid var(--border);
  font-size: var(--fs-2xs);
}
.zw-name { font-size: var(--fs-sm); font-weight: 600; color: var(--fg); white-space: nowrap; }
.zw-meta { color: var(--fg-subtle); text-align: right; font-variant-numeric: tabular-nums; }

.zw-badge {
  display: inline-block; margin-left: 4px; padding: 0 5px;
  border-radius: 99px; font-size: var(--fs-2xs); font-weight: 700; letter-spacing: 0.04em;
  vertical-align: middle;
}
.zw-soul { background: var(--accent); color: var(--on-ink); }
.zw-body { background: var(--surface-2); color: var(--accent); border: 1px solid var(--accent); }

/* centre 2×2 info box */
.zw-center-cell {
  grid-row: 2 / 4;
  grid-column: 2 / 4;
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-3);
}
.zw-centre { display: flex; flex-direction: column; gap: var(--sp-2); font-size: var(--fs-sm); line-height: 1.5; }
.zw-c-row { color: var(--fg); }
.zw-c-row b { color: var(--fg-muted); font-weight: 600; font-size: var(--fs-2xs); margin-right: 2px; }
.zw-c-sub { color: var(--fg-subtle); font-size: var(--fs-xs); border-top: 1px solid var(--border); padding-top: var(--sp-2); margin-top: 2px; }
.zw-centre .zw-star { font-size: var(--fs-sm); }

/* element hues */
.el-wood  { color: var(--wood); }
.el-fire  { color: var(--fire); }
.el-earth { color: var(--earth); }
.el-metal { color: var(--metal); }
.el-water { color: var(--water); }

/* --------------------------------------------------------------------------
   verdict strip
   -------------------------------------------------------------------------- */

/* --------------------------------------------------------------------------
   论命依据 — evidence panel: WHY the strength / 用神 verdicts were reached.
   A scorecard bar (得令/得地/得势 crossing the 50 身强线) + the 扶抑 logic.
   -------------------------------------------------------------------------- */
.evidence {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  margin-bottom: var(--sp-5);
}
.evidence:empty { display: none; }
.ev-card {
  min-width: 0;
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.ev-top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.ev-title { font-size: var(--fs-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--fg-subtle); }
.ev-grade {
  font-size: var(--fs-sm); font-weight: 700; padding: 2px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-strong);
  border: 1px solid color-mix(in srgb, var(--accent-strong) 30%, transparent);
}
.ev-str.is-weak .ev-grade { background: color-mix(in srgb, var(--fg-subtle) 14%, var(--surface)); color: var(--fg-muted); border-color: var(--border); }

/* the scorecard bar: a 0–100 track; segments fill from the left; a dashed 50 line */
.ev-bar {
  position: relative; display: flex; height: 26px; border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--fg-subtle) 12%, var(--surface));
  overflow: hidden; /* segments clip to rounded track; the 50-line sits above via z-index */
}
.ev-seg { height: 100%; transition: width .5s cubic-bezier(.2,.7,.3,1); }
.ev-seg-ling { background: var(--accent-strong); }
.ev-seg-di   { background: color-mix(in srgb, var(--accent-strong) 55%, var(--water) 45%); }
.ev-seg-shi  { background: color-mix(in srgb, var(--accent-strong) 40%, var(--fg-subtle) 30%); }
.ev-seg-ju   { background: var(--water); }
.ev-line { position: absolute; top: -3px; bottom: -3px; width: 0; border-left: 2px dashed var(--fg-muted); z-index: 2; }
.ev-line i {
  position: absolute; top: -16px; left: 3px; font-size: var(--fs-2xs); font-style: normal;
  font-weight: 600; color: var(--fg-muted); white-space: nowrap;
}
.ev-legend { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-3); margin-top: var(--sp-3); font-size: var(--fs-xs); color: var(--fg-muted); }
.ev-key { display: inline-flex; align-items: center; gap: 5px; }
.ev-key b { color: var(--fg); font-variant-numeric: tabular-nums; }
.ev-dot { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.ev-dot-ling { background: var(--accent-strong); }
.ev-dot-di   { background: color-mix(in srgb, var(--accent-strong) 55%, var(--water) 45%); }
.ev-dot-shi  { background: color-mix(in srgb, var(--accent-strong) 40%, var(--fg-subtle) 30%); }
.ev-dot-ju   { background: var(--water); }
.ev-total { margin-left: auto; font-weight: 700; color: var(--fg); font-variant-numeric: tabular-nums; }
.ev-total i { font-style: normal; font-weight: 400; color: var(--fg-subtle); }
.ev-why { margin: var(--sp-3) 0 0; font-size: var(--fs-sm); line-height: 1.6; color: var(--fg-muted); }

/* 用神 logic card */
.ev-yong .ev-logic { margin: 0 0 var(--sp-3); font-size: var(--fs-base); font-weight: 600; line-height: 1.55; color: var(--fg); }
.ev-pair { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.ev-fav, .ev-avoid {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0;
  padding: 6px 12px; border-radius: 999px; font-size: var(--fs-base); font-weight: 600;
  border: 1px solid var(--border);
}
.ev-fav   { background: var(--wood-bg); }
.ev-avoid { background: color-mix(in srgb, var(--fg-subtle) 13%, var(--surface)); }
.ev-tag { font-size: var(--fs-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.ev-fav .ev-tag { color: var(--wood); }
.ev-avoid .ev-tag { color: var(--fg-subtle); }
.ev-method { margin: var(--sp-3) 0 0; font-size: var(--fs-sm); line-height: 1.6; color: var(--fg-muted); }
@media (prefers-reduced-motion: reduce) { .ev-seg { transition: none; } }

.verdict {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
/* each row is a subtle colour chip: a 3px left bar + faint tint + tinted label,
   grouped by meaning (identity / favourable / avoid / timing). Colour is an
   accent only — every label and value still reads without it. */
.verdict > div {
  min-width: 0;
  padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  border-left: 3px solid var(--v-accent, var(--border-strong));
  background: var(--v-bg, var(--surface-2));
}
.verdict .v-id    { --v-accent: var(--accent-strong); --v-bg: var(--accent-soft); }
.verdict .v-fav   { --v-accent: var(--wood);          --v-bg: var(--wood-bg); }   /* pastel colour (favourable) */
/* 忌神 — a neutral pastel GREY, distinct from the warm paper */
.verdict .v-avoid { --v-accent: var(--fg-subtle);     --v-bg: color-mix(in srgb, var(--fg-subtle) 15%, var(--surface)); }
.verdict .v-time  { --v-accent: var(--water);         --v-bg: var(--water-bg); }
.verdict dt {
  font-size: var(--fs-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--v-accent, var(--fg-subtle));
  margin-bottom: var(--sp-1);
}
.verdict dd { margin: 0; font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.01em; color: var(--fg); }
.verdict dd small { display: block; font-size: var(--fs-sm); font-weight: 400; color: var(--fg-muted); margin-top: 2px; }

/* --------------------------------------------------------------------------
   bars (elements / ten gods)
   -------------------------------------------------------------------------- */

.bars { display: grid; gap: var(--sp-2); }
.bar {
  display: grid;
  grid-template-columns: 7.5rem 1fr 3.2rem;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-md);
}
.bar .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 99px; transition: width 420ms var(--ease); }
.bar .value { text-align: right; font-variant-numeric: tabular-nums; color: var(--fg-muted); font-size: var(--fs-sm); }
.bar.is-absent .value { color: var(--danger); font-weight: 600; }

.fill-wood { background: var(--wood); }
.fill-fire { background: var(--fire); }
.fill-earth { background: var(--earth); }
.fill-metal { background: var(--metal); }
.fill-water { background: var(--water); }
.fill-neutral { background: var(--fg-subtle); }
.fill-tg { background: var(--accent); }   /* 十神 bars: one neutral colour, no element hue */

/* --------------------------------------------------------------------------
   luck cycles
   -------------------------------------------------------------------------- */

.cycles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: var(--sp-2);
}
.cycle {
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--r-sm);
  padding: var(--sp-3) var(--sp-2);
  text-align: center;
  font-size: var(--fs-xs);
  background: var(--surface);
}
.cycle .gz { display: block; font-size: var(--fs-xl); font-weight: 600; letter-spacing: 0.04em; margin-bottom: 2px; }
.cycle .years, .cycle .ages { color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.cycle .tone { display: block; margin-top: var(--sp-1); font-size: var(--fs-2xs); font-weight: 600; }

/* 大运 favorability — 喜用 red (good), 平和 green (ok/neutral), 忌神 black (hard) */
.cycle.tone-good  { border-left-color: var(--verdict-good); }
.cycle.tone-good .tone { color: var(--verdict-good); }
.cycle.tone-ok    { border-left-color: var(--verdict-normal); }
.cycle.tone-ok .tone { color: var(--verdict-normal); }
.cycle.tone-neutral { border-left-color: var(--verdict-normal); }
.cycle.tone-neutral .tone { color: var(--verdict-normal); }
.cycle.tone-hard  { border-left-color: var(--verdict-bad); }
.cycle.tone-hard .tone { color: var(--verdict-bad); }

.cycle.is-current {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  background: var(--accent-soft);
}
.cycle .now {
  display: block;
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

/* --- 大运 as buttons: click one to load its ten 流年 below ------------------ */
.cycle.is-clickable { cursor: pointer; transition: box-shadow .15s ease, border-color .15s ease, transform .15s ease; }
.cycle.is-clickable:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.cycle.is-clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cycle.is-selected {
  outline: 2px solid var(--ink);
  outline-offset: -1px;
  background: var(--surface-2);
  box-shadow: var(--shadow-md);
}

/* the decade currently shown, named in the 流年 heading */
.annual-scope {
  font-family: var(--font);
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: normal;
  color: var(--fg-muted);
}
.annual-scope .scope-gz { color: var(--fg); font-weight: 700; }
.annual-reset {
  margin-left: var(--sp-2);
  font: inherit;
  font-size: var(--fs-xs);
  color: var(--accent);
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 9px;
  cursor: pointer;
}
.annual-reset:hover { background: var(--accent-soft); border-color: var(--accent); }

/* --------------------------------------------------------------------------
   reading prose
   -------------------------------------------------------------------------- */

.reading section { margin-bottom: var(--sp-6); }
.reading section:last-child { margin-bottom: 0; }

.reading h3 {
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-3);
}
.reading h3 .cn { font-weight: 400; color: var(--fg-muted); margin-left: var(--sp-2); font-size: var(--fs-base); }

.prose p { margin: 0 0 var(--sp-3); line-height: 1.75; max-width: 68ch; }
.prose p:last-child { margin-bottom: 0; }
.prose strong { font-weight: 600; }
.prose ul { margin: 0; padding-left: 0; list-style: none; max-width: 68ch; }
.prose li {
  position: relative;
  padding-left: var(--sp-5);
  margin-bottom: var(--sp-2);
  line-height: 1.7;
}
.prose li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.72em;
  width: 6px;
  height: 6px;
  border-radius: 99px;
  background: var(--accent);
}
/* ordered lists (大运 walk-through, 行动建议) — numbered, one item per line */
.prose ol { margin: 0; padding-left: 1.6em; list-style: decimal; max-width: 68ch; }
.prose ol li { padding-left: var(--sp-1); }
.prose ol li::before { content: none; }        /* use the number, not the dot */
.prose ol li::marker { color: var(--accent); font-weight: 600; }

/* verdict words in the 大运 / 流年 report prose — same semaphore as the 大运 cards */
.rb-v-good   { color: var(--verdict-good); }
.rb-v-normal { color: var(--verdict-normal); }
.rb-v-bad    { color: var(--verdict-bad); }
.prose h2 {
  font-size: var(--fs-lg);
  font-weight: 600;
  text-transform: none;
  letter-spacing: -0.01em;
  color: var(--fg);
  margin: var(--sp-5) 0 var(--sp-3);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border);
}
.prose h2:first-child { margin-top: 0; }

.interactions { margin: 0; padding: 0; list-style: none; }
.interactions li {
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-md);
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
}
.interactions li:last-child { border-bottom: 0; }
.interactions .where {
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-width: 7.5rem;
  flex: none;
  padding-top: 2px;
}
.interactions .rel-body { display: flex; flex-direction: column; gap: 3px; }
.interactions .rel-text { font-weight: 600; color: var(--fg); }
.interactions .rel-mean {
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--fg-muted);
  max-width: var(--measure);
}
.interactions .rel-area {
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
  color: var(--accent-strong);
  max-width: var(--measure);
}

/* --------------------------------------------------------------------------
   AI panel
   -------------------------------------------------------------------------- */

.ai-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.ai-head h2 { margin: 0; }
.ai-head .actions { padding: 0; margin-left: auto; }

/* The PDF button under 行动建议 sits at the foot of the report; give it a little
   more breathing room above so it does not crowd the last reading section. */
.report-actions { margin-top: var(--sp-5); }

/* 命理依据 print toggle, sitting beside the PDF button. A native checkbox keeps it
   accessible and keyboard-operable; the whole label is a comfortable tap target. */
.pdf-opt {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: 0 var(--sp-1);
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  cursor: pointer;
  user-select: none;
}
.pdf-opt input {
  width: 18px;
  height: 18px;
  flex: none;
  accent-color: var(--accent);
  cursor: pointer;
}
.pdf-opt:hover { color: var(--fg); }

.ai-note {
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  background: var(--surface-2);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
}
.ai-note code {
  font-family: var(--mono);
  font-size: var(--fs-xs);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
}

.caret-cursor::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* --------------------------------------------------------------------------
   data table
   -------------------------------------------------------------------------- */

.facts { width: 100%; border-collapse: collapse; }
.facts th, .facts td {
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-md);
  text-align: left;
  vertical-align: top;
}
.facts tr:last-child th, .facts tr:last-child td { border-bottom: 0; }
.facts th { font-weight: 500; color: var(--fg-muted); width: 45%; }
.facts td { font-variant-numeric: tabular-nums; }

.caveats { margin: 0; padding: 0; list-style: none; }
.caveats li {
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  line-height: 1.65;
  margin-bottom: var(--sp-2);
  padding-left: var(--sp-4);
  position: relative;
}
.caveats li::before { content: "—"; position: absolute; left: 0; }

.colophon {
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--fg-subtle);
  padding-top: var(--sp-5);
  margin-top: var(--sp-5);
  border-top: 1px solid var(--border);
}
.colophon a { color: var(--fg-muted); }

.scroll-x { overflow-x: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --------------------------------------------------------------------------
   基本资料 — calendar facts, two columns of label/value
   -------------------------------------------------------------------------- */

.basic {
  display: grid;
  /* Two columns before three: at three, long values like the 农历 string wrap and
     stretch the whole grid row, leaving a gap under its shorter neighbours. */
  grid-template-columns: 1fr;
  gap: 0 var(--sp-6);
  margin: 0;
}
@media (min-width: 640px)  { .basic { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .basic { grid-template-columns: repeat(3, 1fr); } }

.basic > div {
  display: flex;
  gap: var(--sp-3);
  align-items: center;        /* a taller wrapped row stays visually centred */
  min-height: 44px;
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
}
.basic dt {
  flex: none;
  width: 5.5rem;
  font-size: var(--fs-sm);
  color: var(--fg-subtle);
}
.basic dd {
  margin: 0;
  font-size: var(--fs-md);
  line-height: var(--lh-snug);
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  white-space: pre-line;   /* honour the newline in the 农历 value (时辰 on its own line) */
}

/* --------------------------------------------------------------------------
   流年 — the annual pillars table
   -------------------------------------------------------------------------- */

.annual { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.annual th, .annual td {
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.annual thead th {
  font-size: var(--fs-xs); font-weight: 600; color: var(--fg-muted); white-space: nowrap;
}
.annual tbody tr:last-child td { border-bottom: 0; }
.annual tr.is-current { background: var(--accent-soft); }
.an-year { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.an-now {
  margin-left: 6px; padding: 1px 6px; border-radius: 999px;
  background: var(--accent); color: var(--on-accent); font-size: var(--fs-2xs); font-weight: 700;
}
.an-gz { font-size: 16px; font-weight: 600; white-space: nowrap; }
.an-age, .an-cycle { color: var(--fg-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.annual .muted { color: var(--fg-subtle); }
.an-rel {
  display: inline-block; margin: 0 4px 3px 0; padding: 2px 8px;
  border-radius: 999px; font-size: var(--fs-xs); white-space: nowrap;
  border: 1px solid var(--border);
}
/* 六合 harmony is auspicious → red (good); 六冲 clash is adverse → black (bad) */
.an-combine { background: var(--verdict-good-bg); color: var(--verdict-good); border-color: transparent; }
.an-clash { background: var(--verdict-bad-bg); color: var(--verdict-bad); border-color: transparent; }
/* Scoped to the table: `.cycle` already uses .tone-* for the 大运 cards, and an
   unscoped rule here would silently restyle that component too. */
.annual .tone {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--fg-muted);
}
/* 流年 favorability — 喜用 red (good), 平和 green (ok/neutral), 忌神 black (hard) */
.annual .tone-good { background: var(--verdict-good-bg); color: var(--verdict-good); border-color: transparent; }
.annual .tone-hard { background: var(--verdict-bad-bg); color: var(--verdict-bad); border-color: transparent; }
.annual .tone-ok { background: var(--verdict-normal-bg); color: var(--verdict-normal); border-color: transparent; }
.annual .tone-neutral { background: var(--verdict-normal-bg); color: var(--verdict-normal); border-color: transparent; }

/* --------------------------------------------------------------------------
   十神分布 — the ten, grouped under their five categories
   -------------------------------------------------------------------------- */

.tengods { display: grid; gap: var(--sp-4); }
.tg-group { display: grid; gap: var(--sp-2); }
.tg-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--sp-3); padding-bottom: var(--sp-1);
  border-bottom: 1px solid var(--border);
}
.tg-cat { font-size: var(--fs-sm); font-weight: 600; color: var(--fg); }
.tg-pair { font-weight: 400; color: var(--fg-subtle); }
.tg-el { margin-left: var(--sp-2); font-size: var(--fs-2xs); font-weight: 700; letter-spacing: 0.03em; }
.tg-total { font-size: var(--fs-sm); font-weight: 600; color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.tg-total.is-absent { color: var(--fg-subtle); font-weight: 400; }
.tg-group .bars { gap: var(--sp-2); }
/* wider name column so each god can carry its 六亲 (relationship) beneath it */
.tg-group .bar { grid-template-columns: 12rem 1fr 3.2rem; }
.tg-group .bar .name {
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  white-space: normal;
  overflow: visible;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.tg-group .bar .name .tg-rel {
  font-size: var(--fs-2xs);
  font-weight: 400;
  color: var(--fg-subtle);
}
@media (max-width: 560px) { .tg-group .bar { grid-template-columns: 9rem 1fr 2.8rem; } }

/* 大运 / 流年 transit columns — set apart from the four natal pillars */
.paipan th.is-transit, .paipan td.is-transit { background: var(--surface-2); }
.paipan th.is-transit { border-left: 2px solid var(--border-strong); }
.paipan td.is-transit { border-left: 2px solid var(--border-strong); }

/* 干支关系 — two labelled groups in one card */
.rel-sub { font-size: var(--fs-sm); color: var(--fg-muted); margin: var(--sp-4) 0 var(--sp-2); }
.rel-sub:first-of-type { margin-top: 0; }
.rel-scope {
  margin: calc(-1 * var(--sp-2)) 0 var(--sp-4);
  padding: var(--sp-2) var(--sp-3);
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

/* 大运 cards carry the same 冲/合 annotations as the 流年 table */
.cy-rels { display: block; margin-top: var(--sp-2); }
.cy-rel {
  display: inline-block; margin: 2px 3px 0 0; padding: 1px 7px;
  border-radius: 999px; font-size: var(--fs-2xs); line-height: 1.6;
  border: 1px solid var(--border); white-space: nowrap;
}

/* --------------------------------------------------------------------------
   人生大事 — life-event timeline (per 大运 theme strip + chronological highlights)
   -------------------------------------------------------------------------- */
.le-good  { --le: var(--wood);  --le-bg: var(--wood-bg); }
.le-watch { --le: var(--earth); --le-bg: var(--earth-bg); }
.le-hard  { --le: var(--fire);  --le-bg: var(--fire-bg); }

/* 大运 theme strip */
.le-cycles { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-5); }
.le-cyc {
  display: flex; align-items: center; gap: var(--sp-2); min-width: 0;
  padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border);
  border-radius: var(--r-md); background: var(--surface-2); font-size: var(--fs-sm);
}
.le-cyc.is-current { border-color: color-mix(in srgb, var(--accent-strong) 45%, transparent); background: var(--accent-soft); }
.le-cyc-age { font-weight: 700; color: var(--fg); font-variant-numeric: tabular-nums; }
.le-cyc-gz { color: var(--fg-muted); font-weight: 600; margin-right: var(--sp-1); }
.le-chip { padding: 1px 8px; border-radius: 999px; font-size: var(--fs-2xs); font-weight: 600; background: var(--le-bg); color: var(--le); border: 1px solid color-mix(in srgb, var(--le) 22%, transparent); }

/* chronological highlights */
.le-timeline { display: flex; flex-direction: column; gap: var(--sp-3); }
.le-row {
  display: grid; grid-template-columns: 92px 1fr; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border);
  border-left: 3px solid var(--le, var(--border-strong)); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--le-bg, var(--surface-2)) 45%, var(--surface));
}
.le-when { display: flex; flex-direction: column; line-height: 1.35; }
.le-when b { font-size: var(--fs-lg); color: var(--fg); font-variant-numeric: tabular-nums; }
.le-when span { font-size: var(--fs-xs); color: var(--fg-subtle); }
.le-body { min-width: 0; }
.le-badge { display: inline-block; margin-bottom: var(--sp-2); padding: 3px 11px; border-radius: 999px; font-size: var(--fs-sm); font-weight: 700; background: var(--le-bg); color: var(--le); border: 1px solid color-mix(in srgb, var(--le) 26%, transparent); }
.le-why { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 5px; }
.le-why li { font-size: var(--fs-sm); line-height: 1.55; color: var(--fg-muted); }
.le-src { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 4px; font-size: var(--fs-2xs); font-weight: 700; vertical-align: 1px; }
.le-src-bazi  { background: var(--accent-soft); color: var(--accent-strong); }
.le-src-ziwei { background: var(--water-bg); color: var(--water); }
@media (max-width: 520px) { .le-row { grid-template-columns: 1fr; gap: var(--sp-2); } }

/* 婚姻推断 / 子女推断 — forecast banners atop 人生大事 (side by side, then stack) */
.le-forecasts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--sp-4); margin-bottom: var(--sp-6);
}
.le-fc {
  padding: var(--sp-4) var(--sp-5);
  border: 1px solid color-mix(in srgb, var(--accent-strong) 28%, var(--border));
  border-left: 3px solid var(--accent-strong);
  border-radius: var(--r-md); background: var(--accent-soft);
}
.le-fc-children { border-left-color: var(--wood); border-color: color-mix(in srgb, var(--wood) 26%, var(--border)); background: var(--wood-bg); }
.le-fc-tag { display: block; margin-bottom: var(--sp-3); font-size: var(--fs-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent-strong); }
.le-fc-children .le-fc-tag { color: var(--wood); }
.le-fc ul { margin: 0; padding-left: 1.15em; display: flex; flex-direction: column; gap: var(--sp-2); }
.le-fc li { font-size: var(--fs-base); line-height: 1.7; color: var(--fg); }

/* 分析范畴 — the areas legend */
.le-legend { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-6); }
.le-legend-title { font-size: var(--fs-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-subtle); }
.le-legend-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.le-lchip { padding: 2px 9px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; background: var(--le-bg); color: var(--le); border: 1px solid color-mix(in srgb, var(--le) 20%, transparent); }

/* section labels above the 大运 strip and the timeline */
.le-section-label { font-size: var(--fs-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-subtle); margin: 0 0 var(--sp-3); }
.le-cycles + .le-section-label { margin-top: var(--sp-6); }

/* ==========================================================================
   Main navigation (命理 / 占测) + 占测 casting view
   ========================================================================== */

.mainnav {
  display: flex;
  gap: var(--sp-2);
  justify-content: center;
  flex-wrap: wrap;
  margin: 0 auto var(--sp-6);
}
.nav-btn {
  font: inherit;
  font-weight: 600;
  padding: var(--sp-2) var(--sp-5, 20px);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg-muted);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
}
.nav-btn:hover { background: var(--surface-2); color: var(--fg); }
.nav-btn.is-active {
  background: var(--ink);
  color: var(--on-ink);
  border-color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.nav-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 占测 system sub-tabs */
.ztabs { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.ztab {
  font: inherit; font-weight: 600;
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface); color: var(--fg-muted); cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.ztab:hover { background: var(--surface-2); color: var(--fg); }
.ztab.is-active { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent); }
.ztab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.zmethods, .zcoins { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.zradio, .zcheck, .zcoin { display: inline-flex; align-items: center; gap: var(--sp-2); }
.zradio span, .zcheck span { white-space: nowrap; }
.zradio input, .zcheck input { flex: none; }
.zcoin { flex-direction: column; gap: var(--sp-1); font-size: .82rem; color: var(--fg-muted); }
.zcoin select { padding: 6px 8px; }

/* cast result header chips */
.zhead {
  display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4);
  align-items: center; margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-3); border-bottom: 1px solid var(--border);
  font-size: .9rem; color: var(--fg-muted);
}
.zhead .zju { font-weight: 700; color: var(--accent-strong); font-size: 1rem; }
.zrel { padding: 2px 10px; border-radius: 999px; font-weight: 600; }
.zrel-good { background: var(--wood-bg); color: var(--wood); }
.zrel-bad { background: var(--fire-bg); color: var(--fire); }
.zrel-weak { background: var(--earth-bg); color: var(--earth); }
.zrel-neutral { background: var(--surface-2); color: var(--fg-muted); }

/* hexagram chips + yao ladders (梅花) */
.hexchips { display: flex; flex-wrap: wrap; gap: var(--sp-4); }
.hexchip {
  flex: 1 1 140px; min-width: 130px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: var(--sp-4) var(--sp-3);
}
.hc-label { font-size: .8rem; color: var(--fg-subtle); margin-bottom: var(--sp-2); }
.hc-name { font-weight: 700; margin-top: var(--sp-2); }
.hc-tri { font-size: .82rem; color: var(--fg-muted); }
.hc-mean { font-size: .78rem; color: var(--fg-subtle); margin-top: 4px; }

.yao-ladder { display: flex; flex-direction: column; gap: 5px; align-items: center; margin: var(--sp-2) 0; }
.yao { position: relative; width: 88px; height: 12px; display: inline-flex; align-items: center; }
.yao .bar { width: 100%; height: 10px; border-radius: 2px; }
.yao.yang .bar { background: var(--fg); }
.yao.yin  .bar { background: linear-gradient(90deg, var(--fg) 0 42%, transparent 42% 58%, var(--fg) 58% 100%); }
.yao.moving .bar { background: var(--accent); }
.yao.moving.yin .bar { background: linear-gradient(90deg, var(--accent) 0 42%, transparent 42% 58%, var(--accent) 58% 100%); }
.yao .mv { position: absolute; right: -18px; font-size: .8rem; color: var(--accent-strong); }

/* 六爻 table */
.liuyao-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.liuyao-table th, .liuyao-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.liuyao-table th { color: var(--fg-subtle); font-weight: 600; font-size: .82rem; }
.liuyao-table .ly-bar .yao { width: 46px; height: 12px; }
.liuyao-table .is-shi { background: var(--accent-soft); }
.liuyao-table .is-ying td { box-shadow: inset 3px 0 0 var(--water); }
.liuyao-table .is-moving .ly-qin { font-weight: 700; color: var(--accent-strong); }
.ly-el { color: var(--fg-subtle); font-size: .78rem; margin-left: 4px; }
.ly-tag { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 6px; background: var(--surface-2); font-size: .74rem; color: var(--fg-muted); }
.ly-tag.mv { background: var(--accent-soft); color: var(--accent-strong); }
.ly-mark b { color: var(--accent-strong); margin-right: 4px; }
.ly-change { color: var(--fg-muted); font-size: .84rem; }

/* 奇门 nine-palace grid */
.qimen-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-width: 560px; }
.qm-cell {
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface-2); padding: 8px; min-height: 92px;
  display: flex; flex-direction: column; gap: 3px; font-size: .82rem; text-align: center;
}
.qm-cell.is-fu { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.qm-cell.is-shi { background: var(--accent-soft); }
.qm-shen { color: var(--water); font-weight: 600; }
.qm-tian { color: var(--fire); }
.qm-tian b { color: var(--accent-strong); }
.qm-door { color: var(--wood); font-weight: 600; }
.qm-di { color: var(--fg-muted); }
.qm-di b { color: var(--fg); }
.qm-foot { margin-top: auto; font-size: .72rem; color: var(--fg-subtle); }
.qm-tags { color: var(--accent-strong); font-weight: 700; }

.znotes { margin: var(--sp-4) 0 0; padding-left: 1.1rem; color: var(--fg-muted); font-size: .9rem; }
.znotes li { margin: 4px 0; }

/* ==========================================================================
   命理老师 chatbot — floating launcher + drawer (global, both views)
   ========================================================================== */

.chat-launcher {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  display: inline-flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 8px; border: 0; background: transparent; cursor: pointer;
}
.chat-launcher-pill {
  display: none; font-weight: 700; font-size: .9rem;
  padding: 9px 15px; border-radius: 999px;
  background: var(--ink); color: var(--on-ink); box-shadow: var(--shadow-md);
}
@media (min-width: 640px) { .chat-launcher-pill { display: inline-flex; } }
.chat-launcher-logo {
  display: grid; place-items: center; height: 54px; width: 54px; border-radius: 999px;
  background: var(--surface); border: 2px solid var(--accent); box-shadow: var(--shadow-md);
  transition: transform .15s;
}
.chat-launcher:hover .chat-launcher-logo { transform: scale(1.06); }
.chat-launcher:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 999px; }

.chat-panel {
  position: fixed; z-index: 61; display: flex; flex-direction: column;
  background: var(--surface); overflow: hidden;
  inset: 0; /* full-screen sheet on mobile */
}
@media (min-width: 640px) {
  .chat-panel {
    inset: auto; right: 20px; bottom: 20px;
    width: 400px; height: 620px; max-height: calc(100vh - 40px);
    border: 1px solid var(--border-strong); border-radius: 16px; box-shadow: var(--shadow-lg);
  }
}

.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px; background: var(--ink); color: var(--on-ink);
}
.chat-head-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-avatar { display: grid; place-items: center; height: 36px; width: 36px; border-radius: 999px; background: var(--surface); border: 1px solid var(--accent); flex: none; }
.chat-head-txt { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.chat-name { font-family: var(--display, inherit); font-weight: 700; font-size: .98rem; }
.chat-sub { display: inline-flex; align-items: center; gap: 6px; font-size: .74rem; color: rgba(255,255,255,.62); }
.chat-dot { height: 7px; width: 7px; border-radius: 999px; background: #4ade80; }
.chat-head-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.chat-h-btn {
  font: inherit; font-size: .78rem; font-weight: 600; color: rgba(255,255,255,.8);
  background: transparent; border: 0; border-radius: 8px; padding: 5px 8px; cursor: pointer;
}
.chat-h-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.chat-icon-btn { display: grid; place-items: center; padding: 6px; }

.chat-body { flex: 1; overflow-y: auto; padding: 16px 14px; background: var(--surface-2); }
.chat-greeting {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px 14px 14px 4px;
  padding: 12px 14px; font-size: .9rem; line-height: 1.6; color: var(--fg);
}
.chat-suggests { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.chat-suggest {
  font: inherit; font-size: .86rem; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; color: var(--fg);
  transition: border-color .15s, background .15s;
}
.chat-suggest:hover { border-color: var(--accent); background: var(--accent-soft); }

.chat-messages { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.chat-msg { display: flex; }
.chat-msg.chat-user { justify-content: flex-end; }
.chat-bubble {
  max-width: 86%; padding: 9px 13px; border-radius: 14px; font-size: .9rem; line-height: 1.6;
  word-break: break-word; overflow-wrap: anywhere;
}
.chat-user .chat-bubble { background: var(--ink); color: var(--on-ink); border-bottom-right-radius: 4px; }
.chat-master .chat-bubble { background: var(--surface); border: 1px solid var(--border); color: var(--fg); border-bottom-left-radius: 4px; }
.chat-master .chat-bubble p { margin: 0 0 .5em; }
.chat-master .chat-bubble p:last-child { margin-bottom: 0; }
.chat-master .chat-bubble ol, .chat-master .chat-bubble ul { margin: .3em 0; padding-left: 1.2em; }
.chat-cursor { color: var(--accent); animation: chat-blink 1s step-end infinite; }
@keyframes chat-blink { 50% { opacity: 0; } }

.chat-typing { display: flex; gap: 5px; padding: 8px 4px 0; }
.chat-typing span { height: 7px; width: 7px; border-radius: 999px; background: var(--accent); opacity: .5; animation: chat-bounce 1.2s infinite ease-in-out; }
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chat-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-5px); opacity: 1; } }

.chat-composer { border-top: 1px solid var(--border); background: var(--surface); padding: 10px 12px; }
.chat-input-wrap { display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--border-strong); border-radius: 14px; background: var(--surface-2); padding: 6px 6px 6px 10px; }
.chat-input-wrap:focus-within { border-color: var(--accent); }
#chat-input {
  flex: 1; border: 0; background: transparent; resize: none; font: inherit; font-size: .9rem;
  color: var(--fg); max-height: 120px; padding: 6px 0; outline: none;
}
.chat-send {
  flex: none; display: grid; place-items: center; height: 38px; width: 38px; border: 0; border-radius: 11px;
  background: var(--accent); color: #fff; cursor: pointer; transition: background .15s;
}
.chat-send:hover { background: var(--accent-strong); }
.chat-foot { margin: 8px 2px 0; text-align: center; font-size: .72rem; color: var(--fg-subtle); }

@media print { .chat-launcher, .chat-panel { display: none !important; } }
