/* Neurika Mobile-First CSS - Optimized for PWA */

/* ===========================================
   ROOT VARIABLES & BASE STYLES
   =========================================== */
:root {
  --primary: #667eea;
  --primary-dark: #5a67d8;
  --secondary: #764ba2;
  --success: #48bb78;
  --warning: #ed8936;
  --danger: #f56565;
  --dark: #2d3748;
  --light: #f7fafc;
  --gold: #ffd700;

  /* Mobile-specific sizes */
  --touch-target: 44px;
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;

  /* Safe areas for notched devices */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
}

/* ===========================================
   PWA-SPECIFIC STYLES
   =========================================== */

/* Standalone mode (installed PWA) */
@media (display-mode: standalone) {
  body {
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
  }

  .app-header {
    padding-top: calc(var(--safe-area-top) + 10px);
  }

  /* Hide browser-specific elements */
  .browser-only {
    display: none !important;
  }
}

/* ===========================================
   MOBILE TOUCH OPTIMIZATIONS
   =========================================== */

/* Minimum touch targets (44x44px per Apple HIG) */
button,
.btn,
a.nav-link,
.card-clickable,
input[type="submit"],
input[type="button"],
.touch-target {
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  padding: var(--spacing-sm) var(--spacing-md);
}

/* Remove tap highlight on mobile */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Prevent text selection during touch interactions */
.no-select {
  -webkit-user-select: none;
  user-select: none;
}

/* ===========================================
   AGE-APPROPRIATE DESIGNS
   =========================================== */

/* K-2: Larger buttons, high contrast, icons */
.grade-k-2 {
  --btn-size: 60px;
  --font-size-base: 20px;
  --icon-size: 48px;
}

.grade-k-2 .btn {
  min-height: var(--btn-size);
  font-size: var(--font-size-base);
  border-radius: 20px;
  font-weight: bold;
}

.grade-k-2 .answer-btn {
  padding: 20px 30px;
  font-size: 24px;
  margin: 10px 0;
}

.grade-k-2 .question-text {
  font-size: 26px;
  line-height: 1.5;
}

/* 3-5: Balanced design */
.grade-3-5 {
  --btn-size: 50px;
  --font-size-base: 18px;
  --icon-size: 36px;
}

.grade-3-5 .btn {
  min-height: var(--btn-size);
  font-size: var(--font-size-base);
}

.grade-3-5 .answer-btn {
  padding: 15px 25px;
  font-size: 18px;
}

/* 6-8: More text-based, competitive */
.grade-6-8 {
  --btn-size: 44px;
  --font-size-base: 16px;
  --icon-size: 28px;
}

/* ===========================================
   MOBILE NAVIGATION
   =========================================== */

/* Bottom navigation bar (iOS/Android style) */
.mobile-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  display: flex;
  justify-content: space-around;
  padding: var(--spacing-sm);
  padding-bottom: calc(var(--spacing-sm) + var(--safe-area-bottom));
  z-index: 1000;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--spacing-xs) var(--spacing-sm);
  color: #666;
  text-decoration: none;
  font-size: 12px;
  min-width: 60px;
}

.mobile-nav-item.active {
  color: var(--primary);
}

.mobile-nav-item i {
  font-size: 24px;
  margin-bottom: 4px;
}

/* Account for bottom nav */
.main-content {
  padding-bottom: calc(70px + var(--safe-area-bottom));
}

/* ===========================================
   MOBILE CARDS & COMPONENTS
   =========================================== */

/* Swipeable cards */
.card-stack {
  position: relative;
  height: 400px;
  perspective: 1000px;
}

.swipe-card {
  position: absolute;
  width: 100%;
  height: 100%;
  background: white;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  transition: transform 0.3s ease;
  cursor: grab;
}

.swipe-card:active {
  cursor: grabbing;
}

/* Pull-to-refresh indicator */
.pull-refresh {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  transition: transform 0.3s;
}

.pull-refresh.active {
  transform: translateX(-50%) translateY(60px);
}

/* ===========================================
   BATTLE ARENA MOBILE
   =========================================== */

/* Full-screen battle mode */
.battle-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
}

/* Battle timer (prominent on mobile) */
.battle-timer-mobile {
  position: fixed;
  top: var(--safe-area-top);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 10px 30px;
  border-radius: 0 0 20px 20px;
  font-size: 28px;
  font-weight: bold;
  z-index: 2001;
}

.battle-timer-mobile.warning {
  background: var(--warning);
  animation: pulse 0.5s infinite;
}

.battle-timer-mobile.danger {
  background: var(--danger);
  animation: shake 0.3s infinite;
}

/* Answer buttons grid (2x2 for mobile) */
.answer-grid-mobile {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-md);
  padding: var(--spacing-md);
}

