:root {
  --verde: #1e7d32;
  --verde-oscuro: #145a24;
  --verde-claro: #e8f5e9;
  --texto: #1c1c1c;
  --gris: #6b6b6b;
  --borde: #e0e0e0;
  --fondo: #f7f8f6;
  --blanco: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--fondo);
  color: var(--texto);
}

.site-header {
  background: linear-gradient(135deg, var(--verde), var(--verde-oscuro));
  color: var(--blanco);
  padding: 40px 20px;
  text-align: center;
}

.header-inner h1 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.header-inner p {
  margin: 0;
  opacity: 0.9;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 8px;
}

#buscador {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--borde);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--blanco);
}

#buscador:focus {
  outline: 2px solid var(--verde);
  outline-offset: 1px;
}

.filtros {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filtro-btn {
  border: 1px solid var(--borde);
  background: var(--blanco);
  color: var(--texto);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filtro-btn:hover {
  border-color: var(--verde);
}

.filtro-btn.activo {
  background: var(--verde);
  border-color: var(--verde);
  color: var(--blanco);
}

.contador {
  color: var(--gris);
  font-size: 0.9rem;
  margin: 16px 0 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.card {
  background: var(--blanco);
  border: 1px solid var(--borde);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.card-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  color: white;
  background: rgba(0, 0, 0, 0.15);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.card:hover .card-play {
  opacity: 1;
}

.card-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--verde-claro);
  color: var(--verde-oscuro);
  white-space: nowrap;
}

.badge-nivel {
  background: #eef1f4;
  color: var(--gris);
}

.card-body h3 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.3;
}

.card-desc {
  margin: 0;
  font-size: 0.87rem;
  color: var(--gris);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.sin-resultados {
  text-align: center;
  color: var(--gris);
  padding: 40px 0;
}

/* ============================================================
   MODAL (la ventana que se abre al hacer clic en un ejercicio)
   ============================================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* IMPORTANTE: no borrar esta regla.
   Sin ella el modal se muestra siempre (rectángulo negro al abrir
   la página y el botón de cerrar no funciona), porque el
   "display: flex" de arriba le gana al atributo hidden del HTML. */
.modal[hidden] {
  display: none;
}

.modal-fondo {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-contenido {
  position: relative;
  background: var(--blanco);
  border-radius: 14px;
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1;
}

.modal-cerrar {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  background: rgba(0, 0, 0, 0.55);
  color: white;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
}

.modal-video {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

#modal-video-wrapper iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.modal-info {
  padding: 20px 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-info h2 {
  margin: 4px 0 0;
}

.modal-info p {
  margin: 0;
  color: var(--texto);
  line-height: 1.5;
}

.site-footer {
  text-align: center;
  padding: 24px;
  color: var(--gris);
  font-size: 0.85rem;
}

@media (max-width: 480px) {
  .header-inner h1 {
    font-size: 1.5rem;
  }
}
