/**
 * Rompecabezas clásico con imágenes en alta definición (puzzle-imagenes-hd)
 * Hojas de estilo responsive y temas corporativos claro/oscuro
 */

:root {
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Colores tema oscuro (predeterminado) */
  --bg-page: #0b0f17;
  --bg-card: #131926;
  --bg-card-subtle: #192233;
  --bg-canvas-outer: #0e131d;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #3b82f6;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-glow: rgba(59, 130, 246, 0.25);
  --accent: #10b981;
  --amber: #f59e0b;
  --rose: #f43f5e;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-canvas-outer: #e2e8f0;
  --border-color: rgba(0, 0, 0, 0.08);
  --border-focus: #2563eb;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-glow: rgba(37, 99, 235, 0.15);
}

/* Reset y estructura canónica */
*, *::before, *::after {
  box-sizing: border-box;
}

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

.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
  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%;
}

/* Tipografías de encabezados */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  line-height: 1.25;
}

.text-mono {
  font-family: var(--font-mono);
}

/* Tarjeta principal del juego */
.puzzle-hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-md);
  position: relative;
}

/* Barra superior HUD de estado */
.puzzle-hud-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.hud-stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.hud-stat-pill svg {
  color: var(--primary);
  flex-shrink: 0;
}

.progress-track {
  width: 110px;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* Barra de herramientas y controles */
.puzzle-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.difficulty-group {
  display: flex;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 3px;
  overflow-x: auto;
  max-width: 100%;
}

.btn-difficulty {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

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

.btn-difficulty.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 6px var(--primary-glow);
}

.tools-action-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-tool-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.45rem 0.8rem;
  min-height: 40px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-tool-action:hover {
  background: var(--primary-glow);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-tool-action.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-tool-action.muted {
  color: var(--rose);
  border-color: rgba(244, 63, 94, 0.3);
}

/* Área de trabajo y lienzo de tapete */
.puzzle-workspace-container {
  width: 100%;
  height: 580px;
  background: radial-gradient(circle at center, #141926 0%, #0a0e17 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
  touch-action: none;
}

[data-theme="light"] .puzzle-workspace-container {
  background: radial-gradient(circle at center, #e2e8f0 0%, #cbd5e1 100%);
}

.puzzle-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

.puzzle-workspace-container.drag-hover {
  border: 2px dashed var(--primary);
  background: rgba(59, 130, 246, 0.1);
}

/* Ventana miniatura flotante */
.floating-preview-box {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 220px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.6rem;
  box-shadow: var(--shadow-lg);
  z-index: 20;
  display: none;
  flex-direction: column;
  gap: 0.45rem;
  backdrop-filter: blur(8px);
}

.floating-preview-box.visible {
  display: flex;
}

.floating-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.floating-preview-header h5 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0;
}

.btn-close-mini {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px;
  display: flex;
}

.btn-close-mini:hover {
  color: var(--rose);
}

.preview-thumbnail-img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.preview-info-box {
  font-size: 0.78rem;
  line-height: 1.3;
}

.preview-title {
  font-weight: 600;
  color: var(--text-main);
  display: block;
}

.preview-author {
  color: var(--text-muted);
  font-size: 0.72rem;
  display: block;
}

/* Sección de galería de imágenes curadas */
.gallery-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-md);
}

.gallery-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.gallery-categories-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.cat-pill {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cat-pill:hover {
  color: var(--text-main);
  border-color: var(--text-dim);
}

.cat-pill.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1.2rem;
}

.gallery-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.gallery-card:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.gallery-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary);
}

.gallery-thumb-box {
  width: 100%;
  height: 135px;
  position: relative;
  overflow: hidden;
  background: #000000;
}

.gallery-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.gallery-card:hover .gallery-thumb-img {
  transform: scale(1.05);
}

.gallery-cat-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  text-transform: capitalize;
}

.gallery-info {
  padding: 0.75rem 0.85rem;
}

.gallery-title {
  font-size: 0.9rem;
  margin: 0 0 0.2rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-author {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Modal de victoria */
.victory-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.victory-modal-overlay.visible {
  display: flex;
}

.victory-modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 2rem;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  position: relative;
  animation: popIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.victory-trophy-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  color: var(--amber);
  animation: bounceTrophy 1s infinite alternate ease-in-out;
}

@keyframes bounceTrophy {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}

.victory-stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.victory-stat-box {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
}

.victory-stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.25rem;
}

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

.victory-actions {
  display: flex;
  gap: 0.75rem;
}

.btn-primary-victory {
  flex: 1;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.8rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary-victory:hover {
  background: var(--primary-hover);
}

.btn-secondary-victory {
  background: var(--bg-card-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.8rem 1.2rem;
  font-size: 0.95rem;
  cursor: pointer;
}

/* Toast flotante accesible */
.puzzle-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 0.65rem 1.25rem;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

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

/* Adaptación táctil y responsiva */
@media (max-width: 768px) {
  .puzzle-workspace-container {
    height: 460px;
  }

  .puzzle-hud-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .hud-left, .hud-right {
    width: 100%;
    justify-content: space-between;
  }

  .puzzle-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .difficulty-group {
    justify-content: space-between;
  }

  .tools-action-group {
    justify-content: space-between;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .gallery-grid {
    grid-template-columns: 1fr;
  }
}

