/* ==================== 紫微斗数命盘样式（文墨天机风格） ==================== */

:root {
  --bg: #f5f0e8;
  --surface: #fffdf7;
  --border: #c8b88a;
  --border-dark: #8a7a52;
  --text: #2c2416;
  --text-dim: #7a6e5a;
  --text-muted: #a09880;
  --accent: #8b1a1a;
  --accent-gold: #b8860b;

  /* 星曜颜色 */
  --star-major: #c41e3a;
  --star-soft: #6a5acd;
  --star-tough: #2e8b57;
  --star-lucun: #d4a017;
  --star-tianma: #d4a017;

  /* 四化颜色 */
  --lu-color: #228b22;
  --quan-color: #8b008b;
  --ke-color: #1e90ff;
  --ji-color: #dc143c;

  /* 宫位 */
  --palace-bg: #faf6ee;
  --palace-name-color: #1e90ff;
  --ganzhi-color: #2c2416;
  --center-bg: #f0e8d4;
}

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

body {
  font-family: 'PingFang SC', 'Microsoft YaHei', 'SimSun', serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 680px;
  margin: 0 auto;
  padding: 12px;
}

/* ==================== 输入面板 ==================== */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.panel-header {
  text-align: center;
  margin-bottom: 20px;
}

.panel-header h1 {
  font-size: 1.3rem;
  color: var(--accent);
  margin-bottom: 4px;
  font-weight: 700;
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.8rem;
}

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

.form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 3px;
}

.form-group input,
.form-group select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent-gold);
}

#submit-btn {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

#submit-btn:hover { background: #a02020; }

/* ==================== 命盘头部 ==================== */

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

.btn-back {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-dim);
}

.btn-share {
  background: var(--accent-gold);
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 1rem;
  cursor: pointer;
  color: #fff;
  transition: background 0.2s;
}

.btn-share:hover { background: #9a7209; }

.chart-info {
  flex: 1;
}

.chart-info h2 {
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 700;
}

.chart-info p {
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* ==================== 命盘主体（截图区域） ==================== */

.chart-capture {
  background: var(--palace-bg);
  border: 2px solid var(--border-dark);
  border-radius: 4px;
  padding: 2px;
}

/* ==================== 12宫格网格 ==================== */

.chart-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border-dark);
  aspect-ratio: 1 / 1;
  max-width: 660px;
  margin: 0 auto;
}

/* ==================== 宫位单元格 ==================== */

.palace-cell {
  background: var(--palace-bg);
  padding: 4px 5px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: background 0.15s;
  min-height: 0;
}

.palace-cell:hover {
  background: #f5eed8;
}

.palace-cell.is-minggong {
  background: #f8f2e0;
}

/* 宫位名称 */
.palace-name {
  font-size: 0.68rem;
  color: var(--palace-name-color);
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 1px;
}

/* 天干地支 */
.palace-ganzhi {
  font-size: 0.62rem;
  color: var(--ganzhi-color);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 2px;
}

/* 星曜列表 */
.palace-stars {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0px;
}

.star-row {
  display: flex;
  align-items: center;
  gap: 2px;
  line-height: 1.3;
  flex-wrap: wrap;
}

.star-name {
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.star-name.major { color: var(--star-major); }
.star-name.soft { color: var(--star-soft); }
.star-name.tough { color: var(--star-tough); }
.star-name.lucun { color: var(--star-lucun); }
.star-name.tianma { color: var(--star-tianma); }

/* 四化标记 - 紧跟星曜后面 */
.sihua-tag {
  display: inline-block;
  font-size: 0.55rem;
  font-weight: 700;
  padding: 0 2px;
  border-radius: 2px;
  line-height: 1.3;
  vertical-align: baseline;
}

.sihua-tag.lu { color: var(--lu-color); }
.sihua-tag.quan { color: var(--quan-color); }
.sihua-tag.ke { color: var(--ke-color); }
.sihua-tag.ji { color: var(--ji-color); }

/* 亮度标记 */
.brightness-tag {
  font-size: 0.5rem;
  color: var(--text-muted);
  margin-left: 1px;
}

/* ==================== 中心区域 ==================== */

.center-cell {
  background: var(--center-bg);
  grid-column: 2 / 4;
  grid-row: 2 / 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  text-align: center;
  border: none;
}

.center-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 4px;
  letter-spacing: 2px;
}

.center-subtitle {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.center-info {
  font-size: 0.65rem;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 6px;
}

.center-info-line {
  margin: 1px 0;
}

/* 生年四化图示 */
.sihua-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.sihua-legend-item {
  display: flex;
  align-items: center;
  gap: 1px;
  font-size: 0.6rem;
  font-weight: 600;
}

.sihua-legend-item .star-name { font-size: 0.6rem; }

.sihua-legend-arrow {
  font-size: 0.5rem;
  color: var(--text-muted);
}

/* 自化图示 */
.zihua-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  margin-top: 4px;
  font-size: 0.55rem;
  color: var(--text-dim);
}

.zihua-legend-arrow {
  font-size: 0.5rem;
}

/* ==================== 声明 ==================== */

.disclaimer {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
  padding: 10px 8px;
}

/* ==================== 加载/错误 ==================== */

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}

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

.error {
  background: rgba(220, 20, 60, 0.08);
  border: 1px solid rgba(220, 20, 60, 0.2);
  border-radius: 6px;
  padding: 12px;
  color: #c41e3a;
  text-align: center;
  font-size: 0.85rem;
}

/* ==================== 分享弹窗 ==================== */

.share-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.share-modal-content {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}

.share-modal-content h3 {
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 12px;
}

.share-preview {
  max-width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.share-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.share-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
}

.share-btn.primary {
  background: var(--accent);
  color: #fff;
}

.share-btn.secondary {
  background: var(--border);
  color: var(--text);
}

/* ==================== 响应式 ==================== */

@media (max-width: 400px) {
  .palace-cell { padding: 3px 4px; }
  .palace-name { font-size: 0.6rem; }
  .palace-ganzhi { font-size: 0.55rem; }
  .star-name { font-size: 0.62rem; }
  .sihua-tag { font-size: 0.48rem; }
  .center-title { font-size: 0.9rem; }
  .center-info { font-size: 0.58rem; }
}

@media (min-width: 500px) {
  .palace-cell { padding: 5px 7px; }
  .palace-name { font-size: 0.72rem; }
  .palace-ganzhi { font-size: 0.66rem; }
  .star-name { font-size: 0.74rem; }
  .sihua-tag { font-size: 0.58rem; }
  .center-title { font-size: 1.2rem; }
  .center-info { font-size: 0.7rem; }
}

@media (min-width: 768px) {
  #app { padding: 20px; }
  .chart-grid { max-width: 640px; }
  .palace-cell { padding: 6px 8px; }
  .star-name { font-size: 0.78rem; }
}
