/* ==========================================================================
   RPG EDU-QUEST - OPTIMIZED STYLESHEET
   Design System: Bento Grid + Light Glassmorphism + Golden Ratio (Phi = 1.618)
   Optimized for: Mobile Performance (No GPU overload), Responsive Touch UX
   ========================================================================== */

:root {
  --phi: 1.6180339887;
  --phi-inv: 0.6180339887;

  /* Colors */
  --bg-deep: #070913;
  --glass-bg: rgba(18, 24, 43, 0.72);
  --glass-bg-hover: rgba(28, 38, 68, 0.9);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-border-focus: rgba(139, 92, 246, 0.6);
  --glass-shine: linear-gradient(135deg, rgba(255, 255, 255, 0.18) 0%, rgba(255, 255, 255, 0.02) 100%);

  --neon-cyan: #06b6d4;
  --neon-purple: #8b5cf6;
  --neon-pink: #ec4899;
  --neon-emerald: #10b981;
  --neon-amber: #f59e0b;
  --neon-rose: #f43f5e;

  /* Golden Ratio Spacing Scale */
  --gr-xs: 0.382rem;
  --gr-sm: 0.618rem;
  --gr-md: 1rem;
  --gr-lg: 1.618rem;
  --gr-xl: 2.618rem;
}

/* Base resets & aesthetics */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  background-color: var(--bg-deep);
  background-image: 
    radial-gradient(at 0% 0%, rgba(139, 92, 246, 0.15) 0px, transparent 40%),
    radial-gradient(at 100% 0%, rgba(6, 182, 212, 0.15) 0px, transparent 40%),
    radial-gradient(at 50% 100%, rgba(236, 72, 153, 0.12) 0px, transparent 40%);
  background-attachment: scroll; /* 'scroll' prevents mobile viewport repaint lag */
  color: #f1f5f9;
  font-family: 'Outfit', 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(10, 15, 30, 0.5);
}
::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.4);
  border-radius: 4px;
}

/* Glassmorphism Master Classes (Optimized for Mobile Performance) */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.5);
  border-radius: 1.15rem;
  transition: border-color 0.2s ease, transform 0.2s ease;
  will-change: transform;
}

.glass-panel-hover:hover {
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
}

.glass-input {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border-radius: 0.75rem;
  transition: border-color 0.2s ease;
}
.glass-input:focus {
  background: rgba(23, 33, 60, 0.9);
  border-color: var(--neon-cyan);
  outline: none;
}

/* Bento Grid System with Golden Ratio proportions */
.bento-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gr-md);
  width: 100%;
}

/* Golden Ratio columns on desktop */
.bento-col-phi-main {
  grid-column: span 7 / span 7; /* ~61.8% of 12 cols */
}

.bento-col-phi-side {
  grid-column: span 5 / span 5; /* ~38.2% of 12 cols */
}

.bento-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.bento-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: var(--glass-shine);
  pointer-events: none;
}

/* Golden Ratio Typography */
.phi-title {
  font-size: calc(1rem * var(--phi) * var(--phi));
  line-height: 1.2;
}

.phi-subtitle {
  font-size: calc(1rem * var(--phi));
}

/* Buttons */
.btn-neon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  letter-spacing: 0.025em;
  border-radius: 0.75rem;
  transition: opacity 0.2s ease, transform 0.15s ease;
  user-select: none;
  touch-action: manipulation;
}
.btn-neon:active {
  transform: scale(0.98);
}

.btn-neon-primary {
  background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-neon-cyan {
  background: linear-gradient(135deg, #06b6d4 0%, #0284c7 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Badges */
.badge-grade {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.badge-grade-sd {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.35);
  color: #34d399;
}
.badge-grade-smp {
  background: rgba(6, 182, 212, 0.15);
  border-color: rgba(6, 182, 212, 0.35);
  color: #38bdf8;
}
.badge-grade-sma {
  background: rgba(139, 92, 246, 0.15);
  border-color: rgba(139, 92, 246, 0.35);
  color: #c084fc;
}
.badge-boss {
  background: linear-gradient(135deg, rgba(244, 63, 94, 0.25), rgba(236, 72, 153, 0.25));
  border-color: rgba(244, 63, 94, 0.5);
  color: #fda4af;
}

/* Canvas & World Rendering Container */
#gameCanvasContainer {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 260px;
  max-height: 68vh;
  background: #050811;
  border-radius: 0.85rem;
  overflow: hidden;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8);
  touch-action: none; /* Prevents window scrolling while dragging or tapping canvas */
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Mobile Virtual D-PAD Controller */
.touch-dpad-btn {
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
  border-radius: 0.5rem;
  font-size: 1.1rem;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.1s ease;
}
.touch-dpad-btn:active {
  background: #06b6d4;
  color: #000;
  transform: scale(0.95);
}

/* Battle Stage Arena Overlay */
#battleModal {
  transition: opacity 0.25s ease;
  overscroll-behavior: contain;
}
#battleModal.hidden {
  opacity: 0;
  pointer-events: none;
}
#battleModal:not(.hidden) {
  opacity: 1;
  pointer-events: auto;
}

