/* ===== CSS Variables ===== */
:root {
  --bg: #060612;
  --bg-secondary: #0f0f23;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-hover: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f0f0f5;
  --text-secondary: #a0a0b8;
  --primary: #dc2626;
  --primary-hover: #ef4444;
  --primary-glow: rgba(220, 38, 38, 0.3);
  --gold: #fbbf24;
  --gold-dim: rgba(251, 191, 36, 0.2);
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 16px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg: #fef7f0;
  --bg-secondary: #fff5ee;
  --surface: rgba(220, 38, 38, 0.06);
  --surface-hover: rgba(220, 38, 38, 0.12);
  --border: rgba(220, 38, 38, 0.15);
  --text: #1a1a2e;
  --text-secondary: #555568;
  --primary-glow: rgba(220, 38, 38, 0.15);
  --gold-dim: rgba(251, 191, 36, 0.15);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

/* ===== Skip Link ===== */
.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  z-index: 10001;
  text-decoration: none;
  font-weight: 600;
  transition: top 0.2s;
}

.skip-link:focus {
  top: 8px;
}

/* ===== App Loader ===== */
.app-loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  gap: 16px;
  transition: opacity 0.4s;
}

.app-loader.hidden {
  opacity: 0;
  pointer-events: none;
}

.loader-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== Language Bar ===== */
.lang-bar {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 100;
}

.lang-bar select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-height: 44px;
}

.theme-toggle-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background var(--transition);
}

.theme-toggle-btn:hover {
  background: var(--surface-hover);
}

[data-theme="dark"] .icon-moon,
[data-theme="light"] .icon-sun {
  display: none;
}

[data-theme="dark"] .icon-sun,
[data-theme="light"] .icon-moon {
  display: block;
}

/* ===== Ad Banners ===== */
.ad-banner {
  max-width: 728px;
  margin: 0 auto;
  text-align: center;
  min-height: 50px;
}

.ad-top { margin-top: 60px; }
.ad-bottom { margin-bottom: 20px; }

/* ===== Container ===== */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* ===== Screens ===== */
.screen {
  display: none;
  animation: fadeIn 0.5s ease;
}

.screen.active {
  display: block;
}

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

/* ===== Glass Card ===== */
.glass-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 24px;
  transition: background var(--transition), border var(--transition);
}

/* ===== Intro Screen ===== */
.intro-decoration {
  display: flex;
  justify-content: center;
  gap: 80px;
  margin-bottom: 16px;
  animation: sway 3s ease-in-out infinite;
}

@keyframes sway {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg); }
}

.lantern {
  animation: lanternGlow 2s ease-in-out infinite alternate;
}

.lantern-right {
  animation-delay: 0.5s;
}

@keyframes lanternGlow {
  from { filter: drop-shadow(0 0 8px rgba(220, 38, 38, 0.4)); }
  to { filter: drop-shadow(0 0 20px rgba(220, 38, 38, 0.8)); }
}

.intro-title {
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 800;
  text-align: center;
  background: linear-gradient(135deg, var(--primary), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.intro-subtitle {
  text-align: center;
  color: var(--gold);
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.intro-desc {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 480px;
  margin: 0 auto 32px;
  line-height: 1.7;
}

/* ===== Year Selector ===== */
.year-selector-wrap {
  text-align: center;
  margin-bottom: 32px;
}

.year-selector-wrap label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.year-select {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 24px;
  font-size: 1.1rem;
  min-height: 48px;
  min-width: 200px;
  cursor: pointer;
  transition: border-color var(--transition);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.year-select:focus {
  outline: none;
  border-color: var(--primary);
}

.zodiac-display {
  margin-top: 12px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gold);
  min-height: 30px;
  transition: opacity 0.3s;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 44px;
  min-width: 44px;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #b91c1c);
  color: #fff;
  box-shadow: 0 4px 16px var(--primary-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-hover), var(--primary));
  transform: translateY(-2px);
  box-shadow: 0 6px 24px var(--primary-glow);
}

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface-hover);
}

.btn-lg {
  padding: 16px 48px;
  font-size: 1.15rem;
  border-radius: var(--radius);
}

#btn-start {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}

/* ===== Drawing Screen ===== */
.drawing-title {
  text-align: center;
  font-size: 1.5rem;
  margin-bottom: 8px;
  color: var(--gold);
}

.drawing-subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 1rem;
}

.drawing-instruction {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 20px;
  animation: pulse 2s ease-in-out infinite;
}

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

.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  max-width: 400px;
  margin: 0 auto;
}

/* ===== Fortune Card ===== */
.fortune-card {
  perspective: 1000px;
  cursor: pointer;
  min-height: 180px;
}

