/* ============================================
   紫微斗数 - Purple Star Astrology App
   华丽深色中国风主题
   ============================================ */

/* === CSS Custom Properties === */
:root {
  /* Backgrounds */
  --bg-deep: #06060e;
  --bg-primary: #0a0a14;
  --bg-secondary: #10101e;
  --bg-palace: #12122a;
  --bg-palace-hover: #1a1a3a;
  --bg-palace-active: #1e1e42;
  --bg-center: #0e0e1a;
  --bg-card: #141428;
  --bg-input: #16162e;
  --bg-modal: rgba(6, 6, 14, 0.92);

  /* Gold spectrum */
  --gold-dark: #8b6914;
  --gold: #d4a853;
  --gold-light: #e8c87a;
  --gold-bright: #f5dea3;
  --gold-glow: rgba(212, 168, 83, 0.15);
  --gold-border: rgba(212, 168, 83, 0.25);

  /* Red spectrum */
  --red: #c41e3a;
  --red-light: #e8505b;
  --red-soft: rgba(196, 30, 58, 0.15);

  /* Jade green */
  --jade: #3cb371;
  --jade-light: #50c878;
  --jade-soft: rgba(60, 179, 113, 0.15);

  /* Blue */
  --blue: #4a90d9;
  --blue-light: #6ab0ff;
  --blue-soft: rgba(74, 144, 217, 0.15);

  /* Text */
  --text-primary: #e8e0d0;
  --text-secondary: #a09888;
  --text-dim: #665e50;
  --text-bright: #fff8ee;

  /* Star colors */
  --star-major: var(--gold);
  --star-lucky: var(--jade-light);
  --star-unlucky: var(--red-light);
  --star-minor: #7a7a9a;
  --sihua-lu: #50c878;
  --sihua-quan: #d4a853;
  --sihua-ke: #6ab0ff;
  --sihua-ji: #e8505b;

  /* Typography */
  --font-primary: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --font-classical: 'STKaiti', 'KaiTi', 'PingFang SC', serif;
  --font-lang: var(--font-primary);  /* Overridden per language via JS */

  /* Spacing */
  --palace-gap: 2px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;
}

/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-lang, var(--font-primary));
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* === Starfield Background === */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    radial-gradient(1px 1px at 10% 20%, rgba(212,168,83,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 30% 60%, rgba(212,168,83,0.2) 0%, transparent 100%),
    radial-gradient(1px 1px at 50% 10%, rgba(212,168,83,0.25) 0%, transparent 100%),
    radial-gradient(1px 1px at 70% 40%, rgba(212,168,83,0.15) 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 80%, rgba(212,168,83,0.2) 0%, transparent 100%),
    radial-gradient(1px 1px at 15% 85%, rgba(232,200,122,0.15) 0%, transparent 100%),
    radial-gradient(1px 1px at 45% 45%, rgba(232,200,122,0.1) 0%, transparent 100%),
    radial-gradient(1px 1px at 75% 15%, rgba(232,200,122,0.2) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 25% 35%, rgba(255,248,238,0.15) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 55% 75%, rgba(255,248,238,0.1) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 85% 55%, rgba(255,248,238,0.15) 0%, transparent 100%),
    radial-gradient(0.8px 0.8px at 5% 50%, rgba(212,168,83,0.2) 0%, transparent 100%),
    radial-gradient(0.8px 0.8px at 35% 90%, rgba(212,168,83,0.15) 0%, transparent 100%),
    radial-gradient(0.8px 0.8px at 65% 25%, rgba(212,168,83,0.2) 0%, transparent 100%),
    radial-gradient(0.8px 0.8px at 95% 65%, rgba(212,168,83,0.15) 0%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}

/* === App Shell === */
#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Top Navigation === */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: linear-gradient(180deg, rgba(10,10,20,0.95) 0%, rgba(10,10,20,0.8) 100%);
  border-bottom: 1px solid var(--gold-border);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Language selector */
.lang-selector {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}
.lang-btn {
  background: transparent;
  border: 1px solid var(--gold-border);
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.78rem;
  font-family: var(--font-primary);
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.lang-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}
.lang-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg-card);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-md);
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 200;
  max-height: 70vh;
  overflow-y: auto;
}
.lang-dropdown.open {
  display: block;
}
.lang-item {
  padding: 8px 14px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.82rem;
  transition: all var(--transition-fast);
}
.lang-item:hover {
  background: rgba(212,168,83,0.08);
  color: var(--gold-light);
}
.lang-item.active {
  background: rgba(212,168,83,0.12);
  color: var(--gold);
}
/* Text-based language icon (简/繁) */
.lang-text-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4em;
  height: 1.4em;
  font-size: 0.72em;
  font-weight: 700;
  color: var(--gold);
  border: 1.5px solid var(--gold-border);
  border-radius: 3px;
  vertical-align: middle;
  line-height: 1;
  font-family: var(--font-primary);
}
.lang-emoji-icon {
  vertical-align: middle;
}
/* RTL support for Arabic */
[dir="rtl"] .top-nav { flex-direction: row-reverse; }
[dir="rtl"] .nav-tabs { flex-direction: row-reverse; }
[dir="rtl"] .lang-selector { margin-left: 0; margin-right: auto; }
[dir="rtl"] .lang-dropdown { right: auto; left: 0; }
[dir="rtl"] .form-row { direction: rtl; }
[dir="rtl"] .birth-info-bar { direction: rtl; }
[dir="rtl"] .palace-cell { direction: rtl; }
[dir="rtl"] .detail-panel { direction: rtl; text-align: right; }
[dir="rtl"] .filter-bar { direction: rtl; }
[dir="rtl"] .analysis-toggle { direction: rtl; }

