/* ---------- 页面切换过渡（跨文档视图过渡） ----------
   点链接跳页时整体淡入淡出，不再「白一下」。
   Chrome / Edge / Safari 18.2+ 支持，其它浏览器自动忽略。 */
@view-transition { navigation: auto; }
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: .22s;
}
/* 紫微斗数排盘 —— 网站版样式
 *
 * 版式对照小程序 sky.wxss：
 *   宫位 = view_top（星曜区） + view_center（长生） + bottom（底部三栏）
 *   bottom 三栏 = bottom_left（博士/岁前/将前，竖排三行）
 *               + bottom_center（流年/年宫/运宫/宫名，竖排）
 *               + bottom_right（流月/天干/地支，竖排）
 * 三栏内部都是块级元素自然竖排，不依赖 flex 方向。
 *
 * 容器按 750px 设计，1rpx ≈ 1px（小屏会等比缩窄）
 */

:root {
  --line: #979797;
  --main: #c00b22;    /* 主星 */
  --aux: #9940e6;     /* 辅星 */
  --sha: #307ad2;     /* 煞星 */
  --normal: #888;     /* 杂曜 */
  --boshi: #3fbebb;
  --lu: #66a81f;
  --quan: #cf45ec;
  --ke: #4492ee;
  --ji: #ff5146;
}

* { box-sizing: border-box; }

/* 跟博客一套的宣纸底纹：两层固定图层，正文压在上面 */
body {
  margin: 0;
  padding: 0;
  background: #f7f4ee;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  color: #222;
}

/* 宣纸底纹：固定图层 + 一层纸白纱，和博客一致 */
body::before{
  content:"";position:fixed;inset:0;z-index:-2;
  background:#f2ece1 url(img/paper.jpg) center/cover no-repeat;
}
body::after{
  content:"";position:fixed;inset:0;z-index:-1;pointer-events:none;
  background:rgba(250,247,241,.70);
}

.wrap { max-width: 782px; margin: 0 auto; padding: 0 16px; }

