/*
 * Word Search Puzzle Viewer Styles
 * Responsive, accessible, and feature-rich CSS for word search puzzles
 */

/* ========================================================================
   CSS Custom Properties / Design Tokens
   ======================================================================== */

:root {
  /* Grid sizing */
  --ws-cell-size: 32px;
  --ws-cell-gap: 2px;
  --ws-font-size: 16px;
  --ws-font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

  /* Colors - Light Mode */
  --ws-bg-color: #ffffff;
  --ws-cell-bg: #f5f5f5;
  --ws-cell-border: #d0d0d0;
  --ws-cell-hover: #e8e8e8;
  --ws-text-color: #333333;
  --ws-text-secondary: #666666;

  /* Selection and Found Colors */
  --ws-selection-color: rgba(59, 130, 246, 0.4);
  --ws-selection-border: #3b82f6;
  --ws-found-color: rgba(34, 197, 94, 0.4);
  --ws-found-border: #22c55e;
  --ws-found-line: #15803d;

  /* Word List */
  --ws-wordlist-bg: #fafafa;
  --ws-wordlist-found: #22c55e;

  /* UI Elements */
  --ws-timer-bg: #f0f0f0;
  --ws-timer-text: #1f2937;
  --ws-button-primary: #3b82f6;
  --ws-button-hover: #2563eb;

  /* Accessibility */
  --ws-focus-ring: 2px solid #3b82f6;
  --ws-focus-offset: 2px;

  /* Animation */
  --ws-transition-speed: 0.2s;
  --ws-strikethrough-duration: 0.3s;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --ws-bg-color: #1a1a1a;
    --ws-cell-bg: #2d2d2d;
    --ws-cell-border: #404040;
    --ws-cell-hover: #3a3a3a;
    --ws-text-color: #e5e5e5;
    --ws-text-secondary: #a0a0a0;

    --ws-selection-color: rgba(96, 165, 250, 0.5);
    --ws-selection-border: #60a5fa;
    --ws-found-color: rgba(74, 222, 128, 0.5);
    --ws-found-border: #4ade80;
    --ws-found-line: #86efac;

    --ws-wordlist-bg: #252525;
    --ws-wordlist-found: #4ade80;

    --ws-timer-bg: #2d2d2d;
    --ws-timer-text: #e5e5e5;
  }
}

/* High Contrast Mode */
.high-contrast {
  --ws-bg-color: #ffffff;
  --ws-cell-bg: #ffffff;
  --ws-cell-border: #000000;
  --ws-cell-hover: #ffff00;
  --ws-text-color: #000000;
  --ws-text-secondary: #000000;

  --ws-selection-color: rgba(0, 0, 255, 0.3);
  --ws-selection-border: #0000ff;
  --ws-found-color: rgba(0, 128, 0, 0.3);
  --ws-found-border: #008000;
  --ws-found-line: #000000;

  --ws-wordlist-bg: #ffffff;
  --ws-wordlist-found: #008000;

  --ws-timer-bg: #ffffff;
  --ws-timer-text: #000000;
}

.high-contrast * {
  border-width: 2px !important;
  font-weight: 600 !important;
}

/* ========================================================================
   Base Container
   ======================================================================== */

.wordsearch-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  background-color: var(--ws-bg-color);
  color: var(--ws-text-color);
  font-family: var(--ws-font-family);
}

/* ========================================================================
   Puzzle Grid
   ======================================================================== */

.wordsearch-grid {
  display: inline-grid;
  gap: var(--ws-cell-gap);
  padding: 1rem;
  background-color: var(--ws-bg-color);
  border: 2px solid var(--ws-cell-border);
  border-radius: 8px;
  margin: 1rem auto;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  touch-action: none;
}

/* Grid cells */
.wordsearch-cell {
  width: var(--ws-cell-size);
  height: var(--ws-cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--ws-cell-bg);
  border: 1px solid var(--ws-cell-border);
  border-radius: 4px;
  font-size: var(--ws-font-size);
  font-weight: 600;
  color: var(--ws-text-color);
  cursor: pointer;
  transition: background-color var(--ws-transition-speed),
              transform var(--ws-transition-speed);
  position: relative;
  overflow: hidden;
}

/* Cell hover state */
.wordsearch-cell:hover {
  background-color: var(--ws-cell-hover);
  transform: scale(1.05);
  z-index: 1;
}

/* Cell focus state for keyboard navigation */
.wordsearch-cell:focus {
  outline: var(--ws-focus-ring);
  outline-offset: var(--ws-focus-offset);
  z-index: 2;
}

/* Active selection highlight */
.wordsearch-cell.selecting {
  background-color: var(--ws-selection-color);
  border-color: var(--ws-selection-border);
  border-width: 2px;
  z-index: 3;
}

/* Found word highlight */
.wordsearch-cell.found {
  background-color: var(--ws-found-color);
  border-color: var(--ws-found-border);
  position: relative;
}

/* Line-through effect for found words */
.wordsearch-cell.found::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background-color: var(--ws-found-line);
  transform: translateY(-50%);
  animation: drawLine var(--ws-strikethrough-duration) ease-out;
}

