/* ==========================================================================
   🎨 프리미엄 레트로 스페이스 디자인 시스템 & 반응형 CSS
   ========================================================================== */

/* 1. 디자인 시스템 변수 정의 */
:root {
  --color-bg-space: #050515;
  --color-primary: #8a2be2;      /* 네온 퍼플 */
  --color-primary-glow: rgba(138, 43, 226, 0.4);
  --color-secondary: #00f0ff;    /* 일렉트릭 시안 */
  --color-secondary-glow: rgba(0, 240, 255, 0.3);
  --color-accent: #ff007f;       /* 핫 마젠타 */
  --color-accent-glow: rgba(255, 0, 127, 0.3);
  --color-star: #ffd700;         /* 노란색 별빛 */
  --color-glass-bg: rgba(13, 13, 35, 0.75);
  --color-glass-border: rgba(255, 255, 255, 0.1);
  --font-title: 'Orbitron', 'Inter', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-retro: 'Press Start 2P', monospace;
}

/* 2. 초기 리셋 및 모바일 제스처 방지 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  height: 100dvh;
  background-color: #020208;
  color: #ffffff;
  font-family: var(--font-body);
  overflow: hidden;
  touch-action: none;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 3. 9:16 비율 잠금 및 필러박스 (Pillarbox) 콘테이너 */
#app-container {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 9/16;
  background-color: var(--color-bg-space);
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.8), 0 0 100px rgba(138, 43, 226, 0.15);
  border: 1px solid var(--color-glass-border);
  display: flex;
  flex-direction: column;
}

/* 가로 화면일 때 9:16 종횡비 잠금 및 중앙 배치 (Pillarbox 효과) */
@media (min-aspect-ratio: 9/16) {
  #app-container {
    width: auto;
    height: 100dvh;
    border-left: 2px solid rgba(138, 43, 226, 0.3);
    border-right: 2px solid rgba(138, 43, 226, 0.3);
  }
}

/* 4. 공통 화면(Screen) 클래스 */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s cubic-bezier(0.25, 0.8, 0.25, 1), visibility 0.4s;
  z-index: 10;
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top));
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

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

/* 5. 우주 배경 효과 */
.stars-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, #0e0a29 0%, #03030d 100%);
  background-size: cover;
  z-index: -1;
  pointer-events: none;
}

