/* =============================================
   BASE — Reset y variables globales
   ============================================= */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: system-ui, Arial, sans-serif; }
img { max-width: 100%; display: block; }
.app { padding: 16px; }
:root { --gap: 12px; }

/* =============================================
   UTILIDADES DE PRESENTACIÓN
   (solo para distinguir cada ejercicio visualmente)
   ============================================= */
.section-title {
  margin: 48px 0 16px;
  padding: 12px 20px;
  background: #111;
  color: #fff;
  border-radius: 10px;
  font-size: 1.1rem;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.ejercicio {
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 32px;
  background: #f8fafc;
}

.ej-label {
  margin: 0 0 16px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #6366f1;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px dashed #c7d2fe;
  padding-bottom: 8px;
}

.demo-box {
  border: 1px dashed #c7d2fe;
  border-radius: 10px;
  background: #eef2ff;
  min-height: 300px;
}

/* =============================================
   EJERCICIO 1 — Centrado perfecto
   ============================================= */
.full {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 300px;          /* 100vh en producción real */
}

.card {
  padding: 24px 32px;
  border: 1px solid #ddd;
  border-radius: 12px;
  background: #fff;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
}

.card h1 { margin: 0 0 8px; color: #4f46e5; }
.card p  { margin: 0; color: #64748b; }

/* =============================================
   EJERCICIO 2 — Navbar flexible
   ============================================= */
.nav {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  background: #fff;
  border-radius: 10px;
}

.logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: #4f46e5;
  white-space: nowrap;
}

.menu {
  display: flex;
  gap: var(--gap);
  justify-content: center;
  flex: 1;
}

.menu a {
  text-decoration: none;
  color: #374151;
  font-size: 0.95rem;
  transition: color .2s;
}
.menu a:hover { color: #4f46e5; }

.cta {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid #ddd;
  background: #4f46e5;
  color: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: background .2s;
}
.cta:hover { background: #4338ca; }

/* =============================================
   EJERCICIO 3 — Cards en filas con wrap
   ============================================= */
.cards {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
}

.card-wrap {
  flex: 1 1 220px;
  padding: 28px 20px;
  border: 1px solid #eee;
  border-radius: 10px;
  text-align: center;
  background: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  color: #4f46e5;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}

/* =============================================
   EJERCICIO 4 — Layout con sidebar (Flex)
   ============================================= */
.layout {
  display: flex;
  gap: var(--gap);
  min-height: 200px;
}

.sidebar {
  width: 200px;
  flex-shrink: 0;
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 16px;
  background: #f1f5f9;
  line-height: 2;
}

.content {
  flex: 1;
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 16px;
  background: #fff;
}

.content h2 { margin-top: 0; color: #4f46e5; }

/* =============================================
   EJERCICIO 5 — Pricing con baseline
   ============================================= */
.pricing {
  display: flex;
  gap: 32px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.price {
  font-size: 18px;
  display: flex;
  gap: 4px;
  align-items: baseline;
}

.currency { font-size: 1.3rem; font-weight: 600; color: #4f46e5; }
.amount   { font-size: 56px; font-weight: 800; color: #111; line-height: 1; }
.period   { font-size: 0.95rem; color: #64748b; }

/* =============================================
   EJERCICIO 6 — Tres columnas fijas
   ============================================= */
.grid3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
}

.grid3 > * {
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 24px 16px;
  text-align: center;
  background: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  color: #4f46e5;
}

/* =============================================
   EJERCICIO 7 — Layout clásico con áreas
   ============================================= */
.page {
  display: grid;
  grid-template-columns: 200px 1fr;
  grid-template-rows: auto 1fr auto;
  gap: var(--gap);
  grid-template-areas:
    "hdr hdr"
    "sbr mn"
    "ftr ftr";
  min-height: 280px;
}

.hdr { grid-area: hdr; }
.sbr { grid-area: sbr; }
.mn  { grid-area: mn; }
.ftr { grid-area: ftr; }

.page > * {
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 14px;
  background: #fff;
  font-weight: 600;
  color: #374151;
}

.hdr { background: #4f46e5; color: #fff; border-color: #4f46e5; }
.ftr { background: #1e1b4b; color: #c7d2fe; border-color: #1e1b4b; }
.sbr { background: #f1f5f9; }

/* =============================================
   EJERCICIO 8 — Grid fluido auto-fit + minmax
   ============================================= */
.auto {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.card-auto {
  padding: 28px 20px;
  border: 1px solid #eee;
  border-radius: 12px;
  text-align: center;
  background: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  color: #7c3aed;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}

/* =============================================
   EJERCICIO 9 — Galería con relación de aspecto
   ============================================= */
.galeria {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.galeria img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
}

/* =============================================
   EJERCICIO 10 — Superposición tipo hero
   ============================================= */
.hero {
  display: grid;
  place-items: center;
  min-height: 300px;
  border-radius: 14px;
  overflow: hidden;
}

.hero > * {
  grid-area: 1 / 1;
}

.hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-text {
  text-align: center;
  z-index: 1;
}

.hero-text h1 {
  background: rgba(0, 0, 0, .50);
  color: #fff;
  padding: 16px 28px;
  border-radius: 12px;
  margin: 0 0 10px;
  font-size: clamp(1.2rem, 3vw, 2rem);
}

.hero-text p {
  background: rgba(0, 0, 0, .40);
  color: #e2e8f0;
  padding: 8px 20px;
  border-radius: 8px;
  margin: 0;
}

/* =============================================
   EJERCICIO 11 — Mobile-first: apilar columnas
   ============================================= */
.mf {
  display: grid;
  gap: var(--gap);
  grid-template-columns: 1fr;  /* móvil: 1 columna */
}

@media (min-width: 768px) {
  .mf {
    grid-template-columns: repeat(3, 1fr);  /* desktop: 3 columnas */
  }
}

.mf > * {
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 24px 16px;
  text-align: center;
  background: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  color: #0891b2;
}

/* =============================================
   EJERCICIO 12 — Navbar colapsable (sin JS)
   ============================================= */
.rnav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid #eee;
  background: #fff;
  border-radius: 10px;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: #4f46e5;
}

.rmenu {
  position: relative;
}

.rmenu summary {
  cursor: pointer;
  padding: 6px 14px;
  background: #4f46e5;
  color: #fff;
  border-radius: 8px;
  list-style: none;
  font-size: 0.9rem;
  user-select: none;
}
.rmenu summary::-webkit-details-marker { display: none; }

.rmenu nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 0 4px;
  position: absolute;
  right: 0;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 10px;
  min-width: 160px;
  padding: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.10);
  z-index: 10;
}

.rmenu nav a {
  text-decoration: none;
  color: #374151;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: background .15s;
}
.rmenu nav a:hover { background: #f1f5f9; }

/* En desktop: esconde el botón hamburguesa y muestra nav inline */
@media (min-width: 768px) {
  .rmenu > summary {
    display: none;
  }

  .rmenu {
    position: static;
  }

  .rmenu nav,
  .rmenu[open] nav {
    display: flex;
    flex-direction: row;
    gap: 16px;
    position: static;
    border: none;
    box-shadow: none;
    background: transparent;
    padding: 0;
    min-width: unset;
  }
}

/* =============================================
   EJERCICIO 13 — Tipografía fluida con clamp()
   ============================================= */
.title {
  font-size: clamp(1.5rem, 2.5vw + 1rem, 3rem);
  line-height: 1.15;
  color: #4f46e5;
  margin: 0 0 12px;
}

/* =============================================
   EJERCICIO 14 — Formulario responsive
   ============================================= */
.rf {
  display: grid;
  gap: var(--gap);
  grid-template-columns: 1fr;   /* móvil: 1 columna */
  max-width: 720px;
}

.rf label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #374151;
}

.rf input {
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color .2s;
  outline: none;
}
.rf input:focus { border-color: #4f46e5; }

.rf button {
  padding: 14px;
  border: 0;
  border-radius: 10px;
  background: #4f46e5;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.rf button:hover { background: #4338ca; }

/* Desktop: 2 columnas y botón ancho completo */
@media (min-width: 640px) {
  .rf {
    grid-template-columns: 1fr 1fr;
  }
  .rf button {
    grid-column: 1 / -1;
  }
}

/* =============================================
   BONUS — Container queries + Dark mode
   ============================================= */
.bonus-wrapper {
  container-type: inline-size;
  max-width: 700px;
}

.bonus-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
  border: 1px solid #eee;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.bonus-card img {
  width: 100%;
  height: 180px;
  object-fit: cover;
}

.bonus-info {
  padding: 16px;
}

.bonus-info h3 { margin: 0 0 8px; color: #4f46e5; }
.bonus-info p  { margin: 0; color: #64748b; font-size: 0.9rem; }

/* Container query: cuando el contenedor tiene ≥ 420px */
@container (min-width: 420px) {
  .bonus-card {
    grid-template-columns: 180px 1fr;
  }
  .bonus-card img {
    height: 100%;
    min-height: 140px;
  }
}

/* Bonus: dark mode automático */
@media (prefers-color-scheme: dark) {
  body                { background: #0b0b0b; color: #eaeaea; }
  .ejercicio          { background: #161b27; border-color: #2d3748; }
  .card, .card-wrap, .card-auto,
  .content, .grid3 > *,
  .mf > *             { background: #1e2638; border-color: #2d3748; color: #e2e8f0; }
  .nav, .rnav,
  .rmenu nav          { background: #1e2638; border-color: #2d3748; }
  .logo, .brand       { color: #818cf8; }
  .sidebar            { background: #111827; border-color: #2d3748; }
  .rf input           { background: #1e2638; border-color: #374151; color: #e2e8f0; }
  .rf label           { color: #d1d5db; }
  .bonus-card         { background: #1e2638; border-color: #2d3748; }
  .bonus-info h3      { color: #818cf8; }
  .bonus-info p       { color: #9ca3af; }
  .sbr                { background: #111827; }
}

/* =============================================
   JAVASCRIPT — Estilos de los ejercicios JS
   ============================================= */
.js-demo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  margin-bottom: 16px;
}

@media (max-width: 640px) {
  .js-demo { grid-template-columns: 1fr; }
}

.js-code {
  background: #0f172a;
  border-radius: 10px;
  padding: 16px;
  overflow-x: auto;
}

.js-code pre {
  margin: 0;
}

.js-code code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.82rem;
  color: #7dd3fc;
  line-height: 1.6;
  white-space: pre;
}

.js-output {
  background: #0f172a;
  border-radius: 10px;
  padding: 16px;
  border-left: 3px solid #22c55e;
}

.js-output-label {
  margin: 0 0 10px;
  font-size: 0.8rem;
  color: #86efac;
  font-weight: 600;
  font-family: monospace;
}

.js-result {
  min-height: 28px;
}

.js-line {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.88rem;
  color: #f0fdf4;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,.05);
}

.js-ejercicio-propio {
  background: #1e1b4b;
  border-radius: 10px;
  padding: 16px;
  border-left: 3px solid #818cf8;
  margin-top: 12px;
}

.ej-custom-label {
  margin: 0 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #a5b4fc;
  font-family: monospace;
}

.js-ejercicio-propio pre {
  margin: 0 0 10px;
  background: #0f172a;
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
}

.js-ejercicio-propio code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.82rem;
  color: #c4b5fd;
  line-height: 1.6;
  white-space: pre;
}

.js-note {
  margin: 12px 0 0;
  font-size: 0.85rem;
  color: #64748b;
  background: #f1f5f9;
  padding: 10px 14px;
  border-radius: 8px;
}

.js-note code {
  background: #e2e8f0;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.82rem;
}

@media (prefers-color-scheme: dark) {
  .js-note { background: #1e2638; color: #94a3b8; }
  .js-note code { background: #2d3748; color: #e2e8f0; }
}