.fortune-card-inner {
  position: relative;
  width: 100%;
  height: 180px;
  transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

.fortune-card.flipped .fortune-card-inner {
  transform: rotateY(180deg);
}

.fortune-card-front,
.fortune-card-back {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border: 1px solid var(--border);
}

.fortune-card-front {
  background: linear-gradient(145deg, #dc2626, #991b1b);
  border-color: rgba(251, 191, 36, 0.3);
  box-shadow: 0 4px 20px rgba(220, 38, 38, 0.3);
}

.fortune-card-front::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px solid rgba(251, 191, 36, 0.3);
  border-radius: 12px;
  pointer-events: none;
}

.fortune-card-front .card-emoji {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.fortune-card-front .card-label {
  color: rgba(255, 255, 255, 0.9);
  font-weight: 700;
  font-size: 1rem;
}

.fortune-card-back {
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transform: rotateY(180deg);
  text-align: center;
}

.fortune-card-back .card-category {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.fortune-card-back .card-level {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.fortune-card-back .card-message {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.fortune-card-back .level-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 12px;
  overflow: hidden;
}

.fortune-card-back .level-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 1s ease;
}

/* Level colors */
.level-great { color: #fbbf24; }
.level-good { color: #22c55e; }
.level-normal { color: #60a5fa; }
.level-caution { color: #f97316; }
.level-bad { color: #ef4444; }

.level-fill-great { background: linear-gradient(90deg, #fbbf24, #f59e0b); width: 100%; }
.level-fill-good { background: linear-gradient(90deg, #22c55e, #16a34a); width: 80%; }
.level-fill-normal { background: linear-gradient(90deg, #60a5fa, #3b82f6); width: 60%; }
.level-fill-caution { background: linear-gradient(90deg, #f97316, #ea580c); width: 40%; }
.level-fill-bad { background: linear-gradient(90deg, #ef4444, #dc2626); width: 20%; }

/* Card flip animation shake */
.fortune-card.shake {
  animation: cardShake 0.5s ease;
}

@keyframes cardShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px) rotate(-1deg); }
  40% { transform: translateX(5px) rotate(1deg); }
  60% { transform: translateX(-3px) rotate(-0.5deg); }
  80% { transform: translateX(3px) rotate(0.5deg); }
}

/* ===== Result Screen ===== */
.result-header {
  text-align: center;
  margin-bottom: 24px;
}

.result-title {
  font-size: 1.8rem;
  background: linear-gradient(135deg, var(--primary), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.result-zodiac {
  font-size: 1.1rem;
  color: var(--gold);
  font-weight: 600;
  margin-bottom: 8px;
}

.result-overall {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
}

.result-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: transform 0.2s;
}

.result-card:hover {
  transform: translateY(-2px);
}

.result-card .rc-emoji {
  font-size: 2rem;
  margin-bottom: 8px;
}

.result-card .rc-category {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.result-card .rc-level {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.result-card .rc-message {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.result-card .rc-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 12px;
  overflow: hidden;
}

.result-card .rc-fill {
  height: 100%;
  border-radius: 3px;
}

/* ===== Result Extras ===== */
.result-extras {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
  text-align: center;
}

.extra-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.extra-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.extra-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
}

/* ===== Share Section ===== */
.share-section {
  text-align: center;
  margin-bottom: 24px;
}

.share-section h3 {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.share-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.btn-share {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.btn-share:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
}

.btn-share svg {
  flex-shrink: 0;
}

/* ===== Result Actions ===== */
.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.result-actions .btn {
  flex: 1;
  max-width: 200px;
}

/* ===== Footer ===== */
.app-footer {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.app-footer a {
  color: var(--primary);
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

.portal-link {
  display: inline-block;
  margin-top: 8px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  color: var(--text);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  font-size: 0.9rem;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Confetti ===== */
.confetti-piece {
  position: fixed;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  z-index: 999;
  pointer-events: none;
  animation: confettiFall 3s ease-in forwards;
}

@keyframes confettiFall {
  0% { opacity: 1; transform: translateY(0) rotate(0deg); }
  100% { opacity: 0; transform: translateY(100vh) rotate(720deg); }
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .cards-grid {
    gap: 12px;
  }

  .fortune-card-inner {
    height: 160px;
  }

  .result-extras {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .share-buttons {
    flex-direction: column;
    align-items: stretch;
  }

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

  .result-actions .btn {
    max-width: none;
  }
}

@media (min-width: 768px) {
  .container {
    padding: 32px 24px;
  }

  .result-cards {
    grid-template-columns: repeat(4, 1fr);
  }
}

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

  .fortune-card-inner {
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }
}
