/* ============================================
   Fortunova — Mystic Dark Theme
   AI 사주/명리 운세 시스템
   ============================================ */

/* --- Custom Properties --- */
:root {
  /* Navy depths */
  --navy-900: #0a0e27;
  --navy-800: #0f1433;
  --navy-700: #141a3d;
  --navy-600: #1a2147;
  --navy-500: #232b5c;

  /* Gold spectrum */
  --gold-600: #b8923d;
  --gold-500: #d4a853;
  --gold-400: #e8c170;
  --gold-300: #f0d590;
  --gold-200: #f5e3af;

  /* Glass surfaces */
  --glass-subtle: rgba(255, 255, 255, 0.03);
  --glass-light: rgba(255, 255, 255, 0.06);
  --glass-medium: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-border-hover: rgba(255, 255, 255, 0.15);

  /* Text hierarchy */
  --text-primary: #f0f0f5;
  --text-secondary: #a0aec0;
  --text-muted: #718096;
  --text-gold: var(--gold-400);

  /* Semantic */
  --error-bg: rgba(239, 68, 68, 0.1);
  --error-border: rgba(239, 68, 68, 0.3);
  --error-text: #fca5a5;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --warning-border: rgba(245, 158, 11, 0.3);
  --warning-text: #fcd34d;

  /* Spacing & Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Shadows */
  --shadow-gold: 0 0 20px rgba(212, 168, 83, 0.15);
  --shadow-gold-hover: 0 0 30px rgba(212, 168, 83, 0.25);
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* --- Keyframe Animations --- */

@keyframes twinkle {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

@keyframes aurora {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes glow-pulse {
  0%, 100% {
    box-shadow: 0 0 8px rgba(212, 168, 83, 0.3);
  }
  50% {
    box-shadow: 0 0 20px rgba(212, 168, 83, 0.5), 0 0 40px rgba(212, 168, 83, 0.2);
  }
}

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

@keyframes shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* --- Aurora Background --- */

.aurora-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  background: linear-gradient(
    135deg,
    var(--navy-900) 0%,
    #120f2e 25%,
    var(--navy-800) 50%,
    #0d1540 75%,
    var(--navy-900) 100%
  );
  background-size: 400% 400%;
  animation: aurora 20s ease infinite;
  will-change: background-position;
}

/* --- Starfield --- */

.stars-container {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.star {
  position: absolute;
  width: 2px;
  height: 2px;
  background: white;
  border-radius: 50%;
  animation: twinkle var(--duration, 3s) ease-in-out var(--delay, 0s) infinite;
  opacity: 0;
}

.star--large {
  width: 3px;
  height: 3px;
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.3);
}

/* --- Glassmorphism Card --- */

.glass-card {
  background: var(--glass-light);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.glass-card:hover {
  border-color: var(--glass-border-hover);
}

/* Fallback for browsers without backdrop-filter */
@supports not ((-webkit-backdrop-filter: blur(16px)) or (backdrop-filter: blur(16px))) {
  .glass-card {
    background: rgba(15, 20, 51, 0.95);
  }
}

/* --- Gold Button --- */

.btn-gold {
  background: linear-gradient(135deg, var(--gold-600), var(--gold-500), var(--gold-400));
  color: var(--navy-900);
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.3s ease, transform 0.15s ease;
  box-shadow: var(--shadow-gold);
}

.btn-gold:hover {
  box-shadow: var(--shadow-gold-hover);
  transform: translateY(-1px);
}

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

/* Shimmer overlay on hover */
.btn-gold::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.2) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.btn-gold:hover::after {
  opacity: 1;
  animation: shimmer 1.5s ease infinite;
}

/* --- Dark Input --- */

.input-dark {
  background: var(--glass-subtle);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-dark:focus {
  outline: none;
  border-color: var(--gold-500);
  box-shadow: 0 0 0 2px rgba(212, 168, 83, 0.2);
}

.input-dark::placeholder {
  color: var(--text-muted);
}

/* Select styling for dark theme */
.input-dark option {
  background: var(--navy-800);
  color: var(--text-primary);
}

/* --- Fortune Reveal --- */

.fortune-reveal {
  animation: fadeInUp 0.6s ease-out both;
}

.fortune-reveal > * {
  animation: fadeInUp 0.6s ease-out both;
}

.fortune-reveal > *:nth-child(1) { animation-delay: 0.1s; }
.fortune-reveal > *:nth-child(2) { animation-delay: 0.2s; }
.fortune-reveal > *:nth-child(3) { animation-delay: 0.3s; }
.fortune-reveal > *:nth-child(4) { animation-delay: 0.4s; }

/* --- Gold Divider --- */

.divider-gold {
  border: none;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--gold-500),
    transparent
  );
  margin: 1.5rem 0;
}

/* --- Score Glow --- */

.score-glow {
  animation: glow-pulse 2s ease-in-out infinite;
  border-radius: var(--radius-lg);
  display: inline-block;
}

/* --- HTMX Indicator (Dark Theme) --- */

.htmx-indicator {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}

.htmx-indicator .loading-text {
  color: var(--gold-400);
  font-weight: 500;
}

/* Pulsing dots indicator */
.loading-dots::after {
  content: '';
  animation: loading-dots 1.5s steps(4, end) infinite;
}

@keyframes loading-dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* --- Error & Warning Glass Cards --- */

.glass-error {
  background: var(--error-bg);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-md);
}

