/* ============================================================
   TeclaRápida — Game & Play Screens Styles
   Premium Dark-Mode Edition
   ============================================================ */

/* ─── Game Container (Main Wrapper) ─── */
.game-container {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.game-header {
  order: 1;
}

.game-progress {
  order: 2;
}

.typing-area {
  order: 3;
}

.survival-area {
  order: 3;
}

.finger-hint {
  order: 4;
}

.keyboard-container {
  order: 5;
}


/* ─── Game Header (Dashboard Stats Bar) ─── */
.game-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0;
  padding: var(--space-3) var(--space-4);
  background: rgba(24, 24, 37, 0.35);
  border: 1px solid rgba(99, 102, 241, 0.08);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.game-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  padding: var(--space-2) var(--space-4);
  position: relative;
}

/* Subtle vertical dividers between stats */
.game-stat + .game-stat {
  border-left: 1px solid rgba(99, 102, 241, 0.12);
}

.game-stat-main {
  border-left: none;
  border-right: none;
}

.game-stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: lowercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-1);
  font-weight: var(--weight-medium);
}

.game-stat-value {
  font-size: 1.75rem;
  font-weight: 300;
  color: var(--color-text);
  font-family: var(--font-mono);
  transition: transform var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out);
  line-height: 1.1;
}

.game-ppm-value {
  color: var(--color-primary-light);
  font-size: 2.15rem;
  font-weight: var(--weight-normal);
  text-shadow: 0 0 24px rgba(99, 102, 241, 0.25);
}


/* ─── Progress Bar ─── */
.game-progress {
  width: 100%;
  margin-top: calc(var(--space-2) * -1);
  margin-bottom: var(--space-2);
}


/* ─── Typing Area (Core Interaction — Monkeytype Style) ─── */
.typing-area {
  position: relative;
  background: rgba(24, 24, 37, 0.025);
  border: none;
  border-left: 2px solid transparent;
  border-image: linear-gradient(
    180deg,
    var(--color-primary) 0%,
    var(--color-secondary) 50%,
    transparent 100%
  ) 1;
  border-radius: 0;
  padding: var(--space-6) var(--space-6) var(--space-6) var(--space-8);
  min-height: 130px;
  max-height: 220px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: var(--weight-normal);
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  backdrop-filter: none;
  box-shadow: none;
  cursor: text;
  outline: none;
  text-align: left;
  transition: border-color var(--duration-normal) var(--ease-out);
}

.typing-area:focus-within {
  border-image: linear-gradient(
    180deg,
    var(--color-primary-light) 0%,
    var(--color-secondary) 40%,
    transparent 100%
  ) 1;
  box-shadow: inset 4px 0 16px -8px rgba(99, 102, 241, 0.12);
}


/* ─── Individual Character Styling ─── */
.char {
  position: relative;
  transition: color var(--duration-fast) var(--ease-out);
  border-radius: 0;
  border-bottom: 2px solid transparent;
}

.char.pending {
  color: var(--color-char-pending);
}

.char.correct {
  color: var(--color-char-correct);
  background: none;
}

.char.incorrect {
  color: #ff6b7a;
  background: rgba(202, 71, 84, 0.12);
  border-bottom: 2.5px solid var(--color-char-error);
  border-radius: 2px 2px 0 0;
  text-shadow: 0 0 6px rgba(202, 71, 84, 0.35);
}

.char.current {
  color: var(--color-char-pending);
  background: none;
}


/* ─── Caret / Cursor ─── */
.typing-caret {
  position: absolute;
  background: var(--color-kbd-glow);
  width: 2.5px;
  border-radius: var(--radius-full);
  transition: left 0.08s var(--ease-out),
              top 0.08s var(--ease-out),
              height 0.08s var(--ease-out);
  animation: caretPulse 1s var(--ease-in-out) infinite;
  pointer-events: none;
  z-index: 10;
  box-shadow:
    0 0 6px rgba(6, 182, 212, 0.5),
    0 0 14px rgba(6, 182, 212, 0.25),
    0 0 28px rgba(6, 182, 212, 0.1);
}

@keyframes caretPulse {
  0%, 100% { opacity: 1; }
  40%      { opacity: 1; }
  60%      { opacity: 0; }
  80%      { opacity: 0; }
}


