:root {
  --bg-deep: #0b0f17;
  --bg-panel: #131a26;
  --bg-card: #192233;
  --bg-card-hover: #1f2b40;
  --border: #2a364d;
  --border-gold: rgba(212, 175, 55, 0.45);
  --text-main: #eef2f7;
  --text-muted: #9aa7bd;
  --gold: #e5c158;
  --gold-soft: rgba(229, 193, 88, 0.14);
  --jade: #2dd4bf;
  --jade-soft: rgba(45, 212, 191, 0.14);
  --crimson: #fb7185;
  --crimson-soft: rgba(251, 113, 133, 0.14);
  --sky: #60a5fa;
  --sky-soft: rgba(96, 165, 250, 0.14);
  --radius: 14px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", sans-serif;
  background: radial-gradient(circle at top center, #162033 0%, var(--bg-deep) 60%);
  color: var(--text-main);
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
}

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 18px 60px;
}

/* Header */
.app-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.brand {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.brand-logo-wrap {
  background: #ffffff;
  border-radius: 12px;
  padding: 6px 12px;
  border: 1px solid var(--border-gold);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.brand-logo {
  height: 36px;
  width: auto;
  display: block;
  object-fit: contain;
}

.brand h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--gold);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.brand p {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  padding: 8px 13px;
  min-height: 38px;
  border-radius: 9px;
  font-size: 0.84rem;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--gold);
}

.btn-gold {
  background: var(--gold-soft);
  border-color: var(--border-gold);
  color: var(--gold);
  font-weight: 600;
}

.btn-jade {
  background: var(--jade-soft);
  border-color: rgba(45, 212, 191, 0.45);
  color: var(--jade);
  font-weight: 600;
}

/* Control Bar */
.control-bar {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.date-inputs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

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

.field label {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.field input,
.field select {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 7px 10px;
  min-height: 38px;
  border-radius: 8px;
  font-size: 0.88rem;
}

.pillars-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.pillar-pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 5px;
}

.pillar-pill .lbl {
  color: var(--text-muted);
  font-size: 0.74rem;
}

.pillar-pill .val {
  font-weight: 700;
  color: var(--gold);
}

/* Navigation Tabs */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  padding: 10px 16px;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.tab-btn.active {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold);
}

/* Layout Grid */
.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.95fr);
  gap: 20px;
  align-items: start;
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

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

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-title {
  font-size: 1.04rem;
  font-weight: 700;
  color: var(--text-main);
}

.sub-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chip-group {
  display: inline-flex;
  flex-wrap: wrap;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
  max-width: 100%;
}

.chip {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}

.chip.active {
  background: var(--bg-card-hover);
  color: var(--gold);
  font-weight: 600;
}

/* 3x3 Luoshu Board */
.luoshu-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.palace-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px;
  min-height: 148px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  min-width: 0;
}

.palace-card:hover {
  border-color: var(--gold);
  transform: translateY(-1px);
}

.palace-card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(229, 193, 88, 0.28);
}

.palace-card.center-palace {
  background: linear-gradient(145deg, #1a2130, #121722);
  border-style: dashed;
}

.palace-card.auspicious-highlight {
  border-color: var(--jade);
  background: linear-gradient(160deg, rgba(45, 212, 191, 0.12), var(--bg-card));
}

.palace-card.best-match {
  border-color: var(--gold);
  background: linear-gradient(160deg, rgba(229, 193, 88, 0.16), var(--bg-card));
}

.palace-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  gap: 4px;
}

.palace-dir {
  font-weight: 600;
  color: var(--text-main);
}

.purple-badge {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.purple-badge.five-yellow {
  background: var(--crimson-soft);
  color: var(--crimson);
  border: 1px solid var(--crimson);
}

.palace-mid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  margin: 4px 0;
}

.spirit-tag {
  font-size: 0.78rem;
  color: var(--sky);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.star-tag {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

.gate-tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
}

.gate-tag.good {
  background: var(--jade-soft);
  color: var(--jade);
}

.gate-tag.jiksa {
  border: 1px solid var(--gold);
}

.stems-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.stem-heaven {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--gold);
}

