:root {
  --bg: #0c0b10;
  --panel: #14131a;
  --panel-2: #1d1b24;
  --line: rgba(216, 184, 117, .22);
  --gold: #d9b76e;
  --gold-soft: #f0d79c;
  --text: #f5eedc;
  --muted: #b9ab92;
  --red: #bd4053;
  --teal: #4aa3a2;
  --green: #5fbf7a;
  --blue: #5b8def;
  --shadow: 0 24px 80px rgba(0, 0, 0, .42);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 8%, rgba(122, 48, 72, .28), transparent 32rem),
    radial-gradient(circle at 88% 18%, rgba(46, 128, 130, .22), transparent 28rem),
    linear-gradient(135deg, #08070b, #17111b 42%, #0f1118);
  font-family: ui-serif, "Noto Serif SC", "Songti SC", STSong, serif;
}

button, input, select {
  font: inherit;
}

button { cursor: pointer; }

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.form-panel,
.report-panel {
  background: rgba(20, 19, 26, .86);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.form-panel {
  position: sticky;
  top: 20px;
  border-radius: 10px;
  padding: 18px;
}

.report-panel {
  min-height: calc(100vh - 48px);
  border-radius: 10px;
  padding: 24px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: #140d10;
  background: linear-gradient(135deg, var(--gold-soft), var(--gold));
  border-radius: 8px;
  font-size: 22px;
  font-weight: 700;
}

.brand h1 {
  margin: 0 0 4px;
  font-size: 22px;
  letter-spacing: 1px;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.birth-form {
  display: grid;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 4px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 8px;
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  text-align: center;
  padding: 10px 8px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
}

.segmented input:checked + span {
  color: #120c11;
  background: var(--gold);
  font-weight: 700;
}

.field-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.toggle-line span {
  color: var(--muted);
  font-size: 12px;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid rgba(216, 184, 117, .22);
  border-radius: 8px;
  color: var(--text);
  background: rgba(8, 7, 11, .72);
  padding: 11px 12px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(217, 183, 110, .14);
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quick-times {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.quick-times button,
.ghost-btn {
  border: 1px solid rgba(216, 184, 117, .22);
  color: var(--gold-soft);
  background: rgba(255, 255, 255, .04);
  border-radius: 8px;
  padding: 9px 6px;
  font-size: 12px;
}

.quick-times button:hover,
.ghost-btn:hover {
  border-color: var(--gold);
}

.primary-btn {
  position: relative;
  border: 0;
  border-radius: 8px;
  color: #130d10;
  background: linear-gradient(135deg, var(--gold-soft), var(--gold));
  padding: 13px 16px;
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(217, 183, 110, .18);
}

.primary-btn.loading .btn-text { opacity: .2; }

.loader {
  display: none;
  position: absolute;
  inset: 0;
  margin: auto;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(20, 13, 16, .25);
  border-top-color: #130d10;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.primary-btn.loading .loader { display: block; }

.form-error {
  min-height: 18px;
  margin: 0;
  color: #ff8b9d;
  font-size: 12px;
}

.empty-state {
  min-height: calc(100vh - 96px);
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  gap: 18px;
}

.empty-state h2 {
  margin: 0;
  font-size: clamp(24px, 4vw, 42px);
}

.empty-state p {
  max-width: 480px;
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
}

.empty-orbit {
  position: relative;
  width: 124px;
  height: 124px;
  border: 1px solid var(--line);
  border-radius: 50%;
}

.empty-orbit span {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gold);
}

.empty-orbit span:nth-child(1) { left: 56px; top: -6px; }
.empty-orbit span:nth-child(2) { right: 4px; bottom: 24px; background: var(--teal); }
.empty-orbit span:nth-child(3) { left: 12px; bottom: 18px; background: var(--red); }

.hidden { display: none !important; }

.report-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 4px;
}

.report-header h2 {
  margin: 0;
  font-size: clamp(28px, 5vw, 48px);
}

.report-sub {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.info-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  border: 1px solid var(--line);
  background: var(--line);
  margin: 22px 0;
}

.info-cell {
  background: rgba(14, 13, 19, .95);
  padding: 14px 12px;
  min-height: 76px;
}

.info-label {
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 8px;
}

.info-value {
  color: var(--gold-soft);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.35;
}

.four-hua {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.hua-tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255,255,255,.04);
  color: var(--gold-soft);
  font-size: 12px;
}

.hua-lu { border-color: rgba(95, 191, 122, .55); color: #99e3ad; }
.hua-quan { border-color: rgba(217, 183, 110, .65); color: var(--gold-soft); }
.hua-ke { border-color: rgba(91, 141, 239, .55); color: #a9c3ff; }
.hua-ji { border-color: rgba(189, 64, 83, .7); color: #ff9aaa; }

.section-heading {
  margin: 28px 0 12px;
  color: var(--gold);
  font-size: 13px;
  letter-spacing: 4px;
}

.palace-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--line);
  background: var(--line);
}

.palace {
  min-height: 116px;
  padding: 12px;
  background: rgba(15, 14, 20, .96);
  position: relative;
  overflow: hidden;
}

.palace.active {
  background: linear-gradient(135deg, rgba(189, 64, 83, .32), rgba(15, 14, 20, .96));
}

.palace.current-limit {
  background: linear-gradient(135deg, rgba(74, 163, 162, .32), rgba(15, 14, 20, .96));
}

.palace-name {
  color: var(--muted);
  font-size: 12px;
}

.palace-branch {
  position: absolute;
  right: 10px;
  top: 10px;
  color: rgba(217, 183, 110, .28);
}

.stars {
  margin-top: 18px;
  display: grid;
  gap: 3px;
}

.star {
  display: block;
  font-size: 14px;
  font-weight: 700;
}

.main-star { color: var(--gold-soft); }
.minor-star { color: #e9e4d7; }
.mut-star { color: #ff7d91; }

.palace-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.palace-badge {
  border-radius: 3px;
  padding: 3px 5px;
  font-size: 10px;
  border: 1px solid var(--line);
}

.badge-ming { color: #ffb6c0; border-color: var(--red); }
.badge-body { color: #a9c3ff; border-color: var(--blue); }
.badge-limit { color: #9de1df; border-color: var(--teal); }

.center-card {
  grid-column: 2 / span 2;
  grid-row: 2 / span 2;
  min-height: 232px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
  background: rgba(8, 7, 11, .9);
}

.center-card strong {
  display: block;
  color: var(--gold-soft);
  font-size: 22px;
  margin-bottom: 10px;
}

.center-card span {
  color: var(--muted);
  line-height: 1.7;
}

.reading-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.reading-card {
  border: 1px solid rgba(216, 184, 117, .2);
  border-radius: 8px;
  background: rgba(15, 14, 20, .88);
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.reading-card::before {
  content: attr(data-num);
  position: absolute;
  right: 14px;
  top: 10px;
  color: rgba(216, 184, 117, .15);
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
}

.reading-card.full {
  grid-column: 1 / -1;
}

.reading-card.highlight {
  border-color: rgba(189, 64, 83, .65);
  background: linear-gradient(135deg, rgba(189, 64, 83, .12), rgba(15, 14, 20, .9));
}

.reading-card.teal {
  border-color: rgba(74, 163, 162, .65);
  background: linear-gradient(135deg, rgba(74, 163, 162, .12), rgba(15, 14, 20, .9));
}

.reading-title {
  color: var(--gold-soft);
  font-size: 18px;
  font-weight: 800;
}

.reading-badge {
  margin: 8px 0 12px;
  color: var(--teal);
  font-size: 13px;
}

.reading-body {
  color: #eee4d2;
  line-height: 1.85;
  font-size: 14px;
}

.reading-body strong { color: #fff; }
.reading-body .good { color: #9ee1ad; }
.reading-body .warn { color: #ff9aaa; }

.prob-group {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.prob-bar {
  display: grid;
  grid-template-columns: minmax(82px, 120px) 1fr 42px;
  gap: 10px;
  align-items: center;
}

.prob-label {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.prob-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, .08);
}

.prob-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--gold-soft));
}

.prob-pct {
  color: var(--gold-soft);
  font-size: 12px;
  text-align: right;
}

.calibration-list {
  display: grid;
  gap: 8px;
}

.cal-q {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(216, 184, 117, .18);
  border-radius: 8px;
  background: rgba(255,255,255,.035);
}

.cal-num {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #130d10;
  background: var(--gold);
  font-weight: 900;
}

.cal-text strong,
.cal-text {
  line-height: 1.7;
}

.cal-text span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: end;
}

.sheet.open { display: flex; }

.sheet-card {
  width: min(760px, 100%);
  margin: 0 auto;
  max-height: 76vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  background: #15131b;
  padding: 22px;
  box-shadow: var(--shadow);
}

.sheet-close {
  float: right;
  border: 0;
  color: var(--text);
  background: transparent;
  font-size: 28px;
}

.sheet h3 {
  margin: 0 42px 12px 0;
  color: var(--gold-soft);
}

#sheetBody {
  color: #eee4d2;
  line-height: 1.85;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .app-shell {
    padding: 12px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .form-panel {
    position: static;
  }

  .report-panel {
    min-height: 60vh;
    padding: 16px;
  }

  .info-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .palace-grid {
    grid-template-columns: repeat(4, minmax(76px, 1fr));
    overflow-x: auto;
  }

  .palace {
    min-height: 108px;
    padding: 10px;
  }

  .center-card {
    min-height: 216px;
  }

  .reading-cards {
    grid-template-columns: 1fr;
  }

  .quick-times {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .field-row {
    grid-template-columns: 1.2fr 1fr 1fr;
  }

  .report-header {
    display: grid;
  }

  .header-actions {
    justify-content: stretch;
  }

  .header-actions button {
    flex: 1;
  }

  .palace-grid {
    font-size: 12px;
  }

  .star {
    font-size: 13px;
  }
}