/* ─── Hidden Game Input ─── */
.game-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}


/* ─── Survival Mode (Floating Words) ─── */
.survival-area {
  position: relative;
  height: 400px;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
    linear-gradient(180deg, rgba(15, 23, 42, 0.65) 0%, rgba(10, 14, 23, 0.95) 100%);
  border: 1px solid rgba(99, 102, 241, 0.15);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow:
    var(--shadow-lg),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.survival-words-container {
  position: relative;
  width: 100%;
  height: 330px;
}

.survival-word {
  position: absolute;
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  padding: 0.4rem 0.9rem;
  background: rgba(30, 41, 59, 0.88);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  will-change: transform;
  transform: translate(-50%, 0);
  transition: background var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

.survival-word.target {
  border-color: var(--color-primary);
  box-shadow:
    0 0 12px rgba(99, 102, 241, 0.35),
    0 0 24px rgba(99, 102, 241, 0.15);
  background: rgba(99, 102, 241, 0.18);
}

.survival-word .typed {
  color: var(--color-success);
}

.survival-input-area {
  height: 70px;
  background: rgba(15, 23, 42, 0.92);
  border-top: 1px solid rgba(99, 102, 241, 0.1);
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.survival-current-word {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--color-text-secondary);
}

.survival-lives {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: var(--text-lg);
  letter-spacing: 0.15rem;
  z-index: 10;
  text-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
}


/* ─── Exercise List (Lesson Detail) ─── */
.exercise-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

.exercise-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: all var(--duration-normal) var(--ease-out);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

/* Subtle shine on hover */
.exercise-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.02) 0%, transparent 50%);
  opacity: 0;
  transition: opacity var(--duration-fast) ease;
  pointer-events: none;
}

.exercise-card:hover::before {
  opacity: 1;
}

.exercise-card:hover {
  border-color: var(--color-primary);
  background: var(--color-surface-hover);
  transform: translateX(4px);
  box-shadow: var(--shadow-md);
}

.exercise-info {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.exercise-type-icon {
  font-size: 1.5rem;
  width: 42px;
  height: 42px;
  background: rgba(99, 102, 241, 0.1);
  border-radius: var(--radius-full);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
}

.exercise-title {
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.exercise-meta {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  margin-top: 0.15rem;
}

.exercise-stats {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.exercise-stars {
  font-size: 1.2rem;
  color: var(--color-gold);
}

.exercise-card.locked {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
  filter: grayscale(0.3);
}


/* ─── Results Screen ─── */
.results-container {
  max-width: 700px;
  margin: 0 auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-4);
}

.results-header {
  padding: var(--space-6) var(--space-4);
  position: relative;
}

/* Subtle radial glow behind results header */
.results-header::before {
  content: '';
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 300px;
  height: 120px;
  background: radial-gradient(ellipse, rgba(99, 102, 241, 0.12) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.results-title {
  font-size: var(--text-4xl);
  font-weight: var(--weight-black);
  margin-bottom: var(--space-4);
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  position: relative;
  z-index: 1;
}

.results-stars {
  font-size: 3.25rem;
  color: var(--color-text-muted);
  display: flex;
  justify-content: center;
  gap: var(--space-3);
  position: relative;
  z-index: 1;
}

.results-stars .result-star.filled {
  color: var(--color-gold);
  text-shadow:
    0 0 12px rgba(245, 158, 11, 0.5),
    0 0 30px rgba(245, 158, 11, 0.2);
  animation: starBounceIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.results-stars .result-star.filled:nth-child(2) {
  animation-delay: 0.1s;
}

.results-stars .result-star.filled:nth-child(3) {
  animation-delay: 0.2s;
}


/* ─── Stats Grid ─── */
.results-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
}

@media (min-width: 600px) {
  .results-stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.result-stat-card {
  padding: var(--space-5) var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(24, 24, 37, 0.5);
  border: 1px solid rgba(99, 102, 241, 0.1);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
  transition: all var(--duration-normal) var(--ease-out);
}

/* Inner shine */
.result-stat-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.025) 0%, transparent 60%);
  pointer-events: none;
}

.result-stat-card:hover {
  transform: translateY(-3px);
  border-color: rgba(99, 102, 241, 0.2);
  box-shadow: var(--shadow-md);
}

.result-stat-icon {
  font-size: 1.5rem;
  margin-bottom: var(--space-2);
}

.result-stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-black);
  font-family: var(--font-mono);
  line-height: 1.2;
}