.app-title {
  font-family: var(--font-classical);
  font-size: 1.5rem;
  color: var(--gold);
  letter-spacing: 4px;
  text-shadow: 0 0 20px rgba(212,168,83,0.3);
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-title .icon {
  font-size: 1.8rem;
}

.nav-tabs {
  display: flex;
  gap: 4px;
  list-style: none;
}

.nav-tabs li {
  padding: 8px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.9rem;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  letter-spacing: 1px;
}

.nav-tabs li:hover {
  color: var(--gold-light);
  background: var(--gold-glow);
}

.nav-tabs li.active {
  color: var(--gold);
  background: rgba(212,168,83,0.1);
  border-color: var(--gold-border);
}

/* === Main Content Area === */
.main-content {
  flex: 1;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* === Sections (pages) === */
.section {
  display: none;
  width: 100%;
  max-width: 1400px;
  animation: fadeIn 0.4s ease;
}

.section.active {
  display: block;
}

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

/* === Input Form Section === */
.input-section {
  display: none;
  flex-direction: column;
  align-items: center;
  padding-top: 40px;
}

.input-section.active {
  display: flex;
}

.input-card {
  background: linear-gradient(145deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-lg);
  padding: 40px 48px;
  width: 100%;
  max-width: 520px;
  box-shadow:
    0 4px 30px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(212,168,83,0.1);
}

.input-card h2 {
  font-family: var(--font-classical);
  color: var(--gold);
  font-size: 1.6rem;
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: 6px;
}

.input-card .subtitle {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 32px;
  letter-spacing: 2px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 6px;
  letter-spacing: 1px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

.input-field, select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid rgba(212,168,83,0.15);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 0.95rem;
  transition: border-color var(--transition-fast);
  outline: none;
  -webkit-appearance: none;
}

select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23d4a853' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.input-field:focus, select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-glow);
}

/* Calendar type toggle */
.calendar-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--gold-border);
}

.calendar-toggle button {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-primary);
  font-size: 0.9rem;
  transition: all var(--transition-fast);
  letter-spacing: 2px;
}

.calendar-toggle button.active {
  background: linear-gradient(135deg, rgba(212,168,83,0.2) 0%, rgba(212,168,83,0.1) 100%);
  color: var(--gold);
}

.calendar-toggle button:hover:not(.active) {
  background: rgba(212,168,83,0.05);
  color: var(--gold-light);
}

/* Gender toggle */
.gender-toggle {
  display: flex;
  gap: 12px;
}

.gender-option {
  flex: 1;
  padding: 10px;
  text-align: center;
  background: var(--bg-input);
  border: 1px solid rgba(212,168,83,0.15);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  font-size: 0.95rem;
}

