/* ── 全局 ── */
:root {
  --bg: #0f0f1a;
  --card: #1a1a2e;
  --card-hover: #222240;
  --accent: #e8b84b;
  --accent-dim: #b8942a;
  --text: #e0e0e8;
  --text-dim: #8888aa;
  --border: #2a2a44;
  --good: #4ade80;
  --bad: #f87171;
  --wood: #4ade80;
  --fire: #f87171;
  --earth: #e8b84b;
  --metal: #f0f0f0;
  --water: #60a5fa;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
header h1 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--accent);
}
header h1 span { color: var(--text-dim); font-weight: 300; }
header .subtitle {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-left: auto;
  white-space: nowrap;
}

/* ── 容器 ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 0.75rem;
}

/* ── 输入表单 ── */
.input-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.input-card h2 {
  font-size: 0.95rem;
  color: var(--accent);
  margin-bottom: 0.8rem;
}

/* 表单网格：手机两列布局 */
/* 桌面：水平行布局 */
.form-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: flex-end;
}
.form-grid .form-group {
  flex: 0 0 auto;
  min-width: 0;
}
.form-grid .btn-wrap {
  display: flex;
  gap: 0.5rem;
  align-self: flex-end;
}
/* 输入宽度限制（桌面不 stretched） */
.form-grid input[type="number"] { width: 80px; }
.form-grid input[name="name"] { width: 100px; }
.form-grid select { min-width: 90px; }

/* 手机：两列网格 */
@media (max-width: 768px) {
  .form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }
  .form-grid .btn-wrap {
    grid-column: 1 / -1;
    display: flex;
    gap: 0.5rem;
    margin-top: 0.2rem;
  }
  .form-grid .btn-wrap .btn { flex: 1; }
  .form-grid input[type="number"] { width: 100%; }
  .form-grid input[name="name"] { width: 100%; }
  .form-grid select { min-width: 0; width: 100%; }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}
.form-group label {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-weight: 500;
}
.form-group input,
.form-group select {
  background: #12121e;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238888aa'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 2rem;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
}
.form-group input[type="number"] {
  width: 100%;
}
.form-group input[name="name"] {
  width: 100%;
}

.btn {
  background: linear-gradient(135deg, var(--accent-dim), var(--accent));
  color: #111;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
  min-height: 42px;
  -webkit-user-select: none;
  user-select: none;
}
.btn:hover { opacity: 0.9; }
.btn:active { transform: scale(0.97); }
.btn-small {
  padding: 0.45rem 0.8rem;
  font-size: 0.78rem;
  min-height: 36px;
}
.btn-outline {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}

