* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #000;
  --red: #e6001e;
  --gap: 6px;
  --radius: 12px;
  --cols: 4;
  --pad: 24px;
  --tile-h: calc((100vw - var(--pad) * 2 - (var(--cols) - 1) * var(--gap)) / var(--cols) * 0.72);
}

body {
  background: var(--bg);
  color: #fff;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */

.site-header {
  display: flex;
  align-items: center;
  gap: 40px;
  padding: 18px var(--pad);
}

.brand { display: inline-flex; align-items: center; flex: none; }
.brand img { height: 46px; width: auto; display: block; }

.main-nav {
  display: flex;
  gap: 34px;
  align-items: center;
}

.main-nav a {
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.75;
  position: relative;
  padding-bottom: 4px;
  transition: opacity 0.2s;
}
/* Subrayado rojo animado al pasar el cursor (mismo efecto que Vacantes) */
.main-nav a::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 2px;
  background: var(--red);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s ease;
}
.main-nav a:hover,
.main-nav a.active { opacity: 1; }
.main-nav a:hover::after,
.main-nav a.active::after { transform: scaleX(1); }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 18px;
}
.header-right .lang {
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.85;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.header-right .flag { font-size: 15px; }

/* Botón de acceso al panel de administración */
.login-link {
  color: #fff;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.9;
  transition: background 0.2s, border-color 0.2s;
}
.login-link:hover {
  background: var(--red);
  border-color: var(--red);
  opacity: 1;
}

@media (max-width: 700px) {
  .site-header { flex-wrap: wrap; gap: 16px 24px; }
  .brand img { height: 38px; }
  .main-nav { gap: 20px; }
}

/* ---------- Filtros ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px var(--pad) 20px;
}

.filter-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: transparent;
  color: #fff;
  font-size: 14px;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.filter-btn:hover {
  border-color: rgba(255, 255, 255, 0.6);
}

/* Solo el recuadro se pinta de rojo; el texto se queda blanco */
.filter-btn.active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

/* ---------- Grid ---------- */

main {
  padding: 0 var(--pad) var(--pad);
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-auto-rows: var(--tile-h);
  grid-auto-flow: row dense; /* rellena huecos: nunca quedan recuadros vacíos */
  gap: var(--gap);
}

/* .tile es la celda del grid: recibe las animaciones de tamaño (FLIP) y
   aporta la perspectiva para el parallax 3D de su contenido. */
.tile {
  position: relative;
  cursor: pointer;
  transform-origin: top left;
  perspective: 900px;
}

.tile.focused { z-index: 3; }

/* .tile-inner es la capa que se inclina en 3D (parallax) sin interferir
   con el FLIP; aquí viven el recorte redondeado y el overflow. */
.tile-inner {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: #111;
  transform-style: preserve-3d;
  transition: transform 0.3s ease-out;
  will-change: transform;
}

.tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease-out;
  will-change: transform;
}

/* Brillo especular que sigue al cursor */
.glare {
  position: absolute;
  inset: 0;
  z-index: 2;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease-out;
}

/* Formas base */
.tile.square { grid-column: span 1; grid-row: span 1; }
.tile.wide   { grid-column: span 2; grid-row: span 1; }
.tile.tall   { grid-column: span 1; grid-row: span 2; }
.tile.big    { grid-column: span 2; grid-row: span 2; }

/* Al enfocar, el recuadro seleccionado se ancla y crece mediante estilos
   inline (ver app.js); los demás se encogen a 1×1 para adaptarse y ceder
   protagonismo. */
.grid.has-focus .tile:not(.focused) {
  grid-column: span 1 !important;
  grid-row: span 1 !important;
}

/* Difuminado rojo en el tercio inferior */
.tile-inner::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 38%;
  background: linear-gradient(to top, rgba(230, 0, 30, 0.92), rgba(230, 0, 30, 0));
  opacity: 0;
  transition: opacity 0.45s ease;
  pointer-events: none;
  z-index: 3;
}

.tile.focused .tile-inner::after {
  opacity: 1;
}

.tile .title {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 14px;
  z-index: 4;
  color: #fff;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.2px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.45s ease, transform 0.45s ease;
  pointer-events: none;
}

.tile.focused .title {
  opacity: 1;
  transform: translateY(0);
}

/* Baldosa de relleno: muestra la imagen de un proyecto para tapar los huecos
   sin dejar espacios en negro. No es interactiva. */
.filler {
  grid-column: span 1;
  grid-row: span 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: #141414;
  cursor: default;
}

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

/* Aparición al filtrar */
.tile.enter,
.filler.enter {
  animation: tileIn 0.4s ease both;
}

@keyframes tileIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.empty-msg {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 0;
  opacity: 0.5;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  :root { --cols: 3; }
}

@media (max-width: 600px) {
  :root {
    --cols: 2;
    --pad: 12px;
    --tile-h: calc((100vw - var(--pad) * 2 - var(--gap)) / 2 * 0.8);
  }
  .tile.wide,  .tile.big  { grid-column: span 2; }
}

/* ============================================================
   Página de detalle del proyecto (project.html)
   ============================================================ */
.project-page main { padding-bottom: 120px; }

/* Portada a todo lo ancho, oscura como la referencia */
.proj-cover {
  width: 100%;
  height: 52vh;
  min-height: 320px;
  max-height: 600px;
  background-size: cover;
  background-position: center;
  background-color: #000;
  position: relative;
}
.proj-cover::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.15) 40%, rgba(0,0,0,0.85) 100%);
  pointer-events: none;
}

