/* ============================================
   MOBILE-FIRST UX IMPROVEMENTS
   Optimized for 90% mobile traffic
   Created: 2025-11-11
   ============================================ */

/* ============================================
   1. ENLARGED TOUCH TARGETS (64px for primary actions)
   ============================================ */

/* Quiz Answer Buttons - CRITICAL for mobile */
@media (max-width: 768px) {
  .choice-btn,
  .choice-button {
    min-height: 64px !important; /* Increased from 44px */
    padding: 16px 20px !important;
    margin-bottom: 12px !important;
    font-size: 16px !important;
    line-height: 1.5 !important;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
  }

  .choice-btn:active,
  .choice-button:active {
    transform: scale(0.98);
    background-color: var(--bg-light);
  }

  .choice-btn.selected,
  .choice-button.selected {
    border-color: var(--primary-color);
    background: rgba(0, 132, 61, 0.05);
    font-weight: 600;
  }

  .choice-btn.correct {
    border-color: var(--success-color);
    background: rgba(56, 142, 60, 0.1);
  }

  .choice-btn.incorrect {
    border-color: var(--danger-color);
    background: rgba(211, 47, 47, 0.1);
  }

  /* Primary action buttons */
  .btn-primary,
  .btn-cta,
  #nextButton,
  #authSubmit {
    min-height: 56px !important;
    font-size: 16px !important;
    font-weight: 600;
    padding: 16px 32px !important;
  }

  /* Start Practice/Mock Test buttons */
  #startModeA,
  #startModeB {
    min-height: 56px !important;
    width: 100%;
    font-size: 17px !important;
    font-weight: 600;
  }
}

/* ============================================
   2. STICKY PROGRESS BAR
   ============================================ */

.quiz-progress {
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 50;
  padding: 12px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  border-bottom: 1px solid var(--border-color);
}

/* Enhanced progress bar */
.progress-bar-container {
  position: relative;
  height: 8px;
  background: var(--bg-light);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-color), var(--success-color));
  transition: width 0.3s ease;
  position: relative;
  width: 0%;
}

/* Animated shimmer effect */
.progress-bar-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 100%
  );
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* Enhanced question counter */
#questionCounter {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================
   3. FORM INPUT OPTIMIZATION
   ============================================ */

/* Mobile-optimized inputs */
input[type="email"],
input[type="password"],
input[type="text"],
input[type="tel"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: 52px !important; /* Larger than 44px */
  padding: 14px 16px !important;
  font-size: 16px !important; /* Prevents iOS zoom on focus */
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background: var(--white);
  transition: all 0.2s ease;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* Focus state with larger touch area */
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(0, 132, 61, 0.1);
}

/* Placeholder styling */
input::placeholder,
textarea::placeholder {
  color: var(--text-light);
  font-size: 16px !important;
  opacity: 0.7;
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
  input,
  select,
  textarea {
    font-size: 16px !important; /* Prevent zoom */
  }
}

/* ============================================
   4. PASSWORD VISIBILITY TOGGLE
   ============================================ */

.password-input-group {
  position: relative;
  width: 100%;
}

.password-input-group input {
  padding-right: 56px !important; /* Space for toggle button */
}

.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-light);
  transition: all 0.2s ease;
  padding: 0;
  z-index: 10;
  /* Mobile-specific touch enhancements */
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0, 132, 61, 0.1);
  user-select: none;
  -webkit-user-select: none;
}

.password-toggle:hover,
.password-toggle:focus {
  color: var(--primary-color);
  background: rgba(0, 132, 61, 0.05);
  border-radius: 50%;
}

.password-toggle:active {
  transform: translateY(-50%) scale(0.9);
  color: var(--primary-color);
  background: rgba(0, 132, 61, 0.15);
  border-radius: 50%;
}

.password-toggle .toggle-icon {
  display: block;
  width: 24px;
  height: 24px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

/* Eye icon states */
.password-toggle[data-visible="false"] .toggle-icon {
  /* Eye closed icon */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23616161' stroke-width='2'%3E%3Cpath d='M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E");
}

.password-toggle[data-visible="true"] .toggle-icon {
  /* Eye open with slash icon */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2300843D' stroke-width='2'%3E%3Cpath d='M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cline x1='1' y1='1' x2='23' y2='23'/%3E%3C/svg%3E");
}

/* ============================================
   5. LOADING BUTTON STATES
   ============================================ */

.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
  cursor: not-allowed;
  opacity: 0.8;
}

