/* iOS / Apple HIG 系统配色 */
:root {
  --system-blue: #007aff;
  --system-blue-press: #0062cc;
  --system-red: #ff3b30;
  --system-green: #34c759;
  --label: #000000;
  --secondary-label: rgba(60, 60, 67, 0.6);
  --tertiary-label: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.29);
  --opaque-separator: #c6c6c8;
  --grouped-bg: #f2f2f7;
  --secondary-grouped: #ffffff;
  --fill: rgba(120, 120, 128, 0.16);
  --fill-secondary: rgba(120, 120, 128, 0.08);
  --bg: var(--grouped-bg);
  --card: var(--secondary-grouped);
  --ink: var(--label);
  --muted: #8e8e93;
  --line: rgba(60, 60, 67, 0.12);
  --accent: var(--system-blue);
  --accent-press: var(--system-blue-press);
  --accent-soft: rgba(0, 122, 255, 0.14);
  --danger: var(--system-red);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "PingFang SC", "Helvetica Neue", "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--grouped-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.bg-orb {
  display: none;
}

.page {
  position: relative;
  z-index: 1;
  width: min(580px, 100%);
  margin: 0 auto;
  padding: 28px 16px 80px;
}

.top {
  text-align: left;
  margin-bottom: 20px;
  padding: 4px 4px 0;
}

.eyebrow {
  margin: 0;
  color: var(--system-blue);
  letter-spacing: 0.06em;
  font-size: 0.8rem;
  font-weight: 600;
}

.title {
  margin: 6px 0 8px;
  font-family: var(--font);
  font-size: clamp(1.85rem, 6vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--label);
  line-height: 1.15;
}

.subtitle {
  margin: 0;
  max-width: 28em;
  color: var(--secondary-label);
  font-size: 0.95rem;
  line-height: 1.5;
}

.card {
  background: var(--secondary-grouped);
  border-radius: var(--radius);
  padding: 6px 0 14px;
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: none;
  border: 0.5px solid rgba(0, 0, 0, 0.04);
}

.card > .row-2,
.card > .field,
.card > .picker-field,
.card > .family-block,
.card > .btn-primary,
.card > .chart-head,
.card > .meta,
.card > .pillars,
.card > .calendar-line,
.card > .tiny,
.card > .engine-trace,
.card > .ai-badge,
.card > .block-title,
.card > .note,
.card > .life-essay,
.card > .warn-list,
.card > .timeline,
.card > h3 {
  margin-left: 16px;
  margin-right: 16px;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 16px;
}

.field {
  margin: 12px 16px;
}

.row-2 .field {
  margin: 0;
}

.label {
  display: block;
  margin-bottom: 8px;
  color: var(--secondary-label);
  font-size: 0.78rem;
  font-weight: 500;
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  background: var(--fill);
  padding: 2px;
  border-radius: 9px;
}

.seg-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.seg-item {
  position: relative;
  text-align: center;
  border-radius: 7px;
  padding: 8px 4px;
  cursor: pointer;
  color: var(--label);
  font-weight: 500;
  font-size: 0.9rem;
  transition: background 0.15s ease;
}

.seg-item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg-item:has(input:checked) {
  background: #fff;
  box-shadow: 0 0.5px 1px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.06);
}