.answer-btn-mobile {
  background: white;
  border: 3px solid transparent;
  border-radius: 15px;
  padding: 20px;
  font-size: 18px;
  font-weight: 600;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: all 0.2s ease;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.answer-btn-mobile:active {
  transform: scale(0.95);
}

.answer-btn-mobile.selected {
  border-color: var(--primary);
  background: rgba(102, 126, 234, 0.1);
}

.answer-btn-mobile.correct {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.answer-btn-mobile.incorrect {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

/* ===========================================
   STREAK & GAMIFICATION
   =========================================== */

/* Streak display (Duolingo-style) */
.streak-banner {
  background: linear-gradient(135deg, #ff9a56 0%, #ff6b6b 100%);
  color: white;
  padding: var(--spacing-md);
  border-radius: 15px;
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-md);
}

.streak-fire {
  font-size: 40px;
  animation: bounce 1s infinite;
}

.streak-count {
  font-size: 32px;
  font-weight: bold;
}

.streak-text {
  font-size: 14px;
  opacity: 0.9;
}

/* XP gain animation */
.xp-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--gold);
  color: #333;
  padding: 15px 30px;
  border-radius: 50px;
  font-size: 24px;
  font-weight: bold;
  animation: xp-fly 1.5s ease-out forwards;
  z-index: 3000;
}

@keyframes xp-fly {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -150%) scale(1.5);
  }
}

/* Level up celebration */
.level-up-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 4000;
  animation: fadeIn 0.5s;
}

.level-up-badge {
  font-size: 100px;
  animation: bounce 0.5s infinite;
}

.level-up-text {
  color: var(--gold);
  font-size: 36px;
  font-weight: bold;
  margin-top: 20px;
  text-shadow: 0 0 20px rgba(255,215,0,0.5);
}

/* ===========================================
   OFFLINE MODE INDICATOR
   =========================================== */

.offline-banner {
  position: fixed;
  top: var(--safe-area-top);
  left: 0;
  right: 0;
  background: var(--warning);
  color: white;
  text-align: center;
  padding: 10px;
  z-index: 5000;
  display: none;
}

body.offline .offline-banner {
  display: block;
}

body.offline .online-only {
  opacity: 0.5;
  pointer-events: none;
}

/* ===========================================
   INSTALL PROMPT (PWA)
   =========================================== */

.install-prompt {
  position: fixed;
  bottom: 80px;
  left: var(--spacing-md);
  right: var(--spacing-md);
  background: white;
  border-radius: 20px;
  padding: var(--spacing-lg);
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  z-index: 1001;
  animation: slideUp 0.3s ease;
}

.install-prompt-icon {
  font-size: 48px;
  text-align: center;
  margin-bottom: var(--spacing-md);
}

.install-prompt-title {
  font-size: 20px;
  font-weight: bold;
  text-align: center;
  margin-bottom: var(--spacing-sm);
}

.install-prompt-text {
  text-align: center;
  color: #666;
  margin-bottom: var(--spacing-md);
}

.install-prompt-buttons {
  display: flex;
  gap: var(--spacing-md);
}

.install-prompt-buttons .btn {
  flex: 1;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ===========================================
   ANIMATIONS
   =========================================== */

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

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

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

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

/* Confetti animation for celebrations */
.confetti-piece {
  position: fixed;
  width: 10px;
  height: 20px;
  background: var(--primary);
  animation: confetti-fall 3s linear forwards;
  z-index: 5000;
}

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

/* ===========================================
   RESPONSIVE BREAKPOINTS
   =========================================== */

/* Small phones */
@media (max-width: 320px) {
  :root {
    --spacing-md: 12px;
    --spacing-lg: 16px;
  }

  .answer-btn-mobile {
    font-size: 14px;
    padding: 15px;
  }
}

/* Standard phones */
@media (min-width: 321px) and (max-width: 480px) {
  .card {
    border-radius: 15px;
  }
}

/* Large phones / Small tablets */
@media (min-width: 481px) and (max-width: 768px) {
  .answer-grid-mobile {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Tablets */
@media (min-width: 769px) {
  .mobile-nav {
    display: none;
  }

  .answer-grid-mobile {
    grid-template-columns: repeat(4, 1fr);
    max-width: 800px;
    margin: 0 auto;
  }
}

/* Landscape mode on phones */
@media (max-height: 500px) and (orientation: landscape) {
  .battle-fullscreen {
    flex-direction: row;
  }

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

  .question-text {
    font-size: 18px;
  }
}

/* ===========================================
   DARK MODE SUPPORT
   =========================================== */

@media (prefers-color-scheme: dark) {
  :root {
    --dark: #f7fafc;
    --light: #1a202c;
  }

  body.auto-dark {
    background: #1a202c;
    color: #f7fafc;
  }

  body.auto-dark .card,
  body.auto-dark .answer-btn-mobile {
    background: #2d3748;
    color: #f7fafc;
  }

  body.auto-dark .mobile-nav {
    background: #2d3748;
  }
}

/* ===========================================
   ACCESSIBILITY
   =========================================== */

/* High contrast mode */
@media (prefers-contrast: high) {
  .btn, .answer-btn-mobile {
    border: 3px solid currentColor;
  }
}

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

/* Focus visible for keyboard navigation */
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
