/* ============================================
   HOPE2MARS — Global Design System
   ============================================ */

:root {
  /* Color Palette */
  --bg-deep: #0a0a1a;
  --bg-surface: #12122a;
  --bg-card: #1a1a3e;
  --bg-card-hover: #222260;
  --accent-orange: #ff6b35;
  --accent-red: #e63946;
  --accent-mars: #d4421e;
  --accent-blue: #4cc9f0;
  --accent-purple: #7b2ff7;
  --accent-gold: #ffd700;
  --text-primary: #f0f0ff;
  --text-secondary: #a0a0cc;
  --text-muted: #666699;
  --glass-bg: rgba(26, 26, 62, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);
  --gradient-mars: linear-gradient(135deg, #ff6b35, #d4421e, #e63946);
  --gradient-sky: linear-gradient(135deg, #4cc9f0, #7b2ff7);
  --gradient-gold: linear-gradient(135deg, #ffd700, #ff6b35);
  --shadow-glow: 0 0 40px rgba(255, 107, 53, 0.3);
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.4);
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --font-main: 'Outfit', 'Noto Sans KR', sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-main);
  background: var(--bg-deep);
  color: var(--text-primary);
}

/* ============================================
   Stars Background
   ============================================ */
.stars-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 0;
}

.stars-bg::before,
.stars-bg::after {
  content: '';
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: white;
  box-shadow:
    25px 50px white, 80px 120px white, 150px 30px white,
    200px 200px white, 300px 80px white, 400px 150px white,
    50px 300px white, 180px 250px white, 320px 320px white,
    450px 50px white, 500px 200px white, 600px 100px white,
    700px 300px white, 100px 400px white, 250px 450px white,
    350px 500px white, 550px 350px white, 650px 450px white,
    750px 150px white, 800px 400px white, 900px 250px white,
    1000px 100px white, 1100px 350px white, 50px 550px white,
    200px 600px white, 400px 650px white, 600px 550px white,
    800px 600px white, 1000px 500px white, 150px 700px white;
  animation: starsTwinkle 4s ease-in-out infinite alternate;
}

.stars-bg::after {
  width: 1px;
  height: 1px;
  box-shadow:
    30px 80px rgba(255,255,255,.6), 120px 200px rgba(255,255,255,.5),
    250px 100px rgba(255,255,255,.7), 400px 300px rgba(255,255,255,.4),
    550px 150px rgba(255,255,255,.6), 700px 250px rgba(255,255,255,.5),
    850px 50px rgba(255,255,255,.7), 100px 350px rgba(255,255,255,.4),
    300px 450px rgba(255,255,255,.6), 500px 500px rgba(255,255,255,.5),
    650px 400px rgba(255,255,255,.4), 800px 550px rgba(255,255,255,.6),
    950px 300px rgba(255,255,255,.5), 1050px 450px rgba(255,255,255,.7);
  animation: starsTwinkle 6s ease-in-out infinite alternate-reverse;
}

@keyframes starsTwinkle {
  0% { opacity: 0.4; }
  100% { opacity: 1; }
}

/* ============================================
   Screen Management
   ============================================ */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s ease, visibility 0.6s ease;
  z-index: 1;
  overflow-y: auto;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  z-index: 10;
}

/* ============================================
   SCREEN 1: START
   ============================================ */
.start-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  z-index: 2;
  text-align: center;
  animation: fadeInUp 1s ease;
  justify-content: flex-end;
  height: 100%;
  padding-bottom: 10vh;
}

.pov-hero-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.plane-wings-pov {
  position: absolute;
  bottom: -20%;
  left: 50%;
  transform: translateX(-50%);
  width: 120%;
  max-width: 800px;
  height: auto;
  z-index: 2;
  pointer-events: none;
  animation: planeSway 5s ease-in-out infinite;
}

@keyframes planeSway {
  0%, 100% { transform: translateX(-50%) rotate(-1deg) translateY(5px); }
  50% { transform: translateX(-48%) rotate(1deg) translateY(-5px); }
}

.planet.mars-far {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #e8845a, #d4421e 40%, #8b2500 80%);
  box-shadow: 
    inset -15px -15px 30px rgba(0,0,0,0.5),
    0 0 60px rgba(212, 66, 30, 0.4),
    0 0 120px rgba(212, 66, 30, 0.2);
  animation: planetPulse 6s ease-in-out infinite;
  z-index: 1;
  position: absolute;
  top: 20%;
}

.title-main {
  font-size: 4rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  line-height: 1;
}