.picker-field {
  width: calc(100% - 32px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  border: 0;
  background: var(--fill-secondary);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 8px 16px;
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s ease;
}

.picker-field:active {
  background: var(--fill);
}

.picker-datetime {
  width: calc(100% - 32px);
}

.picker-field .label {
  margin: 0;
}

.picker-field .value {
  color: var(--label);
  font-weight: 600;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

.picker-field .value.is-empty {
  color: var(--system-blue);
  font-weight: 500;
}

.tiny {
  margin: 8px 16px 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.55;
}

.tiny.center {
  text-align: center;
  margin-top: 10px;
}

.block-title {
  margin: 12px 16px 6px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.block-title.sm {
  font-size: 0.95rem;
  margin-top: 18px;
}

.family-block {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 0.5px solid var(--separator);
  animation: fadeIn 0.22s ease;
}

.family-head {
  margin-bottom: 4px;
}

.btn-primary,
.btn-ghost,
.btn-text {
  font: inherit;
  border: 0;
  cursor: pointer;
}

.btn-primary {
  display: block;
  width: calc(100% - 32px);
  margin: 16px 16px 4px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--system-blue);
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 1.02rem;
}

.btn-primary:active {
  background: var(--system-blue-press);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary.solid {
  margin: 0;
  width: auto;
  flex: 1.2;
}

.btn-ghost {
  flex: 1;
  padding: 13px 14px;
  border-radius: 12px;
  background: var(--fill);
  color: var(--label);
  font-weight: 600;
}

.btn-text {
  background: transparent;
  color: var(--system-blue);
  font-size: 0.95rem;
  padding: 0;
  font-weight: 500;
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 16px 0;
}

.chart-head .block-title {
  margin: 0;
}

.meta {
  margin: 6px 16px 12px;
  color: var(--secondary-label);
  font-size: 0.88rem;
}

.pillars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0 16px 12px;
}

.pillar {
  background: var(--grouped-bg);
  border-radius: 10px;
  padding: 12px 4px;
  text-align: center;
}

.pillar .p-label {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  margin-bottom: 6px;
}

.pillar .p-gan,
.pillar .p-zhi {
  display: block;
  font-size: 1.28rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.04em;
}

.calendar-line {
  color: var(--label);
  font-size: 0.9rem;
  line-height: 1.75;
  margin: 0 16px 8px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--grouped-bg);
}

/* 排盘推理中的铁板信息 */
.engine-trace {
  margin: 12px 16px 8px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--grouped-bg);
  border: 0.5px solid var(--line);
}

.engine-status {
  margin: 0 0 8px;
  color: var(--system-blue);
  font-size: 0.86rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.engine-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--system-blue);
  animation: pulse 1s ease-in-out infinite;
}

.engine-detail {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-all;
  font-family: var(--font);
}

.life-card {
  border: 0.5px solid rgba(0, 0, 0, 0.04);
  padding-top: 12px;
}

.ai-badge {
  display: inline-block;
  margin: 4px 16px 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--system-blue);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.note {
  color: var(--secondary-label);
  font-size: 0.9rem;
  margin: 0 16px 10px;
}

.life-essay {
  background: var(--grouped-bg);
  border-radius: 10px;
  padding: 16px 15px;
  margin: 0 16px;
  font-size: 1.02rem;
  line-height: 1.9;
  color: var(--label);
}

.life-essay p {
  margin: 0 0 0.95em;
}

.life-essay p:last-child {
  margin-bottom: 0;
}

.life-card.is-streaming .ai-badge::after {
  content: " · 生成中";
  font-weight: 500;
}

.stream-caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.1em;
  background: var(--system-blue);
  animation: caretBlink 0.9s step-end infinite;
}

.stream-dots {
  display: inline-block;
  min-width: 1.2em;
}

@keyframes caretBlink {
  50% {
    opacity: 0;
  }
}

.warn-list {
  margin: 12px 16px 0;
  padding-left: 1.1rem;
  color: var(--system-red);
  font-size: 0.86rem;
}

.timeline {
  display: grid;
  gap: 10px;
  margin: 0 16px 12px;
}

.tl-item {
  background: var(--grouped-bg);
  border-radius: 10px;
  padding: 12px;
}

.tl-item strong {
  display: block;
  margin-bottom: 4px;
}

.tl-item span {
  color: var(--muted);
  font-size: 0.86rem;
}

/* modal — iOS action sheet / alert feel */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
  padding: 14px;
}

.modal-mask[hidden] {
  display: none !important;
}

.modal {
  width: min(440px, 100%);
  background: rgba(242, 242, 247, 0.96);
  border-radius: 14px;
  padding: 18px 16px 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  animation: rise 0.26s ease;
}

.modal-top {
  text-align: center;
  margin-bottom: 14px;
}

.modal-kicker {
  margin: 0 0 6px;
  color: var(--system-blue);
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 600;
}

.modal h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.confirm-body {
  display: grid;
  gap: 10px;
}

.confirm-hero {
  text-align: center;
  padding: 16px 12px;
  border-radius: 12px;
  background: #fff;
}

