/* ===== 基礎變數 ===== */
:root {
  --primary: #6b4ee6;
  --primary-dark: #5239c7;
  --secondary: #ff6b9d;
  --bg: #f8f9fa;
  --card-bg: #ffffff;
  --text: #2d3436;
  --text-light: #636e72;
  --border: #dfe6e9;
  --success: #00b894;
  --warning: #fdcb6e;
  --danger: #e17055;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
}

/* ===== 頁首 ===== */
.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 2rem 1rem;
  text-align: center;
}
.app-header h1 { font-size: 2rem; letter-spacing: 2px; }
.app-header .subtitle { opacity: 0.9; font-size: 0.95rem; margin-top: 0.25rem; }

/* ===== 頁面容器 ===== */
.page { display: none; padding-bottom: 3rem; }
.page.active { display: block; }

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

/* ===== 表單 ===== */
.birth-form, .liuren-form {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.form-row { margin-bottom: 1rem; }

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
  color: var(--text-light);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.city-group { position: relative; }

.city-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  box-shadow: var(--shadow);
}

.city-option {
  padding: 0.625rem 1rem;
  cursor: pointer;
  font-size: 0.9375rem;
}
.city-option:hover { background: var(--bg); }

/* ===== 按鈕 ===== */
.btn-primary, .btn-secondary {
  display: inline-block;
  padding: 0.875rem 2rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  width: 100%;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(107,78,230,0.35); }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

/* ===== 進度頁 ===== */
.progress-container {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.progress-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9375rem;
}
.progress-step:last-child { border-bottom: none; }

.step-status { font-size: 1.25rem; }

/* ===== 報告頁 ===== */
.report-header {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.fallback-notice {
  color: var(--danger);
  font-size: 0.8125rem;
  margin: 0.5rem 0;
}

/* ===== 排盤總覽 ===== */
.overview-section {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.overview-block {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.overview-block h4 {
  font-size: 1rem;
  color: var(--primary);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
}

.bazi-pillars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.pillar {
  text-align: center;
  padding: 0.75rem 0.5rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.pillar .label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-light);
  margin-bottom: 0.25rem;
}

.pillar .value {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}

/* ===== 紫微宮位 ===== */
.palace-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.375rem;
  margin-top: 0.75rem;
}

.palace-cell {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  text-align: center;
  font-size: 0.75rem;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.palace-cell.empty { opacity: 0.6; }

.palace-name { font-size: 0.6875rem; color: var(--text-light); }
.palace-zhi { font-weight: 700; color: var(--primary); font-size: 0.8125rem; }
.palace-stars { font-size: 0.6875rem; color: var(--secondary); margin-top: 0.125rem; }

/* ===== 時間軸 ===== */
.timeline-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.timeline-section h3 {
  font-size: 1rem;
  color: var(--primary);
  margin-bottom: 1rem;
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.timeline-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.timeline-item.current .timeline-age,
.timeline-item.current .timeline-pillar {
  color: var(--primary);
  font-weight: 700;
}

.timeline-age { width: 80px; font-size: 0.8125rem; flex-shrink: 0; }
.timeline-pillar { width: 50px; font-size: 0.9375rem; flex-shrink: 0; }

.timeline-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  position: relative;
}

.timeline-item.current .timeline-bar {
  background: linear-gradient(90deg, var(--primary), var(--secondary));
}

/* ===== 模組卡片 ===== */
.modules-section { margin-bottom: 1.5rem; }
.modules-section h3 {
  font-size: 1.125rem;
  margin-bottom: 1rem;
  color: var(--text);
}

.module-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.module-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  cursor: pointer;
  transition: background 0.2s;
}

.module-header:hover { background: var(--bg); }

.module-id {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  background: rgba(107,78,230,0.1);
  padding: 0.125rem 0.5rem;
  border-radius: 4px;
}

.module-title { flex: 1; font-weight: 600; font-size: 0.9375rem; }

.credibility-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.125rem 0.5rem;
  border-radius: 4px;
}

.credibility-A { background: #d4edda; color: #155724; }
.credibility-B { background: #fff3cd; color: #856404; }
.credibility-C { background: #ffe0b2; color: #e65100; }
.credibility-D { background: #f8d7da; color: #721c24; }

.toggle-icon { font-size: 0.75rem; color: var(--text-light); }

.module-content {
  padding: 0 1.25rem 1.25rem;
  border-top: 1px solid var(--border);
}

.module-text {
  font-size: 0.9375rem;
  line-height: 1.8;
  color: var(--text);
}

.module-text h1 { font-size: 1.25rem; margin: 1rem 0 0.5rem; }
.module-text h2 { font-size: 1.1rem; margin: 0.875rem 0 0.5rem; color: var(--primary); }
.module-text h3 { font-size: 1rem; margin: 0.75rem 0 0.375rem; }
.module-text strong { color: var(--primary-dark); }

/* ===== 大六壬 ===== */
.liuren-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.liuren-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1rem;
  box-shadow: var(--shadow);
}

.liuren-card h4 { color: var(--primary); margin-bottom: 0.75rem; }
.liuren-card h5 { color: var(--text); margin: 1rem 0 0.5rem; font-size: 0.9375rem; }

.four-ke, .san-chuan {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin: 0.5rem 0;
}

.ke-item, .chuan-item {
  padding: 0.25rem 0;
  font-size: 0.9375rem;
}

.interpretation pre {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 0.9375rem;
  line-height: 1.7;
  background: var(--bg);
  padding: 1rem;
  border-radius: var(--radius-sm);
}

/* ===== 免責聲明 ===== */
.disclaimer {
  background: #fff8e1;
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 2rem;
  border-left: 4px solid var(--warning);
}

.disclaimer h4 { color: #856404; margin-bottom: 0.5rem; font-size: 0.9375rem; }
.disclaimer p { font-size: 0.8125rem; color: #856404; line-height: 1.7; }

/* ===== 響應式：平板 ===== */
@media (min-width: 768px) {
  .container { padding: 2rem; max-width: 720px; }
  
  .app-header h1 { font-size: 2.5rem; }
  
  .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }
  
  .form-row .form-group { margin-bottom: 0; }
  
  .palace-grid { grid-template-columns: repeat(6, 1fr); }
  
  .overview-section { grid-template-columns: 1fr 1fr; }
  
  .timeline { flex-direction: row; flex-wrap: wrap; }
  .timeline-item { width: 50%; }
}

/* ===== 響應式：桌面 ===== */
@media (min-width: 1024px) {
  .container { max-width: 960px; padding: 2.5rem; }
  
  .app-header { padding: 3rem 1rem; }
  .app-header h1 { font-size: 3rem; }
  
  .palace-grid { grid-template-columns: repeat(6, 1fr); }
  
  .overview-section { grid-template-columns: 1fr 1fr; }
  
  .timeline-item { width: 25%; }
  
  .module-header { padding: 1.25rem 1.5rem; }
  .module-content { padding: 0 1.5rem 1.5rem; }
}

/* ===== 動畫 ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.page.active {
  animation: fadeIn 0.3s ease-out;
}