.gender-option.active {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-glow);
}

.gender-option:hover:not(.active) {
  border-color: rgba(212,168,83,0.3);
  color: var(--text-primary);
}

/* Submit button */
.btn-primary {
  width: 100%;
  padding: 14px;
  margin-top: 12px;
  background: linear-gradient(135deg, var(--gold-dark) 0%, var(--gold) 50%, var(--gold-dark) 100%);
  background-size: 200% 100%;
  border: none;
  border-radius: var(--radius-md);
  color: var(--bg-deep);
  font-family: var(--font-classical);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 8px;
  cursor: pointer;
  transition: all var(--transition-normal);
  text-shadow: 0 1px 0 rgba(255,255,255,0.1);
}

.btn-primary:hover {
  background-position: 100% 0;
  box-shadow: 0 0 30px rgba(212,168,83,0.3);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

/* === Chart Section === */
.chart-section {
  display: none;
}

.chart-section.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Birth info bar */
.birth-info-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--bg-card);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-lg);
  font-size: 0.85rem;
  color: var(--text-secondary);
  flex-wrap: wrap;
  justify-content: center;
}

.birth-info-bar .info-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.birth-info-bar .info-label {
  color: var(--text-dim);
}

.birth-info-bar .info-value {
  color: var(--gold-light);
  font-weight: 500;
}

.birth-info-bar .divider {
  width: 1px;
  height: 16px;
  background: var(--gold-border);
}

.btn-back {
  padding: 6px 16px;
  background: transparent;
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--transition-fast);
}

.btn-back:hover {
  border-color: var(--gold);
  color: var(--gold);
}

/* === The 命盘 Grid === */
.chart-wrapper {
  display: flex;
  gap: 16px;
  width: 100%;
  align-items: stretch;
  justify-content: center;
}

.chart-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  grid-template-areas:
    "si   wu   wei  shen"
    "chen center center you"
    "mao  center center xu"
    "yin  chou  zi   hai";
  gap: var(--palace-gap);
  width: 100%;
  max-width: 720px;
  min-width: 480px;
  aspect-ratio: 1;
  flex-shrink: 0;
  position: relative;
}

/* 三方四正 SVG overlay */
.sanfang-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 10;
}

/* Highlight 三方四正 palaces */
.palace-cell.sanfang-target {
  box-shadow: inset 0 0 12px rgba(212,168,83,0.25), 0 0 8px rgba(212,168,83,0.15);
  border-color: rgba(212,168,83,0.5);
}

/* Palace cells */
.palace-cell {
  background: var(--bg-palace);
  border: 1px solid rgba(212,168,83,0.12);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.palace-cell::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--gold-border) 50%, transparent 100%);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.palace-cell:hover {
  background: var(--bg-palace-hover);
  border-color: rgba(212,168,83,0.25);
  z-index: 2;
}

.palace-cell:hover::before {
  opacity: 1;
}

.palace-cell.is-ming {
  border-color: var(--gold);
  box-shadow: 0 0 15px rgba(212,168,83,0.15), inset 0 0 15px rgba(212,168,83,0.05);
}

.palace-cell.is-shen {
  border-color: var(--blue);
  box-shadow: 0 0 15px rgba(74,144,217,0.15);
}

.palace-cell.selected {
  background: var(--bg-palace-active);
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(212,168,83,0.2);
}

/* Grid area assignments */
.palace-si   { grid-area: si; }
.palace-wu   { grid-area: wu; }
.palace-wei  { grid-area: wei; }
.palace-shen { grid-area: shen; }
.palace-you  { grid-area: you; }
.palace-xu   { grid-area: xu; }
.palace-hai  { grid-area: hai; }
.palace-zi   { grid-area: zi; }
.palace-chou { grid-area: chou; }
.palace-yin  { grid-area: yin; }
.palace-mao  { grid-area: mao; }
.palace-chen { grid-area: chen; }

