/* Shared Letter Boxes CSS - Configurable letter box styles for games and training */

:root {
  /* Letter box sizing */
  --letter-box-size: 50px;
  --letter-box-font-size: 1.5rem;
  --letter-box-border-radius: 8px;
  --letter-box-margin: 5px;
  --letter-box-border-width: 2px;

  /* Colors - Light theme */
  --letter-box-bg: var(--bg-surface, #f8f9fa);
  --letter-box-border: var(--primary-color, #0d6efd);
  --letter-box-text: var(--text-primary, #212529);

  /* Current box colors */
  --letter-box-current-bg: var(--game-current-bg, rgba(13, 110, 253, 0.1));
  --letter-box-current-border: var(--primary-color, #0d6efd);
  --letter-box-current-shadow: var(--game-current-shadow, rgba(13, 110, 253, 0.5));
  --letter-box-current-border-width: 3px;
  --letter-box-current-glow: 0 0 15px rgba(13, 110, 253, 0.4);

  /* State colors */
  --letter-box-correct-bg: var(--game-correct-bg, #d1e7dd);
  --letter-box-correct-border: var(--success-color, #198754);
  --letter-box-wrong-bg: var(--game-wrong-bg, #f8d7da);
  --letter-box-wrong-border: var(--danger-color, #dc3545);
  --letter-box-locked-bg: var(--game-correct-bg, #d1e7dd);
  --letter-box-locked-border: var(--success-color, #198754);

  /* Animation */
  --letter-box-transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  --letter-box-pulse-animation: pulse 0.5s ease-in-out;
  --letter-box-current-pulse: current-pulse 1.5s ease-in-out infinite;
}

[data-bs-theme="dark"] {
  /* Dark theme overrides */
  --letter-box-bg: var(--bg-surface-alt, #2d3748);
  --letter-box-text: var(--text-primary-dark, #e2e8f0);

  /* Current box colors - dark theme */
  --letter-box-current-bg: var(--game-current-bg-dark, rgba(59, 130, 246, 0.2));
  --letter-box-current-border: var(--primary-color-dark, #3b82f6);
  --letter-box-current-shadow: var(--game-current-shadow-dark, rgba(59, 130, 246, 0.6));
  --letter-box-current-glow: 0 0 20px rgba(59, 130, 246, 0.5);

  /* State colors */
  --letter-box-correct-bg: var(--game-correct-bg-dark, #14532d);
  --letter-box-wrong-bg: var(--game-wrong-bg-dark, #7f1d1d);
  --letter-box-locked-bg: var(--game-correct-bg-dark, #14532d);
}

/* Base letter box styles */
.letter-box {
  width: var(--letter-box-size);
  height: var(--letter-box-size);
  border: var(--letter-box-border-width) solid var(--letter-box-border);
  border-radius: var(--letter-box-border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--letter-box-font-size);
  font-weight: bold;
  margin: var(--letter-box-margin);
  background-color: var(--letter-box-bg);
  color: var(--letter-box-text);
  transition: var(--letter-box-transition);
  cursor: pointer;
  user-select: none;
}

/* Current (active) box - Enhanced visibility */
.letter-box.current {
  border-width: var(--letter-box-current-border-width);
  border-color: var(--letter-box-current-border);
  background-color: var(--letter-box-current-bg);
  box-shadow:
    0 0 0 4px var(--letter-box-current-shadow),
    var(--letter-box-current-glow);
  transform: translateY(-2px);
  z-index: 10;
  animation: var(--letter-box-current-pulse);
}

/* Current box when it also has other states (correct/wrong/locked) */
.letter-box.current.correct {
  border-color: color-mix(in srgb, var(--letter-box-correct-border) 70%, var(--letter-box-current-border) 30%);
  background-color: color-mix(in srgb, var(--letter-box-correct-bg) 80%, var(--letter-box-current-bg) 20%);
}

.letter-box.current.wrong {
  border-color: color-mix(in srgb, var(--letter-box-wrong-border) 70%, var(--letter-box-current-border) 30%);
  background-color: color-mix(in srgb, var(--letter-box-wrong-bg) 80%, var(--letter-box-current-bg) 20%);
}

.letter-box.current.locked {
  border-color: color-mix(in srgb, var(--letter-box-locked-border) 70%, var(--letter-box-current-border) 30%);
  background-color: color-mix(in srgb, var(--letter-box-locked-bg) 80%, var(--letter-box-current-bg) 20%);
}

/* Correct letter */
.letter-box.correct {
  background-color: var(--letter-box-correct-bg);
  border-color: var(--letter-box-correct-border);
  color: var(--letter-box-text);
}

/* Wrong letter */
.letter-box.wrong {
  border-color: var(--letter-box-wrong-border);
  background-color: var(--letter-box-wrong-bg);
  color: var(--letter-box-text);
}

/* Locked letter (cannot be edited) */
.letter-box.locked {
  pointer-events: none;
  cursor: default;
  background-color: var(--letter-box-locked-bg);
  border-color: var(--letter-box-locked-border);
}

/* Word completed animation */
.word-correct {
  animation: var(--letter-box-pulse-animation);
}

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

@keyframes current-pulse {
  0% {
    box-shadow:
      0 0 0 4px var(--letter-box-current-shadow),
      var(--letter-box-current-glow);
  }
  50% {
    box-shadow:
      0 0 0 6px var(--letter-box-current-shadow),
      0 0 25px var(--letter-box-current-shadow);
  }
  100% {
    box-shadow:
      0 0 0 4px var(--letter-box-current-shadow),
      var(--letter-box-current-glow);
  }
}

/* Responsive design */
@media (max-width: 768px) {
  :root {
    --letter-box-size: 45px;
    --letter-box-font-size: 1.3rem;
    --letter-box-margin: 4px;
  }
}

@media (max-width: 576px) {
  :root {
    --letter-box-size: 40px;
    --letter-box-font-size: 1.2rem;
    --letter-box-margin: 3px;
  }
}

@media (max-width: 400px) {
  :root {
    --letter-box-size: 35px;
    --letter-box-font-size: 1.1rem;
    --letter-box-margin: 2px;
  }
}

/* Container for letter boxes */
.letter-boxes-container {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

/* Accessibility */
.letter-box:focus {
  outline: 2px solid var(--letter-box-border);
  outline-offset: 2px;
}

.letter-box:focus:not(:focus-visible) {
  outline: none;
}

.letter-box:focus-visible {
  outline: 2px solid var(--letter-box-border);
  outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .letter-box {
    transition: none;
    animation: none;
  }

  .letter-box.current {
    animation: none;
    box-shadow:
      0 0 0 4px var(--letter-box-current-shadow),
      var(--letter-box-current-glow);
    transform: translateY(-2px);
  }

  .word-correct {
    animation: none;
  }
}

/* Print styles */
@media print {
  .letter-box {
    border: 1px solid #000;
    background-color: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
    transform: none !important;
    animation: none !important;
  }

  .letter-box.current {
    border: 2px solid #000 !important;
    background-color: #f0f0f0 !important;
  }

  .letter-box.correct,
  .letter-box.locked {
    background-color: #e8f5e9 !important;
  }

  .letter-box.wrong {
    background-color: #ffebee !important;
  }
}