/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;500;600;700;800;900&display=swap');

/* ── CSS Variables (Design Tokens) ── */
:root {
  /* Colors */
  --bg-primary: #0a0a0f;
  --bg-secondary: #13131a;
  --bg-tertiary: #1e1e2a;
  --bg-card: #13131a;
  --bg-input: #1a1a25;

  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #6b7280;
  --text-dark: #191F28;

  --accent: #8b5cf6;
  --accent-light: rgba(139, 92, 246, 0.15);
  --accent-dark: #7c3aed;
  --accent-glow: rgba(139, 92, 246, 0.4);

  --border: #2a2a3a;
  --border-light: #3a3a4a;

  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;

  /* Five Elements */
  --wood: #22C55E;
  --fire: #EF4444;
  --earth: #EAB308;
  --metal: #94A3B8;
  --water: #3B82F6;

  /* Typography */
  --font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Spacing & Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--accent-glow);
}

/* ── Reset & Base ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Layout ── */
.app-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
  min-height: 100vh;
  position: relative;
}

/* ── Header ── */
.app-header {
  text-align: center;
  padding: 40px 0 24px;
}

.app-logo {
  font-size: 2rem;
  margin-bottom: 8px;
}

.app-title {
  font-size: 1.75rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #c084fc, var(--accent-dark));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

.app-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Sections ── */
.section {
  display: none;
}

.section.active {
  display: block;
  animation: fadeIn 0.4s ease-out;
}

/* ── Form Card ── */
.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px 24px;
  margin-bottom: 24px;
}

.form-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 4px;
}

.form-description {
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 24px;
}

/* ── Form Groups ── */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* ── Input Fields ── */
.form-input {
  width: 100%;
  height: 48px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 16px;
  font-size: 1rem;
  font-family: var(--font-family);
  color: var(--text-primary);
  transition: all 0.2s ease;
  outline: none;
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-input::-webkit-inner-spin-button,
.form-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.form-input[type="number"] {
  -moz-appearance: textfield;
  text-align: center;
}

/* ── Select ── */
.form-select {
  width: 100%;
  height: 48px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 16px;
  font-size: 1rem;
  font-family: var(--font-family);
  color: var(--text-primary);
  transition: all 0.2s ease;
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  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='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}

.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* ── Birth Date Row ── */
.birth-date-row {
  display: flex;
  gap: 8px;
}

.birth-date-row .form-input:first-child {
  flex: 2;
}

.birth-date-row .form-input:nth-child(2),
.birth-date-row .form-input:nth-child(3) {
  flex: 1;
}

/* ── Toggle Buttons (Gender / Calendar) ── */
.toggle-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toggle-btn {
  height: 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 500;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 0.2s ease;
}

.toggle-btn:hover {
  border-color: var(--border-light);
}

.toggle-btn.active {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

/* ── Submit Button ── */
.btn-submit {
  width: 100%;
  height: 54px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border: none;
  border-radius: var(--radius-md);
  color: #ffffff;
  font-size: 1.125rem;
  font-weight: 700;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.btn-submit:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.btn-submit:active {
  transform: translateY(0);
}

.btn-submit::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  transition: left 0.5s ease;
}

.btn-submit:hover::after {
  left: 100%;
}

/* ── Error Messages ── */
.error-msg {
  color: var(--danger);
  font-size: 0.75rem;
  margin-top: 4px;
}

/* ── Loading Spinner ── */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 10, 15, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  margin-top: 16px;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ================================================
   RESULT SECTION
   ================================================ */

/* ── Back Button ── */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 20px;
}

.btn-back:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

/* ── Result Header ── */
.result-header {
  text-align: center;
  padding: 24px 0;
}

.result-name {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.result-birth {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ── Result Card ── */
.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  margin-bottom: 16px;
  animation: slideUp 0.5s ease-out both;
}

.result-card:nth-child(2) { animation-delay: 0.05s; }
.result-card:nth-child(3) { animation-delay: 0.1s; }
.result-card:nth-child(4) { animation-delay: 0.15s; }
.result-card:nth-child(5) { animation-delay: 0.2s; }
.result-card:nth-child(6) { animation-delay: 0.25s; }

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .icon {
  font-size: 1.1rem;
}

/* ── Four Pillars Table ── */
.pillar-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 6px;
}

.pillar-table th {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  padding-bottom: 8px;
  text-align: center;
}

.pillar-cell {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  transition: all 0.2s ease;
}

.pillar-cell:hover {
  background: var(--border);
}

.pillar-stem {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  display: block;
  margin-bottom: 4px;
}

.pillar-branch {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
  display: block;
  margin-bottom: 6px;
}

.pillar-hangul {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
}

/* ── Pillar Detail Rows ── */
.pillar-detail-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 6px 4px;
  margin-top: 12px;
}

.pillar-detail-table th {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 4px;
  text-align: center;
  white-space: nowrap;
}

.pillar-detail-table td {
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding: 6px 4px;
  text-align: center;
  background: var(--bg-tertiary);
  border-radius: 6px;
}

/* ── Five Element Chart ── */
.ohang-chart-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ohang-canvas {
  width: 100%;
  max-width: 280px;
  height: 280px;
}

.ohang-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.ohang-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.ohang-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* ── Bar Chart (Alternative) ── */
.ohang-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.ohang-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ohang-bar-label {
  font-size: 0.8125rem;
  font-weight: 600;
  width: 55px;
  text-align: right;
  color: var(--text-secondary);
}

.ohang-bar-track {
  flex: 1;
  height: 24px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.ohang-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.8s ease-out;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  font-size: 0.6875rem;
  font-weight: 700;
  color: #fff;
  min-width: 28px;
}

/* ── Sipsin / Unseong Tags ── */
.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 600;
  background: var(--accent-light);
  color: var(--accent);
}