/* Palace header */
.palace-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.palace-name {
  font-family: var(--font-classical);
  font-size: 0.8rem;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

/* ★ and ◆ markers are individually colored via inline styles in JS */

.palace-branch {
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* Stars in palace */
.palace-stars {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.star-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 4px;
}

.star-name {
  font-size: 0.78rem;
  white-space: nowrap;
  line-height: 1.4;
  overflow: visible;
}

.star-name.major {
  color: var(--star-major);
  font-weight: 600;
}

.star-name.lucky {
  color: var(--star-lucky);
}

.star-name.unlucky {
  color: var(--star-unlucky);
}

.star-name.minor {
  color: var(--star-minor);
  font-size: 0.7rem;
}

/* Clickable star links */
.star-link {
  cursor: pointer;
  transition: all 0.2s ease;
  border-bottom: 1px dotted transparent;
}
.star-link:hover {
  filter: brightness(1.3);
  border-bottom-color: currentColor;
}
.palace-cell .star-link:hover {
  text-shadow: 0 0 8px currentColor;
}

/* Star category labels in palace cells */
.star-cat-label {
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0 3px;
  border-radius: 2px;
  line-height: 1.4;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0.55;
  transition: opacity 0.2s;
  border: 1px solid;
}
.star-cat-label:hover {
  opacity: 1;
}
.star-cat-label.cat-major {
  color: var(--star-major);
  border-color: var(--star-major);
}
.star-cat-label.cat-lucky {
  color: var(--star-lucky);
  border-color: var(--star-lucky);
}
.star-cat-label.cat-unlucky {
  color: var(--star-unlucky);
  border-color: var(--star-unlucky);
}

/* Glossary collapse */
.glossary-content {
  overflow: hidden;
  max-height: 2000px;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  opacity: 1;
}
.glossary-content.collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0 !important;
}

/* Brightness indicator */
.star-brightness {
  font-size: 0.6rem;
  color: var(--text-dim);
  margin-left: 1px;
  vertical-align: super;
}

/* 四化 badge */
.sihua-badge {
  font-size: 0.6rem;
  padding: 0 3px;
  border-radius: 2px;
  margin-left: 2px;
  font-weight: 600;
  vertical-align: super;
}

.sihua-badge.lu { color: var(--sihua-lu); background: rgba(80,200,120,0.15); }
.sihua-badge.quan { color: var(--sihua-quan); background: rgba(212,168,83,0.15); }
.sihua-badge.ke { color: var(--sihua-ke); background: rgba(106,176,255,0.15); }
.sihua-badge.ji { color: var(--sihua-ji); background: rgba(232,80,91,0.15); }

/* Palace footer - 大限 */
.palace-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.04);
  flex-shrink: 0;
}

.daxian-label {
  font-size: 0.55rem;
  color: var(--text-dim);
  opacity: 0.6;
  letter-spacing: 1px;
}

.daxian-range {
  font-size: 0.65rem;
  color: var(--text-dim);
}

.daxian-range.active-period {
  color: var(--gold);
  font-weight: 500;
}

/* === Center Panel === */
.center-panel {
  grid-area: center;
  background: linear-gradient(145deg, var(--bg-center) 0%, rgba(8,8,16,0.95) 100%);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  position: relative;
  overflow: hidden;
}

.center-panel::before {
  content: '';
  position: absolute;
  top: -50%; left: -50%; right: -50%; bottom: -50%;
  background: radial-gradient(circle at center, rgba(212,168,83,0.04) 0%, transparent 70%);
  pointer-events: none;
}

/* center-title removed — app title already in top nav */

.center-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  position: relative;
}

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

.center-info .label {
  color: var(--text-dim);
}

.center-info .value {
  color: var(--text-primary);
}

.center-info .highlight {
  color: var(--gold);
}

.center-divider {
  width: 60%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-border), transparent);
  margin: 4px 0;
  flex-shrink: 0;
}

/* 五行局 badge */
.wuxingju-badge {
  display: inline-block;
  padding: 4px 16px;
  border: 1px solid var(--gold-border);
  border-radius: 20px;
  font-family: var(--font-classical);
  font-size: 0.9rem;
  color: var(--gold);
  margin: 8px 0;
  letter-spacing: 2px;
}

/* === Detail Panel (side) === */
.detail-panel {
  flex: 1;
  min-width: 280px;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  overflow-y: auto;
  display: block;
  /* Match chart height for visual balance */
  max-height: 720px;
}

.detail-panel.visible {
  animation: slideIn 0.3s ease;
}