.proj-head {
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px var(--pad) 0;
}
.proj-back {
  display: inline-block;
  color: #999;
  text-decoration: none;
  font-size: 14px;
  letter-spacing: 0.06em;
  margin-bottom: 26px;
  transition: color 0.2s;
}
.proj-back:hover { color: #fff; }
.proj-cat {
  color: var(--red);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.18em;
  margin-bottom: 14px;
}
.proj-title {
  font-size: clamp(40px, 7vw, 88px);
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: -0.02em;
}
.proj-date {
  color: #8a8a8a;
  font-size: 15px;
  margin-top: 18px;
}

.proj-intro {
  max-width: 760px;
  margin: 44px auto 0;
  padding: 0 var(--pad);
  font-size: 19px;
  line-height: 1.7;
  color: #cfcfcf;
}

.proj-meta {
  max-width: 1180px;
  margin: 40px auto 0;
  padding: 26px var(--pad);
  display: flex;
  flex-wrap: wrap;
  gap: 40px;
  border-top: 1px solid #1d1d1d;
  border-bottom: 1px solid #1d1d1d;
}
.proj-meta-item { display: flex; flex-direction: column; gap: 4px; }
.proj-meta-item span { color: #7d7d7d; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.proj-meta-item strong { font-size: 16px; font-weight: 500; }

/* Cuerpo tipo Behance: bloques apilados a lo ancho */
.proj-body {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--pad);
}
.blk { margin-top: 26px; }
.blk-text {
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
  font-size: 18px;
  line-height: 1.75;
  color: #d6d6d6;
}
.blk-image { margin-top: 26px; }
.blk-image img { width: 100%; display: block; border-radius: 10px; }
.blk-image figcaption,
.blk-caption { color: #8a8a8a; font-size: 13px; text-align: center; margin-top: 10px; }

.blk-gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-top: 26px;
}
.blk-gallery img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; display: block; }

.blk-video video.blk-video,
.blk-video-wrap video.blk-video {
  width: 100%;
  display: block;
  border-radius: 10px;
  background: #000;
}
.blk-embed {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 */
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}
.blk-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.proj-error { text-align: center; padding: 120px 24px; color: #888; }

@media (max-width: 700px) {
  .blk-gallery { grid-template-columns: 1fr; }
  .proj-cover { height: 44vh; }
}

/* ============================================================
   Pie de página (footer.js)
   ============================================================ */
.site-footer {
  margin-top: 100px;
  padding: 40px var(--pad) 70px;
  max-width: 1600px;
  margin-left: auto;
  margin-right: auto;
}
.footer-top { margin-bottom: 24px; }
.footer-logo img { height: 116px; width: auto; display: block; border-radius: 8px; }
.footer-divider { height: 1px; background: #262626; margin-bottom: 46px; }

.footer-cols {
  display: grid;
  grid-template-columns: 1fr 1fr 1.1fr 1.9fr;
  gap: 40px 48px;
}
.fcol h4 { font-size: 22px; font-weight: 700; margin-bottom: 26px; }
.fcol > a {
  display: block;
  color: #b9b9b9;
  text-decoration: none;
  font-size: 19px;
  margin-bottom: 22px;
  transition: color 0.2s;
}
.fcol > a:hover { color: #fff; }

.social-icons { display: flex; gap: 20px; color: #fff; margin-bottom: 26px; }
.social-icons a { color: #fff; opacity: 0.9; transition: opacity 0.2s, color 0.2s; }
.social-icons a:hover { color: var(--red); opacity: 1; }

.subscribe {
  display: inline-flex;
  align-items: center;
  background: #2a2a2a;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 16px 22px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 18px;
  transition: background 0.2s;
}
.subscribe:hover { background: #383838; }

.lang-select {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #2a2a2a;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 16px;
  width: 210px;
  justify-content: flex-start;
}
.lang-select .flag { font-size: 20px; }
.lang-select .chev { margin-left: auto; opacity: 0.7; }

/* Tarjeta de última historia / BTS */
.story-tabs { display: flex; gap: 12px; margin-bottom: 18px; }
.story-tab {
  border: 1px solid #3a3a3a;
  background: transparent;
  color: #fff;
  border-radius: 12px;
  padding: 13px 26px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.story-tab.active { background: #fff; color: #000; border-color: #fff; }

.story-card {
  border: 1px solid #3a3a3a;
  border-radius: 16px;
  padding: 28px 32px;
  min-height: 220px;
}
.story-card h3 { font-size: 30px; font-weight: 700; margin-bottom: 16px; }
.story-body { display: flex; gap: 28px; align-items: flex-start; justify-content: space-between; }
.story-body p { color: #bdbdbd; font-size: 16px; line-height: 1.6; max-width: 460px; }
.story-more {
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  text-decoration: underline;
  white-space: nowrap;
  flex: none;
}
.story-more:hover { color: var(--red); }
.story-empty { color: #888; font-size: 16px; }

/* Medio: cuando la tarjeta de historia ya no cabe al lado, baja también
   "Social" y queda un 2×2 simétrico:
   Nosotros | Portafolio  /  Social | Historia */
@media (max-width: 1100px) {
  .footer-cols { grid-template-columns: 1fr 1fr; gap: 44px 48px; }
}
/* La tarjeta apila su texto y "Leer más" cuando la columna es angosta. */
@media (max-width: 820px) {
  .story-body { flex-direction: column; gap: 16px; }
  .story-more { align-self: flex-start; }
}
/* Móvil: todo apilado en una sola columna. */
@media (max-width: 560px) {
  .site-footer { padding-bottom: 48px; }
  .footer-cols { grid-template-columns: 1fr; gap: 30px; }
  .fcol h4 { margin-bottom: 18px; }
  .fcol > a { font-size: 17px; margin-bottom: 16px; }
  .footer-logo img { height: 84px; }
  .lang-select { width: 100%; }
  .story-card h3 { font-size: 24px; }
}
