/* 此刻四柱 is a quiet view in the chart's place: the site header stays, the panel takes the
   board's cell (as the BaZi panel does), and the four pillars lead a single centred column. */
.current-pillars-overlay {
  /* BaZi panel type: glyph, label size and the ratios between glyph, label gap, stem gap and column gap. */
  --cp-glyph: calc(clamp(54px, 5.65vw, 96px) * var(--chart-font-scale, 1));
  --cp-text: calc(clamp(13px, .9vw, 16px) * var(--chart-font-scale, 1));
  --cp-quiet: rgba(98, 102, 109, .82);
  --cp-soft: #4f5359;
  grid-area: 1 / 1;
  position: relative;
  z-index: 90;
  align-self: center;
  justify-self: center;
  width: var(--board-width, 1392px);
  height: var(--board-height, 900px);
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  font-family: var(--taiwei-sans-font, sans-serif);
  color: var(--ink, #171717);
}

.current-pillars-overlay[hidden],
.current-pillars-overlay [hidden] { display: none !important; }

/* Same stage treatment as the BaZi panel: keep geometry, paint only the active view. */
body.has-current-pillars { overflow: hidden; }
/* The study-page cover is fixed, so that page keeps its own height and scroll position. */
body.has-current-pillars:not(.is-study-page) .page-shell { height: 100dvh; overflow: hidden; }
body.has-current-pillars .chart-stage { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); overflow: hidden; }
body.has-current-pillars .board-shell,
body.has-current-pillars .guest-entry { visibility: hidden; pointer-events: none; }
body.has-current-pillars .command-dock { visibility: hidden; opacity: 0; pointer-events: none; }

/* The member study page has no chart cell, so the view covers the page there, below the header
   row so the 太微 logo still leads home (app.js sets --site-header-row-bottom). */