.detail-panel .panel-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-dim);
  text-align: center;
  gap: 12px;
}
.detail-panel .panel-placeholder .hint-icon {
  font-size: 2rem;
  opacity: 0.4;
}
.detail-panel .panel-placeholder p {
  font-size: 0.85rem;
  letter-spacing: 1px;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.detail-panel h3 {
  font-family: var(--font-classical);
  color: var(--gold);
  font-size: 1.2rem;
  letter-spacing: 3px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gold-border);
}

/* === Chart Legend Panel === */
.chart-legend {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
}
.legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.legend-title {
  font-family: var(--font-classical);
  color: var(--gold);
  font-size: 0.9rem;
  letter-spacing: 2px;
}
.legend-header .toggle-icon {
  color: var(--gold);
  font-size: 1rem;
}
.legend-body {
  margin-top: 14px;
  overflow: hidden;
  max-height: 800px;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  opacity: 1;
}
.legend-body.collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}
.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px 24px;
}
.legend-group h4 {
  color: var(--text-primary);
  font-size: 0.82rem;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 3px 0;
  cursor: pointer;
  transition: color 0.2s;
}
.legend-item:hover {
  color: var(--gold-light);
}
.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-item .sihua-badge {
  vertical-align: baseline;
  font-size: 0.7rem;
}
.legend-item .star-brightness {
  vertical-align: baseline;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.legend-tip {
  margin-top: 12px;
  font-size: 0.78rem;
  color: var(--text-dim);
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 10px;
}

.detail-section {
  margin-bottom: 16px;
}

.detail-section h4 {
  color: var(--gold-light);
  font-size: 0.9rem;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.detail-section h4::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 14px;
  background: var(--gold);
  border-radius: 2px;
}

.detail-text {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.8;
  text-align: justify;
}

/* Star list in detail */
.detail-star-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.detail-star-tag {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  border: 1px solid;
}

.detail-star-tag.major {
  color: var(--star-major);
  border-color: rgba(212,168,83,0.3);
  background: rgba(212,168,83,0.08);
}

.detail-star-tag.lucky {
  color: var(--star-lucky);
  border-color: rgba(80,200,120,0.3);
  background: rgba(80,200,120,0.08);
}

.detail-star-tag.unlucky {
  color: var(--star-unlucky);
  border-color: rgba(232,80,91,0.3);
  background: rgba(232,80,91,0.08);
}

/* === Pattern Section === */
.pattern-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pattern-card {
  background: var(--bg-card);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  transition: all var(--transition-fast);
}

.pattern-card:hover {
  border-color: var(--gold);
  box-shadow: 0 2px 15px rgba(212,168,83,0.1);
}

.pattern-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.pattern-name {
  font-family: var(--font-classical);
  font-size: 1.1rem;
  color: var(--text-bright);
  letter-spacing: 2px;
}

.pattern-badge {
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 1px;
}

.pattern-badge.auspicious {
  color: var(--jade);
  background: var(--jade-soft);
  border: 1px solid rgba(60,179,113,0.3);
}

.pattern-badge.inauspicious {
  color: var(--red-light);
  background: var(--red-soft);
  border: 1px solid rgba(196,30,58,0.3);
}

.pattern-desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.7;
}

