:root {
  color-scheme: light dark;

  --bg: #f4efe4;
  --surface: #fbf8f1;
  --surface-2: #f0e9da;
  --ink: #1f1b16;
  --ink-2: #554c40;
  --ink-3: #746a5c;
  --line: #d9cfbb;
  --control-border: #7a6f60;
  --accent: #b3261e;
  --accent-ink: #ffffff;
  --focus: #1d5fa8;
  --error: #a3180f;

  /* Five-element mark colors (validated per mode against the surface). */
  --el-wood: #2f9e63;
  --el-fire: #c8322b;
  --el-earth: #7a4e2a;
  --el-metal: #c9a227;
  --el-water: #1d5fa8;

  /* Five-element text colors (darker where needed for small text on the surface). */
  --el-wood-ink: #1d7a48;
  --el-fire-ink: #b3261e;
  --el-earth-ink: #6b4423;
  --el-metal-ink: #8a6a00;
  --el-water-ink: #1d5fa8;

  --serif-zh: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;

  accent-color: var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110d;
    --surface: #1f1b16;
    --surface-2: #2a251e;
    --ink: #efe8da;
    --ink-2: #c4baa8;
    --ink-3: #a09683;
    --line: #3b352b;
    --control-border: #8d8271;
    --accent: #e0655a;
    --accent-ink: #1a0f0d;
    --focus: #8ab8f0;
    --error: #ff9a8f;

    --el-wood: #45a86c;
    --el-fire: #c23a32;
    --el-earth: #8f6038;
    --el-metal: #d4af37;
    --el-water: #3070c4;

    --el-wood-ink: #5cc488;
    --el-fire-ink: #ff7a70;
    --el-earth-ink: #c8946a;
    --el-metal-ink: #e3bd4a;
    --el-water-ink: #7fb2f0;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
}

h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  clip-path: inset(50%);
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  white-space: nowrap;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---- header / footer ---- */

.site-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 0.5rem;
}

.seal {
  flex: none;
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 0.5rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--serif-zh);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  writing-mode: vertical-rl;
  letter-spacing: 0.1em;
}

.site-header h1 { font-size: 1.5rem; line-height: 1.2; }
.tagline { color: var(--ink-2); font-size: 0.95rem; }

.site-footer {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1rem 1rem 2.5rem;
  color: var(--ink-3);
  font-size: 0.875rem;
}

/* ---- layout ---- */

.layout {
  display: grid;
  gap: 1.25rem;
  max-width: 72rem;
  margin: 0 auto;
  padding: 1rem;
  align-items: start;
}

@media (min-width: 60rem) {
  .layout { grid-template-columns: 21rem minmax(0, 1fr); }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 1.25rem;
}

/* minmax(0, 1fr): cards may never be wider than the column, so wide content
   (the pillar table) scrolls inside its card instead of stretching the page. */
.sidebar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; min-width: 0; }
.results { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; min-width: 0; }
.results > h2 { font-size: 1.25rem; }
.card h2 { font-size: 1.125rem; margin-block-end: 1rem; }
.card h3 { font-size: 1.05rem; margin-block-end: 0.75rem; }
.zh { font-family: var(--serif-zh); }
h3 .zh { color: var(--ink-3); font-weight: 400; margin-inline-start: 0.35rem; }

.summary { color: var(--ink-2); margin-block-start: -0.75rem; }

/* ---- reorderable result panels ---- */
.panel-grip {
  float: left;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  margin: -0.3rem 0.25rem -0.3rem -0.5rem;
  padding: 0;
  border: 0;
  border-radius: 0.4rem;
  background: transparent;
  color: var(--ink-3);
  cursor: grab;
  touch-action: none; /* a touch drag on the grip moves the panel, not the page */
}
.panel-grip::before {
  content: '';
  width: 9px;
  height: 15px;
  background: radial-gradient(circle, currentColor 1.4px, transparent 1.5px) 0 0 / 4.5px 5px;
}
.panel-grip:hover { background: var(--surface-2); color: var(--ink); }
.card.is-dragging {
  position: relative;
  z-index: 5;
  opacity: 0.95;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
  user-select: none;
  -webkit-user-select: none;
}
.card.is-dragging .panel-grip { cursor: grabbing; background: var(--surface-2); color: var(--ink); }
.panel-reset {
  justify-self: start;
  margin-block-start: -0.75rem;
  padding: 0.25rem 0;
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink-2);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}
.panel-reset:hover { color: var(--ink); }