.page-shell > .current-pillars-overlay {
  position: fixed;
  inset: var(--site-header-row-bottom, 0px) 0 auto;
  z-index: 180;
  width: 100%;
  height: calc(100dvh - var(--site-header-row-bottom, 0px));
  max-height: none;
  place-items: center;
  padding: clamp(12px, 3.5vmin, 40px);
  background: var(--bg, #f7f7f8);
}
.page-shell > .current-pillars-overlay .current-pillars-panel {
  width: min(var(--board-width, 1392px), 100%);
  height: min(var(--board-height, 900px), 100%);
}

.current-pillars-panel {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  container: current-pillars / size;
  overflow: hidden;
  border: 1px solid rgba(23, 23, 23, .12);
  border-radius: 6px;
  background: #fff;
  outline: none;
}

/* The header button already names the view; the heading stays for assistive technology. */
.current-pillars-title {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.current-pillars-overlay button,
.current-pillars-overlay input,
.current-pillars-overlay select { font: inherit; }

.current-pillars-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: rgba(98, 102, 109, .72);
  cursor: pointer;
}
.current-pillars-close:hover { color: rgba(23, 23, 23, .86); }

.current-pillars-scroll {
  /* With less content than the BaZi panel, a taller panel lets the pillars grow instead of
     leaving a small cluster in a large field; spacing and small text follow the glyph.
     Browsers without container units keep the BaZi viewport sizes (see @supports below). */
  --cp-size: var(--cp-glyph);
  --cp-small: max(var(--cp-text), min(16px, calc(var(--cp-size) * .18)));
  --cp-label-gap: calc(var(--cp-size) * .186);
  --cp-stem-gap: calc(var(--cp-size) * .372);
  --cp-column-gap: calc(var(--cp-size) * .955);
  --cp-caption-gap: calc(var(--cp-size) * .62);
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  display: grid;
  align-content: safe center;
  justify-items: center;
  padding: 56px 32px;
  scrollbar-width: thin;
}
@supports (width: 1cqw) {
  .current-pillars-scroll { --cp-size: max(var(--cp-glyph), min(12cqh, 7.4cqw, 112px)); padding-inline: clamp(20px, 4cqw, 56px); }
}

.current-pillars-content {
  width: 100%;
  min-width: 0;
  /* Centres where align-content: safe center is unsupported; stays top-aligned when content overflows. */
  margin-block: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
}

.current-pillars-reading {
  display: grid;
  justify-items: center;
  min-width: 0;
  max-width: 100%;
}

.current-pillars-grid {
  display: grid;
  grid-template-columns: repeat(4, min-content);
  justify-content: center;
  column-gap: var(--cp-column-gap);
  user-select: none;
}
.current-pillars-column { display: grid; justify-items: center; min-width: 0; }
.current-pillars-label {
  margin-bottom: var(--cp-label-gap);
  color: var(--cp-quiet);
  font-size: var(--cp-small);
  font-weight: 440;
  line-height: 1.2;
  white-space: nowrap;
}
.current-pillars-character {
  font-family: var(--taiwei-serif-font, serif);
  font-size: var(--cp-size);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
}
.current-pillars-label + .current-pillars-character { margin-bottom: var(--cp-stem-gap); }
/* Element palette of the BaZi panel, including its bright gold. */
.current-pillars-wood { color: rgb(38, 137, 66); }
.current-pillars-fire { color: rgb(198, 49, 42); }
.current-pillars-earth { color: rgb(176, 103, 43); }
.current-pillars-metal { color: #d1a405; }
.current-pillars-water { color: rgb(32, 35, 40); }

/* Two equal four-character labels make one aligned block under the pillars. */
.current-pillars-times {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 1.1em;
  row-gap: .3em;
  margin: var(--cp-caption-gap) 0 0;
  font-size: var(--cp-small);
  line-height: 1.45;
}
.current-pillars-times > div { display: contents; }
.current-pillars-times dt { color: var(--cp-quiet); font-weight: 440; white-space: nowrap; }
.current-pillars-times dd { margin: 0; color: var(--cp-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }

.current-pillars-place {
  min-width: 0;
  max-width: 100%;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 6px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--cp-soft);
  font-size: var(--cp-small) !important;
  line-height: 1.3;
  cursor: pointer;
}
.current-pillars-place:hover { color: rgba(23, 23, 23, .9); }
.current-pillars-place-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.current-pillars-place svg { flex: 0 0 auto; color: var(--cp-quiet); transition: transform .16s ease; }
.current-pillars-place[aria-expanded="true"] svg { transform: rotate(180deg); }

/* Choosing a place is a short separate step: the card takes the reading's place, as on first
   open, so nothing is left half cut by scrolling. Choosing a city returns to the pillars. */
.current-pillars-content:has(> .current-pillars-settings:not([hidden])) > .current-pillars-reading { display: none !important; }
.current-pillars-content:has(> .current-pillars-settings:not([hidden])) > .current-pillars-place { margin-top: 0; }

.current-pillars-clock-error { margin: 0 0 8px; font-size: 13px; color: #62666d; line-height: 1.5; text-align: center; }

.current-pillars-settings {
  width: min(400px, 100%);
  margin-top: 10px;
  padding: 16px;
  border: 1px solid rgba(23, 23, 23, .1);
  border-radius: 6px;
  background: #fff;
  text-align: left;
  font-size: 13px;
}

.current-pillars-locate,
.current-pillars-search-button,
.current-pillars-coordinate-form > button,
.current-pillars-zone-confirm {
  min-height: 40px;
  border: 1px solid #dedfe1;
  border-radius: 4px;
  background: #fff;
  color: #3e4247;
  padding: 8px 12px;
  cursor: pointer;
}
.current-pillars-locate { width: 100%; margin-bottom: 12px; }
.current-pillars-overlay button:disabled { opacity: .55; cursor: default; }
.current-pillars-search-form { display: flex; gap: 8px; }
.current-pillars-search-input { flex: 1; min-width: 0; }

.current-pillars-settings input,
.current-pillars-settings select {
  min-height: 40px;
  min-width: 0;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #dedfe1;
  border-radius: 4px;
  color: #35383d;
  background: #fff;
}

.current-pillars-results { list-style: none; margin: 10px 0 0; padding: 0; }
.current-pillars-results:empty { margin: 0; }
.current-pillars-city {
  width: 100%;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 10px 6px;
  border: 0;
  border-bottom: 1px solid #ececed;
  background: transparent;
  text-align: left;
  overflow-wrap: anywhere;
  color: #30343a;
  cursor: pointer;
}
.current-pillars-city:hover { background: #fafafa; }
.current-pillars-city-detail { font-size: 11px; color: #7a7d83; }
.current-pillars-status { margin: 12px 0 0; font-size: 13px; color: #62666d; line-height: 1.5; }
.current-pillars-coordinates { margin-top: 14px; }
.current-pillars-coordinates summary { padding: 6px 0; color: #757980; cursor: pointer; font-size: 12px; }
.current-pillars-coordinate-form { margin-top: 10px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.current-pillars-coordinate-form label { display: grid; gap: 6px; color: #686c73; font-size: 12px; }
.current-pillars-zone-field,
.current-pillars-coordinate-form > button { grid-column: 1 / -1; }
.current-pillars-zone-field { display: grid; gap: 6px; }
.current-pillars-zone-row { display: flex; gap: 8px; }
.current-pillars-zone-row input { flex: 1; min-width: 0; }
.current-pillars-zone-confirm { flex: 0 0 auto; font-size: 12px !important; }

.current-pillars-settings-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #ececed;
}
.current-pillars-settings-footer label { display: flex; align-items: center; gap: 8px; color: #777b82; font-size: 12px; }
.current-pillars-settings-footer select { width: auto; min-height: 36px; padding: 4px 6px; }
.current-pillars-attribution { display: grid; gap: 3px; text-align: right; }
.current-pillars-settings-footer a { color: #91949a; text-decoration: none; font-size: 10px; }

.current-pillars-overlay :is(button, input, select, summary, a):focus-visible { outline: 2px solid #6b7179; outline-offset: 2px; }
/* Automatic location updates restore focus without painting a pointer-mode frame. */
body:not(.is-keyboard-navigation) .current-pillars-overlay :is(button, summary, a):focus { outline: none; }

@media (max-width: 1180px) {
  .chart-stage > .current-pillars-overlay { align-self: start; }
}

/* Phones get the BaZi panel's card, filling the screen below the header row. */
@media (max-width: 720px) {
  .current-pillars-overlay,
  .page-shell > .current-pillars-overlay {
    /* The phone chart scale only enlarges here (reading mode); it never takes times below 12px. */
    --cp-glyph: calc(clamp(48px, 13.6vw, 58px) * max(1, var(--chart-font-scale, 1)));
    --cp-text: calc(12px * max(1, var(--chart-font-scale, 1)));
    position: fixed;
    inset: var(--site-header-row-bottom, 0px) 0 auto;
    z-index: 180;
    width: 100%;
    height: calc(100dvh - var(--site-header-row-bottom, 0px));
    max-width: none;
    max-height: none;
    padding: max(8px, calc(env(safe-area-inset-top) - var(--site-header-row-bottom, 0px))) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: var(--bg, #f7f7f8);
  }
  .page-shell > .current-pillars-overlay .current-pillars-panel,
  .current-pillars-panel { width: 100%; height: 100%; border-radius: 8px; }
  .current-pillars-close { top: 4px; right: 4px; }
  .current-pillars-scroll {
    --cp-size: var(--cp-glyph);
    --cp-small: max(var(--cp-text), min(15px, calc(var(--cp-size) * .2)));
    --cp-label-gap: max(12px, calc(var(--cp-size) * .2));
    --cp-stem-gap: max(18px, calc(var(--cp-size) * .34));
    --cp-caption-gap: max(34px, calc(var(--cp-size) * .62));
    /* Slightly more room below than above puts the column at the optical centre of a tall card. */
    padding: 48px 16px 96px;
  }
  /* Phone size on phones; a wider card (small tablet, narrow window) grows the column with it. */
  @supports (width: 1cqw) {
    .current-pillars-scroll { --cp-size: max(var(--cp-glyph), min(11cqw, 9cqh, 84px)); }
  }
  .current-pillars-reading { width: min(94%, calc(var(--cp-size) * 6.2)); }
  .current-pillars-grid { width: 100%; grid-template-columns: repeat(4, minmax(0, 1fr)); column-gap: clamp(10px, 3.4vw, 18px); }
  .current-pillars-times { column-gap: 1em; }
  .current-pillars-place { min-height: 44px; margin-top: 8px; font-size: max(calc(13px * max(1, var(--chart-font-scale, 1))), var(--cp-small)) !important; }
  .current-pillars-settings { padding: 12px; }
}

@media (pointer: coarse) {
  .current-pillars-place { min-height: 44px; }
}

/* Short panels (landscape phones, very low windows) shrink the type and gaps, never enlarge them. */
@container current-pillars (max-height: 520px) {
  .current-pillars-scroll { --cp-size: min(var(--cp-glyph), clamp(30px, 13cqh, 64px)); --cp-label-gap: min(12px, 2cqh); --cp-stem-gap: min(18px, 4cqh); --cp-caption-gap: min(34px, 6cqh); padding-block: 24px; }
  .current-pillars-place { margin-top: 2px; }
}

@container current-pillars (max-height: 360px) {
  .current-pillars-scroll { padding-block: 16px; }
}

/* A wide but very low panel puts the times and place beside the pillars rather than below. */
@container current-pillars (max-height: 250px) and (min-width: 540px) {
  .current-pillars-scroll { --cp-size: clamp(30px, 17cqh, 48px); --cp-column-gap: calc(var(--cp-size) * .8); padding: 12px 56px; }
  .current-pillars-content:has(> .current-pillars-reading:not([hidden])):not(:has(> .current-pillars-settings:not([hidden]))) { grid-template-columns: auto auto; grid-template-areas: "pillars times" "pillars place"; justify-content: center; align-items: center; column-gap: clamp(32px, 7cqw, 72px); }
  .current-pillars-content:has(> .current-pillars-reading:not([hidden])):not(:has(> .current-pillars-settings:not([hidden]))) > .current-pillars-reading { display: contents; }
  .current-pillars-content:has(> .current-pillars-reading:not([hidden])):not(:has(> .current-pillars-settings:not([hidden]))) .current-pillars-grid { grid-area: pillars; }
  .current-pillars-content:has(> .current-pillars-reading:not([hidden])):not(:has(> .current-pillars-settings:not([hidden]))) .current-pillars-times { grid-area: times; align-self: end; margin: 0; }
  .current-pillars-content:has(> .current-pillars-reading:not([hidden])):not(:has(> .current-pillars-settings:not([hidden]))) > .current-pillars-place { grid-area: place; align-self: start; justify-self: start; margin: 2px 0 0 -12px; }
}