@keyframes drawLine {
  from {
    width: 0;
    left: 50%;
  }
  to {
    width: 100%;
    left: 0;
  }
}

/* Multiple found words - show multiple lines */
.wordsearch-cell.found[data-found-count="2"]::after {
  box-shadow: 0 -4px 0 var(--ws-found-line);
}

.wordsearch-cell.found[data-found-count="3"]::after {
  box-shadow: 0 -4px 0 var(--ws-found-line),
              0 4px 0 var(--ws-found-line);
}

/* ========================================================================
   Word List
   ======================================================================== */

.wordsearch-wordlist {
  background-color: var(--ws-wordlist-bg);
  border: 1px solid var(--ws-cell-border);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1rem 0;
}

.wordsearch-wordlist h3 {
  margin-top: 0;
  margin-bottom: 1rem;
  color: var(--ws-text-color);
  font-size: 1.25rem;
}

.wordsearch-words {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

.wordsearch-word {
  padding: 0.5rem 0.75rem;
  background-color: var(--ws-cell-bg);
  border-radius: 4px;
  font-size: 0.95rem;
  color: var(--ws-text-color);
  transition: all var(--ws-transition-speed);
  position: relative;
  overflow: hidden;
}

.wordsearch-word:hover {
  background-color: var(--ws-cell-hover);
  transform: translateX(4px);
}

/* Found word styling with strikethrough animation */
.wordsearch-word.found {
  color: var(--ws-wordlist-found);
  background-color: var(--ws-found-color);
  position: relative;
}

.wordsearch-word.found::before {
  content: '\2713';
  margin-right: 0.5rem;
  font-weight: bold;
}

.wordsearch-word.found::after {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  height: 2px;
  background-color: var(--ws-wordlist-found);
  transform: translateY(-50%) scaleX(0);
  transform-origin: left;
  animation: strikethrough var(--ws-strikethrough-duration) ease-out forwards;
}

@keyframes strikethrough {
  to {
    transform: translateY(-50%) scaleX(1);
  }
}

/* ========================================================================
   Timer Display
   ======================================================================== */

.wordsearch-timer {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--ws-timer-bg);
  color: var(--ws-timer-text);
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 1.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border: 2px solid var(--ws-cell-border);
  margin: 1rem 0;
}

.wordsearch-timer-icon::before {
  content: '\23F1';
  font-size: 1.5rem;
}

.wordsearch-timer.paused {
  opacity: 0.6;
}

.wordsearch-timer.completed {
  background-color: var(--ws-found-color);
  border-color: var(--ws-found-border);
  color: var(--ws-found-line);
}

/* ========================================================================
   Control Buttons (Bulma CSS Compatible)
   ======================================================================== */

.wordsearch-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1rem 0;
  align-items: center;
}

.wordsearch-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background-color: var(--ws-button-primary);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--ws-transition-speed),
              transform var(--ws-transition-speed);
  min-height: 44px;
  min-width: 44px;
  font-family: var(--ws-font-family);
}

.wordsearch-button:hover {
  background-color: var(--ws-button-hover);
  transform: translateY(-2px);
}

.wordsearch-button:active {
  transform: translateY(0);
}

.wordsearch-button:focus {
  outline: var(--ws-focus-ring);
  outline-offset: var(--ws-focus-offset);
}

.wordsearch-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Button variants */
.wordsearch-button.is-success {
  background-color: #22c55e;
}

.wordsearch-button.is-success:hover {
  background-color: #16a34a;
}

.wordsearch-button.is-warning {
  background-color: #f59e0b;
}

.wordsearch-button.is-warning:hover {
  background-color: #d97706;
}

.wordsearch-button.is-danger {
  background-color: #ef4444;
}

.wordsearch-button.is-danger:hover {
  background-color: #dc2626;
}

.wordsearch-button.is-light {
  background-color: var(--ws-cell-bg);
  color: var(--ws-text-color);
  border: 1px solid var(--ws-cell-border);
}

.wordsearch-button.is-light:hover {
  background-color: var(--ws-cell-hover);
}

/* ========================================================================
   Status Messages
   ======================================================================== */

.wordsearch-status {
  padding: 1rem 1.5rem;
  border-radius: 8px;
  margin: 1rem 0;
  font-weight: 500;
  text-align: center;
}

.wordsearch-status.success {
  background-color: rgba(34, 197, 94, 0.1);
  border: 2px solid var(--ws-found-border);
  color: var(--ws-found-line);
}

.wordsearch-status.info {
  background-color: rgba(59, 130, 246, 0.1);
  border: 2px solid var(--ws-selection-border);
  color: var(--ws-selection-border);
}

/* ========================================================================
   Progress Indicator
   ======================================================================== */

.wordsearch-progress {
  margin: 1rem 0;
}

.wordsearch-progress-bar {
  width: 100%;
  height: 8px;
  background-color: var(--ws-cell-bg);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--ws-cell-border);
}