/* ── Relations ── */
.relation-list {
  list-style: none;
}

.relation-item {
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.relation-type {
  font-weight: 700;
  color: var(--accent);
  min-width: 32px;
}

/* ── Daewoon (大運) ── */
.daewoon-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}

.daewoon-scroll::-webkit-scrollbar {
  height: 4px;
}

.daewoon-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.daewoon-grid {
  display: flex;
  gap: 8px;
  min-width: max-content;
}

.daewoon-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  min-width: 72px;
  transition: all 0.2s ease;
}

.daewoon-item:hover {
  background: var(--border);
  transform: translateY(-2px);
}

.daewoon-age {
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.daewoon-ganzi {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.daewoon-sipsin {
  font-size: 0.625rem;
  color: var(--accent);
  font-weight: 600;
}

/* ── Save Button ── */
.btn-save {
  width: 100%;
  height: 50px;
  background: var(--bg-tertiary);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 0.2s ease;
  margin-top: 8px;
  margin-bottom: 32px;
}

.btn-save:hover {
  background: var(--accent-light);
  box-shadow: var(--shadow-glow);
}

/* ── Toast Notification ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-tertiary);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 12px 24px;
  color: var(--text-primary);
  font-size: 0.875rem;
  z-index: 2000;
  opacity: 0;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ── Footer ── */
.app-footer {
  text-align: center;
  padding: 32px 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: 24px;
}

.app-footer a {
  color: var(--accent);
  text-decoration: none;
}

/* ================================================
   ANIMATIONS
   ================================================ */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 5px var(--accent-glow); }
  50% { box-shadow: 0 0 25px var(--accent-glow); }
}

@keyframes shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}

/* ================================================
   RESPONSIVE
   ================================================ */

@media (max-width: 360px) {
  .app-container {
    padding: 0 12px;
  }

  .form-card, .result-card {
    padding: 20px 16px;
  }

  .pillar-stem, .pillar-branch {
    font-size: 1.25rem;
  }
}

@media (min-width: 768px) {
  .app-container {
    max-width: 520px;
  }
}

/* ── AI Interpretation ── */
.ai-interpretation-content {
  font-size: 0.95rem;
  line-height: 1.8;
  color: var(--text-primary);
  background: var(--bg-input);
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-light);
}

.ai-interpretation-content strong {
  color: #fff;
  font-weight: 700;
  background-color: var(--accent-light);
  padding: 0 4px;
  border-radius: 4px;
}