.placeholder { text-align: center; color: var(--ink-2); padding: 3rem 1.5rem; }
.placeholder-glyphs {
  font-family: var(--serif-zh);
  font-size: 2.25rem;
  letter-spacing: 0.4em;
  color: var(--line);
  margin-block-end: 1rem;
}

/* ---- form ---- */

.field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  margin: 0 0 1.25rem;
  padding: 0;
  border: 0;
  min-width: 0;
}

label, legend { font-weight: 600; font-size: 0.95rem; }
legend { padding: 0; margin-block-end: 0.25rem; }
.hint, .hint-inline { color: var(--ink-3); font-size: 0.85rem; font-weight: 400; }

input[type="date"], input[type="time"], input[type="text"], input[type="number"] {
  font: inherit;
  font-size: max(1rem, 1em);
  width: 100%;
  min-height: 48px;
  padding: 0.6rem 0.75rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--control-border);
  border-radius: 0.5rem;
}

/* iOS Safari sizes its native time control from its own content and ignores
   width: 100% inside a flex column, so the field spilled out of the card. */
input[type="time"], input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  max-width: 100%;
}
input::-webkit-date-and-time-value { text-align: start; }

input:disabled { opacity: 0.5; }

input:user-invalid, input[aria-invalid="true"] {
  border-color: var(--error);
  border-width: 2px;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
}
.check input { width: 1.2rem; height: 1.2rem; margin: 0; flex: none; }
.check label { font-weight: 400; padding-block: 0.6rem; }
.radio-row { display: flex; gap: 1.5rem; }
/* Second label inside one field (出生城市, then 经度). */
.field .hint + label { margin-block-start: 0.75rem; }

.advanced {
  margin-block-end: 1.25rem;
  border-block: 1px solid var(--line);
}
.advanced summary {
  cursor: pointer;
  padding-block: 0.8rem;
  font-weight: 600;
  font-size: 0.95rem;
}
.advanced[open] summary { margin-block-end: 0.5rem; }

button.primary {
  font: inherit;
  font-weight: 600;
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 1rem;
  border: 0;
  border-radius: 0.5rem;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
button.primary:hover { filter: brightness(1.08); }

button.secondary {
  font: inherit;
  font-weight: 600;
  width: 100%;
  min-height: 48px;
  margin-block-start: 0.6rem;
  padding: 0.7rem 1rem;
  border: 1px solid var(--control-border);
  border-radius: 0.5rem;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
button.secondary:hover { background: var(--surface-2); }

/* ---- saved profiles ---- */

.profile-search {
  font: inherit;
  font-size: max(1rem, 1em);
  width: 100%;
  min-height: 44px;
  margin-block-end: 0.6rem;
  padding: 0.5rem 0.75rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--control-border);
  border-radius: 0.5rem;
}
#profiles-nomatch { margin-block-end: 0.5rem; }

/* Capped height: a long list scrolls inside the card instead of stretching the page. */
.profiles {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
  max-height: 22rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}
.profiles:empty { display: none; }
.profiles li {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--bg);
  overflow: hidden;
}
.profiles li.is-active { border: 2px solid var(--accent); }
.profiles button {
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 0;
  cursor: pointer;
  min-height: 48px;
}
.profiles button:hover { background: var(--surface-2); }
.profiles button:focus-visible { outline-offset: -3px; }
.profile-open { flex: 1; min-width: 0; text-align: start; padding: 0.55rem 0.75rem; }
.profile-name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-meta { display: block; font-size: 0.8rem; color: var(--ink-2); }
.profile-chart { display: block; font-family: var(--serif-zh); font-size: 0.95rem; letter-spacing: 0.05em; }
.profile-delete {
  flex: none;
  padding: 0 0.75rem;
  font-size: 0.85rem;
  color: var(--ink-2) !important;
  border-inline-start: 1px solid var(--line) !important;
}
.profile-delete.is-confirm { color: var(--error) !important; font-weight: 600; }
.profiles-note { margin-block-start: 0.75rem; }
.profiles:empty + .profiles-note { display: none; }