.stars-bg::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: 
    radial-gradient(1px 1px at 20px 30px, #fff, rgba(0,0,0,0)),
    radial-gradient(1.5px 1.5px at 100px 150px, #ffd700, rgba(0,0,0,0)),
    radial-gradient(1px 1px at 200px 80px, #fff, rgba(0,0,0,0)),
    radial-gradient(2px 2px at 250px 300px, #00f0ff, rgba(0,0,0,0)),
    radial-gradient(1.5px 1.5px at 80px 420px, #fff, rgba(0,0,0,0)),
    radial-gradient(2.5px 2.5px at 150px 250px, #ff007f, rgba(0,0,0,0));
  background-repeat: repeat;
  background-size: 300px 500px;
  opacity: 0.45;
  animation: bgMove 60s linear infinite;
}

@keyframes bgMove {
  from { background-position: 0 0; }
  to { background-position: 0 -500px; }
}

/* 6. 메인 메뉴 화면 스타일링 */
.menu-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: 80%;
  width: 100%;
}

.game-title {
  display: flex;
  flex-direction: column;
  margin-top: 20px;
}

.title-sub {
  font-family: var(--font-title);
  font-size: 0.9rem;
  letter-spacing: 0.3em;
  color: var(--color-secondary);
  text-shadow: 0 0 10px var(--color-secondary-glow);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.title-main {
  font-family: var(--font-title);
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 30%, #bb86fc 70%, #8a2be2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 15px var(--color-primary-glow));
}

.rocket-container {
  margin: 30px 0;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.floating-rocket {
  width: 110px;
  height: auto;
  image-rendering: pixelated;
  animation: floatRocket 3s ease-in-out infinite;
}

@keyframes floatRocket {
  0% { transform: translateY(0px) rotate(-3deg); }
  50% { transform: translateY(-15px) rotate(3deg); }
  100% { transform: translateY(0px) rotate(-3deg); }
}

.button-group {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 100%;
  max-width: 280px;
}

.flex-row {
  flex-direction: row !important;
}

/* 7. 프리미엄 유리막(Glassmorphism) 버튼 스타일 */
.btn {
  font-family: var(--font-body);
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-radius: 16px;
  border: 1px solid var(--color-glass-border);
  cursor: pointer;
  outline: none;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  text-align: left;
}

.btn-icon {
  font-size: 1.8rem;
  margin-right: 15px;
  flex-shrink: 0;
}

.btn-text-wrapper {
  display: flex;
  flex-direction: column;
}

.btn-title {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.1rem;
  color: #ffffff;
}

.btn-desc {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 2px;
}

.btn-primary {
  background: linear-gradient(135deg, rgba(138, 43, 226, 0.35) 0%, rgba(138, 43, 226, 0.15) 100%);
  border-color: rgba(138, 43, 226, 0.5);
  box-shadow: 0 4px 15px var(--color-primary-glow);
}

.btn-primary:active {
  transform: scale(0.95);
  background: linear-gradient(135deg, rgba(138, 43, 226, 0.6) 0%, rgba(138, 43, 226, 0.3) 100%);
}

.btn-secondary {
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.2) 0%, rgba(0, 240, 255, 0.05) 100%);
  border-color: rgba(0, 240, 255, 0.4);
  box-shadow: 0 4px 15px var(--color-secondary-glow);
}

.btn-secondary:active {
  transform: scale(0.95);
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.4) 0%, rgba(0, 240, 255, 0.1) 100%);
}

.footer-info {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 15px;
}

/* 8. 룰렛 화면 스타일 */
.roulette-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 90%;
}

.section-title {
  font-family: var(--font-title);
  font-size: 1.4rem;
  letter-spacing: 0.1em;
  color: #ffffff;
  margin-bottom: 25px;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.roulette-container-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  margin-bottom: 25px;
}

.roulette-wheel-wrapper {
  position: relative;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  padding: 10px;
  background: radial-gradient(circle, #251d54 0%, #0c0824 100%);
  box-shadow: 0 0 25px rgba(138, 43, 226, 0.4), inset 0 0 15px rgba(0, 240, 255, 0.2);
  border: 4px solid var(--color-secondary);
}

#roulette-wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  transition: transform 4s cubic-bezier(0.1, 0.8, 0.1, 1);
  transform: rotate(0deg);
}

.sector {
  position: absolute;
  width: 50%;
  height: 50%;
  transform-origin: 100% 100%;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
}

.sector span {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 0.65rem;
  font-weight: 800;
  color: #ffffff;
  transform: rotate(45deg) translate(-20px, -20px);
  font-family: var(--font-body);
  line-height: 1.2;
}

.sec-1 { transform: rotate(0deg); background-color: rgba(138, 43, 226, 0.4); border-right: 1px solid rgba(255,255,255,0.2); border-bottom: 1px solid rgba(255,255,255,0.2); }
.sec-2 { transform: rotate(90deg); background-color: rgba(0, 240, 255, 0.3); border-right: 1px solid rgba(255,255,255,0.2); border-bottom: 1px solid rgba(255,255,255,0.2); }
.sec-3 { transform: rotate(180deg); background-color: rgba(255, 0, 127, 0.3); border-right: 1px solid rgba(255,255,255,0.2); border-bottom: 1px solid rgba(255,255,255,0.2); }
.sec-4 { transform: rotate(270deg); background-color: rgba(255, 215, 0, 0.2); border-right: 1px solid rgba(255,255,255,0.2); border-bottom: 1px solid rgba(255,255,255,0.2); }

.roulette-pointer {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 20px solid var(--color-accent);
  filter: drop-shadow(0 2px 5px var(--color-accent-glow));
  z-index: 5;
}

.btn-spin {
  background: var(--color-accent);
  color: white;
  border-radius: 12px;
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1rem;
  padding: 12px 24px;
  border: none;
  box-shadow: 0 4px 15px var(--color-accent-glow);
  text-align: center;
  display: block;
}

.btn-spin:active {
  transform: scale(0.95);
  filter: brightness(1.2);
}

/* 9. 정보 요약 카드 (Glassmorphism) */
.info-card {
  width: 100%;
  max-width: 320px;
  background: var(--color-glass-bg);
  border: 1px solid var(--color-glass-border);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  transform: translateY(0px);
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.info-card.hide {
  display: none !important;
  opacity: 0;
  transform: translateY(10px);
}

.info-card h3 {
  font-family: var(--font-title);
  font-size: 1.25rem;
  color: #ffffff;
}

.badge {
  display: inline-block;
  align-self: flex-start;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  background-color: var(--color-secondary);
  color: var(--color-bg-space);
}

.info-details p {
  font-size: 0.8rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.8);
}

.curve-tip-box {
  margin-top: 10px;
  padding: 10px;
  background-color: rgba(255, 255, 255, 0.05);
  border-left: 3px solid var(--color-primary);
  border-radius: 4px;
}

.curve-tip-box strong {
  display: block;
  font-size: 0.75rem;
  color: var(--color-primary);
  margin-bottom: 2px;
}

.curve-tip-box span {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.75);
}

.btn-large {
  width: 100%;
  justify-content: center;
  font-size: 1rem;
  padding: 14px;
  border-radius: 12px;
  text-align: center;
}

/* 10. 게임플레이 화면 HUD */
#game-screen {
  padding: 0;
  position: relative;
}

#game-canvas {
  width: 100%;
  height: 100%;
  background-color: #03030b;
  display: block;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* 클릭 이벤트가 뒷배경 캔버스로 통과되게 설정 */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  padding-top: calc(15px + env(safe-area-inset-top));
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 30;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.hud-stat-box {
  background: rgba(8, 8, 24, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  padding: 8px 14px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
}

.font-pixel {
  font-family: var(--font-retro);
  font-size: 0.55rem;
  letter-spacing: 0.05em;
  color: var(--color-secondary);
}

.font-pixel-large {
  font-family: var(--font-retro);
  font-size: 1rem;
  color: #ffffff;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
  margin-top: 3px;
}

.hud-bottom {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  align-items: flex-start;
}

#multiplier-badge {
  font-size: 0.9rem;
  font-weight: 900;
  padding: 4px 8px;
  background-color: var(--color-accent);
  color: #ffffff;
  border-radius: 8px;
  box-shadow: 0 0 10px var(--color-accent-glow);
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.1); }
}