.btn-loading::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Dark button loading state */
.btn-secondary.btn-loading::after,
.btn-outline.btn-loading::after {
  border-color: rgba(0, 132, 61, 0.3);
  border-top-color: var(--primary-color);
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* Loading text indicator */
.btn-loading .btn-text {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--white);
  font-size: 14px;
  white-space: nowrap;
  margin-top: 28px;
}

/* ============================================
   6. VISUAL FEEDBACK IMPROVEMENTS
   ============================================ */

/* Button press feedback */
@media (max-width: 768px) {
  .btn:active,
  button:active {
    transform: scale(0.95);
    opacity: 0.9;
  }

  /* Ripple effect on tap */
  .btn {
    position: relative;
    overflow: hidden;
  }

  .btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
  }

  .btn:active::before {
    width: 300px;
    height: 300px;
  }
}

/* Success/Error flash feedback */
@keyframes flashSuccess {
  0% {
    background: rgba(56, 142, 60, 0);
  }
  50% {
    background: rgba(56, 142, 60, 0.2);
  }
  100% {
    background: rgba(56, 142, 60, 0);
  }
}

@keyframes flashError {
  0% {
    background: rgba(211, 47, 47, 0);
  }
  50% {
    background: rgba(211, 47, 47, 0.2);
  }
  100% {
    background: rgba(211, 47, 47, 0);
  }
}

.feedback-flash {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 9999;
}

.feedback-flash.feedback-success {
  animation: flashSuccess 0.3s ease;
}

.feedback-flash.feedback-error {
  animation: flashError 0.3s ease;
}

/* ============================================
   7. IMPROVED MOBILE TYPOGRAPHY
   ============================================ */

@media (max-width: 768px) {
  /* Prevent text selection on interactive elements */
  .btn,
  button,
  .choice-btn,
  .choice-button {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  /* Larger, more readable text */
  body {
    font-size: 16px !important; /* Base size to prevent iOS zoom */
  }

  .question-text,
  #questionText {
    font-size: 18px !important;
    line-height: 1.6;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 24px;
  }

  .choice-text {
    font-size: 16px !important;
    line-height: 1.5;
  }

  .feedback-description {
    font-size: 15px !important;
    line-height: 1.6;
  }

  /* Improve contrast */
  :root {
    --text-dark: #1a1a1a; /* Darker for better readability */
    --text-light: #4a4a4a; /* Still lighter but more readable */
  }
}

/* ============================================
   8. QUIT TEST BUTTON MOBILE OPTIMIZATION
   ============================================ */

@media (max-width: 768px) {
  .btn-quit-test {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 60;
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid var(--danger-color);
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }

  .btn-quit-test .quit-text {
    display: none;
  }

  .btn-quit-test .quit-icon {
    font-size: 24px;
    color: var(--danger-color);
    font-weight: bold;
  }

  .btn-quit-test:active {
    transform: scale(0.9);
  }
}

/* ============================================
   9. MOBILE MODAL IMPROVEMENTS
   ============================================ */

@media (max-width: 768px) {
  .modal-content {
    width: 95%;
    max-width: 100%;
    margin: 20px auto;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .close-modal {
    min-width: 48px;
    min-height: 48px;
    font-size: 28px;
    padding: 12px;
  }
}

/* ============================================
   10. IMPROVED TAB/MODE SELECTION
   ============================================ */

@media (max-width: 768px) {
  .auth-tabs {
    display: flex;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border-color);
  }

  .auth-tab {
    flex: 1;
    padding: 14px;
    min-height: 48px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    background: none;
    color: var(--text-light);
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
  }

  .auth-tab.active {
    color: var(--white) !important; /* Force white text on green background */
    background-color: var(--primary-color);
    border: none;
    border-radius: 8px 8px 0 0;
  }

  .mode-card {
    padding: 20px;
    margin-bottom: 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    transition: all 0.2s ease;
  }

  .mode-card:active {
    transform: scale(0.98);
    background: var(--bg-light);
  }
}

/* ============================================
   11. SAFE AREA SUPPORT (iPhone X+)
   ============================================ */

@supports (padding: max(0px)) {
  .container {
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
  }

  .quiz-header,
  .quiz-progress {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
}

/* ============================================
   12. PERFORMANCE OPTIMIZATIONS
   ============================================ */

/* Hardware acceleration for animations */
.btn,
.choice-btn,
.modal,
.progress-bar-fill {
  will-change: transform;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

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