.result-stat-ppm {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12) 0%, rgba(139, 92, 246, 0.12) 100%);
  border-color: rgba(99, 102, 241, 0.2);
}

.result-stat-ppm:hover {
  box-shadow: var(--shadow-md), 0 0 20px rgba(99, 102, 241, 0.15);
}

.result-stat-accuracy {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.12) 0%, rgba(52, 211, 153, 0.12) 100%);
  border-color: rgba(16, 185, 129, 0.2);
}

.result-stat-accuracy:hover {
  box-shadow: var(--shadow-md), 0 0 20px rgba(16, 185, 129, 0.15);
}


/* ─── XP Card ─── */
.result-xp-card {
  padding: var(--space-5);
  text-align: left;
  background: rgba(24, 24, 37, 0.5);
  border: 1px solid rgba(245, 158, 11, 0.12);
  border-radius: var(--radius-lg);
}

.result-xp-header {
  display: flex;
  justify-content: space-between;
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-3);
}

.result-xp-value {
  color: var(--color-xp);
  text-shadow: 0 0 12px rgba(245, 158, 11, 0.25);
}

.progress-bar-xp {
  background: var(--gradient-gold);
}


/* ─── Errors Card ─── */
.result-errors-card {
  padding: var(--space-5);
  text-align: left;
  background: rgba(24, 24, 37, 0.5);
  border: 1px solid rgba(239, 68, 68, 0.1);
  border-radius: var(--radius-lg);
}

.result-errors-card h4 {
  margin-bottom: var(--space-3);
  font-weight: var(--weight-semibold);
}

.result-error-keys {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.error-key-badge {
  padding: var(--space-1) 0.65rem;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-error-light);
  transition: all var(--duration-fast) ease;
}

.error-key-badge:hover {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.4);
}


/* ─── Results Actions ─── */
.results-actions {
  display: flex;
  gap: var(--space-4);
  justify-content: center;
  flex-wrap: wrap;
  margin-top: var(--space-4);
  padding: 0 var(--space-4);
}


/* ─── Keyframe Animations ─── */
@keyframes cursorBlink {
  0%, 100% {
    border-bottom: 2px solid var(--color-primary);
  }
  50% {
    border-bottom: 2px solid transparent;
  }
}

@keyframes starBounceIn {
  0% {
    transform: scale(0) rotate(-15deg);
    opacity: 0;
  }
  60% {
    transform: scale(1.25) rotate(5deg);
    opacity: 1;
  }
  80% {
    transform: scale(0.95) rotate(-2deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}


/* ─── Responsive — Mobile ─── */
@media (max-width: 600px) {
  .game-container {
    padding: var(--space-3) var(--space-4);
    gap: var(--space-4);
  }

  .game-header {
    gap: 0;
    padding: var(--space-2) var(--space-2);
    border-radius: var(--radius-lg);
  }

  .game-stat {
    padding: var(--space-1) var(--space-2);
  }

  .game-stat-value {
    font-size: var(--text-lg);
  }

  .game-ppm-value {
    font-size: var(--text-xl);
  }

  .typing-area {
    padding: var(--space-4) var(--space-4) var(--space-4) var(--space-5);
    font-size: var(--text-lg);
    min-height: 120px;
    max-height: 180px;
    line-height: 1.65;
  }

  .survival-area {
    height: 320px;
    border-radius: var(--radius-lg);
  }

  .survival-words-container {
    height: 260px;
  }

  .results-container {
    padding: var(--space-2);
    gap: var(--space-4);
  }

  .results-title {
    font-size: var(--text-3xl);
  }

  .results-stars {
    font-size: 2.5rem;
    gap: var(--space-2);
  }

  .results-actions {
    flex-direction: column;
    align-items: stretch;
    padding: 0;
  }

  .result-stat-card {
    padding: var(--space-4) var(--space-3);
  }
}

/* ─── Tablet tweaks ─── */
@media (min-width: 601px) and (max-width: 900px) {
  .game-container {
    padding: var(--space-4) var(--space-6);
  }
}