.stem-earth {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stem-jia {
  color: #fde047;
  text-shadow: 0 0 8px rgba(253, 224, 71, 0.4);
}

.palace-bottom {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.mini-badge {
  font-size: 0.69rem;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--gold-soft);
  color: var(--gold);
}

.mini-badge.jade {
  background: var(--jade-soft);
  color: var(--jade);
}

/* AI Prompt Builder Panel */
.prompt-panel {
  border-color: var(--border-gold);
  background: linear-gradient(180deg, rgba(229, 193, 88, 0.06), var(--bg-panel) 45%);
}

.prompt-input {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-main);
  padding: 10px 12px;
  font-size: 0.88rem;
  font-family: inherit;
  resize: vertical;
  min-height: 68px;
  margin-bottom: 10px;
}

.prompt-input:focus {
  outline: none;
  border-color: var(--gold);
}

.prompt-preview {
  width: 100%;
  background: rgba(8, 11, 18, 0.85);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: #cbd5e1;
  padding: 12px;
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  line-height: 1.5;
  min-height: 170px;
  max-height: 260px;
  resize: vertical;
}

.prompt-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

/* Right Side Cards */
.list-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.list-item:last-child {
  margin-bottom: 0;
}

.list-item-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
}

.badge-gold { background: var(--gold-soft); color: var(--gold); }
.badge-jade { background: var(--jade-soft); color: var(--jade); }
.badge-crimson { background: var(--crimson-soft); color: var(--crimson); }
.badge-sky { background: var(--sky-soft); color: var(--sky); }

.muted {
  color: var(--text-muted);
  font-size: 0.84rem;
}

/* Hour Timeline */
.hours-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 9px;
}

.hour-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.hour-card.good {
  border-color: var(--jade);
  background: linear-gradient(150deg, rgba(45, 212, 191, 0.14), var(--bg-card));
}

.hour-card.bad {
  opacity: 0.65;
}

/* Comparison Table */
.compare-box {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  text-align: center;
  padding: 10px;
  background: var(--bg-card);
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

/* Guide Section */
.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.guide-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.guide-card h3 {
  color: var(--gold);
  font-size: 1.04rem;
  margin-bottom: 10px;
}

.guide-card ul {
  padding-left: 18px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.guide-card li {
  margin-bottom: 6px;
}

.guide-card strong {
  color: var(--text-main);
}

/* Mobile Responsive Refinements */
@media (max-width: 640px) {
  .container {
    padding: 14px 10px 44px;
  }

  .brand h1 {
    font-size: 1.24rem;
  }

  .presets {
    width: 100%;
  }

  .presets .btn {
    flex: 1 1 auto;
    font-size: 0.78rem;
    padding: 7px 9px;
  }

  .control-bar {
    padding: 12px;
    gap: 10px;
  }

  .date-inputs {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .field {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }

  .field input,
  .field select {
    width: 100%;
    font-size: 0.84rem;
  }

  .pillars-strip {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .pillar-pill {
    justify-content: center;
    padding: 5px 6px;
    font-size: 0.76rem;
  }

  .panel {
    padding: 12px 10px;
    border-radius: 12px;
  }

  .luoshu-grid {
    gap: 6px;
  }

  .palace-card {
    padding: 7px 6px;
    min-height: 118px;
    border-radius: 9px;
  }

  .palace-top {
    font-size: 0.68rem;
    margin-bottom: 3px;
  }

  .purple-badge {
    width: 17px;
    height: 17px;
    font-size: 0.66rem;
  }

  .spirit-tag {
    font-size: 0.68rem;
  }

  .star-tag {
    font-size: 0.76rem;
  }

  .star-hangul {
    display: none;
  }

  .stem-heaven {
    font-size: 0.82rem;
  }

  .stem-earth {
    font-size: 0.72rem;
  }

  .gate-tag {
    font-size: 0.7rem;
    padding: 2px 5px;
  }

  .mini-badge {
    font-size: 0.62rem;
    padding: 1px 4px;
  }

  .hours-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 7px;
  }

  .prompt-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .prompt-actions .btn {
    width: 100%;
  }
}