.profile-io { display: flex; gap: 0.5rem; margin-block-start: 0.75rem; }
button.small {
  flex: 1;
  font: inherit;
  font-size: 0.9rem;
  min-height: 40px;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
button.small:hover:not(:disabled) { background: var(--surface-2); border-color: var(--control-border); }
button.small:disabled { color: var(--ink-3); cursor: not-allowed; }
.profiles-msg { font-size: 0.85rem; color: var(--ink-2); margin-block-start: 0.5rem; }
.profiles-msg:empty { display: none; }
.profiles-msg.is-error { color: var(--error); }

.error { color: var(--error); font-size: 0.9rem; margin-block-start: 0.6rem; }
.error:empty { display: none; }

/* ---- pillars table ---- */

.table-wrap { overflow-x: auto; }

.pillars {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  text-align: center;
}

.pillars th, .pillars td { padding: 0.6rem 0.25rem; vertical-align: top; }
.pillars thead th { font-size: 0.9rem; font-weight: 600; color: var(--ink-2); padding-block-end: 0.4rem; }
.pillars thead th .zh { display: block; font-size: 1.05rem; color: var(--ink); }
.pillars thead td { width: 5.5rem; }
.pillars tbody th {
  text-align: start;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-3);
  vertical-align: middle;
}
.pillars tbody tr + tr > * { border-block-start: 1px solid var(--line); }
.pillars .is-day { background: var(--surface-2); }
.pillars thead .is-day { border-radius: 0.5rem 0.5rem 0 0; }
.pillars tbody tr:last-child .is-day { border-radius: 0 0 0.5rem 0.5rem; }

.glyph {
  display: block;
  font-family: var(--serif-zh);
  font-size: clamp(2rem, 9vw, 3rem);
  font-weight: 700;
  line-height: 1.15;
}
.glyph-bar {
  display: block;
  width: 1.75rem;
  height: 4px;
  border-radius: 2px;
  margin: 0.25rem auto 0.35rem;
  background: var(--el);
}
.sub { display: block; font-size: 0.8rem; color: var(--ink-2); }
.sub-strong { display: block; font-size: 0.85rem; color: var(--ink); }
.god-zh { display: block; font-family: var(--serif-zh); font-size: 1rem; }
.empty { color: var(--ink-3); }

.hidden-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.3rem; }
.hidden-list li { font-size: 0.8rem; color: var(--ink-2); line-height: 1.3; }
.hidden-list .zh { font-size: 1rem; color: var(--ink); white-space: nowrap; }