.hidden {
  display: none !important;
}

#buff-bar-container {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.5);
  padding: 6px 10px;
  border-radius: 20px;
  width: 140px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.buff-progress-wrapper {
  flex-grow: 1;
  height: 6px;
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  overflow: hidden;
}

#buff-progress {
  height: 100%;
  width: 100%;
  background-color: var(--color-secondary);
  border-radius: 3px;
  transition: width 0.1s linear;
}

/* 11. 가로 회전 가이드 오버레이 */
#orientation-warning {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background-color: rgba(5, 5, 20, 0.95);
  z-index: 999;
  display: flex;
  justify-content: center;
  align-items: center;
}

.warning-content {
  text-align: center;
  padding: 30px;
}

.rotate-phone-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2300f0ff'%3E%3Cpath d='M16 1H8C6.34 1 5 2.34 5 4v16c0 1.66 1.34 3 3 3h8c1.66 0 3-1.34 3-3V4c0-1.66-1.34-3-3-3zm-2 20h-4v-1h4v1zm3-3H7V4h10v14z'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  animation: rotateAnim 2s infinite ease-in-out;
}

@keyframes rotateAnim {
  0% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

.sub-warn {
  font-size: 0.8rem;
  color: var(--color-accent);
  margin-top: 8px;
}

/* 12. 결과 화면 (Game Over) */
.gameover-content {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  text-align: center;
  align-items: center;
}

.gameover-title {
  font-family: var(--font-title);
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--color-accent);
  text-shadow: 0 0 15px var(--color-accent-glow);
  margin-bottom: 5px;
}

.score-summary-box {
  width: 100%;
  background: var(--color-glass-bg);
  border: 1px solid var(--color-glass-border);
  padding: 15px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.summary-item-row {
  display: flex;
  justify-content: space-around;
  border-top: 1px solid var(--color-glass-border);
  padding-top: 10px;
}

.sum-label {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.55);
}

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

.education-card {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 14px;
  border-radius: 14px;
  text-align: left;
}

.education-card h4 {
  font-family: var(--font-title);
  font-size: 0.95rem;
  color: var(--color-secondary);
  margin-bottom: 6px;
}

.education-card p {
  font-size: 0.75rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.75);
}

.graph-preview {
  margin-top: 10px;
  background-color: rgba(0, 0, 0, 0.4);
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
}

.graph-title {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 5px;
  text-align: center;
}

#graph-canvas {
  width: 100%;
  height: 80px;
  display: block;
}

/* 13. 카운트다운 오버레이 */
#countdown-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(5, 5, 15, 0.65);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
  pointer-events: none;
}

#countdown-number {
  font-family: var(--font-retro);
  font-size: 5rem;
  color: var(--color-secondary);
  text-shadow: 0 0 25px var(--color-secondary-glow);
  transform: scale(1);
  animation: countdownPulse 1s ease-in-out infinite;
}

@keyframes countdownPulse {
  0% {
    transform: scale(1.8);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(0.8);
    opacity: 0;
  }
}

/* 14. 게임 설명 팝업 가이드 스타일 */
.popup-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(5, 5, 15, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(8px);
}

.popup-content {
  background: var(--color-glass-bg);
  border: 2px solid var(--color-glass-border);
  border-radius: 24px;
  padding: 24px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), 0 0 30px var(--color-primary-glow);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.animate-pop {
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.popup-title {
  font-family: var(--font-title);
  font-size: 1.4rem;
  color: var(--color-secondary);
  text-shadow: 0 0 10px var(--color-secondary-glow);
  text-align: center;
  border-bottom: 1px solid var(--color-glass-border);
  padding-bottom: 10px;
}

.guide-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.guide-sec-title {
  font-family: var(--font-title);
  font-size: 0.95rem;
  color: #ffffff;
  border-left: 3px solid var(--color-accent);
  padding-left: 8px;
  margin-bottom: 4px;
}

.guide-text {
  font-size: 0.78rem;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.8);
}

.guide-item-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.05);
}

.guide-item-row:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.item-icon-box {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.box-shield {
  background-color: rgba(0, 240, 255, 0.15);
  border-color: var(--color-secondary);
  color: var(--color-secondary);
}

.box-magnet {
  background-color: rgba(255, 215, 0, 0.15);
  border-color: var(--color-star);
  color: var(--color-star);
}

.box-booster {
  background-color: rgba(255, 0, 127, 0.15);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.item-text-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.item-text-box strong {
  font-size: 0.82rem;
  font-weight: 700;
}

.color-shield { color: var(--color-secondary); }
.color-magnet { color: var(--color-star); }
.color-booster { color: var(--color-accent); }

.btn-center {
  margin: 0 auto;
  width: 100%;
}