.glass-warning {
  background: var(--warning-bg);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-md);
}

@supports not ((-webkit-backdrop-filter: blur(16px)) or (backdrop-filter: blur(16px))) {
  .glass-error {
    background: rgba(50, 10, 10, 0.95);
  }
  .glass-warning {
    background: rgba(50, 40, 10, 0.95);
  }
}

/* --- Inline Auth Error --- */

.auth-error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-sm);
  color: var(--error-text);
}

/* --- Radio & Checkbox Dark Theme --- */

.radio-dark,
.checkbox-dark {
  accent-color: var(--gold-500);
}

/* --- Scrollbar (Webkit) --- */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--navy-900);
}

::-webkit-scrollbar-thumb {
  background: var(--navy-500);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--gold-600);
}

/* --- Form Collapse --- */

.form-section {
  max-height: 2000px;
  overflow: hidden;
  transition: max-height 0.5s ease-out, opacity 0.3s ease;
  opacity: 1;
}

.form-section.collapsed {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
  margin: 0;
  padding: 0;
}

/* --- Form Summary (shown when collapsed) --- */

.form-summary {
  animation: fadeInUp 0.4s ease-out;
  margin-bottom: 0.5rem;
}

/* --- Loading Orb --- */

@keyframes orb-glow {
  0%, 100% {
    box-shadow: 0 0 20px rgba(212, 168, 83, 0.4), 0 0 60px rgba(212, 168, 83, 0.2);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 40px rgba(212, 168, 83, 0.6), 0 0 80px rgba(212, 168, 83, 0.3), 0 0 120px rgba(212, 168, 83, 0.1);
    transform: scale(1.1);
  }
}

.orb-glow {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, var(--gold-400), var(--gold-600), transparent);
  animation: orb-glow 2s ease-in-out infinite;
}

.loading-container {
  animation: fadeInUp 0.4s ease-out;
}

/* --- Sub Fortune Grid --- */

.sub-fortune-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* --- Lucky Card --- */

.lucky-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
}

/* --- Proverb Card --- */

.proverb-card {
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(212, 168, 83, 0.08), rgba(212, 168, 83, 0.03));
  border: 1px solid rgba(212, 168, 83, 0.2);
}

/* --- Gold Outline Button --- */

.btn-gold-outline {
  background: transparent;
  color: var(--gold-400);
  border: 1px solid var(--gold-500);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-gold-outline:hover {
  background: rgba(212, 168, 83, 0.1);
  box-shadow: 0 0 15px rgba(212, 168, 83, 0.2);
  transform: translateY(-1px);
}

/* --- Small Orb --- */

.orb-glow--small {
  width: 36px;
  height: 36px;
}

/* --- Detail Promo --- */

.detail-promo {
  background: linear-gradient(135deg, rgba(212, 168, 83, 0.06), rgba(212, 168, 83, 0.02));
  border: 1px dashed rgba(212, 168, 83, 0.25);
  text-align: center;
}

.detail-btn {
  position: relative;
}

.detail-btn-badge {
  display: inline-block;
  background: linear-gradient(135deg, var(--gold-500), var(--gold-400));
  color: var(--navy-900);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 6px;
  vertical-align: middle;
}

/* --- Detailed Result (PREMIUM) --- */

.detailed-result {
  margin-top: 1rem;
  border-radius: var(--radius-lg);
  background: var(--glass-light);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(212, 168, 83, 0.25);
  box-shadow: 0 0 30px rgba(212, 168, 83, 0.08), var(--shadow-card);
  overflow: hidden;
}

.detailed-header {
  background: linear-gradient(135deg, rgba(212, 168, 83, 0.12), rgba(212, 168, 83, 0.04));
  border-bottom: 1px solid rgba(212, 168, 83, 0.15);
}

.detailed-badge {
  display: inline-block;
  background: linear-gradient(135deg, var(--gold-500), var(--gold-400));
  color: var(--navy-900);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 3px 10px;
  border-radius: 20px;
}

/* --- Section Cards (Detailed) --- */

.section-card {
  padding: 1rem;
  border-radius: var(--radius-sm);
}

.section-card--gold {
  background: rgba(212, 168, 83, 0.06);
  border: 1px solid rgba(212, 168, 83, 0.15);
}

.section-card--warn {
  background: rgba(239, 68, 68, 0.06);
  border: 1px solid rgba(239, 68, 68, 0.15);
}

/* --- Accessibility: Reduced Motion --- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .aurora-bg {
    animation: none;
    background-size: 100% 100%;
  }

  .star {
    animation: none;
    opacity: 0.4;
  }

  .btn-gold::after {
    animation: none;
  }

  .fortune-reveal,
  .fortune-reveal > * {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .score-glow {
    animation: none;
  }
}