.shensha-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.2rem; }
.shensha-list li { line-height: 1.3; white-space: nowrap; }
.shensha-btn {
  font: inherit;
  font-size: 0.8rem;
  color: var(--ink-2);
  background: none;
  border: 0;
  border-radius: 0.25rem;
  padding: 0.15rem 0.25rem;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 0.2em;
}
.shensha-btn:hover { color: var(--ink); background: var(--surface-2); }
.shensha-btn[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent); text-decoration: none; }
.shensha-btn:focus-visible, .shensha-close:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ---- 喜用神 highlights: green = 用神 / 喜神, red = 忌神 ---- */
:root { --fav-good: #1d7a48; --fav-bad: #b3261e; --fav-palace: #8a5a00; }
@media (prefers-color-scheme: dark) { :root { --fav-good: #5fc98f; --fav-bad: #f0766c; --fav-palace: #e0b04f; } }

.fav-tag {
  display: inline-block;
  margin-inline-start: 0.3rem;
  padding: 0 0.35rem;
  font-size: 0.7rem;
  line-height: 1.5;
  font-weight: 600;
  border-radius: 1rem;
  border: 1px solid currentColor;
  color: var(--ink-3);
  vertical-align: middle;
}
/* Same code as the glyph boxes: 用 = green tint inside a green ring, 喜 = green tint, 忌 = red tint. */
.fav-tag.fav-yong { color: var(--fav-good); background: color-mix(in srgb, var(--fav-good) 26%, transparent); border-color: var(--fav-good); font-weight: 700; }
.fav-tag.fav-xi { color: var(--fav-good); background: color-mix(in srgb, var(--fav-good) 16%, transparent); border-color: transparent; }
.fav-tag.fav-ji { color: var(--fav-bad); background: color-mix(in srgb, var(--fav-bad) 16%, transparent); border-color: transparent; }

.glyph.fav-yong, .glyph.fav-xi, .glyph.fav-ji { width: fit-content; margin-inline: auto; border-radius: 0.5rem; padding-inline: 0.35rem; }
.glyph.fav-yong { background: color-mix(in srgb, var(--fav-good) 26%, transparent); box-shadow: inset 0 0 0 2px var(--fav-good); }
.glyph.fav-xi { background: color-mix(in srgb, var(--fav-good) 16%, transparent); }
.glyph.fav-ji { background: color-mix(in srgb, var(--fav-bad) 16%, transparent); }

/* Glyph whose 合 flips its 喜忌: a faint dashed ring, and faded 合忌 / 合用 / 合喜 tags on a line of
   their own that wraps inside the column, so it never widens it. */
.glyph.he-bad, .glyph.he-good { width: fit-content; max-width: 100%; margin-inline: auto; border-radius: 0.5rem; padding-inline: 0.35rem; }
.glyph.he-bad { outline: 1.5px dashed color-mix(in srgb, var(--fav-bad) 55%, transparent); }
.glyph.he-good { outline: 1.5px dashed color-mix(in srgb, var(--fav-good) 55%, transparent); }
.he-line { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.15rem; margin-top: 0.2rem; }
/* max-width + normal wrapping: a long tag (冲刑害·合解) breaks inside a narrow phone column instead of spilling out. */
.fav-tag.he-mark, .fav-tag.xc-mark { margin: 0; padding: 0 0.25rem; max-width: 100%; font-size: 0.62rem; line-height: 1.4; white-space: normal; background: none; opacity: 0.75; cursor: help; }
.fav-tag.he-bad, .fav-tag.xc-bad { color: var(--fav-bad); }
.fav-tag.he-good, .fav-tag.xc-good { color: var(--fav-good); }
/* 合而逢冲: a natal 合 broken by a 大运 / 流年 冲 (合用·冲开) */
.fav-tag.he-broken { color: var(--ink-3); }
/* 合而不化: a 天干五合 that only ties the two stems up (合绊) */
.fav-tag.he-ban { color: var(--ink-3); }
/* 刑冲 tags (冲刑 / 害 / 破) share the line, with a dashed border to tell them from the 合 tags */
.fav-tag.xc-mark { border-style: dashed; }
.fav-tag.xc-neutral { color: var(--ink-3); }
/* 宫位 moved by a 冲 / 刑 (夫妻宫动), whatever its 喜忌 */
.fav-tag.xc-palace { color: var(--fav-palace); border-style: dotted; }
.luck-btn > .he-line { display: flex; }
.he-line:empty, .luck-btn > .he-line:empty { display: none; }
/* Each switch hides its own tags; the line goes when nothing on it is left showing. */
.card.he-off .glyph.he-bad, .card.he-off .glyph.he-good { outline: none; }
.card.he-off .he-mark, .card.xc-off .xc-mark { display: none; }
.card.he-off .he-line:not(:has(.xc-mark)),
.card.xc-off .he-line:not(:has(.he-mark)),
.card.he-off.xc-off .he-line { display: none; }

/* 大运 / 流年 / 流月 cards */
.glyphs .fav-yong, .glyphs .fav-xi, .glyphs .fav-ji { border-radius: 0.35rem; padding-inline: 0.1em; }
.glyphs .fav-yong { background: color-mix(in srgb, var(--fav-good) 26%, transparent); box-shadow: inset 0 0 0 2px var(--fav-good); }
.glyphs .fav-xi { background: color-mix(in srgb, var(--fav-good) 16%, transparent); }
.glyphs .fav-ji { background: color-mix(in srgb, var(--fav-bad) 16%, transparent); }
.fav-tag.is-mini { margin-inline-start: 0.15rem; padding: 0 0.25rem; font-size: 0.65rem; line-height: 1.4; }
.sub:has(.fav-tag.is-mini) { white-space: nowrap; }

.hidden-list li.fav-yong, .hidden-list li.fav-xi, .hidden-list li.fav-ji { border-radius: 0.3rem; padding: 0.05rem 0.25rem; }
.hidden-list li.fav-yong { background: color-mix(in srgb, var(--fav-good) 26%, transparent); box-shadow: inset 0 0 0 1.5px var(--fav-good); }
.hidden-list li.fav-xi { background: color-mix(in srgb, var(--fav-good) 14%, transparent); }
.hidden-list li.fav-ji { background: color-mix(in srgb, var(--fav-bad) 14%, transparent); }

.el-row.fav-yong, .el-row.fav-xi, .el-row.fav-ji { border-radius: 0.4rem; }
.el-row.fav-yong { background: color-mix(in srgb, var(--fav-good) 20%, transparent); box-shadow: inset 0 0 0 1.5px var(--fav-good); }
.el-row.fav-xi { background: color-mix(in srgb, var(--fav-good) 11%, transparent); }
.el-row.fav-ji { background: color-mix(in srgb, var(--fav-bad) 11%, transparent); }

/* 细盘六柱提示: the element a 合 / 会 / 化 produces */
.hint-fav { border-radius: 0.3rem; padding-inline: 0.1em; }
.hint-fav.fav-yong { background: color-mix(in srgb, var(--fav-good) 26%, transparent); box-shadow: inset 0 0 0 1.5px var(--fav-good); }
.hint-fav.fav-xi { background: color-mix(in srgb, var(--fav-good) 16%, transparent); }
.hint-fav.fav-ji { background: color-mix(in srgb, var(--fav-bad) 16%, transparent); }

/* Per-panel switch for the highlights */
.fav-toggle {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-inline-start: 0.75rem;
  font-size: 0.8rem;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}
.fav-toggle input { margin: 0; accent-color: var(--accent); }
/* The panel's switches side by side at the top right; they wrap under each other when the panel is narrow. */
.panel-toggles {
  float: right;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem 0.75rem;
  max-width: 60%;
  margin-inline-start: 0.75rem;
}
.panel-toggles .fav-toggle { float: none; margin: 0; }
/* Text may wrap around the switches, but tables, grids and lists start below them: a scroll box or grid
   placed beside a float is squeezed into the space left of it (on phones the switches wrap onto two lines). */
.card > .panel-toggles ~ :not(h3):not(p) { clear: both; }
/* 合 / 刑冲 tags answer to their own 合化标记 / 刑冲标记 switches, not this one. */
.card.fav-off .fav-tag:not(.he-mark):not(.xc-mark), .card.fav-off .fav-legend { display: none; }
.card.fav-off .glyph[class*="fav-"],
.card.fav-off .glyphs [class*="fav-"],
.card.fav-off .hint-fav,
.card.fav-off .hidden-list li[class*="fav-"],
.card.fav-off .el-row[class*="fav-"] { background: none; box-shadow: none; }

.chip.is-absent { opacity: 0.6; }
.fav-advice { font-weight: 600; }

.fav-hours { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.4rem; }
.fav-hour-btn {
  display: grid;
  justify-items: center;
  min-width: 3rem;
  padding: 0.3rem 0.4rem;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  cursor: pointer;
}
.fav-hour-btn .zh { font-family: var(--serif-zh); font-size: 1rem; line-height: 1.2; }
.fav-hour-btn small { font-size: 0.7rem; color: var(--ink-3); white-space: nowrap; }
.fav-hour-step { min-width: 2.25rem; align-content: center; font-size: 1.4rem; line-height: 1; }
.fav-hour-btn:hover { background: var(--surface-2); }
.fav-hour-btn.is-actual { border-color: var(--control-border); border-style: dashed; }
.fav-hour-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); border-style: solid; color: var(--accent-ink); }
.fav-hour-btn[aria-pressed="true"] small { color: var(--accent-ink); }
.fav-hour-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.fav-hour-roll {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding-inline: 0.4rem;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.fav-hour-roll input { margin: 0; }
@media (max-width: 30rem) {
  .fav-hour-roll { grid-column: 1 / -1; min-height: 32px; }
}

.shensha-tip { margin: 0.5rem 0 0; }
.shensha-info {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}
.shensha-info p { margin: 0 0 0.4rem; }
.shensha-info p:last-child { margin-bottom: 0; }
.shensha-title { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.shensha-title strong { font-family: var(--serif-zh); font-size: 1.1rem; }
.shensha-kind { font-size: 0.75rem; padding: 0.05rem 0.45rem; border-radius: 1rem; border: 1px solid currentColor; }
.shensha-kind.is-good { color: var(--el-wood-ink); }
.shensha-kind.is-bad { color: var(--el-fire-ink); }
.shensha-kind.is-mixed { color: var(--ink-2); }
.shensha-where { font-size: 0.8rem; color: var(--ink-3); }
.shensha-close {
  margin-inline-start: auto;
  font: inherit;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--ink-2);
  background: none;
  border: 0;
  border-radius: 0.25rem;
  padding: 0.1rem 0.4rem;
  cursor: pointer;
}
.shensha-close:hover { color: var(--ink); }

.dot {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--el);
  margin-inline-end: 0.3rem;
  vertical-align: baseline;
}

.el-wood { --el: var(--el-wood); --el-ink: var(--el-wood-ink); }
.el-fire { --el: var(--el-fire); --el-ink: var(--el-fire-ink); }
.el-earth { --el: var(--el-earth); --el-ink: var(--el-earth-ink); }
.el-metal { --el: var(--el-metal); --el-ink: var(--el-metal-ink); }
.el-water { --el: var(--el-water); --el-ink: var(--el-water-ink); }

@media (max-width: 30rem) {
  .card { padding: 1rem 0.75rem; }
  .pillars th, .pillars td { padding-inline: 0.1rem; }
  /* Collapse the row-label column; labels stay available to assistive tech. */
  .pillars thead td, .pillars tbody th { width: 0; padding: 0; }
  .row-label {
    position: absolute;
    clip-path: inset(50%);
    overflow: hidden;
    width: 1px;
    height: 1px;
    white-space: nowrap;
  }
  .hidden-list .dot { margin-inline-end: 0.15rem; }
  .el-row { grid-template-columns: 4.75rem minmax(2rem, 1fr) 1.25rem minmax(3rem, auto); gap: 0.5rem; }
}

/* ---- facts ---- */

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.75rem 1.5rem;
  margin: 1.25rem 0 0;
  padding-block-start: 1rem;
  border-block-start: 1px solid var(--line);
}
.facts dt { font-size: 0.8rem; font-weight: 600; color: var(--ink-3); }
.facts dd { margin: 0; font-size: 0.95rem; }