.title-hope {
  background: var(--gradient-sky);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.title-2 {
  color: var(--text-muted);
  font-size: 2.5rem;
  margin: 0 0.2em;
}

.title-mars {
  background: var(--gradient-mars);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
  line-height: 1.8;
  max-width: 400px;
}

/* ============================================
   Buttons
   ============================================ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 2.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  font-family: var(--font-main);
  border: none;
  border-radius: var(--radius-lg);
  background: var(--gradient-mars);
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  z-index: 2;
}

.btn-primary:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-glow);
}

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

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-glow {
  animation: btnGlow 2s ease-in-out infinite alternate;
}

@keyframes btnGlow {
  0% { box-shadow: 0 0 20px rgba(255, 107, 53, 0.2); }
  100% { box-shadow: 0 0 40px rgba(255, 107, 53, 0.5), 0 0 80px rgba(255, 107, 53, 0.2); }
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 2.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  font-family: var(--font-main);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-lg);
  background: var(--glass-bg);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  z-index: 2;
}

.btn-secondary:hover {
  border-color: var(--accent-orange);
  background: rgba(255, 107, 53, 0.1);
  transform: translateY(-3px);
}

.btn-back {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  font-family: var(--font-main);
  cursor: pointer;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  transition: all 0.3s ease;
}

.btn-back:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.05);
}

.btn-icon {
  font-size: 1.3rem;
}

/* ============================================
   SCREEN 2: MATERIALS
   ============================================ */
.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 900px;
  padding: 1.5rem 2rem;
  z-index: 2;
}

.screen-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

.selected-count {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 0.4rem 1rem;
  font-weight: 600;
  font-size: 1rem;
  color: var(--accent-orange);
}

.materials-hint {
  color: var(--text-secondary);
  font-size: 0.95rem;
  text-align: center;
  z-index: 2;
  margin-bottom: 1rem;
  padding: 0 1rem;
}

#screen-materials {
  justify-content: flex-start;
  padding-top: 0;
}

.materials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  width: 100%;
  max-width: 900px;
  padding: 0 2rem;
  z-index: 2;
}

.material-card {
  background: var(--bg-card);
  border: 2px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 1.2rem 0.8rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.material-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 107, 53, 0.3);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.material-card.selected {
  border-color: var(--accent-orange);
  background: rgba(255, 107, 53, 0.12);
  box-shadow: 0 0 20px rgba(255, 107, 53, 0.15);
}

.material-card.selected::after {
  content: '✓';
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 0.9rem;
  color: var(--accent-orange);
  font-weight: 700;
}

.material-emoji {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  display: block;
}

.material-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.3rem;
}

.material-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* Stats Panel */
.material-stats {
  width: 100%;
  max-width: 900px;
  padding: 1rem 2rem;
  z-index: 2;
}

.material-stats h3 {
  font-size: 1.1rem;
  margin-bottom: 0.8rem;
  color: var(--text-primary);
}

.stats-bars {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.stat-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  width: 70px;
  text-align: right;
}

.stat-track {
  flex: 1;
  height: 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  overflow: hidden;
}

.stat-fill {
  height: 100%;
  border-radius: 10px;
  background: var(--gradient-mars);
  transition: width 0.5s ease;
}

.stat-fill-strength {
  background: var(--gradient-sky);
}

.stat-fill-aero {
  background: var(--gradient-gold);
}

.stat-value {
  font-size: 0.85rem;
  color: var(--accent-orange);
  font-weight: 600;
  width: 30px;
}

/* Launch button */
.btn-launch {
  margin: 1rem 0 2rem;
  z-index: 2;
}

/* ============================================
   SCREEN 3: FLYING / LOADING
   ============================================ */
.flying-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  z-index: 2;
  text-align: center;
}

.loading-rocket {
  position: relative;
}

.rocket-animation {
  font-size: 4rem;
  animation: rocketBounce 1.5s ease-in-out infinite;
}

@keyframes rocketBounce {
  0%, 100% { transform: translateY(0) rotate(-30deg); }
  50% { transform: translateY(-20px) rotate(-30deg); }
}

.flame-trail {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 40px;
  background: linear-gradient(to bottom, #ff6b35, #ffd700, transparent);
  border-radius: 0 0 50% 50%;
  opacity: 0.7;
  animation: flameFlicker 0.3s ease-in-out infinite alternate;
}

@keyframes flameFlicker {
  0% { height: 30px; opacity: 0.5; }
  100% { height: 45px; opacity: 0.8; }
}

.flying-title {
  font-size: 1.8rem;
  font-weight: 700;
}

.flying-sub {
  color: var(--text-secondary);
  font-size: 1rem;
}

.progress-orbit {
  width: 300px;
}

.progress-bar-track {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--gradient-mars);
  border-radius: 10px;
  transition: width 0.3s ease;
}

.progress-text {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--accent-orange);
  font-weight: 600;
}

/* ============================================
   SCREEN 4: RESULT
   ============================================ */
#screen-result {
  justify-content: flex-start;
  padding-top: 1rem;
}