.pattern-stars {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* Clickable 流年 card */
.liunian-card {
  cursor: pointer;
  transition: all var(--transition-fast);
}
.liunian-card:hover {
  border-color: var(--gold);
  box-shadow: 0 2px 12px rgba(212,168,83,0.15);
}
.liunian-card .liunian-expand {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.liunian-card .click-hint {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-align: right;
  margin-top: 4px;
}

/* Current year highlight */
.liunian-card.current-year {
  border-color: var(--gold);
  background: rgba(212,168,83,0.05);
}
.liunian-card.current-year::before {
  content: '今年';
  position: absolute;
  top: 4px; right: 8px;
  font-size: 0.65rem;
  color: var(--gold);
  letter-spacing: 1px;
}

/* === Period Timeline === */
.period-timeline {
  display: flex;
  gap: 2px;
  padding: 12px 0;
  overflow-x: auto;
  /* Don't use justify-content: center — it clips left-side items on overflow.
     Instead, auto-margin on children centers when there's space. */
}

.period-timeline::before,
.period-timeline::after {
  content: '';
  margin: auto;
}

.period-block {
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid rgba(212,168,83,0.1);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all var(--transition-fast);
  min-width: 72px;
  flex-shrink: 0;
}

.period-block:hover {
  border-color: var(--gold-border);
  background: var(--bg-palace-hover);
}

.period-block.active {
  border-color: var(--gold);
  background: var(--gold-glow);
}

.period-block .age-range {
  font-size: 0.75rem;
  color: var(--gold-light);
  font-weight: 500;
}

.period-block .palace-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 2px;
}

/* === Encyclopedia Section === */
.encyclopedia-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.star-card {
  background: var(--bg-card);
  border: 1px solid rgba(212,168,83,0.12);
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.star-card:hover {
  border-color: var(--gold-border);
  box-shadow: 0 2px 15px rgba(0,0,0,0.3);
  transform: translateY(-2px);
}

.star-card .star-title {
  font-family: var(--font-classical);
  font-size: 1.2rem;
  color: var(--gold);
  margin-bottom: 4px;
  letter-spacing: 2px;
}

.star-card .star-element {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.star-card .star-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Brightness table */
.brightness-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.78rem;
}

.brightness-table th {
  color: var(--text-dim);
  font-weight: normal;
  padding: 4px 6px;
  text-align: center;
  border-bottom: 1px solid rgba(212,168,83,0.1);
}

.brightness-table td {
  text-align: center;
  padding: 4px 6px;
  color: var(--text-secondary);
}

.brightness-table .miao { color: var(--gold); font-weight: 600; }
.brightness-table .wang { color: var(--gold-light); }
.brightness-table .de { color: var(--text-primary); }
.brightness-table .ping { color: var(--text-secondary); }
.brightness-table .xian { color: var(--red-light); }

/* === Marriage Section === */
.marriage-section h3 {
  font-family: var(--font-classical);
  color: var(--gold);
  font-size: 1.2rem;
  letter-spacing: 3px;
  margin-bottom: 16px;
}

.marriage-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.marriage-card {
  background: var(--bg-card);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-md);
  padding: 20px;
}

.marriage-card h4 {
  color: var(--gold-light);
  font-size: 0.95rem;
  margin-bottom: 12px;
}

/* === Empty State / Intro === */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.9rem;
  letter-spacing: 1px;
}

/* === Section Headers === */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gold-border);
}

.section-header h2 {
  font-family: var(--font-classical);
  font-size: 1.3rem;
  color: var(--gold);
  letter-spacing: 4px;
}

/* === Scrollbar Styling === */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(212,168,83,0.2);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(212,168,83,0.35);
}

/* === Responsive === */
@media (max-width: 1100px) {
  .chart-wrapper {
    flex-direction: column;
    align-items: center;
  }

  .detail-panel {
    max-width: 100%;
    min-width: auto;
    max-height: none;
  }

  .chart-container {
    max-width: 600px;
    min-width: auto;
  }
}