.wordsearch-progress-fill {
  height: 100%;
  background-color: var(--ws-found-border);
  transition: width 0.5s ease-out;
  border-radius: 4px;
}

.wordsearch-progress-text {
  display: block;
  text-align: center;
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--ws-text-secondary);
  font-weight: 500;
}

/* ========================================================================
   Responsive Design - Mobile
   ======================================================================== */

@media (max-width: 768px) {
  :root {
    --ws-cell-size: 28px;
    --ws-font-size: 14px;
  }

  .wordsearch-container {
    padding: 0.5rem;
  }

  .wordsearch-grid {
    padding: 0.5rem;
    max-width: 100%;
    overflow-x: auto;
  }

  .wordsearch-words {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.5rem;
  }

  .wordsearch-word {
    font-size: 0.85rem;
    padding: 0.4rem 0.6rem;
  }

  .wordsearch-controls {
    flex-direction: column;
    width: 100%;
  }

  .wordsearch-button {
    width: 100%;
    min-height: 48px;
  }

  .wordsearch-timer {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  :root {
    --ws-cell-size: 24px;
    --ws-font-size: 12px;
  }

  .wordsearch-words {
    grid-template-columns: 1fr 1fr;
  }
}

/* Extra small grids */
@media (max-width: 360px) {
  :root {
    --ws-cell-size: 20px;
    --ws-font-size: 11px;
  }
}

/* ========================================================================
   Tablet Landscape
   ======================================================================== */

@media (min-width: 769px) and (max-width: 1024px) {
  :root {
    --ws-cell-size: 30px;
    --ws-font-size: 15px;
  }
}

/* ========================================================================
   Large Screens
   ======================================================================== */

@media (min-width: 1920px) {
  :root {
    --ws-cell-size: 40px;
    --ws-font-size: 18px;
  }
}

/* ========================================================================
   Touch-Friendly Targets
   ======================================================================== */

@media (pointer: coarse) {
  .wordsearch-cell {
    min-width: 44px;
    min-height: 44px;
  }

  .wordsearch-button {
    min-height: 48px;
    min-width: 48px;
    padding: 1rem 1.75rem;
  }

  .wordsearch-word {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* ========================================================================
   Print Styles
   ======================================================================== */

@media print {
  .wordsearch-container {
    max-width: 100%;
    padding: 0;
  }

  .wordsearch-controls,
  .wordsearch-timer,
  .wordsearch-button,
  .wordsearch-status {
    display: none !important;
  }

  .wordsearch-grid {
    border: 2px solid #000;
    page-break-inside: avoid;
    background-color: white;
  }

  .wordsearch-cell {
    background-color: white;
    border: 1px solid #000;
    color: #000;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .wordsearch-cell.found {
    background-color: white;
  }

  .wordsearch-cell.found::after {
    display: none;
  }

  .wordsearch-wordlist {
    page-break-inside: avoid;
    background-color: white;
    border: 1px solid #000;
  }

  .wordsearch-word {
    background-color: white;
    border: 1px solid #ccc;
  }

  .wordsearch-word.found::after {
    background-color: #000;
  }

  .wordsearch-progress {
    display: none;
  }

  /* Print in portrait mode */
  @page {
    margin: 1cm;
    size: portrait;
  }
}

/* ========================================================================
   Animations and Transitions
   ======================================================================== */

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

  .wordsearch-cell:hover {
    transform: none;
  }

  .wordsearch-button:hover {
    transform: none;
  }

  .wordsearch-word:hover {
    transform: none;
  }
}

/* Celebration animation for puzzle completion */
@keyframes celebrate {
  0%, 100% {
    transform: scale(1) rotate(0deg);
  }
  25% {
    transform: scale(1.1) rotate(-5deg);
  }
  75% {
    transform: scale(1.1) rotate(5deg);
  }
}

.wordsearch-grid.completed {
  animation: celebrate 0.6s ease-in-out;
}

/* ========================================================================
   Loading State
   ======================================================================== */

.wordsearch-loading {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 300px;
}

.wordsearch-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--ws-cell-border);
  border-top-color: var(--ws-button-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ========================================================================
   Difficulty Indicators
   ======================================================================== */

.wordsearch-difficulty {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.9rem;
}

.wordsearch-difficulty.easy {
  background-color: rgba(34, 197, 94, 0.1);
  color: #16a34a;
  border: 1px solid #22c55e;
}

.wordsearch-difficulty.medium {
  background-color: rgba(245, 158, 11, 0.1);
  color: #d97706;
  border: 1px solid #f59e0b;
}

.wordsearch-difficulty.hard {
  background-color: rgba(239, 68, 68, 0.1);
  color: #dc2626;
  border: 1px solid #ef4444;
}

/* ========================================================================
   Utility Classes
   ======================================================================== */

.text-center {
  text-align: center;
}

.mb-1 {
  margin-bottom: 0.5rem;
}

.mb-2 {
  margin-bottom: 1rem;
}

.mt-1 {
  margin-top: 0.5rem;
}

.mt-2 {
  margin-top: 1rem;
}

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
