/* Custom CSS for VelocidadEscritura */

/* Font Imports */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@300;400;500;600&display=swap');

/* CSS Variables for consistent theming */
:root {
  --primary-color: #3b82f6;
  --secondary-color: #1e40af;
  --accent-color: #f59e0b;
  --typing-color: #10b981;
  --error-color: #ef4444;
  --correct-color: #22c55e;
  --pending-color: #94a3b8;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --border-color: #e5e7eb;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --transition-fast: 150ms ease-in-out;
  --transition-normal: 300ms ease-in-out;
  --border-radius: 0.75rem;
}

/* Dark mode variables */
[data-theme="dark"] {
  --text-primary: #f9fafb;
  --text-secondary: #d1d5db;
  --bg-primary: #111827;
  --bg-secondary: #1f2937;
  --border-color: #374151;
}

/* Base styles */
* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  line-height: 1.6;
  scroll-behavior: smooth;
}

/* Typing specific font */
.font-mono {
  font-family: 'Fira Code', 'Monaco', 'Menlo', 'Consolas', monospace;
  font-variant-ligatures: none; /* Disable ligatures for typing tests */
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--text-secondary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-color);
}

/* Typing display styles */
#textDisplay {
  user-select: none;
  cursor: default;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 1.125rem;
  line-height: 1.8;
  letter-spacing: 0.02em;
}

/* Character highlighting */
.char-correct {
  background-color: rgba(34, 197, 94, 0.2);
  color: var(--correct-color);
}

.char-incorrect {
  background-color: rgba(239, 68, 68, 0.3);
  color: var(--error-color);
  text-decoration: underline;
  text-decoration-color: var(--error-color);
}

.char-pending {
  color: var(--pending-color);
  background-color: rgba(148, 163, 184, 0.1);
}

.char-current {
  background-color: var(--primary-color);
  color: white;
  animation: cursor-blink 1s step-end infinite;
}

.char-extra {
  background-color: rgba(239, 68, 68, 0.5);
  color: var(--error-color);
  font-weight: bold;
}

/* Cursor animation */
@keyframes cursor-blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0.3; }
}

/* Typing input area */
#typingInput {
  font-family: 'Fira Code', monospace;
  font-size: 1.125rem;
  line-height: 1.8;
  letter-spacing: 0.02em;
  resize: none;
  transition: all var(--transition-fast);
}

#typingInput:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#typingInput:disabled {
  background-color: var(--bg-secondary);
  cursor: not-allowed;
  opacity: 0.7;
}

/* Text card styles */
.text-card {
  transition: all var(--transition-normal);
  cursor: pointer;
  border: 2px solid transparent;
}

.text-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-color);
}

.text-card.selected {
  border-color: var(--primary-color);
  background-color: rgba(59, 130, 246, 0.05);
}

/* Progress bar animation */
.progress-bar {
  background: linear-gradient(90deg, var(--primary-color) 0%, var(--typing-color) 100%);
  height: 12px;
  border-radius: 6px;
  transition: width var(--transition-normal);
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}

/* Live stats animation */
.stat-card {
  transition: all var(--transition-fast);
}

.stat-card:hover {
  transform: scale(1.02);
}

/* Result cards animation */
.result-card {
  animation: slideInUp 0.6s ease-out;
}

.result-card:nth-child(2) {
  animation-delay: 0.1s;
}

.result-card:nth-child(3) {
  animation-delay: 0.2s;
}

.result-card:nth-child(4) {
  animation-delay: 0.3s;
}

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

/* Timer display */
#testTimer {
  font-family: 'Fira Code', monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.1em;
}

/* Live WPM counter animation */
.counter {
  font-variant-numeric: tabular-nums;
  transition: all var(--transition-fast);
}

.counter.updating {
  color: var(--typing-color);
  transform: scale(1.1);
}

/* Modal animations */
.modal-enter {
  animation: modalEnter 0.3s ease-out;
}

.modal-exit {
  animation: modalExit 0.3s ease-in;
}

