/* ==================== Reset & Base ==================== */
*, *::before, *::after { 
  box-sizing: border-box; 
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  height: -webkit-fill-available;
}

body { 
  font-family: 'Noto Sans KR', sans-serif;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.title-font { 
  font-family: 'Orbitron', sans-serif; 
}

/* ==================== App Container ==================== */
#app {
  height: 100dvh;
  height: calc(var(--app-height, 100vh));
  display: flex;
  flex-direction: column;
}

/* ==================== Animations ==================== */
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 20px rgba(139, 92, 246, 0.5); }
  50% { box-shadow: 0 0 40px rgba(139, 92, 246, 0.8), 0 0 60px rgba(59, 130, 246, 0.5); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes levelup {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes scanline {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100%); }
}

@keyframes typing-cursor {
  0%, 100% { border-color: transparent; }
  50% { border-color: #8b5cf6; }
}

@keyframes success-burst {
  0% { transform: scale(0); opacity: 1; }
  100% { transform: scale(2); opacity: 0; }
}

@keyframes slide-up {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

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

@keyframes countdown-pop {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes modal-in {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ==================== Animation Utility Classes ==================== */
.animate-pulse-glow { animation: pulse-glow 2s ease-in-out infinite; }
.animate-float { animation: float 3s ease-in-out infinite; }
.animate-shake { animation: shake 0.5s ease-in-out; }
.animate-levelup { animation: levelup 0.6s ease-out forwards; }
.animate-slide-up { animation: slide-up 0.5s ease-out forwards; }
.animate-countdown { animation: countdown-pop 0.5s ease-out forwards; }
.animate-modal { animation: modal-in 0.3s ease-out forwards; }

.animate-scanline::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(to bottom, transparent, rgba(139, 92, 246, 0.3), transparent);
  animation: scanline 2s linear infinite;
  pointer-events: none;
}

/* ==================== Background & Border Styles ==================== */
.gradient-bg {
  background: linear-gradient(-45deg, #0f0f1a, #1a1a2e, #16213e, #0f0f1a);
  background-size: 400% 400%;
  animation: gradient-shift 15s ease infinite;
}

.cyber-border {
  border: 2px solid transparent;
  background: linear-gradient(#1a1a2e, #1a1a2e) padding-box,
              linear-gradient(135deg, #8b5cf6, #3b82f6, #06b6d4) border-box;
}

.xp-bar-fill {
  background: linear-gradient(90deg, #8b5cf6, #3b82f6, #06b6d4);
  background-size: 200% 100%;
  animation: gradient-shift 2s linear infinite;
}

/* ==================== Interactive Elements ==================== */
.danger-item { 
  transition: all 0.3s ease; 
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.danger-item:active { 
  transform: scale(0.95); 
  filter: brightness(1.3); 
}

.danger-item.found { 
  animation: success-burst 0.5s ease-out forwards; 
}

/* ==================== Quiz Options ==================== */
.quiz-option { 
  transition: all 0.2s ease; 
  min-height: 52px;
  touch-action: manipulation;
}

.quiz-option:active:not(:disabled) { 
  transform: translateX(5px) scale(0.98); 
  background: rgba(139, 92, 246, 0.4); 
}

.quiz-option.correct { 
  background: rgba(34, 197, 94, 0.5) !important; 
  border-color: #22c55e !important; 
}

.quiz-option.wrong { 
  background: rgba(239, 68, 68, 0.5) !important; 
  border-color: #ef4444 !important; 
}

.quiz-option.wrong-shake {
  animation: shake 0.5s ease-in-out;
}

/* ==================== Typing Input ==================== */
.typing-input { 
  animation: typing-cursor 1s step-end infinite; 
}

/* ==================== Leaderboard ==================== */
.leaderboard-row { 
  transition: all 0.3s ease; 
}

.leaderboard-row:active { 
  background: rgba(139, 92, 246, 0.2); 
  transform: scale(1.01); 
}

.leaderboard-row.player {
  background: linear-gradient(90deg, rgba(139, 92, 246, 0.3), rgba(59, 130, 246, 0.3));
  border: 1px solid #8b5cf6;
}

/* ==================== Screen & Toast ==================== */
.screen { 
  display: none !important; 
}

.screen.active { 
  display: flex !important; 
  flex-direction: column;
}

/* 로그인 화면 - 내용이 잘리지 않도록 */
#login-screen.active {
  justify-content: flex-start;
  padding-top: 2rem;
  padding-bottom: 2rem;
}

@media (min-height: 700px) {
  #login-screen.active {
    justify-content: center;
  }
}

.toast {
  position: fixed;
  top: max(20px, env(safe-area-inset-top, 20px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  animation: slide-up 0.3s ease-out;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  max-width: 90vw;
  text-align: center;
}

.toast.error { 
  background: linear-gradient(135deg, #ef4444, #dc2626); 
  color: white; 
}

.toast.success { 
  background: linear-gradient(135deg, #22c55e, #16a34a); 
  color: white; 
}

/* ==================== HP Bar ==================== */
.hp-bar { 
  transition: width 0.5s ease; 
}

/* ==================== Scroll Container ==================== */
.scroll-container {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(139, 92, 246, 0.5) rgba(30, 41, 59, 0.5);
}

.scroll-container::-webkit-scrollbar {
  width: 8px;
}

.scroll-container::-webkit-scrollbar-track {
  background: rgba(30, 41, 59, 0.5);
  border-radius: 4px;
}

.scroll-container::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.5);
  border-radius: 4px;
}

.scroll-container::-webkit-scrollbar-thumb:active {
  background: rgba(139, 92, 246, 0.8);
}

/* ==================== Touch & Button Styles ==================== */
.touch-btn {
  min-height: 48px;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.touch-btn:active {
  transform: scale(0.97);
  filter: brightness(0.9);
}

.profile-item {
  min-height: 44px;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.profile-item:active {
  transform: scale(0.98);
}

/* Stage 1 컴팩트 레이아웃 */
#stage1 .profile-item {
  min-height: 40px;
}

/* ==================== Input Styles ==================== */
input[type="text"] {
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}

/* ==================== Keyboard & Layout ==================== */
.keyboard-open .stage-content {
  padding-bottom: 40vh;
}

.safe-area-bottom {
  padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
}

/* ==================== Game Screen Layout ==================== */
#game-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.game-hud {
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 40;
}

.stage-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Stage 4는 스크롤 없이 화면에 맞춤 */
.stage-content.no-scroll {
  overflow: hidden;
}

#stage4 {
  max-height: 100%;
}

/* ==================== Learn Modal ==================== */
.learn-modal {
  backdrop-filter: blur(8px);
  overflow: hidden;
}

.learn-modal-content {
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.countdown-number {
  font-size: 4rem;
  font-weight: 900;
  text-shadow: 0 0 30px currentColor;
}

@media (min-width: 768px) {
  .countdown-number {
    font-size: 5rem;
  }
}

/* ==================== Modal Close Button ==================== */
.modal-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  transition: all 0.3s ease;
  cursor: pointer;
}

.modal-close-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.modal-close-btn:not(:disabled):hover {
  background: rgba(239, 68, 68, 0.3);
  transform: scale(1.1);
}

.modal-close-btn:not(:disabled):active {
  transform: scale(0.95);
}

/* ==================== Stage 4: Footprint Game ==================== */
.footprint-item {
  position: absolute;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  background: rgba(30, 41, 59, 0.9);
  border: 2px solid rgba(100, 116, 139, 0.5);
  user-select: none;
  -webkit-user-select: none;
  z-index: 10;
  animation: footprint-spawn 0.3s ease-out forwards;
}

@media (min-width: 768px) {
  .footprint-item {
    width: 60px;
    height: 60px;
    font-size: 2rem;
  }
}

@keyframes footprint-spawn {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  70% { transform: scale(1.2) rotate(10deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.footprint-item:hover:not(.removed) {
  transform: scale(1.15);
  border-color: rgba(139, 92, 246, 0.8);
  box-shadow: 0 0 25px rgba(139, 92, 246, 0.5);
  z-index: 20;
}

.footprint-item:active:not(.removed) {
  transform: scale(0.9);
}

.footprint-item.removed {
  pointer-events: none;
  animation: footprint-pop 0.4s ease-out forwards;
}

.footprint-item.wrong-click {
  animation: shake 0.3s ease-in-out, wrong-flash 0.3s ease-in-out;
}

/* 답 티나지 않게 모두 동일한 스타일 */
.footprint-item.danger-type,
.footprint-item.safe-type {
  border-color: rgba(100, 116, 139, 0.5);
}

@keyframes footprint-pop {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.5); opacity: 0.5; }
  100% { transform: scale(0); opacity: 0; }
}

@keyframes wrong-flash {
  0%, 100% { background: rgba(30, 41, 59, 0.9); }
  50% { background: rgba(239, 68, 68, 0.7); }
}

/* Legend */
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.75rem;
}

/* Wave indicator */
.wave-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 9999px;
  font-weight: bold;
}

.wave-indicator.wave-1 {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.3), rgba(16, 185, 129, 0.3));
  border: 1px solid #22c55e;
}

.wave-indicator.wave-2 {
  background: linear-gradient(135deg, rgba(234, 179, 8, 0.3), rgba(245, 158, 11, 0.3));
  border: 1px solid #eab308;
}

.wave-indicator.wave-3 {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.3), rgba(220, 38, 38, 0.3));
  border: 1px solid #ef4444;
}