/* ---- five elements ---- */

.elements { display: grid; gap: 0.3rem; margin-block-start: 0.75rem; }
/* Every row is padded alike, so text in a tinted (喜忌) row stays clear of its edge and lines up with the rest. */
.el-row {
  display: grid;
  grid-template-columns: 5.5rem minmax(3rem, 1fr) 1.5rem minmax(4.5rem, auto);
  align-items: center;
  gap: 0.75rem;
  padding: 0.3rem 0.6rem;
  border-radius: 0.4rem;
}
/* Flex-centred: vertical-align: middle uses the Latin x-height and leaves the 喜忌 chip low beside a 汉字. */
.el-name { display: flex; align-items: center; font-size: 0.95rem; }
.el-name .zh { font-size: 1.1rem; margin-inline-end: 0.3rem; }
.el-track { height: 12px; }
.el-bar {
  height: 100%;
  min-width: 0;
  border-radius: 0 4px 4px 0;
  background: var(--el);
}
.el-count { font-variant-numeric: tabular-nums; font-weight: 600; text-align: end; }
.el-chars { font-family: var(--serif-zh); color: var(--ink-2); letter-spacing: 0.15em; }

/* ---- favourable elements ---- */

.fav-level { font-size: 1.05rem; font-weight: 600; }
.fav-meter { display: flex; gap: 2px; height: 12px; margin-block: 0.6rem 0.3rem; }
.fav-meter div { min-width: 2px; }
#fav-meter-support { background: var(--ink-2); border-radius: 4px 0 0 4px; }
#fav-meter-oppose { flex: 1; background: var(--line); border-radius: 0 4px 4px 0; }
.fav-meter-labels {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.fav-list { display: grid; gap: 0.6rem; margin: 1rem 0; }
.fav-list > div { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.fav-list dt { flex: none; width: 3rem; font-weight: 600; font-size: 0.95rem; }
.fav-list dd { margin: 0; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.2rem 0.7rem 0.2rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-size: 0.9rem;
  white-space: nowrap;
}
.chip .zh { font-size: 1.15rem; font-weight: 700; margin-inline-end: 0.35rem; }
.chip.is-yong { border: 2px solid var(--accent); }
.chip small { color: var(--ink-2); font-size: 0.8rem; }
#fav-reason { font-size: 0.95rem; margin-block-end: 0.6rem; }
#fav-scores { margin-block-end: 0.3rem; }

/* ---- luck pillars ---- */

.luck {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.25rem, 1fr));
  gap: 0.6rem;
}
.luck li {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  text-align: center;
  background: var(--bg);
  overflow: hidden;
}
.luck li.is-current { border: 2px solid var(--accent); }
/* The extra 1px of border comes out of the padding, so its content lines up with its neighbours'. */
.luck li.is-current > .luck-btn, .luck li.is-current > .cell { padding: calc(0.6rem - 1px) calc(0.4rem - 1px); }
.luck li.is-selected { background: var(--surface-2); border-color: var(--ink-2); }
.luck li.is-current.is-selected { border-color: var(--accent); }
.luck .cell, .luck-btn { display: block; width: 100%; height: 100%; padding: 0.6rem 0.4rem; }
/* A button centres its content vertically; a column from the top keeps age / years / glyphs at the same
   height in every card of a row, however many 合 / 刑冲 tags a taller neighbour carries. */
