:root {
  --bg: #0b0e14;
  --bg-2: #121724;
  --panel: #151b27;
  --input: #1c2331;
  --line: rgba(255,255,255,.08);
  --text: #f3f5f8;
  --muted: #8b93a7;
  --gold: #e0b34e;
  --gold-2: #c9962f;
  --blue: #4d8dff;
  --ok: #3dbe8a;
  --err: #e07272;
  --serif: "Noto Serif SC", "Songti SC", serif;
  --sans: "Noto Sans SC", "PingFang SC", sans-serif;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(900px 420px at 50% -10%, rgba(224,179,78,.12), transparent 60%),
    radial-gradient(700px 360px at 100% 20%, rgba(77,141,255,.08), transparent 55%),
    var(--bg);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--gold); text-decoration: none; }
a:hover { color: #f0c86a; }

.top {
  max-width: 920px; margin: 0 auto; padding: .9rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  position: sticky; top: 0; z-index: 20;
  background: rgba(11,14,20,.82); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.logo {
  display: flex; align-items: center; gap: .55rem; color: inherit; text-decoration: none;
}
.logo-box {
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; border-radius: 3px; padding: .15rem .3rem; line-height: 0;
}
.site-logo-img {
  display: block; height: 28px; width: auto; max-width: 118px; object-fit: contain;
}
.logo-sub {
  color: #fff; font-size: .95rem; font-weight: 600; letter-spacing: .08em; white-space: nowrap;
}
.top nav { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; }
.top nav a { color: var(--muted); }
.top nav a.on, .top nav a:hover { color: var(--text); }
.top .pill {
  color: var(--bg) !important; background: var(--gold); padding: .35rem .8rem;
  border-radius: 999px; font-weight: 600;
}
.nav-toggle {
  display: none; background: var(--input); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: .35rem .55rem; font-size: 1.1rem;
}
.who { color: var(--muted); font-size: .9rem; }
.inline { display: inline; margin: 0; }
.linkish {
  background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0;
}
.linkish.danger { color: var(--err); }

.wrap { max-width: 920px; margin: 0 auto; padding: 1rem 1rem 2.5rem; }
.foot {
  max-width: 920px; margin: 0 auto; padding: 1rem 1rem 2rem;
  color: var(--muted); font-size: .85rem; text-align: center;
}
.flash-bar, .flash {
  max-width: 920px; margin: .75rem auto; padding: .7rem .9rem; border-radius: 10px;
}
.flash-bar { margin-left: 1rem; margin-right: 1rem; }
.flash.ok, .flash-bar.ok { background: rgba(61,190,138,.12); color: var(--ok); }
.flash.error, .flash-bar.error { background: rgba(224,114,114,.12); color: var(--err); }

.hero-panel { max-width: 560px; margin: .5rem auto 1.5rem; }
.hero-copy { text-align: center; margin-bottom: 1.1rem; }
.hero-copy h1 {
  font-family: var(--serif); font-size: clamp(1.8rem, 6vw, 2.4rem);
  margin: 0 0 .55rem; letter-spacing: .08em; font-weight: 700;
}
.hero-desc { margin: 0 auto; color: var(--muted); max-width: 28rem; font-size: .95rem; }

.panel-card, .auth-card {
  background: linear-gradient(180deg, #171e2c 0%, var(--panel) 100%);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.15rem 1.1rem 1.25rem;
}
.panel-title {
  margin: 0 0 1rem; font-size: 1.05rem; font-weight: 600; color: var(--text);
}
.field { display: grid; gap: .4rem; margin-bottom: .95rem; }
.field > span { color: var(--muted); font-size: .88rem; }
.field input, .field select, .stack input {
  width: 100%; appearance: none; color: var(--text); background: var(--input);
  border: 1px solid var(--line); border-radius: 10px; padding: .75rem .8rem; font: inherit;
}
.field input:focus, .field select:focus, .stack input:focus {
  outline: 1px solid rgba(224,179,78,.45); border-color: rgba(224,179,78,.45);
}
.row-3, .row-2 { display: grid; gap: .55rem; }
.row-3 { grid-template-columns: 1.2fr .9fr .9fr; }
.row-2 { grid-template-columns: 1fr 1fr; }
.time-hint { margin: .35rem 0 0; color: var(--gold); font-size: .86rem; }
.check-row {
  display: flex; gap: .55rem; align-items: flex-start; color: var(--muted);
  font-size: .88rem; margin: 0 0 1rem;
}
.check-row input { margin-top: .2rem; accent-color: var(--gold); }

.gender-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.gender-btn {
  border: 1px solid var(--line); background: var(--input); color: var(--text);
  border-radius: 12px; padding: .85rem .5rem; font: inherit; cursor: pointer;
}
.gender-btn.on {
  border-color: var(--blue); box-shadow: inset 0 0 0 1px rgba(77,141,255,.45);
  background: rgba(77,141,255,.12);
}
#gender-female.on {
  border-color: #e29bb0; box-shadow: inset 0 0 0 1px rgba(226,155,176,.45);
  background: rgba(226,155,176,.12);
}

.btn-gold {
  width: 100%; border: 0; border-radius: 12px; padding: .95rem 1rem;
  background: linear-gradient(180deg, #ecc36a 0%, var(--gold) 45%, var(--gold-2) 100%);
  color: #1a1408; font: inherit; font-weight: 700; letter-spacing: .04em; cursor: pointer;
  box-shadow: 0 10px 24px rgba(224,179,78,.25);
}
.btn-gold:hover { filter: brightness(1.05); }
.btn-ghost {
  border: 1px solid var(--line); background: transparent; color: var(--text);
  border-radius: 10px; padding: .55rem .9rem; font: inherit; cursor: pointer;
}
.btn-ghost:disabled { opacity: .4; cursor: not-allowed; }
.form-actions-secondary {
  margin-top: .85rem; display: flex; flex-wrap: wrap; gap: .65rem; align-items: center;
}
.hint { margin: 0; color: var(--muted); font-size: .84rem; }
.lead { color: var(--muted); }
.stack { display: grid; gap: .85rem; }
.auth-card { max-width: 420px; margin: 1.5rem auto; }
.auth-card h1, .section-head h1 {
  font-family: var(--serif); margin: 0 0 .4rem; letter-spacing: .06em;
}
.section-head p { color: var(--muted); margin: 0 0 1rem; }

.chart-result { margin-top: 1.25rem; animation: rise .45s ease both; }
.chart-guide-row {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  margin-bottom: .75rem; flex-wrap: wrap;
}
.ai-tip {
  margin: 0; flex: 1; min-width: 200px; color: var(--muted); font-size: .9rem;
  background: rgba(224,179,78,.08); border: 1px solid rgba(224,179,78,.2);
  border-radius: 10px; padding: .65rem .8rem;
}
.ai-tip strong { color: var(--gold); font-weight: 600; }
.txt-red { color: #ff4d4f !important; }
.btn-save-shot {
  border: 1px solid #ff4d4f; border-radius: 10px; padding: .7rem 1.1rem; white-space: nowrap;
  background: rgba(255,77,79,.12); color: #ff4d4f !important;
  font: inherit; font-weight: 700; cursor: pointer;
}
.btn-save-shot:hover { background: rgba(255,77,79,.2); }
.btn-save-shot:disabled { opacity: .45; cursor: not-allowed; }
.chart-capture {
  position: relative;
  background: #0b0e14; border: 1px solid var(--line); border-radius: 12px;
  padding: .75rem; padding-top: 2.75rem;
}
.chart-top-line {
  display: block; margin-bottom: .65rem;
}
/* 固定钉在命盘容器右上角，避免换行落到左侧 */
.shot-top-brand {
  position: absolute; top: .65rem; right: .75rem; z-index: 8;
  text-align: right; max-width: 46%;
  pointer-events: none;
}
.shot-footer-title {
  display: block; font-family: var(--serif); font-size: .98rem; color: var(--gold);
  letter-spacing: .12em; font-weight: 700; line-height: 1.2;
}
.shot-footer-url {
  display: block; margin-top: .12rem; font-size: .72rem; color: #9aa3b5;
  word-break: break-all; line-height: 1.25;
}
.shot-status { margin-top: .55rem; }
.chart-meta {
  display: flex; flex-wrap: wrap; gap: .45rem .85rem;
  color: var(--muted); font-size: .9rem; padding-right: 0;
}
.chart-meta strong { color: var(--text); font-weight: 600; }
.chart-board-scroll {
  width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: .25rem;
}
.chart-board {
  display: grid; gap: .45rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  min-width: 0;
}
.mobile-chart-hint {
  display: none; margin: .45rem 0 0; color: var(--muted); font-size: .78rem; text-align: center;
}
.palace {
  min-height: 132px; background: rgba(28,35,49,.92); border: 1px solid var(--line);
  border-radius: 10px; padding: .5rem .55rem;
}
.palace.is-ming { outline: 2px solid var(--gold); outline-offset: -2px; }
.palace.center-palace {
  display: flex; flex-direction: column; justify-content: center; gap: .3rem;
  background: rgba(21,27,39,.98); z-index: 2; color: var(--muted); font-size: .88rem;
}
.palace-name {
  font-family: var(--serif); font-size: .92rem; margin: 0 0 .2rem;
  display: flex; justify-content: space-between; gap: .35rem; color: var(--text);
}
.palace-branch { font-size: .75rem; color: var(--muted); font-family: var(--sans); }
.stars { display: flex; flex-wrap: wrap; gap: .22rem; margin-top: .25rem; }
.star {
  font-size: .74rem; padding: .1rem .28rem; border-radius: .25rem;
  background: rgba(255,255,255,.06);
}
.star.major { background: rgba(224,179,78,.16); color: #f2d48a; font-weight: 600; }
.star .sihua { color: #ff8e7a; margin-left: .12rem; font-weight: 700; }

.history-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .65rem; }
.history-list li {
  display: flex; justify-content: space-between; gap: .8rem; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .85rem 1rem;
}
.history-list strong { display: block; font-family: var(--serif); }
.history-list span, .history-list time { display: block; color: var(--muted); font-size: .84rem; }
.row-actions { display: flex; gap: .55rem; align-items: center; }
.empty { color: var(--muted); }

.page-install { display: grid; place-items: center; min-height: 100vh; padding: 1rem; background: var(--bg); color: var(--text); }
.install-card { width: min(440px, 100%); }
.brand-mark { color: var(--gold); letter-spacing: .18em; font-family: var(--serif); }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* 保存预览弹层：默认隐藏，.is-open 才显示（避免 hidden 被 display:flex 顶掉） */
.share-modal {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.72); display: none; align-items: flex-end; justify-content: center;
  padding: 0;
}
.share-modal.is-open { display: flex; animation: rise .25s ease both; }
.share-sheet {
  width: min(520px, 100%); max-height: min(92vh, 860px); overflow: auto;
  background: #151b27; border: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 1rem 1rem 1.25rem; box-shadow: var(--shadow);
  position: relative; z-index: 1001;
}
.share-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.share-head h3 { margin: 0; font-family: var(--serif); font-size: 1.15rem; }
.share-close {
  border: 0; background: rgba(255,255,255,.08); color: #fff; width: 2rem; height: 2rem;
  border-radius: 999px; font-size: 1.35rem; line-height: 1; cursor: pointer;
}
.share-desc { margin: .45rem 0 .75rem; color: var(--muted); font-size: .88rem; }
.share-preview-wrap {
  background: #0b0e14; border: 1px solid var(--line); border-radius: 12px;
  padding: .45rem; margin-bottom: .85rem; text-align: center; min-height: 120px;
}
.share-preview-wrap img {
  max-width: 100%; max-height: 42vh; border-radius: 8px; vertical-align: middle;
}
.share-actions { display: grid; gap: .55rem; }
.share-btn {
  display: block; width: 100%; text-align: center; text-decoration: none; border-radius: 12px;
  padding: .85rem .9rem; font: inherit; font-weight: 700; cursor: pointer;
  border: 1px solid var(--line); background: var(--input); color: var(--text);
}
.share-btn.primary {
  border-color: #ff4d4f; background: rgba(255,77,79,.14); color: #ff4d4f;
}
.share-tip {
  margin: .75rem 0 0; color: var(--muted); font-size: .8rem; line-height: 1.45;
}

@media (max-width: 720px) {
  .nav-toggle { display: inline-flex; }
  .top nav {
    display: none; width: 100%; flex-direction: column; align-items: flex-start;
    padding: .4rem 0 .2rem;
  }
  .top nav.open { display: flex; }
  .top { flex-wrap: wrap; }
  /* 手机保持传统 4×4 方盘，可横滑，避免挤成细长条 */
  .chart-board {
    min-width: 680px !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    grid-template-rows: repeat(4, minmax(118px, auto)) !important;
  }
  .palace { min-height: 118px; }
  .palace.center-palace { font-size: .8rem; }
  .mobile-chart-hint { display: block; }
  .history-list li { flex-direction: column; align-items: flex-start; }
  .chart-guide-row { align-items: stretch; }
  .btn-save-shot { width: 100%; }
  .chart-capture { padding-top: 3rem; }
  .shot-top-brand { top: .55rem; right: .55rem; max-width: 48%; }
  .shot-footer-title { font-size: .88rem; }
  .shot-footer-url { font-size: .66rem; }
  .site-logo-img { height: 24px; max-width: 96px; }
  .logo-sub { font-size: .85rem; }
  .share-modal.is-open { align-items: flex-end; }
  .share-sheet { border-radius: 18px 18px 0 0; }
}
@media (min-width: 721px) {
  .share-modal.is-open { align-items: center; padding: 1rem; }
  .share-sheet { border-radius: 16px; }
}
@media (max-width: 420px) {
  .row-3 { grid-template-columns: 1fr; }
  .hero-panel { margin-top: .2rem; }
  .panel-card { padding: 1rem .85rem 1.1rem; }
}