/* Question Option Cards */
.quiz-option-card {
  background: rgba(20, 28, 55, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.75rem;
  padding: 0.85rem 1rem;
  color: #f8fafc;
  font-weight: 500;
  text-align: left;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 48px; /* Accessible touch target */
}
.quiz-option-card:hover {
  background: rgba(35, 48, 92, 0.9);
  border-color: rgba(6, 182, 212, 0.5);
}
.quiz-option-card:active {
  transform: scale(0.99);
}
.quiz-option-card.correct {
  background: rgba(16, 185, 129, 0.25) !important;
  border-color: #10b981 !important;
  color: #34d399 !important;
}
.quiz-option-card.wrong {
  background: rgba(244, 63, 94, 0.25) !important;
  border-color: #f43f5e !important;
  color: #fda4af !important;
}

/* Attack Animation Effects */
@keyframes shake-damage {
  0% { transform: translate(1px, 1px); }
  25% { transform: translate(-3px, 0); }
  50% { transform: translate(3px, 1px); }
  75% { transform: translate(-2px, -1px); }
  100% { transform: translate(0, 0); }
}

.monster-hit, .player-hit {
  animation: shake-damage 0.3s ease-in-out;
}

/* XP & HP Bar styling */
.stat-bar-track {
  height: 0.65rem;
  background: rgba(15, 23, 42, 0.8);
  border-radius: 9999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.stat-bar-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.3s ease;
}
.fill-hp {
  background: linear-gradient(90deg, #f43f5e 0%, #ef4444 100%);
}
.fill-xp {
  background: linear-gradient(90deg, #10b981 0%, #34d399 100%);
}

/* Floating combat text */
.floating-dmg {
  position: absolute;
  font-weight: 800;
  font-size: 1.35rem;
  pointer-events: none;
  animation: float-up-fade 1s forwards ease-out;
}
@keyframes float-up-fade {
  0% { opacity: 0; transform: translateY(0) scale(0.7); }
  20% { opacity: 1; transform: translateY(-10px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-35px) scale(1); }
}

/* ==========================================================================
   MOBILE SCREEN SPECIALIZATIONS (ANTI-OVERLOAD ON SMARTPHONES)
   ========================================================================== */
@media (max-width: 768px) {
  :root {
    --gr-md: 0.65rem;
  }

  body {
    background-image: 
      radial-gradient(at 50% 0%, rgba(139, 92, 246, 0.12) 0px, transparent 60%),
      radial-gradient(at 50% 100%, rgba(6, 182, 212, 0.1) 0px, transparent 60%);
  }

  /* Disable heavy multi-layer blur on mobile GPU */
  .glass-panel {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    background: rgba(14, 20, 36, 0.88);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
    border-radius: 0.85rem;
    padding: 0.85rem !important;
  }

  /* Single Column Stack on Mobile */
  .bento-grid {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
  }
  .bento-col-phi-main,
  .bento-col-phi-side {
    width: 100%;
    grid-column: span 12 / span 12;
  }

  /* Compact Typography */
  .phi-title {
    font-size: 1.45rem;
  }
  .phi-subtitle {
    font-size: 1.1rem;
  }

  /* Canvas height for comfortable phone view */
  #gameCanvasContainer {
    aspect-ratio: 4 / 3;
    max-height: 48vh;
    min-height: 230px;
  }

  /* Battle stage container adjustments */
  #battleStageContainer {
    max-height: 94vh;
    overflow-y: auto;
    padding: 1rem !important;
    gap: 0.85rem !important;
  }
}