@keyframes modalEnter {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes modalExit {
  from {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  to {
    opacity: 0;
    transform: scale(0.9) translateY(-10px);
  }
}

/* Button hover effects */
.btn-primary {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  transition: all var(--transition-normal);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(59, 130, 246, 0.3);
}

/* Difficulty badges */
.difficulty-fácil, .difficulty-facil {
  background-color: #d1fae5;
  color: #065f46;
}

.difficulty-intermedio {
  background-color: #fef3c7;
  color: #92400e;
}

.difficulty-avanzado {
  background-color: #fee2e2;
  color: #991b1b;
}

/* Dark mode difficulty badges */
.dark .difficulty-fácil, .dark .difficulty-facil {
  background-color: #064e3b;
  color: #a7f3d0;
}

.dark .difficulty-intermedio {
  background-color: #78350f;
  color: #fcd34d;
}

.dark .difficulty-avanzado {
  background-color: #7f1d1d;
  color: #fca5a5;
}

/* Category badges */
.category-badge {
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  white-space: nowrap;
}

/* Chart container */
.chart-container {
  position: relative;
  height: 250px;
  margin: 1rem 0;
}

/* Error highlight in text */
.error-highlight {
  background-color: rgba(239, 68, 68, 0.3);
  border-bottom: 2px wavy var(--error-color);
  padding: 0 2px;
  border-radius: 2px;
}

/* Loading spinner */
.spinner {
  border: 4px solid var(--bg-secondary);
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Sound toggle indicator */
.sound-on {
  color: var(--typing-color);
}

.sound-off {
  color: var(--error-color);
}

/* Typing sound visualizer */
.sound-wave {
  width: 4px;
  height: 20px;
  background: var(--primary-color);
  margin: 0 1px;
  animation: sound-wave 1.5s ease-in-out infinite;
  opacity: 0.7;
}

.sound-wave:nth-child(2) { animation-delay: 0.1s; }
.sound-wave:nth-child(3) { animation-delay: 0.2s; }
.sound-wave:nth-child(4) { animation-delay: 0.3s; }

@keyframes sound-wave {
  0%, 100% { height: 10px; }
  50% { height: 25px; }
}

/* WPM level indicators */
.wpm-level-principiante {
  color: #ef4444;
  background-color: rgba(239, 68, 68, 0.1);
}

.wpm-level-basico {
  color: #f59e0b;
  background-color: rgba(245, 158, 11, 0.1);
}

.wpm-level-intermedio {
  color: #3b82f6;
  background-color: rgba(59, 130, 246, 0.1);
}

.wpm-level-avanzado {
  color: #10b981;
  background-color: rgba(16, 185, 129, 0.1);
}

.wpm-level-experto {
  color: #8b5cf6;
  background-color: rgba(139, 92, 246, 0.1);
}

.wpm-level-profesional {
  color: #f59e0b;
  background-color: rgba(245, 158, 11, 0.1);
  font-weight: bold;
}

/* Certificate styles */
.certificate {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 2rem;
  border-radius: 1rem;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.certificate-border {
  border: 4px solid #ffd700;
  padding: 1rem;
  border-radius: 0.5rem;
}

/* Mobile optimizations */
@media (max-width: 768px) {
  #textDisplay {
    font-size: 1rem;
    line-height: 1.6;
    padding: 1rem;
  }
  
  #typingInput {
    font-size: 1rem;
    line-height: 1.6;
  }
  
  .result-card {
    margin-bottom: 1rem;
  }
  
  .modal-content {
    margin: 1rem;
    max-height: calc(100vh - 2rem);
  }
  
  .grid-cols-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Focus styles for accessibility */
button:focus,
select:focus,
input:focus,
textarea:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000000;
    --text-secondary: #000000;
  }
  
  [data-theme="dark"] {
    --border-color: #ffffff;
    --text-secondary: #ffffff;
  }
  
  .char-correct {
    background-color: #00ff00;
    color: #000000;
  }
  
  .char-incorrect {
    background-color: #ff0000;
    color: #ffffff;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .char-current {
    animation: none;
    background-color: var(--primary-color);
  }
}

/* Text selection */
::selection {
  background-color: var(--primary-color);
  color: white;
}

/* Prevent text selection in display area */
#textDisplay {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Custom utilities */
.text-gradient {
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.glass-effect {
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.dark .glass-effect {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

/* Performance optimizations */
.will-change-transform {
  will-change: transform;
}

.will-change-opacity {
  will-change: opacity;
}

/* GPU acceleration for smooth animations */
.gpu-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* Print styles */
@media print {
  .no-print {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
  
  .certificate {
    background: white !important;
    color: black !important;
    border: 2px solid black;
  }
}

/* AdSense optimization */
.adsense-container {
  margin: 2rem 0;
  text-align: center;
}

.adsense-container ins {
  display: inline-block;
  text-decoration: none;
}

/* Keyboard key styling */
.keyboard-key {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  background: #f3f4f6;
  border: 2px solid #d1d5db;
  border-radius: 0.375rem;
  font-family: 'Fira Code', monospace;
  font-size: 0.875rem;
  margin: 0 0.125rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.dark .keyboard-key {
  background: #374151;
  border-color: #4b5563;
  color: #f3f4f6;
}

/* Error frequency visualization */
.error-freq-bar {
  height: 8px;
  background: linear-gradient(90deg, var(--typing-color), var(--error-color));
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* Typing rhythm visualization */
.rhythm-indicator {
  width: 100%;
  height: 60px;
  background: var(--bg-secondary);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.rhythm-bar {
  position: absolute;
  bottom: 0;
  width: 4px;
  background: var(--primary-color);
  border-radius: 2px 2px 0 0;
  transition: height 0.1s ease;
}
