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

:root {
  --gold: #c9a84c;
  --gold-light: #e8d48b;
  --gold-dark: #8a6d2b;
  --red: #b83a2a;
  --red-light: #d4553a;
  --bg-deep: #0c0b14;
  --bg-card: #14121e;
  --bg-card-alt: #1a1728;
  --bg-surface: #1f1b30;
  --border: #2a2540;
  --border-gold: rgba(201, 168, 76, 0.3);
  --text-main: #ddd8e6;
  --text-dim: #8a849e;
  --text-muted: #5e5874;
  --success: #4a9e6f;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Noto Serif SC', 'Source Han Serif SC', 'STSong', 'SimSun', 'Songti SC', serif;
  background: var(--bg-deep);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.7;
  /* 傳統暗紋背景 */
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(201, 168, 76, 0.03) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 50%, rgba(184, 58, 42, 0.03) 0%, transparent 60%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 40px,
      rgba(201, 168, 76, 0.008) 40px,
      rgba(201, 168, 76, 0.008) 41px
    );
}

.hidden { display: none !important; }

/* ===== Header ===== */
.app-header {
  background: linear-gradient(180deg, #1a1528 0%, #14121e 100%);
  padding: 28px 16px 20px;
  text-align: center;
  border-bottom: 1px solid var(--border-gold);
  position: relative;
  overflow: hidden;
}
.app-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.app-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 10%;
  right: 10%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.app-header h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 6px;
  margin-bottom: 4px;
  text-shadow: 0 0 20px rgba(201, 168, 76, 0.15);
}
.app-header .subtitle {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 3px;
  font-family: -apple-system, 'Microsoft YaHei', 'PingFang SC', sans-serif;
}
.app-header .ornament {
  color: var(--gold-dark);
  font-size: 18px;
  margin-top: 6px;
  letter-spacing: 12px;
  opacity: 0.4;
}

/* ===== Layout ===== */
.container {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ===== Card ===== */
.card {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-card-alt) 100%);
  border-radius: 4px;
  padding: 24px 20px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  position: relative;
  transition: border-color 0.3s;
}
.card:hover {
  border-color: var(--border-gold);
}
/* 傳統雙線邊框裝飾 */
.card::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  right: 3px;
  bottom: 3px;
  border: 1px solid rgba(201, 168, 76, 0.08);
  border-radius: 2px;
  pointer-events: none;
}

.card-title {
  font-size: 15px;
  color: var(--gold);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .icon {
  font-size: 18px;
}

/* ===== Entry Buttons (Home) ===== */
.entry-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.entry-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  background: linear-gradient(135deg, var(--bg-surface) 0%, rgba(31, 27, 48, 0.6) 100%);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px 18px;
  cursor: pointer;
  transition: all 0.3s;
  width: 100%;
  text-align: left;
  color: var(--text-main);
  position: relative;
  overflow: hidden;
}
.entry-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 60%, rgba(201, 168, 76, 0.03));
  pointer-events: none;
}
.entry-btn::after {
  content: '';
  position: absolute;
  left: 0;
  top: 10%;
  bottom: 10%;
  width: 2px;
  background: var(--gold-dark);
  transition: background 0.3s;
}
.entry-btn:hover {
  border-color: var(--gold);
  background: linear-gradient(135deg, rgba(31, 27, 48, 0.9) 0%, rgba(201, 168, 76, 0.05) 100%);
  transform: translateY(-1px);
}
.entry-btn:hover::after {
  background: var(--gold);
}
.entry-btn:active {
  transform: translateY(0);
}

.entry-btn .icon-box {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(201, 168, 76, 0.06);
  border: 1px solid rgba(201, 168, 76, 0.12);
  border-radius: 4px;
  flex-shrink: 0;
  font-size: 22px;
}
.entry-btn .info {
  flex: 1;
}
.entry-btn .info h3 {
  font-size: 15px;
  margin-bottom: 2px;
  color: var(--text-main);
  letter-spacing: 1px;
}
.entry-btn .info p {
  font-size: 12px;
  color: var(--text-dim);
  font-family: -apple-system, 'Microsoft YaHei', 'PingFang SC', sans-serif;
}