.confirm-hero .who {
  margin: 0 0 8px;
  color: var(--secondary-label);
  font-size: 0.82rem;
}

.confirm-hero .pillars-inline {
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.5;
}

.confirm-grid {
  display: grid;
  gap: 8px;
}

.confirm-item {
  display: grid;
  grid-template-columns: 3.6em 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border-radius: 12px;
  background: #fff;
}

.confirm-item .k {
  color: var(--muted);
  font-size: 0.78rem;
  padding-top: 2px;
}

.confirm-item .v {
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.45;
}

.confirm-family {
  padding: 12px;
  border-radius: 12px;
  background: #fff;
}

.confirm-family .title {
  margin: 0 0 8px;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--font);
  font-weight: 600;
}

.confirm-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--grouped-bg);
  font-size: 0.8rem;
}

.chip b {
  color: var(--muted);
  font-weight: 500;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

/* iOS wheel sheet */
.wheel-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.36);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.wheel-mask.show {
  opacity: 1;
}

.wheel-sheet {
  width: min(560px, 100%);
  background: var(--grouped-bg);
  border-radius: 14px 14px 0 0;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  transform: translateY(16px);
  transition: transform 0.22s ease;
  overflow: hidden;
}

.wheel-mask.show .wheel-sheet {
  transform: translateY(0);
}

.wheel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 0.5px solid var(--separator);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
}

.wheel-title {
  font-weight: 600;
  font-size: 0.98rem;
}

.wheel-btn {
  border: 0;
  background: transparent;
  color: var(--system-blue);
  font: inherit;
  font-weight: 600;
  font-size: 1.05rem;
  padding: 4px 2px;
  cursor: pointer;
  min-width: 3em;
}

.wheel-btn.cancel {
  color: var(--secondary-label);
  font-weight: 400;
  text-align: left;
}

.wheel-btn.ok {
  text-align: right;
}

.wheel-preview {
  text-align: center;
  padding: 12px 16px 4px;
  color: var(--secondary-label);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.wheel-body {
  position: relative;
  height: 240px;
  overflow: hidden;
  margin: 4px 8px 0;
  background: #fff;
  border-radius: 12px;
}

.wheel-highlight {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  height: 44px;
  margin-top: -22px;
  border-radius: 8px;
  background: var(--fill);
  pointer-events: none;
  z-index: 1;
}

.wheel-cols {
  position: relative;
  z-index: 2;
  display: flex;
  height: 100%;
}

.wheel-col {
  flex: 1;
  min-width: 0;
  height: 100%;
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    #000 22%,
    #000 78%,
    transparent 100%
  );
}

.wheel-scroller {
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  cursor: grab;
  user-select: none;
}

.wheel-scroller.is-dragging {
  cursor: grabbing;
  scroll-snap-type: none;
}

.wheel-scroller::-webkit-scrollbar {
  display: none;
}

.wheel-pad {
  height: 98px;
}

.wheel-item {
  height: 44px;
  line-height: 44px;
  text-align: center;
  font-size: 1.05rem;
  scroll-snap-align: center;
  color: var(--tertiary-label);
  cursor: pointer;
  transition: color 0.12s ease, font-weight 0.12s ease;
}

.wheel-item.is-active {
  color: var(--label);
  font-weight: 600;
}

.wheel-item:hover {
  color: var(--label);
}

.wheel-hint {
  margin: 10px 16px 4px;
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(120%);
  background: rgba(28, 28, 30, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 0.88rem;
  opacity: 0;
  transition: 0.25s ease;
  z-index: 60;
  max-width: 86vw;
  text-align: center;
}

#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

#toast.error {
  background: rgba(255, 59, 48, 0.95);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.9);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 420px) {
  .seg-3 .seg-item {
    font-size: 0.78rem;
    padding: 9px 2px;
  }
  .wheel-item {
    font-size: 0.95rem;
  }
}

@media (min-width: 720px) {
  .modal-mask {
    align-items: center;
  }
  .wheel-mask {
    align-items: center;
    padding: 24px;
  }
  .wheel-sheet {
    border-radius: 14px;
    transform: translateY(8px) scale(0.98);
  }
  .wheel-mask.show .wheel-sheet {
    transform: translateY(0) scale(1);
  }
}
