/**
 * Estilos canónicos para Generador y solucionador interactivo de sopas de letras
 * Fijate Tools - fijate.com
 */

/* ==========================================================================
   1. Variables de diseño y paletas (Dark / Light)
   ========================================================================== */
:root {
  /* Tema Claro (por defecto) */
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-hover: #e2e8f0;
  --border-color: #cbd5e1;
  --border-subtle: #e2e8f0;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;

  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #eff6ff;
  --color-primary-border: #93c5fd;

  --color-success: #16a34a;
  --color-success-light: #f0fdf4;
  --color-danger: #dc2626;
  --color-warning: #d97706;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-glow: 0 0 20px -3px rgba(37, 99, 235, 0.25);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

[data-theme="dark"] {
  --bg-page: #0b0f19;
  --bg-card: #111827;
  --bg-card-subtle: #1f2937;
  --bg-hover: #374151;
  --border-color: #374151;
  --border-subtle: #1f2937;

  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-primary-light: rgba(59, 130, 246, 0.12);
  --color-primary-border: #1d4ed8;

  --color-success: #22c55e;
  --color-success-light: rgba(34, 197, 94, 0.12);
  --color-danger: #ef4444;
  --color-warning: #f59e0b;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.55);
  --shadow-glow: 0 0 24px -2px rgba(59, 130, 246, 0.35);
}

/* ==========================================================================
   2. Reseteo y estructura general
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  margin: 0;
  padding: 0;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Títulos y tipografía */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text-main);
  margin-top: 0;
}

/* ==========================================================================
   3. Tarjeta principal de la herramienta
   ========================================================================== */
.card-main {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 2rem;
  position: relative;
}

@media (max-width: 640px) {
  .card-main {
    padding: 1rem;
  }
}

/* ==========================================================================
   4. Selector de temáticas rápidas
   ========================================================================== */
.theme-selector-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.75rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  scrollbar-width: thin;
}

.theme-selector-bar::-webkit-scrollbar {
  height: 4px;
}

.theme-selector-bar::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-full);
}

.btn-theme-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  min-height: 40px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.btn-theme-chip:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--color-primary-border);
}

.btn-theme-chip.active {
  background: var(--color-primary);
  color: #ffffff;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   5. Barra de telemetría y HUD
   ========================================================================== */
.hud-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.hud-pill {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.hud-pill-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.hud-pill-value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.hud-timer-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-hud-icon {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease;
}

.btn-hud-icon:hover {
  color: var(--color-primary);
}

/* Barra de progreso visual */
.hud-progress-wrapper {
  grid-column: 1 / -1;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  height: 8px;
  overflow: hidden;
  position: relative;
}

.hud-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-primary), #10b981);
  border-radius: var(--radius-full);
  transition: width 0.35s ease;
}

/* ==========================================================================
   6. Área de juego interactiva (Lienzo Canvas + Banco de palabras)
   ========================================================================== */
.game-arena {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .game-arena {
    grid-template-columns: 1fr;
  }
}

/* Contenedor del lienzo */
.board-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
  position: relative;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.canvas-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  touch-action: none;
  user-select: none;
}

#canvas-wordsearch {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  cursor: crosshair;
}

.board-hint {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.75rem;
  text-align: center;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Panel del banco de palabras */
.word-bank-panel {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.word-bank-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.6rem;
}

.word-bank-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.word-bank-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-height: 480px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.word-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  min-height: 36px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-full);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.25s ease;
  user-select: none;
}

.word-chip .chip-icon {
  display: inline-flex;
  opacity: 0.3;
}

.word-chip.word-found {
  color: var(--text-main);
  text-decoration: line-through;
  opacity: 0.85;
  box-shadow: var(--shadow-sm);
}

.word-chip.word-found .chip-icon {
  opacity: 1;
  color: #16a34a;
}

.word-chip.animate-pulse {
  animation: chipPulse 0.6s ease;
}

@keyframes chipPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Aviso de palabras omitidas */
.omitted-notice {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid var(--color-warning);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.8rem;
  font-size: 0.8rem;
  color: var(--color-warning);
}

/* ==========================================================================
   7. Botonera de acciones principales
   ========================================================================== */
.actions-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-subtle);
}

.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 42px;
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--bg-card-subtle);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--text-dim);
}

.btn-danger {
  background: rgba(220, 38, 38, 0.1);
  color: var(--color-danger);
  border-color: rgba(220, 38, 38, 0.3);
}

.btn-danger:hover {
  background: var(--color-danger);
  color: #ffffff;
}

@media (max-width: 640px) {
  .actions-toolbar {
    flex-direction: column;
  }
  .btn-action {
    width: 100%;
  }
}

/* ==========================================================================
   8. Modales nativos accesibles (sin alerts)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.modal-open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: translateY(12px) scale(0.98);
  transition: transform 0.25s ease;
  overflow: hidden;
}

.modal-backdrop.modal-open .modal-card {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.15rem 1.35rem;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
}

.btn-modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
}

.btn-modal-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 1.35rem;
  overflow-y: auto;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1.15rem 1.35rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-card-subtle);
}

/* Formularios dentro de modales */
.form-group {
  margin-bottom: 1.15rem;
}

.form-label {
  display: block;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.4rem;
  font-size: 0.88rem;
}

.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 0.55rem 2.25rem 0.55rem 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-card);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.form-textarea {
  width: 100%;
  min-height: 120px;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-card);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  resize: vertical;
}

.checkbox-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
  margin-top: 0.4rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

/* Modal de Victoria */
.victory-content {
  text-align: center;
  padding: 1rem 0;
}

.victory-trophy {
  font-size: 3.5rem;
  line-height: 1;
  margin-bottom: 0.75rem;
  animation: trophyBounce 0.8s ease infinite alternate;
}

@keyframes trophyBounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-8px); }
}

.victory-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.25rem 0;
  padding: 1rem;
  background: var(--bg-card-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.victory-stat-item {
  display: flex;
  flex-direction: column;
}

.victory-stat-val {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
}

.victory-stat-lbl {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ==========================================================================
   9. Componente Toast de notificaciones
   ========================================================================== */
.toast-message {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(50px);
  background: #0f172a;
  color: #ffffff;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-full);
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 10000;
  white-space: nowrap;
}

[data-theme="dark"] .toast-message {
  background: #1e293b;
  border: 1px solid #334155;
}

.toast-message.toast-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-message.toast-success {
  border-left: 4px solid #22c55e;
}

.toast-message.toast-error {
  border-left: 4px solid #ef4444;
}

.toast-message.toast-info {
  border-left: 4px solid #3b82f6;
}

/* ==========================================================================
   10. Estilos de impresión limpia en navegador
   ========================================================================== */
@media print {
  .app-header,
  .fijate-footer,
  .tools-ad-banner-section,
  .tool-ad-sidebar,
  .theme-selector-bar,
  .hud-bar,
  .actions-toolbar,
  .board-hint,
  .seo-guide-section,
  .modal-backdrop,
  .toast-message {
    display: none !important;
  }

  body, .tool-layout, .card-main {
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    border: none !important;
  }

  .game-arena {
    grid-template-columns: 1fr !important;
  }
}