/* ===== Description ===== */
.desc-text {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 2;
  font-family: -apple-system, 'Microsoft YaHei', 'PingFang SC', sans-serif;
}

/* ===== Back Button ===== */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 12px;
  padding: 6px 10px;
  background: rgba(201, 168, 76, 0.04);
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: all 0.2s;
}
.back-btn:hover {
  color: var(--gold);
  border-color: var(--border-gold);
  background: rgba(201, 168, 76, 0.08);
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: 13px;
  margin-bottom: 5px;
  color: var(--text-dim);
  letter-spacing: 1px;
}
.form-group select,
.form-group input[type="number"],
.form-group input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  background: rgba(12, 11, 20, 0.8);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-main);
  font-size: 14px;
  transition: all 0.25s;
  font-family: -apple-system, 'Microsoft YaHei', 'PingFang SC', sans-serif;
}
.form-group select:focus,
.form-group input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.08);
  background: rgba(12, 11, 20, 1);
}
.form-group select option {
  background: var(--bg-card);
  color: var(--text-main);
}

.form-row {
  display: flex;
  gap: 10px;
}
.form-row .form-group {
  flex: 1;
}
.form-row .form-group input {
  text-align: center;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: 4px;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.25s;
  letter-spacing: 2px;
  font-family: 'Noto Serif SC', 'STSong', serif;
  position: relative;
  overflow: hidden;
}
.btn-primary {
  background: linear-gradient(135deg, var(--red) 0%, #96281b 100%);
  color: #f0e6d0;
  width: 100%;
}
.btn-primary:hover {
  opacity: 0.92;
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(184, 58, 42, 0.3);
}
.btn-primary:active {
  transform: translateY(0);
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
  color: #0c0b14;
  width: 100%;
  font-weight: 700;
}
.btn-gold:hover {
  box-shadow: 0 4px 20px rgba(201, 168, 76, 0.3);
  transform: translateY(-1px);
}
.btn-gold:active {
  transform: translateY(0);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 16px;
  font-size: 13px;
  letter-spacing: 1px;
}
.btn-ghost:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(201, 168, 76, 0.05);
}

/* ===== Toggle (公曆/農曆) ===== */
.toggle-group {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.toggle-btn {
  flex: 1;
  padding: 9px;
  text-align: center;
  background: rgba(12, 11, 20, 0.6);
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.25s;
  letter-spacing: 2px;
  font-family: 'Noto Serif SC', 'STSong', serif;
}
.toggle-btn.active {
  background: var(--bg-surface);
  color: var(--gold);
  border-bottom: 1px solid var(--gold);
}
.toggle-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}
.toggle-btn:hover:not(.active) {
  color: var(--text-main);
  background: rgba(201, 168, 76, 0.04);
}

/* ===== Image Upload ===== */
.upload-area {
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s;
  margin-bottom: 16px;
  background: rgba(12, 11, 20, 0.4);
}
.upload-area:hover {
  border-color: var(--gold);
  background: rgba(201, 168, 76, 0.03);
}
.upload-area .upload-icon {
  font-size: 36px;
  margin-bottom: 10px;
  opacity: 0.6;
}
.upload-area p {
  color: var(--text-dim);
  font-size: 14px;
  letter-spacing: 1px;
}
.upload-area .hint {
  font-size: 12px;
  margin-top: 6px;
  color: var(--text-muted);
}

#imagePreview {
  max-width: 100%;
  max-height: 280px;
  border-radius: 4px;
  margin-bottom: 16px;
  display: none;
  border: 1px solid var(--border);
}