.result-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  z-index: 2;
  width: 100%;
  max-width: 900px;
  padding: 0 2rem 2rem;
}

.result-image-container {
  width: 100%;
  max-width: 700px;
  aspect-ratio: 16/9;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 2px solid var(--glass-border);
  background: var(--bg-card);
  position: relative;
}

.result-image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.result-image-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a0a2e, #2d1b4e, #4a1942);
}

.fallback-plane {
  font-size: 5rem;
  animation: fallbackFly 3s ease-in-out infinite;
}

@keyframes fallbackFly {
  0%, 100% { transform: translate(0, 0) rotate(-10deg); }
  25% { transform: translate(30px, -20px) rotate(-5deg); }
  50% { transform: translate(60px, -10px) rotate(-15deg); }
  75% { transform: translate(30px, -30px) rotate(0deg); }
}

.fallback-stars {
  position: absolute;
  font-size: 2rem;
  top: 20%;
  right: 25%;
  animation: starsTwinkle 2s ease-in-out infinite alternate;
}

.result-data {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
}

.result-title {
  font-size: 1.8rem;
  font-weight: 800;
  background: var(--gradient-gold);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.distance-display {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

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

.distance-number {
  font-size: 3.5rem;
  font-weight: 900;
  background: var(--gradient-mars);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.distance-unit {
  font-size: 1.5rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Distance Visual Bar */
.distance-visual {
  width: 100%;
  max-width: 600px;
}

.distance-bar-container {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.distance-marker {
  font-size: 1.8rem;
}

.distance-track {
  flex: 1;
  height: 14px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  position: relative;
  overflow: hidden;
}

.distance-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-orange), var(--accent-mars));
  border-radius: 14px;
  transition: width 2s cubic-bezier(0.4, 0, 0.2, 1);
}

.distance-plane-icon {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  font-size: 1.2rem;
  transition: left 2s cubic-bezier(0.4, 0, 0.2, 1);
}

.distance-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Result materials */
.result-materials {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.result-mat-tag {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Stats Grid */
.result-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  width: 100%;
  max-width: 500px;
}

.result-stat-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
  backdrop-filter: blur(10px);
}

.stat-card-icon {
  font-size: 1.5rem;
  margin-bottom: 0.3rem;
}

.stat-card-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.stat-card-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-orange);
}

/* Result Actions */
.result-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  z-index: 2;
}

/* ============================================
   SCREEN 5: LEADERBOARD
   ============================================ */
#screen-leaderboard {
  justify-content: flex-start;
  padding-top: 0;
}

.leaderboard-content {
  width: 100%;
  max-width: 700px;
  z-index: 2;
  padding: 0 2rem 2rem;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.leaderboard-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem;
  font-size: 1.1rem;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 0.8rem 1.2rem;
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.lb-row:hover {
  border-color: rgba(255, 107, 53, 0.3);
  background: rgba(255, 107, 53, 0.05);
}

.lb-row.top3 {
  border-color: rgba(255, 215, 0, 0.3);
}

.lb-rank {
  font-size: 1.2rem;
  font-weight: 800;
  width: 40px;
  text-align: center;
  color: var(--text-muted);
}

.lb-row.top3 .lb-rank {
  color: var(--accent-gold);
}

.lb-name {
  flex: 1;
  font-weight: 600;
  font-size: 1rem;
}

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

.lb-distance {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent-orange);
}

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

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-card);
}

.modal-card h3 {
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
}

.modal-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.modal-card input {
  width: 100%;
  padding: 0.8rem 1rem;
  border: 2px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: var(--font-main);
  outline: none;
  transition: border-color 0.3s ease;
  margin-bottom: 1.5rem;
}

.modal-card input:focus {
  border-color: var(--accent-orange);
}

.modal-actions {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
}

.modal-actions .btn-primary,
.modal-actions .btn-secondary {
  padding: 0.7rem 1.5rem;
  font-size: 1rem;
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeInUp {
  from { 
    opacity: 0; 
    transform: translateY(30px); 
  }
  to { 
    opacity: 1; 
    transform: translateY(0); 
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 600px) {
  .title-main {
    font-size: 2.5rem;
  }

  .title-2 {
    font-size: 1.8rem;
  }

  .materials-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    padding: 0 1rem;
  }

  .material-card {
    padding: 0.8rem 0.5rem;
  }

  .material-emoji {
    font-size: 1.8rem;
  }

  .material-name {
    font-size: 0.75rem;
  }

  .material-desc {
    display: none;
  }

  .distance-number {
    font-size: 2.5rem;
  }

  .result-stats-grid {
    gap: 0.6rem;
  }

  .btn-primary, .btn-secondary {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
  }

  .result-image-container {
    aspect-ratio: 4/3;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}