/* ── 排盘展示 ── */
.bazi-display {
  display: none;
  animation: fadeIn 0.3s ease;
}
.bazi-display.show { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 四柱卡片 */
.pillars-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.pillar-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.4rem;
  text-align: center;
}
.pillar-card .pillar-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-bottom: 0.2rem;
}
.pillar-card .pillar-gan {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.1;
}
.pillar-card .pillar-zhi {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--accent);
}
.pillar-card .pillar-naying {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}
.pillar-card .pillar-wuxing {
  font-size: 0.6rem;
  padding: 0.1rem 0.4rem;
  border-radius: 8px;
  display: inline-block;
  margin-top: 0.2rem;
}
.wx-木 { background: #166534; color: #4ade80; }
.wx-火 { background: #7f1d1d; color: #f87171; }
.wx-土 { background: #713f12; color: #e8b84b; }
.wx-金 { background: #1e3a5f; color: #93c5fd; }
.wx-水 { background: #1e1b4b; color: #818cf8; }

/* ── 十神行 ── */
.shishen-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.shishen-cell {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.3rem;
  text-align: center;
  font-size: 0.72rem;
  word-break: break-all;
}
.shishen-cell .ss-label {
  color: var(--text-dim);
  font-size: 0.6rem;
}
.shishen-cell .ss-gan {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.7rem;
}
.shishen-cell .ss-zhi {
  font-size: 0.65rem;
  color: var(--text-dim);
}

/* ── 信息行 ── */
.info-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.info-tag {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
  white-space: nowrap;
}
.info-tag strong {
  color: var(--accent);
}

/* ── 大运走势 ── */
.section-title {
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 0.6rem;
  margin-top: 1.2rem;
}
.dayun-chart {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
  margin-bottom: 1rem;
}
.dayun-timeline {
  display: flex;
  overflow-x: auto;
  gap: 0.4rem;
  padding: 0.3rem 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.dayun-timeline::-webkit-scrollbar {
  height: 3px;
}
.dayun-timeline::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
.dayun-item {
  flex-shrink: 0;
  background: #12121e;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  text-align: center;
  min-width: 60px;
  transition: border-color 0.2s;
  cursor: default;
}
.dayun-item .dy-ganzhi {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
}
.dayun-item .dy-age {
  font-size: 0.65rem;
  color: var(--text-dim);
}
.dayun-item .dy-wx {
  font-size: 0.6rem;
  margin-top: 0.15rem;
}

/* ── 档案列表 ── */
.profiles-section {
  display: none;
  margin-top: 1.5rem;
}
.profiles-section.show { display: block; }
.profile-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}
.profile-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  cursor: pointer;
  transition: border-color 0.2s;
  flex: 1;
  min-width: 140px;
}
.profile-card:active {
  border-color: var(--accent);
}
.profile-card .pc-name {
  font-size: 0.88rem;
  font-weight: 600;
}
.profile-card .pc-detail {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}

/* ── Tabs ── */
.tabs {
  display: none;
  gap: 0.2rem;
  margin-bottom: 0.8rem;
  overflow-x: auto;
  padding: 0.15rem 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  padding: 0.45rem 0.7rem;
  color: var(--text-dim);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  min-height: 38px;
  display: flex;
  align-items: center;
}
.tab:active {
  background: var(--card-hover);
}
.tab.active {
  background: var(--card-hover);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.tab-content { display: none; animation: fadeIn 0.25s ease; }
.tab-content.active { display: block; }

/* ── 白话解读 ── */
.interp-box {
  background: linear-gradient(135deg, #1a1a3e 0%, #1a1a2e 100%);
  border: 1px solid #3a3a6a;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 0.8rem;
}
.interp-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 0.8rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
  user-select: none;
  transition: background 0.2s;
  min-height: 44px;
}
.interp-header:active { background: rgba(232, 184, 75, 0.08); }
.interp-header.open span:last-child { transform: rotate(90deg); }
.interp-body {
  display: none;
  padding: 0 0.8rem 0.8rem;
  font-size: 0.82rem;
  line-height: 1.6;
}
.interp-body.open { display: block; }
.interp-section {
  padding: 0.6rem 0;
  border-top: 1px solid #2a2a4a;
}
.interp-section:first-child { border-top: none; }
.interp-label {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.interp-section p {
  margin: 0.25rem 0;
  color: var(--text);
}

/* ── 响应式 ── */
@media (max-width: 480px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .pillars-grid {
    gap: 0.35rem;
  }
  .pillar-card {
    padding: 0.5rem 0.3rem;
  }
  .pillar-card .pillar-gan { font-size: 1.3rem; }
  .pillar-card .pillar-zhi { font-size: 1.2rem; }

  .shishen-row { gap: 0.35rem; }
  .shishen-cell { padding: 0.3rem 0.2rem; font-size: 0.65rem; }

  header { padding: 0.7rem 0.75rem; }
  header h1 { font-size: 1rem; }
  header .subtitle { font-size: 0.65rem; }

  .container { padding: 0.7rem 0.5rem; }

  .tabs { gap: 0.15rem; }
  .tab { padding: 0.35rem 0.5rem; font-size: 0.7rem; min-height: 34px; }

  .input-card { padding: 0.75rem; }

  .profile-card { min-width: 100%; }
}

@media (min-width: 481px) and (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .form-grid .btn-wrap {
    grid-column: 1 / -1;
  }
  .profile-card { min-width: calc(50% - 0.3rem); }
}

@media (max-width: 768px) {
  .pillars-grid, .shishen-row {
    grid-template-columns: repeat(2, 1fr);
  }
  header .subtitle { display: none; }

  /* 流月网格 6列→3列 */
  #liunian-display [style*="grid-template-columns:repeat(6,1fr)"] {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  /* 择时评分明细行模式 → 列模式 */
  #zetime-display [style*="display:flex"][style*="align-items:center"][style*="gap:0.5rem"] {
    flex-wrap: wrap;
  }
  #zetime-display [style*="min-width:40px"] {
    min-width: 30px !important;
  }
}

/* 防止 iOS 自动缩放 */
@media screen and (max-width: 480px) {
  input, select, textarea, button {
    font-size: 16px !important;
  }
}

/* 触摸优化：按钮去掉桌面hover，保留active */
@media (hover: none) {
  .btn:hover { opacity: 1; }
  .profile-card:hover { border-color: var(--border); }
  .interp-header:hover { background: transparent; }
  .dayun-item:hover { border-color: var(--border); }
}
