:root {
  --md-chrome-earth: #4a3025;
  --md-chrome-earth-2: #5b3b2b;
  --md-chrome-gold: #d3a64f;
  --md-chrome-cream: #f7f0e3;
  --md-chrome-paper: #fffaf2;
  --md-chrome-text: #3b291f;
  --md-chrome-line: rgba(226, 191, 125, .42);
}

/* The story pages are hydrated by their original app. Keep its header and
   footer out of view while the single site chrome lives outside that app. */
body.md-isolated-story-chrome main.story-page > header.zen-header,
body.md-isolated-story-chrome main.story-page > footer.zen-footer {
  display: none !important;
}

body.md-isolated-story-chrome > header.md-site-header,
body.md-isolated-story-chrome > footer.md-site-footer {
  position: relative;
  z-index: 9000;
}

/* v314: Bazi learning pages share the homepage canvas instead of their
   legacy flat white/grey backgrounds. */
body[data-bazi-page],
body.bazi-chart-page {
  background: radial-gradient(circle at 20% 18%, rgba(255,255,255,.6), transparent 29%), linear-gradient(180deg, #f7efdf 0%, #f1e4cc 100%) !important;
  color: var(--md-chrome-text) !important;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif !important;
}

body[data-bazi-page] > main,
body.bazi-chart-page .bazi-chart-main {
  background: transparent !important;
}

header.md-site-header {
  box-sizing: border-box !important;
  position: relative !important;
  z-index: 9000 !important;
  width: 100% !important;
  min-height: 84px !important;
  padding: 12px max(5vw, 34px) !important;
  display: grid !important;
  grid-template-columns: auto minmax(220px, 1fr) auto !important;
  align-items: center !important;
  gap: 24px !important;
  border: 0 !important;
  border-bottom: 1px solid var(--md-chrome-line) !important;
  border-radius: 0 !important;
  background: linear-gradient(100deg, var(--md-chrome-earth), var(--md-chrome-earth-2) 54%, var(--md-chrome-earth)) !important;
  color: var(--md-chrome-cream) !important;
  box-shadow: 0 7px 24px rgba(47, 27, 18, .16) !important;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif !important;
}

.md-site-header *, .md-site-footer * { box-sizing: border-box; }
.md-site-header a, .md-site-footer a { text-decoration: none !important; }

/* Compatibility hooks are intentionally present for legacy scripts, but
   old page CSS must never turn them into a second menu or search control. */
.md-compat-menu,
.md-compat-search { display: none !important; }

.md-site-menu { position: relative; margin: 0 !important; }
.md-site-menu > summary {
  min-height: 42px;
  padding: 0 15px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid rgba(226, 191, 125, .55);
  border-radius: 999px;
  background: rgba(255, 244, 217, .06);
  color: var(--md-chrome-cream);
  cursor: pointer;
  list-style: none;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
}
.md-site-menu > summary::-webkit-details-marker,
.md-site-search > summary::-webkit-details-marker { display: none; }
.md-menu-bars { width: 17px; display: grid; gap: 3px; }
.md-menu-bars i { display: block; height: 2px; border-radius: 2px; background: var(--md-chrome-gold); }
.md-site-menu > summary em { color: inherit; font-style: normal; }
.md-site-menu > nav {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 10000;
  width: 246px;
  padding: 7px;
  display: grid;
  gap: 1px;
  border: 1px solid rgba(112, 77, 48, .18);
  border-radius: 14px;
  background: var(--md-chrome-paper);
  box-shadow: 0 18px 38px rgba(52, 33, 22, .2);
}
.md-site-menu:not([open]) > nav { display: none !important; }
.md-site-menu > nav > a {
  padding: 7px 13px !important;
  border-radius: 9px;
  color: #4e4033 !important;
  font-size: 15px !important;
  font-weight: 600 !important;
  line-height: 1.4 !important;
}
.md-site-menu > nav > a:hover,
.md-site-menu > nav > a:focus-visible { background: #f1e2c5; color: #7a5527 !important; outline: none; }

.md-site-brand {
  min-width: 0;
  justify-self: start;
  display: flex !important;
  align-items: center;
  gap: 11px;
  color: var(--md-chrome-cream) !important;
}
.md-site-brand img { width: 58px !important; height: 58px !important; object-fit: contain; filter: drop-shadow(0 1px 2px rgba(0,0,0,.22)); }
.md-site-brand span { min-width: 0; display: grid; gap: 2px; }
.md-site-brand b { color: var(--md-chrome-cream) !important; font-size: 22px !important; line-height: 1.2 !important; letter-spacing: .08em; white-space: nowrap; }
.md-site-brand small { color: var(--md-chrome-cream) !important; font-size: 13px !important; letter-spacing: .14em; white-space: nowrap; }

.md-site-actions { justify-self: end; display: flex; align-items: center; gap: 18px; }
.md-site-header .md-site-actions { position: relative; z-index: 2; pointer-events: auto !important; }
.md-site-search { position: relative; }
.md-site-search > summary { width: 42px; height: 42px; position: relative; cursor: pointer; list-style: none; }
.md-site-search > summary::before { content: ""; position: absolute; width: 15px; height: 15px; left: 8px; top: 7px; border: 2px solid var(--md-chrome-cream); border-radius: 50%; }
.md-site-search > summary::after { content: ""; position: absolute; width: 10px; height: 2px; left: 23px; top: 25px; border-radius: 2px; background: var(--md-chrome-cream); transform: rotate(48deg); transform-origin: left center; }
.md-site-search > form {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 10000;
  width: min(340px, 82vw);
  padding: 10px;
  display: flex;
  gap: 8px;
  border-radius: 13px;
  background: var(--md-chrome-paper);
  box-shadow: 0 18px 38px rgba(52, 33, 22, .2);
}
.md-site-search:not([open]) > form { display: none !important; }
.md-site-search input { min-width: 0; flex: 1; padding: 10px 12px; border: 1px solid #dccbaa; border-radius: 8px; color: var(--md-chrome-text); background: white; font: inherit; }
.md-site-search button { padding: 9px 13px; border: 0; border-radius: 8px; background: #a97029; color: white; font: inherit; cursor: pointer; }
.md-site-member {
  position: relative;
  z-index: 3;
  pointer-events: auto !important;
  min-height: 42px;
  padding: 0 18px;
  display: inline-flex !important;
  align-items: center;
  border: 2px solid #c99a4b !important;
  border-radius: 999px !important;
  background: rgba(255, 244, 217, .07) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 244, 217, .08) !important;
  color: var(--md-chrome-cream) !important;
  font-size: 15px !important;
  font-weight: 700 !important;
  white-space: nowrap;
}

footer.md-site-footer {
  display: block !important;
  box-sizing: border-box !important;
  width: 100% !important;
  min-height: 100px !important;
  margin: 0 !important;
  padding: 12px max(28px, calc((100vw - 1320px) / 2)) !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: linear-gradient(100deg, var(--md-chrome-earth), var(--md-chrome-earth-2) 54%, var(--md-chrome-earth)) !important;
  color: var(--md-chrome-cream) !important;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif !important;
}
.md-site-footer-inner { width: 100%; max-width: 1320px; min-height: 76px; margin: auto; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.md-site-footer-brand { min-width: 245px; display: flex !important; align-items: center; gap: 12px; color: var(--md-chrome-cream) !important; }
.md-site-footer-brand img {
  width: 70px !important;
  height: 70px !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  object-fit: contain !important;
  filter: brightness(1.22) saturate(1.18) drop-shadow(0 1px 2px rgba(0,0,0,.18)) !important;
  mix-blend-mode: normal !important;
}
.md-site-footer-brand span { display: grid; gap: 2px; }
.md-site-footer-brand b { color: var(--md-chrome-cream) !important; font-size: 22px !important; line-height: 1.25 !important; letter-spacing: .06em; }
.md-site-footer-brand small { color: var(--md-chrome-cream) !important; font-size: 14px !important; letter-spacing: .08em; }
.md-site-footer-legal { display: flex !important; gap: 22px; }
.md-site-footer-legal a, .md-site-copyright { color: var(--md-chrome-cream) !important; font-size: 15px !important; font-weight: 600 !important; white-space: nowrap; }
.md-site-social { display: flex; align-items: center; gap: 16px; }
.md-site-social a { display: flex !important; align-items: center; gap: 7px; color: var(--md-chrome-cream) !important; font-size: 15px !important; white-space: nowrap; }
.md-site-social img { width: 34px !important; height: 34px !important; object-fit: contain; }

@media (max-width: 1120px) {
  header.md-site-header { grid-template-columns: auto 1fr auto !important; gap: 14px !important; padding-inline: 24px !important; }
  .md-site-footer-inner { flex-wrap: wrap; justify-content: center; gap: 10px 24px; }
  .md-site-footer-brand { min-width: 220px; }
}

@media (max-width: 700px) {
  header.md-site-header { min-height: 72px !important; grid-template-columns: auto 1fr auto !important; padding: 9px 16px !important; }
  .md-site-menu > summary { min-height: 38px; padding: 0 11px; }
  .md-site-menu > summary em { font-size: 14px; }
  .md-site-menu > nav { width: 220px; }
  .md-site-brand { justify-self: center; }
  .md-site-brand img { width: 48px !important; height: 48px !important; }
  .md-site-brand span { display: none; }
  .md-site-actions { gap: 4px; }
  .md-site-search { display: none; }
  .md-site-member { max-width: 118px; min-height: 38px; padding: 0 11px; overflow: hidden; text-overflow: ellipsis; font-size: 13px !important; }
  footer.md-site-footer { padding: 14px 18px !important; }
  .md-site-footer-inner { min-height: 0; flex-direction: column; gap: 11px; }
  .md-site-footer-brand { min-width: 0; }
  .md-site-footer-brand img { width: 58px !important; height: 58px !important; }
  .md-site-footer-legal { gap: 14px; }
  .md-site-footer-legal a, .md-site-copyright { font-size: 13px !important; }
  .md-site-social a span { display: none; }
}

@media (max-width: 420px) {
  header.md-site-header { gap: 8px !important; padding-inline: 10px !important; }
  .md-site-menu > summary em { display: none; }
  .md-site-menu > summary { width: 40px; justify-content: center; padding: 0; }
  .md-site-member { max-width: 105px; }
}

/* v309: desktop footer must remain a compact, single horizontal row.
   The second selector also neutralizes older homepage footer rules while
   cached markup is being replaced by the unified chrome. */
@media (min-width: 701px) {
  footer.md-site-footer,
  footer.mh-footer {
    min-height: 100px !important;
    padding-top: 12px !important;
    padding-bottom: 12px !important;
  }

  footer.md-site-footer > .md-site-footer-inner,
  footer.mh-footer > .mh-footer-main {
    width: 100% !important;
    max-width: 1320px !important;
    min-height: 76px !important;
    margin: 0 auto !important;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: clamp(14px, 2vw, 28px) !important;
  }

  footer.md-site-footer .md-site-footer-brand,
  footer.mh-footer .mh-footer-brand {
    flex: 0 0 auto !important;
    min-width: 220px !important;
    margin: 0 !important;
  }

  footer.md-site-footer .md-site-footer-brand img,
  footer.mh-footer .mh-footer-brand img {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    object-fit: contain !important;
    filter: brightness(1.22) saturate(1.18) drop-shadow(0 1px 2px rgba(0,0,0,.18)) !important;
    mix-blend-mode: normal !important;
  }

  footer.md-site-footer .md-site-footer-legal,
  footer.mh-footer .mh-footer-legal,
  footer.md-site-footer .md-site-social,
  footer.mh-footer .mh-social {
    flex: 0 0 auto !important;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    margin: 0 !important;
  }

  footer.md-site-footer .md-site-copyright,
  footer.mh-footer .mh-footer-copyright {
    flex: 0 0 auto !important;
    margin: 0 !important;
    white-space: nowrap !important;
  }
}

@media (min-width: 701px) and (max-width: 1050px) {
  footer.md-site-footer > .md-site-footer-inner,
  footer.mh-footer > .mh-footer-main { gap: 12px !important; }
  footer.md-site-footer .md-site-footer-brand,
  footer.mh-footer .mh-footer-brand { min-width: 170px !important; }
  footer.md-site-footer .md-site-footer-brand img,
  footer.mh-footer .mh-footer-brand img { width: 54px !important; height: 54px !important; }
  footer.md-site-footer .md-site-footer-legal,
  footer.mh-footer .mh-footer-legal { gap: 12px !important; }
  footer.md-site-footer .md-site-social,
  footer.mh-footer .mh-social { gap: 9px !important; }
  footer.md-site-footer .md-site-footer-legal a,
  footer.md-site-footer .md-site-copyright,
  footer.mh-footer .mh-footer-legal a,
  footer.mh-footer .mh-footer-copyright { font-size: 13px !important; }
  footer.md-site-footer .md-site-social a,
  footer.mh-footer .mh-social a { font-size: 13px !important; }
  footer.md-site-footer .md-site-social img,
  footer.mh-footer .mh-social img { width: 28px !important; height: 28px !important; }
}
/* A twelve-link menu remains fully reachable on shorter viewports. */
.md-site-menu > nav {
  max-height: min(72vh, 620px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