@media (max-width: 700px) {
  .top-nav {
    flex-direction: column;
    gap: 10px;
    padding: 10px 16px;
  }

  .nav-tabs {
    flex-wrap: wrap;
    justify-content: center;
  }

  .nav-tabs li {
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  .chart-container {
    max-width: 100%;
    min-width: auto;
  }

  .palace-cell {
    padding: 4px 5px;
  }

  .star-name { font-size: 0.7rem; }
  .palace-name { font-size: 0.72rem; }

  .input-card {
    padding: 24px 20px;
  }

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

/* === Small mobile (≤480px) — prevent text overflow in palace cells === */
@media (max-width: 480px) {
  .chart-container {
    gap: 1px;
    /* Remove square constraint — let rows grow to fit content */
    aspect-ratio: auto;
    grid-template-rows: auto auto auto auto;
    min-width: 0;
  }

  .palace-cell {
    padding: 3px 4px;
    overflow: visible;
    min-width: 0;
    min-height: 0;
  }

  /* On small screens, disable star link clicks inside palace cells
     so tapping anywhere selects the palace instead of triggering
     individual star explanations. Stars are still shown in the detail panel. */
  .palace-cell .star-link {
    pointer-events: none;
  }

  .palace-header {
    margin-bottom: 2px;
  }

  .palace-name {
    font-size: 0.65rem;
    letter-spacing: 0;
  }

  .palace-branch {
    font-size: 0.55rem;
  }

  .star-name {
    font-size: 0.6rem;
    white-space: normal;
    word-break: break-all;
    line-height: 1.3;
  }

  .star-name.minor {
    font-size: 0.52rem;
  }

  .star-row {
    gap: 1px 3px;
  }

  .palace-stars {
    gap: 1px;
    overflow: visible;
    min-height: 0;
  }

  .star-brightness {
    font-size: 0.48rem;
  }

  .sihua-badge {
    font-size: 0.48rem;
    padding: 0 2px;
    margin-left: 1px;
  }

  .palace-footer {
    padding-top: 2px;
  }

  .daxian-label {
    font-size: 0.48rem;
  }

  .daxian-range {
    font-size: 0.52rem;
  }

  /* Center panel compact */
  .center-panel {
    padding: 8px 10px;
    overflow: visible;
  }

  .center-info {
    gap: 4px;
  }

  .center-info .info-line {
    font-size: 0.62rem;
  }

  .center-divider {
    margin: 2px 0;
  }

  .wuxingju-badge {
    font-size: 0.68rem;
    padding: 2px 8px;
    margin: 4px 0;
  }

  .star-cat-label {
    font-size: 0.48rem;
    padding: 0 2px;
  }

  .main-content {
    padding: 10px 4px;
  }

  .birth-info-bar {
    padding: 8px 12px;
    gap: 12px;
    font-size: 0.75rem;
  }

  .chart-wrapper {
    gap: 10px;
  }
}

/* === Extra small mobile (≤360px) — ultra-compact palace display === */
@media (max-width: 360px) {
  .palace-cell {
    padding: 2px 3px;
  }

  .palace-name {
    font-size: 0.58rem;
  }

  .palace-branch {
    font-size: 0.5rem;
  }

  .star-name {
    font-size: 0.52rem;
  }

  .star-name.minor {
    font-size: 0.45rem;
  }

  .star-brightness {
    font-size: 0.42rem;
  }

  .sihua-badge {
    font-size: 0.42rem;
    padding: 0 1px;
  }

  .daxian-label {
    font-size: 0.42rem;
  }

  .daxian-range {
    font-size: 0.46rem;
  }

  .center-panel {
    padding: 6px 6px;
  }

  .center-info .info-line {
    font-size: 0.56rem;
  }

  .wuxingju-badge {
    font-size: 0.6rem;
    padding: 2px 6px;
  }

  .main-content {
    padding: 8px 2px;
  }
}

/* === Decorative Elements === */
.ornament-line {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0;
  color: var(--gold-border);
}

.ornament-line::before,
.ornament-line::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-border), transparent);
}

.ornament-line span {
  font-size: 0.8rem;
  color: var(--text-dim);
  letter-spacing: 4px;
  white-space: nowrap;
}

/* === Tooltip === */
.tooltip {
  position: absolute;
  background: var(--bg-secondary);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.8rem;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  max-width: 250px;
}

/* === Loading Spinner === */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.loading::after {
  content: '';
  width: 32px;
  height: 32px;
  border: 2px solid var(--gold-border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* === Tab Content within sections === */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

/* Filter buttons */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 14px;
  background: transparent;
  border: 1px solid rgba(212,168,83,0.15);
  border-radius: 16px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all var(--transition-fast);
}

.filter-btn:hover {
  border-color: var(--gold-border);
  color: var(--gold-light);
}

.filter-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-glow);
}

/* Analysis primary toggle — 先天命运 / 今年运势 */
.analysis-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--gold-border);
  max-width: 320px;
}

.analysis-toggle .toggle-btn {
  flex: 1;
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-primary);
  font-size: 0.9rem;
  transition: all var(--transition-fast);
  letter-spacing: 1px;
}

.analysis-toggle .toggle-btn.active {
  background: linear-gradient(135deg, rgba(212,168,83,0.2) 0%, rgba(212,168,83,0.1) 100%);
  color: var(--gold);
}