.luck-btn {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.luck-btn:hover { background: var(--surface-2); }
.luck-btn:focus-visible { outline-offset: -3px; }
.luck-btn > span { display: block; }

.liunian-list .glyphs, .liuyue-list .glyphs { font-size: 1.4rem; }
.luck .age { font-size: 0.85rem; font-weight: 600; }
.luck .years { font-size: 0.75rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.luck .glyphs { font-family: var(--serif-zh); font-size: 1.6rem; font-weight: 700; line-height: 1.3; }
.luck .bars { display: flex; justify-content: center; gap: 2px; margin-block: 0.15rem 0.35rem; }
.luck .bars span { width: 1.4rem; height: 4px; border-radius: 2px; background: var(--el); }
.luck .now {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---- 细盘六柱提示 ---- */

.hints { margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.hints > div {
  display: grid;
  grid-template-columns: 3.5rem 1fr;
  gap: 0.75rem;
  align-items: center;
  padding: 0.6rem 0.75rem;
}
.hints > div:nth-child(odd) { background: var(--surface-2); }
.hints dt { font-weight: 600; font-size: 0.95rem; }
.hints dd { margin: 0; font-size: 0.95rem; line-height: 1.6; overflow-wrap: anywhere; }

/* Element-colored characters (stems, branches, element names). */
.ek { color: var(--el-ink); }

/* Selected 大运 / 流年 columns appended to the pillar table. */
.pillars .is-extra-first { border-inline-start: 2px dashed var(--line); }
.pillars thead .col-sub { display: block; font-size: 0.72rem; font-weight: 400; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.pillars:has(.is-extra) .glyph { font-size: clamp(1.7rem, 6.5vw, 2.6rem); }
@media (max-width: 30rem) {
  /* Phone: all six columns (四柱 + 大运 + 流年) fit the card without sideways scrolling. */
  .pillars th, .pillars td { padding-inline: 0; }
  .pillars .sub .fav-tag { display: block; width: fit-content; margin: 0.15rem auto 0; }
  .pillars:has(.is-extra) .glyph { font-size: 1.6rem; }
  .pillars:has(.is-extra) .glyph[class*="fav-"] { padding-inline: 0.2rem; }
  .pillars:has(.is-extra) thead th .zh { font-size: 0.95rem; }
  .pillars:has(.is-extra) thead .col-sub { font-size: 0.62rem; letter-spacing: -0.02em; }
  .pillars:has(.is-extra) .god-zh { font-size: 0.85rem; }
  .pillars:has(.is-extra) .sub, .pillars:has(.is-extra) .sub-strong { font-size: 0.72rem; }
  .pillars:has(.is-extra) .hidden-list li { font-size: 0.68rem; padding-inline: 0; }
  .pillars:has(.is-extra) .hidden-list .zh { font-size: 0.8rem; }
  .pillars:has(.is-extra) .hidden-list .dot { display: none; }
  .pillars:has(.is-extra) .shensha-btn { font-size: 0.68rem; padding: 0.2rem 0; }

  /* 时辰 picker: arrows and 原盘 on one row, then the twelve 时辰 in two rows of six. */
  .fav-hours { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .fav-hour-btn { min-width: 0; padding-inline: 0.1rem; min-height: 44px; }
  .fav-hour-btn small { font-size: 0.62rem; }
  .fav-hour-step, .fav-hour-btn[data-k="orig"] { grid-column: span 2; }

  .fav-meter-labels { font-size: 0.78rem; }
  .fav-list dt { width: 2.5rem; }
}

/* ---- 四柱 精简: glyphs, 十神 and 藏干 only, in a tighter table ---- */
.card.compact .pillars th, .card.compact .pillars td { padding-block: 0.3rem; }
.card.compact .pillars thead th { padding-block-end: 0.2rem; }
.card.compact .pillars thead th .zh { display: inline; font-size: 0.95rem; }
.card.compact .pillars thead .col-sub { font-size: 0.65rem; }
.card.compact .pillars .glyph,
.card.compact .pillars:has(.is-extra) .glyph { font-size: clamp(1.5rem, 6vw, 2rem); line-height: 1.2; }
.card.compact .pillars .glyph-bar,
.card.compact .pillars .sub,
.card.compact .pillars .sub-strong,
.card.compact .pillars .row-nayin,
.card.compact .pillars .row-shensha,
.card.compact .shensha-click,
.card.compact .facts,
.card.compact .shensha-info { display: none; }
.card.compact .pillars .god-zh { font-size: 0.85rem; }
.card.compact .pillars tbody th { font-size: 0.72rem; }
.card.compact .hidden-list { gap: 0.1rem; }
.card.compact .hidden-list li { font-size: 0.68rem; line-height: 1.25; }
.card.compact .hidden-list .zh { font-size: 0.85rem; }
.card.compact .hidden-list .dot { display: none; }
.card.compact .he-line { margin-top: 0.1rem; }
