/**
 * 天机阁 · 紫微斗数命盘样式（宣纸主题）
 *
 * 经典 4×4 版式：外圈十二宫（按地支定位），中宫放基本信息。
 * 宫位与地支的方位（与排盘引擎一致）：
 *   巳 午 未 申
 *   辰 [ 中宫 ] 酉
 *   卯 [      ] 戌
 *   寅 丑 子 亥
 *
 * 颜色全部取 tianji-paper.css 的 token（body.theme-paper 上可用）。
 */

.zw-chart {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: minmax(138px, auto);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--p-shadow-sm);
}

.zw-cell {
  position: relative;
  background: var(--paper-raised);
  padding: 10px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

/* 方位（地支 → 网格位置） */
.zw-cell[data-branch="巳"] { grid-area: 1 / 1; }
.zw-cell[data-branch="午"] { grid-area: 1 / 2; }
.zw-cell[data-branch="未"] { grid-area: 1 / 3; }
.zw-cell[data-branch="申"] { grid-area: 1 / 4; }
.zw-cell[data-branch="酉"] { grid-area: 2 / 4; }
.zw-cell[data-branch="戌"] { grid-area: 3 / 4; }
.zw-cell[data-branch="亥"] { grid-area: 4 / 4; }
.zw-cell[data-branch="子"] { grid-area: 4 / 3; }
.zw-cell[data-branch="丑"] { grid-area: 4 / 2; }
.zw-cell[data-branch="寅"] { grid-area: 4 / 1; }
.zw-cell[data-branch="卯"] { grid-area: 3 / 1; }
.zw-cell[data-branch="辰"] { grid-area: 2 / 1; }

/* 命宫 / 身宫 高亮 */
.zw-cell.is-soul { background: linear-gradient(180deg, rgba(212, 175, 55, .12), var(--paper-raised) 42%); }
.zw-cell.is-soul .zw-name { color: var(--cinnabar); font-weight: 600; }

.zw-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
}
.zw-branch {
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--gold-deep);
  letter-spacing: .04em;
}
.zw-name { color: var(--ink-2); font-size: 12.5px; }
.zw-body-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 4px;
  color: #fff;
  background: var(--jade);
}

.zw-stars { display: flex; flex-wrap: wrap; gap: 2px 9px; }
.zw-star {
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--ink);
  white-space: nowrap;
}
.zw-star.is-minor { font-size: 12.5px; color: var(--ink-2); }
.zw-star .br { font-size: 10.5px; color: var(--ink-3); margin-left: 1px; }
.zw-star .mut { font-size: 10.5px; margin-left: 2px; font-weight: 600; }
.mut-lu { color: var(--jade); }
.mut-quan { color: var(--gold-deep); }
.mut-ke { color: var(--info, #4a7fa5); }
.mut-ji { color: var(--cinnabar); }

.zw-decadal {
  margin-top: auto;
  font-size: 11.5px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* 中宫：基本信息 */
.zw-center {
  grid-area: 2 / 2 / 4 / 4;
  background: var(--paper-sunken);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  text-align: center;
  min-width: 0;
}
.zw-center .zw-c-name {
  font-family: var(--font-serif);
  font-size: 20px;
  color: var(--ink);
  letter-spacing: .06em;
}
.zw-center .zw-c-sub { font-size: 12.5px; color: var(--ink-3); }
.zw-center .zw-c-meta { font-size: 13px; color: var(--ink-2); line-height: 1.9; }
.zw-center .zw-c-meta b { color: var(--ink); font-weight: 600; }
.zw-center .zw-c-pillars {
  margin-top: 6px;
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--ink);
  letter-spacing: .06em;
}
.zw-center .zw-c-pillars span { margin: 0 3px; }
.zw-center .zw-c-tag {
  display: inline-block;
  margin: 2px 3px 0;
  font-size: 11.5px;
  padding: 1px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--gold-deep);
}

.zw-legend {
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--ink-3);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  align-items: center;
}
.zw-legend b { color: var(--ink-2); font-weight: 500; }

@media (max-width: 720px) {
  .zw-chart { grid-auto-rows: minmax(120px, auto); }
  .zw-cell { padding: 8px 9px 6px; }
  .zw-star { font-size: 13px; }
  .zw-star.is-minor { font-size: 11.5px; }
  .zw-branch { font-size: 14px; }
  .zw-center .zw-c-name { font-size: 17px; }
}

/* ================= 排盘推演遮罩（表单提交 → 结果页之间的转场） ================= */
.zw-cast {
  position: fixed; inset: 0; z-index: 120;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 44%, #1b2338 0%, #0d1220 72%);
  color: #e9e2d0; opacity: 0;
  transition: opacity .45s var(--p-ease);
}
.zw-cast.is-active { opacity: 1; }
.zw-cast.is-out { opacity: 0; }
.zw-cast-inner {
  position: relative; width: 300px; height: 300px;
  display: grid; place-items: center;
}
.zw-cast-ring { position: absolute; inset: 0; animation: zwCastSpin 40s linear infinite; }
.zw-cast-cell {
  position: absolute; left: 50%; top: 50%;
  transform: rotate(var(--a)) translateY(-132px) rotate(calc(-1 * var(--a)));
  width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center;
  font-family: var(--font-serif); font-size: 14px;
  color: rgba(233, 226, 208, .5);
  border: 1px solid rgba(212, 175, 55, .28);
  background: rgba(255, 255, 255, .02);
  opacity: 0; animation: zwCastCell .5s var(--p-ease) forwards;
  animation-delay: calc(var(--i, 0) * .09s);
}
.zw-cast-core {
  position: absolute; width: 92px; height: 92px; border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle, rgba(212, 175, 55, .28), rgba(212, 175, 55, 0) 70%);
  border: 1px solid rgba(212, 175, 55, .5);
}
.zw-cast-star {
  font-family: var(--font-serif); font-size: 40px; color: #e9c96a;
  text-shadow: 0 0 18px rgba(212, 175, 55, .7);
  animation: zwCastPulse 1.8s ease-in-out infinite;
}
.zw-cast-title {
  position: absolute; top: -58px; left: 50%; transform: translateX(-50%);
  font-family: var(--font-serif); font-size: 17px; letter-spacing: .3em;
  color: rgba(233, 226, 208, .78); white-space: nowrap;
}
.zw-cast-steps {
  position: absolute; bottom: -56px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; white-space: nowrap;
}
.zw-cast-step {
  font-size: 12px; letter-spacing: .1em; color: rgba(233, 226, 208, .38);
  opacity: 0; animation: zwCastStep .4s var(--p-ease) forwards;
  animation-delay: calc(var(--i, 0) * .28s + .2s);
}
.zw-cast-step.is-now { color: #e9c96a; }

@keyframes zwCastSpin { to { transform: rotate(360deg); } }
@keyframes zwCastCell { from { opacity: 0; } to { opacity: 1; } }
@keyframes zwCastStep { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes zwCastPulse {
  0%, 100% { opacity: .75; transform: scale(.96); }
  50% { opacity: 1; transform: scale(1.05); }
}

@media (max-width: 480px) {
  .zw-cast-inner { width: 250px; height: 250px; }
  .zw-cast-cell { transform: rotate(var(--a)) translateY(-108px) rotate(calc(-1 * var(--a))); }
  .zw-cast-steps { gap: 7px; }
  .zw-cast-step { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .zw-cast { display: none !important; }
}