/* OCR Progress */
.ocr-progress {
  display: none;
  text-align: center;
  padding: 24px;
}
.ocr-progress .spinner {
  width: 36px;
  height: 36px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.ocr-progress p {
  color: var(--text-dim);
  font-size: 13px;
  letter-spacing: 1px;
}

/* ===== Bazi Input Grid (改良：過濾選擇) ===== */
.bazi-input-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.bazi-input-grid .pillar-group {
  background: rgba(31, 27, 48, 0.4);
  border-radius: 4px;
  padding: 12px;
  border: 1px solid var(--border);
}
.bazi-input-grid .pillar-group .pillar-label {
  font-size: 12px;
  color: var(--gold);
  margin-bottom: 8px;
  text-align: center;
  letter-spacing: 4px;
}
.bazi-input-grid select {
  width: 100%;
  padding: 8px;
  background: rgba(12, 11, 20, 0.8);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-main);
  font-size: 14px;
  margin-bottom: 5px;
  text-align: center;
  transition: border-color 0.25s;
  font-family: 'Noto Serif SC', 'STSong', serif;
}
.bazi-input-grid select:focus {
  outline: none;
  border-color: var(--gold);
}
.bazi-input-grid select option {
  background: var(--bg-card);
  color: var(--text-main);
}

/* 干支輸入框的 2col 布局 */
.bazi-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

/* ===== Results ===== */
/* 四柱展示 */
.result-bazi {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 20px;
  padding: 16px 8px;
  background: rgba(12, 11, 20, 0.6);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.result-bazi .pillar {
  text-align: center;
  padding: 10px 6px;
  min-width: 52px;
  position: relative;
}
.result-bazi .pillar + .pillar::before {
  content: '';
  position: absolute;
  left: -3px;
  top: 15%;
  bottom: 15%;
  width: 1px;
  background: var(--border);
}
.result-bazi .pillar .pos {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 2px;
  letter-spacing: 2px;
  font-family: -apple-system, 'Microsoft YaHei', sans-serif;
}
.result-bazi .pillar .gan {
  font-size: 24px;
  color: var(--gold);
  font-weight: 700;
}
.result-bazi .pillar .zhi {
  font-size: 24px;
  color: var(--text-main);
  font-weight: 700;
}

/* ===== Stats Bar ===== */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(12, 11, 20, 0.4);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.stat-chip {
  padding: 4px 12px;
  font-size: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text-dim);
  font-family: -apple-system, 'Microsoft YaHei', sans-serif;
}
.stat-chip.lu {
  border-color: var(--gold);
  color: var(--gold-light);
  background: rgba(201, 168, 76, 0.06);
}
.stat-value {
  color: var(--gold);
  font-weight: 700;
  font-size: 14px;
}

/* ===== Analysis Table ===== */
.analysis-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}
.analysis-table th,
.analysis-table td {
  padding: 10px 6px;
  text-align: center;
  border: 1px solid var(--border);
  font-size: 13px;
  font-family: -apple-system, 'Microsoft YaHei', 'PingFang SC', sans-serif;
}
.analysis-table th {
  background: rgba(12, 11, 20, 0.6);
  color: var(--gold);
  font-weight: 500;
  letter-spacing: 1px;
  font-size: 12px;
}
.analysis-table td.lu {
  color: var(--gold-light);
  font-weight: 700;
}
.analysis-table td {
  color: var(--text-dim);
  transition: background 0.2s;
}
.analysis-table td:hover {
  background: rgba(201, 168, 76, 0.04);
}
.analysis-table .gan-label {
  color: var(--gold);
  font-weight: 700;
  font-family: 'Noto Serif SC', serif;
}

/* ===== 統計摘要 ===== */
.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(12, 11, 20, 0.4);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.stats-item {
  text-align: center;
  padding: 8px 4px;
  border-radius: 2px;
  background: rgba(31, 27, 48, 0.5);
  border: 1px solid var(--border);
}
.stats-item .label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.stats-item .count {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
}
.stats-item.lu .count {
  color: var(--gold-light);
}

/* ===== Report ===== */
.report-box {
  background: rgba(12, 11, 20, 0.8);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 12px;
  white-space: pre-wrap;
  font-family: 'Courier New', 'Source Code Pro', monospace;
  font-size: 13px;
  line-height: 1.9;
  color: var(--text-dim);
  min-height: 80px;
}