.analysis-toggle .toggle-btn:hover:not(.active) {
  background: rgba(212,168,83,0.05);
  color: var(--gold-light);
}

/* ============================================
   About Section
   ============================================ */
.about-container {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 0;
}
.about-hero {
  text-align: center;
  margin-bottom: 32px;
}
.about-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(212,168,83,0.4);
}
.about-hero h2 {
  font-family: var(--font-classical);
  font-size: 1.6rem;
  color: var(--gold);
  letter-spacing: 6px;
}
.about-card {
  background: var(--bg-card);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 16px;
}
.about-card h3 {
  font-family: var(--font-classical);
  color: var(--gold);
  font-size: 1.05rem;
  letter-spacing: 2px;
  margin-bottom: 12px;
}
.about-card p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.8;
}
.about-features {
  list-style: none;
  padding: 0;
}
.about-features li {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.8;
  padding: 4px 0 4px 20px;
  position: relative;
}
.about-features li::before {
  content: '✦';
  position: absolute;
  left: 0;
  color: var(--gold);
  font-size: 0.65rem;
  top: 7px;
}
.about-steps {
  padding-left: 24px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 2;
}
.about-steps li::marker {
  color: var(--gold);
}
.about-url {
  font-size: 0.82rem;
  color: var(--text-dim);
  letter-spacing: 1px;
  margin-top: 4px;
  opacity: 0.7;
}
.about-card p + p {
  margin-top: 10px;
}
.disclaimer-card {
  border-color: rgba(196, 30, 58, 0.3);
  background: linear-gradient(135deg, rgba(196, 30, 58, 0.05), var(--bg-card));
}
.disclaimer-card h3 {
  color: var(--red-light);
}
.disclaimer-card p + p {
  margin-top: 8px;
  font-size: 0.82rem;
}
.about-footer {
  text-align: center;
  margin-top: 32px;
  padding-top: 20px;
}
.about-footer .copyright {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 16px;
  line-height: 1.8;
}

/* Input section disclaimer */
.input-disclaimer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-dim);
  max-width: 420px;
  margin: 16px auto 0;
  line-height: 1.6;
  opacity: 0.7;
}

/* ===== Wisdom Section ===== */
.wisdom-subtitle {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 4px;
}

.wisdom-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.wisdom-card {
  display: flex;
  gap: 14px;
  padding: 18px 20px;
  background: linear-gradient(135deg, rgba(212,168,83,0.06), rgba(212,168,83,0.02));
  border: 1px solid rgba(212,168,83,0.15);
  border-radius: var(--radius-md);
  transition: border-color 0.3s, box-shadow 0.3s;
}
.wisdom-card:hover {
  border-color: rgba(212,168,83,0.35);
  box-shadow: 0 2px 16px rgba(212,168,83,0.08);
}

.wisdom-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.wisdom-content {
  flex: 1;
  min-width: 0;
}

.wisdom-text {
  color: var(--text-primary);
  font-size: 0.88rem;
  line-height: 1.7;
  margin: 0;
}

.wisdom-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 0.75rem;
}

.wisdom-cat {
  color: var(--gold);
  background: rgba(212,168,83,0.1);
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 0.7rem;
}

.wisdom-src {
  color: var(--text-dim);
  font-style: italic;
}

.wisdom-source {
  text-align: center;
  margin-top: 32px;
  padding: 16px;
  border-top: 1px solid rgba(212,168,83,0.1);
  color: var(--text-dim);
  font-size: 0.75rem;
}

@media (max-width: 700px) {
  .wisdom-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================
 * Browser Language Detection Banner
 * ============================================ */
.lang-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: linear-gradient(135deg, rgba(30,28,38,0.97), rgba(40,36,50,0.97));
  border-top: 1px solid rgba(212,168,83,0.3);
  backdrop-filter: blur(12px);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: slideUp 0.4s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.lang-banner-content {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 900px;
  width: 100%;
}
.lang-banner-content span {
  flex: 1;
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.5;
}
.lang-banner-close {
  background: none;
  border: 1px solid rgba(212,168,83,0.3);
  color: var(--gold);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  transition: background 0.2s;
  flex-shrink: 0;
}
.lang-banner-close:hover {
  background: rgba(212,168,83,0.15);
}