/* ---------- 顶部信息栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; }
.btn {
  display: inline-block; padding: 7px 14px; border-radius: 6px;
  background: #c00b22; color: #fff; text-decoration: none; font-size: 13px;
  border: 0; cursor: pointer;
}
.btn.ghost { background: #fff; color: #c00b22; border: 1px solid #c00b22; }
.btn.mini { padding: 6px 14px; font-size: 13px; }

/* ---------- 视图切换 ---------- */
.viewbar { display: flex; gap: 6px; margin: 10px 0 10px; flex-wrap: nowrap; }
.vtab {
  flex: 1 1 0; min-width: 0;
  padding: 7px 4px; border-radius: 6px; background: #fff; color: #555;
  text-decoration: none; font-size: 13px; border: 1px solid #e2e2e2;
  text-align: center; white-space: nowrap;
}
.vtab.on { background: #c00b22; color: #fff; border-color: #c00b22; }

/* ---------- 运限选择 ---------- */
.picker {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #fff; border: 1px solid #e6e6e6; border-radius: 8px;
  padding: 9px 12px; margin-bottom: 10px; font-size: 13px;
}
.picker label { color: #666; }
.picker select {
  padding: 6px 8px; border: 1px solid #ddd; border-radius: 5px;
  font-size: 13px; background: #fff; max-width: 100%;
}
.picker .staropt { display: inline-flex; align-items: center; gap: 4px; color: #666; }
.picker .staropt label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

.headinfo {
  background: #fff8f8; border: 1px solid #f0d8d8; color: #a0392f;
  border-radius: 6px; padding: 8px 12px; margin: 12px 0 10px;
  /* 字号随页面宽度自动缩小，保证永远一行：--n 是这一行的字数（由 PHP 输出） */
  font-size: 13px;
  font-size: min(13px, calc((100vw - 44px) / var(--n, 30)));
  white-space: nowrap; overflow: hidden;
}

/* ---------- 盘面 ----------
   固定 750px 画布，等价于小程序的 750rpx；
   屏幕更窄时由页面脚本整体等比缩放，字号和格线一起缩，不会「乱套」 */
.pan-outer { overflow: hidden; }
.pan-wrap { width: 750px; transform-origin: top left; }

.pan {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, minmax(178px, auto));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: #fff;
}

.palace {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 4px 2px 3px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;      /* 右侧竖列绝对定位的参照 */
}
.palace.hl { background: #fffdf0; }
.palace.dx { background: #f6fff6; box-shadow: inset 0 0 0 2px #66a81f; }

/* 星曜区 */
.p-top {
  position: relative;            /* 右侧带的定位参照 */
  flex: 0 0 auto; display: flex; gap: 0;   /* 星列之间不留缝，宽度全给星，防止末位星挤出去 */
  align-items: flex-start; min-height: 132px;
  font-size: var(--s, 20px);       /* 基准字号，星多的宫会被 --s 缩小 */
}
/* 按星数动态缩小（对应小程序 setTextSize） */
.palace.sz2 { --s: 18px; }
.palace.sz3 { --s: 16px; }
.palace.sz4 { --s: 15px; }
.palace.sz5 { --s: 13px; }

.sgroup { display: flex; gap: 0; }
/* 一颗星 = 一个窄列：星名 / 庙陷 / 本命四化 / 大运四化 / 流年四化 依次向下 */
.star {
  width: 1em;          /* 与小程序的 width:21rpx + font-size:21rpx 同比例，1 个汉字宽 */
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: inherit;
  letter-spacing: 0;
}
.star .nm {
  width: 100%;
  word-break: break-all;      /* 逐字换行 → 竖排 */
  text-align: center;
  line-height: 1.28;
  border-radius: 2px;
}
.miao {
  font-size: 0.82em;
  line-height: 1.2;
  color: #999;
  margin-top: 0.12em;
}
.s-main { color: var(--main); }
.s-aux  { color: var(--aux); }
.s-sha  { color: var(--sha); }
.s-normal { color: var(--normal); }

/* 流月四化：星名底色（对应小程序 item.star==day_lu 等四种背景） */
.shbg-禄 { background: #66a81f; color: #fff; }
.shbg-权 { background: #cf45ec; color: #fff; }
.shbg-科 { background: #4492ee; color: #fff; }
.shbg-忌 { background: #ff5146; color: #fff; }

/* 本命 / 大限 / 流年 四化：星名下方的小方块，用颜色区分层级 */
.sh {
  font-size: 0.8em;
  font-weight: 400;
  color: #fff;
  border-radius: 2px;
  width: 1.35em;
  height: 1.3em;
  line-height: 1.3em;
  margin: 0.1em auto 0;
  text-align: center;
  letter-spacing: 0;
}
.sh-ming { background: #ff5146; }   /* 本命 红 */
.sh-yun  { background: #66a81f; }   /* 大运 绿 */
.sh-nian { background: #4492ee; }   /* 流年 蓝 */

/* 运星 / 年星：靠右的窄竖列（对应小程序 view_center_right 里的 view_star_yun / view_star_nian）
   每个标签两字竖排，多个标签自上而下叠 */
/* 横排的窄列：每个标签自己竖着写两字，多个标签并排右对齐
   —— 对应小程序 .text_green_20{display:flex;justify-content:flex-end} */
.p-labels {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  gap: 1px;
  font-size: 12px;   /* 固定字号，各宫一致 */
  line-height: 1.05;
  text-align: center;
}
.p-labels .nl { color: #4492ee; }   /* 年星蓝，对应 view_star_nian */
.p-labels .yl { color: #2f8f2f; }   /* 运星绿，对应 view_star_yun */
.p-labels > span {
  display: block;
  width: 1.05em;
  word-break: break-all;
  text-align: center;
}

/* 中段：流日块居中 + 右侧竖列（年星/运星/长生，对应小程序 view_center_right） */
.p-mid { position: relative; min-height: 1.4em; }
/* 右侧带：浮在星曜区内部右下角，不占文档流高度
   （对应小程序 view_center { float:right; margin-top:-88rpx }） */
.p-side {
  position: absolute; right: 2px; bottom: 1px;
  text-align: right;
  line-height: 1.1;
  z-index: 1;
}
.p-day {
  /* 整体压在年宫上面一排：年宫占中段本来的位置，日财和四化被顶上去 */
  position: absolute; left: 0; right: 0; bottom: 100%;
  text-align: center;
  line-height: 1.35;
  white-space: nowrap;
  font-size: 16px;   /* 与流月宫名同号，固定不缩放 */
}
/* 流年宫名：浮在中段（日财正下方、运宫正上方），不参与底栏排版 */
.p-nian {
  /* 贴在整组正上方：盒底正好压在「运宫」的盒顶，
     间距和「运宫→宫名」一致，看着就齐了 */
  position: absolute; left: 0; right: 0; bottom: 100%;
  text-align: center; line-height: 1.45;
  font-size: 19px; color: #2b6fbf;
}
/* 流日宫名：灰色小字，不抢眼；位置固定不动 */
.p-day .dname { font-weight: 400; color: #9a9a9a; }
/* 流日四化：绝对定位到宫名「上方一格」，不再把宫名顶下去 */
.p-day .dsihua {
  position: absolute; left: 0; right: 0; bottom: 100%;
  line-height: 1.15; margin-bottom: 1px;
}
.p-day .dsihua > span {
  display: inline; font-size: 1.4em; font-weight: 700;
  margin: 0 1px; letter-spacing: 0;
}
.d-禄 { color: #4f8a13; }
.d-权 { color: #a626c6; }
.d-科 { color: #2a6fc7; }
.d-忌 { color: #d63a2f; }
.changsheng { font-size: 14px; color: #999; line-height: 1.15; }

/* ---------- 底部三栏 ---------- */
.p-bottom {
  margin-top: 4px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 2px;
}

/* 左：博士 / 岁前 / 将前 —— 三行竖排（小程序 bottom_left 是三个块级 view） */
.p-six {
  font-size: 15px;
  color: #999;
  line-height: 1.3;
  text-align: left;
  white-space: nowrap;
}
.p-six > div { display: block; }   /* 三个块级 div，天然竖排 */
.p-six .boshi { color: var(--boshi); }

/* 中：流年 / 年宫 / 运宫 / 流月 / 宫名 —— 竖排 */
.p-mid2 {
  position: relative;   /* 年宫绝对定位的参照 */
  font-size: 19px;
  line-height: 1.45;
  text-align: center;
  min-width: 0;
  padding: 0 1px;
}
.p-mid2 > div { display: block; }
/* 年宫、运宫仍竖排（年在上、运在下），只是比宫名小一号：
   三行（年/运/宫名）合起来正好等于左栏三行的高度，
   切到流年/流月/流日时底栏不再被撑高。 */
.gong2 { color: #1f7a1f; }
.gong2.nian { color: #2b6fbf; }
.gong2.yue { color: #c46a12; }
.month2 { color: #ed8129; font-size: 16px; }
.p-name { font-size: 19px; color: #d00; }
.p-name .shen { font-size: 13px; font-weight: 400; }

/* 右：流月 / 天干 / 地支 —— 竖排 */
.p-ganzhi {
  font-size: 19px;
  line-height: 1.05;  /* 多出的流月行不额外占高 */
  text-align: right;
  white-space: nowrap;
}
.p-ganzhi > * { display: block; }

/* ---------- 中心面板 ---------- */
.center {
  grid-area: 2 / 2 / 4 / 4;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  font-size: 18px;
  color: #4a4a4a;
  display: flex;
  flex-direction: column;
}
.center .row { line-height: 1.85; }
.center .nm { font-size: 22px; font-weight: 400; color: #222; }
.center .nm .tag {
  font-size: 14px; font-weight: 400; color: #c00b22;
  border: 1px solid #f0c0c0; border-radius: 3px; padding: 0 5px; margin-left: 8px;
}
/* 星系那一行：黄色记号笔划一下。月运要结合星系看，很多人找不到这行 */
.center .row.galaxy{
  width: fit-content; max-width: 100%;
  padding: 0 10px; margin-left: -10px;
  background: url(marker.webp) center / 100% 100% no-repeat;
}
/* 星系行末尾的「免费月运」入口 */
.center .yx-link{
  margin-left: 8px; font-size: 15px; color: #c00b22;
  text-decoration: none; border-bottom: 1px solid rgba(192,11,34,.28);
  white-space: nowrap;
}
.center .yx-link:hover{ border-bottom-color: #c00b22; }
.center .lbl { color: #888; }
.center .pv {
  /* 命宫 / 星系 的结论：跟正文同色即可。
     星系那行已经有荧光笔底，本身就是重点，再加粗会和中宫其它行不协调。 */
  color: inherit;
}
/* 中宫：上一/下一 翻页按钮 */
/* 两个按钮居中，中间空开约半个按钮宽（40px） */
.center .c-nav{ display:flex; justify-content:center; gap:40px; margin-top:12px; }
.center .c-btn{
  flex:0 0 auto; padding:2px 12px; border:1px solid #dcdcdc; border-radius:4px;
  font-size:15px; line-height:1.7; color:#666; text-decoration:none;
  background:#fff; transition:.15s;
}
.center .c-btn:hover{ color:#c00b22; border-color:#f0c0c0; background:#fff7f8; }
.center .c-btn.off{ color:#cfcfcf; border-color:#eee; background:transparent; cursor:default; }

.center .sihua-legend {
  margin-top: auto; padding-top: 12px;
  display: flex; gap: 12px; font-size: 14px; color: #666;
}
.center .sihua-legend i {
  display: inline-block; width: 13px; height: 13px; border-radius: 2px;
  vertical-align: -2px; margin-right: 4px;
}
.layerbox {
  background: #f7f7f7; border-radius: 5px; padding: 5px 8px;
  margin-top: 6px; font-size: 12px; color: #555;
}

/* ---------- 表单 ---------- */
.card {
  background: #fff; border-radius: 10px; padding: 22px 24px 26px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); max-width: 560px; margin: 24px auto;
}
.card h2 { margin: 0 0 4px; font-size: 19px; }
.card .sub { color: #888; font-size: 13px; margin-bottom: 20px; }
.field { margin-bottom: 15px; }
.field > label { display: block; font-size: 13px; color: #555; margin-bottom: 6px; }
.field input[type=text], .field input[type=date], .field input[type=time], .field select {
  width: 100%; padding: 8px 10px; border: 1px solid #ddd; border-radius: 6px;
  font-size: 14px; background: #fff; color: #222;
}
.row3 { display: flex; gap: 8px; }
.row3 > * { flex: 1; min-width: 0; }
.radio { display: flex; gap: 16px; font-size: 14px; }
.radio label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.hint { font-size: 12px; color: #999; margin-top: 6px; line-height: 1.6; }
.submit { width: 100%; padding: 11px; font-size: 15px; }

.err {
  background: #fff3f3; border: 1px solid #f3c0c0; color: #b00;
  padding: 10px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 14px;
}

/* ---------- 打印 ---------- */
@media print {
  body { background: #fff; padding: 0; }
  .noprint { display: none !important; }
  .pan { page-break-inside: avoid; }
}

/* ---------- 窄屏 ---------- */
@media (max-width: 780px) {
  /* 窄屏不再改字号：整张盘由脚本等比缩放（等价于小程序的 rpx） */
  .wrap { padding: 0 10px; }
}



/* 中宫图例：禄权科忌 色块 */
.sihua-legend.legend2 { margin-top: 2px; gap: 8px; flex-wrap: wrap; }
.sihua-legend .lgcap { color: #999; }
.sihua-legend .sw { background: #ccc; }
.sihua-legend .sw-禄 { background: #66a81f; }
.sihua-legend .sw-权 { background: #cf45ec; }
.sihua-legend .sw-科 { background: #4492ee; }
.sihua-legend .sw-忌 { background: #ff5146; }

/* ---------- 保存栏（登录后可保存） ---------- */
.savebar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #fff; border: 1px solid #e8e8e8; border-radius: 8px;
  padding: 10px 14px; margin: 0 0 12px; font-size: 13px; color: #666;
}
.savebar select {
  padding: 6px 10px; border: 1px solid #ddd; border-radius: 6px;
  font-size: 13px; background: #fff;
}
.savebar .savehint { color: #aaa; font-size: 12px; }
.savebar .btn.mini { padding: 7px 18px; font-size: 13px; }

/* 流日四化的图例：用文字颜色，不是底色 */
.sihua-legend .dt {
  display: inline-block; min-width: 13px; text-align: center;
  font-weight: 700; font-size: 13px;
}
.sihua-legend .dt.d-禄 { color: #4f8a13; }
.sihua-legend .dt.d-权 { color: #a626c6; }
.sihua-legend .dt.d-科 { color: #2a6fc7; }
.sihua-legend .dt.d-忌 { color: #d63a2f; }

/* 出生日期 + 时辰 同一行 */
.field-row { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.field-row > .grow { flex: 1 1 220px; min-width: 0; }
.field-row > .fixed { flex: 0 0 132px; }
.field-row input[type=date], .field-row input[type=time], .field-row select { width: 100%; }
@media (max-width: 420px) {
  .field-row > .fixed { flex: 1 1 100%; }
}

/* 排盘页：盘面别贴着导航，上下留一点气口 */
.wrap-chart { padding-top: 14px; padding-bottom: 22px; }
@media (max-width: 480px) { .wrap-chart { padding-top: 10px; padding-bottom: 18px; } }
@media print { .wrap-chart { padding: 0; } }