.copy-hint {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: #f0e6d0;
  padding: 10px 24px;
  border-radius: 4px;
  font-size: 14px;
  z-index: 999;
  letter-spacing: 2px;
  animation: toastIn 0.3s ease;
  box-shadow: 0 4px 20px rgba(74, 158, 111, 0.3);
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Error ===== */
.error-box {
  background: rgba(184, 58, 42, 0.08);
  border: 1px solid rgba(184, 58, 42, 0.3);
  border-radius: 4px;
  padding: 10px 14px;
  color: var(--red-light);
  font-size: 13px;
  margin-top: 12px;
  line-height: 1.6;
  font-family: -apple-system, 'Microsoft YaHei', sans-serif;
}

/* ===== Section Divider ===== */
.or-divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin: 14px 0;
  position: relative;
  letter-spacing: 2px;
}
.or-divider::before,
.or-divider::after {
  content: '';
  display: inline-block;
  width: 50px;
  height: 1px;
  background: var(--border);
  vertical-align: middle;
  margin: 0 12px;
}

/* ===== Footer ===== */
.app-footer {
  text-align: center;
  padding: 24px 16px 32px;
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 2px;
  font-family: -apple-system, 'Microsoft YaHei', sans-serif;
  border-top: 1px solid var(--border);
  margin-top: 20px;
}

/* ===== 密碼保護 ===== */
.access-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  z-index: 1000;
  padding: 20px;
}
.access-box {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-card-alt) 100%);
  border: 1px solid var(--border-gold);
  border-radius: 4px;
  padding: 40px 32px 32px;
  width: 100%;
  max-width: 320px;
  text-align: center;
  position: relative;
}
.access-box::before {
  content: '';
  position: absolute;
  top: 2px; left: 2px; right: 2px; bottom: 2px;
  border: 1px solid rgba(201, 168, 76, 0.08);
  border-radius: 2px;
  pointer-events: none;
}
.access-icon {
  font-size: 40px;
  margin-bottom: 12px;
}
.access-box h2 {
  font-size: 18px;
  color: var(--gold);
  letter-spacing: 4px;
  margin-bottom: 6px;
}
.access-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 20px;
  letter-spacing: 1px;
  font-family: -apple-system, 'Microsoft YaHei', sans-serif;
}
.access-input {
  width: 100%;
  padding: 12px 14px;
  background: rgba(12, 11, 20, 0.8);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-main);
  font-size: 16px;
  text-align: center;
  letter-spacing: 4px;
  transition: border-color 0.25s;
}
.access-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.08);
}

/* ===== 各天干獨立統計 ===== */
.gan-stats-block {
  margin-bottom: 12px;
  padding: 12px;
  background: rgba(12, 11, 20, 0.3);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.gan-stats-label {
  font-size: 14px;
  color: var(--gold);
  margin-bottom: 8px;
  letter-spacing: 1px;
  font-weight: 700;
}
.gan-stats-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.gan-stats-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 13px;
  font-family: -apple-system, 'Microsoft YaHei', sans-serif;
}
.gan-stats-item.lu {
  border-color: var(--gold);
  background: rgba(201, 168, 76, 0.06);
}
.gan-stats-item .gs-name {
  color: var(--text-dim);
}
.gan-stats-item .gs-count {
  color: var(--gold);
  font-weight: 700;
  font-size: 15px;
}
.gan-stats-item.lu .gs-count {
  color: var(--gold-light);
}
.container > section {
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== 行動端優化 ===== */
@media (max-width: 400px) {
  .container { padding: 16px 12px 32px; }
  .card { padding: 18px 14px; }
  .result-bazi { gap: 4px; }
  .result-bazi .pillar { min-width: 44px; padding: 8px 4px; }
  .result-bazi .pillar .gan,
  .result-bazi .pillar .zhi { font-size: 20px; }
  .stats-summary { grid-template-columns: repeat(3, 1fr); }
  .app-header h1 { font-size: 22px; letter-spacing: 4px; }
}
