/* ==========================================================================
   SCHOBRAS.CL /v2/: "del plano a la obra" (docs/06-frontend/v2-direccion-artistica.md).
   Se carga solo en /v2/, sobre site.css: mismos tokens, misma tipografía.
   Un solo momento protagonista: en el Proceso, la elevación de la casa de la
   portada se dibuja y se construye con el scroll. Todo lo demás, quieto.
   ========================================================================== */

/* ── Portada: el plano ─────────────────────────────────────────────────── */
.v2-hero {
  padding-block: clamp(2rem, 6vw, 4rem) clamp(3rem, 8vw, 6rem);
}

.v2-hero__grid {
  display: grid;
  grid-template-areas:
    "where"
    "title"
    "plan"
    "lead"
    "actions";
}

.v2-hero__where {
  grid-area: where;
  max-width: 26rem;
  font-size: var(--text-small);
  font-weight: 600;
  line-height: 1.5;
}

.v2-hero__title {
  grid-area: title;
  max-width: 10em;
  margin-top: clamp(1.25rem, 4vw, 2.5rem);
}

.v2-plan {
  grid-area: plan;
  width: min(100%, 34rem);
  margin: clamp(2rem, 6vw, 3rem) 0 0;
}

.v2-hero__lead {
  grid-area: lead;
  margin-top: clamp(2rem, 5vw, 3rem);
}

.v2-hero__actions {
  grid-area: actions;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.v2-hero__actions .btn { flex: 1 1 auto; }

/* La escena 3D solo existe cuando v2.js la arma (ver más abajo). */
.v2-hero__scene { display: none; }

@media (min-width: 48em) {
  .v2-hero__actions .btn { flex: 0 0 auto; }
}

@media (min-width: 64em) {
  .v2-hero__grid {
    min-height: min(calc(100svh - var(--header-height) - clamp(2rem, 6vw, 4rem) - clamp(3rem, 8vw, 6rem)), 50rem);
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: auto 1fr auto auto;
    grid-template-areas:
      "where   where   plan plan"
      "title   title   plan plan"
      "lead    lead    plan plan"
      "actions actions plan plan";
    column-gap: var(--space-6);
  }

  .v2-hero__title { align-self: end; }

  .v2-plan {
    align-self: center;
    justify-self: end;
    width: 100%;
    margin: 0;
  }
}

/* ── Portada 3D ───────────────────────────────────────────────────────────
   Solo con JS, movimiento permitido y pantalla de alto suficiente (v2.js usa las
   mismas condiciones y, si three.js no carga, pone .no-3d). El diseño fijo se
   aplica desde el primer pintado: mientras carga three.js se ve una imagen fija del
   primer cuadro de la escena (portada-plano-*.webp, 4:5, en el mismo lugar y con el
   mismo encuadre), así el cambio a 3D no se nota. Hay un tamaño por pantalla y
   densidad para que las líneas tengan el mismo grosor que en la escena. Si el 3D falla, vuelve el plano SVG. La sección es más alta que la
   pantalla: ese recorrido es el que arma la casa mientras la portada queda fija. */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) and (min-height: 34em) {
  .v2-hero:not(.no-3d) {
    height: 220svh;
    padding: 0;
  }

  .v2-hero:not(.no-3d) .v2-hero__pin {
    position: sticky;
    top: var(--header-height);
    display: flex;
    height: calc(100svh - var(--header-height));
  }

  .v2-hero:not(.no-3d) .v2-hero__grid {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    padding-block: clamp(1.25rem, 4svh, 3rem) clamp(1.25rem, 4svh, 2.5rem);
  }

  .v2-hero:not(.no-3d) .v2-hero__title { margin-top: clamp(0.75rem, 2.5svh, 2.5rem); }
  .v2-hero:not(.no-3d) .v2-hero__lead { margin-top: var(--space-3); }

  .v2-hero:not(.no-3d) .v2-plan,
  .v2-hero:not(.no-3d) .v2-hero__scene {
    grid-area: plan;
    align-self: stretch;
    justify-self: stretch;
    width: 100%;
    min-height: 0;
    margin: var(--space-3) 0 0;
  }

  .v2-hero:not(.no-3d) .v2-plan {
    display: flex;
    justify-content: center;
    background: 50% 50% / cover no-repeat;
    background-image: image-set(url("../img/portada-plano-400.31f211518afe.webp") 1x, url("../img/portada-plano-800.21cf46420c77.webp") 2x);
    transition: opacity 400ms var(--ease);
  }

  .v2-hero:not(.no-3d) .v2-plan__svg {
    width: auto;
    max-width: 100%;
    height: 100%;
    visibility: hidden;
  }

  .v2-hero:not(.no-3d) .v2-hero__scene {
    display: block;
    position: relative;
    opacity: 0;
    transition: opacity 600ms var(--ease);
  }

  /* Avance de obra y etapa en curso con su servicio: la información cambia con el
     scroll. En el celular solo el avance y la etapa, para no tapar la obra. */
  .v2-hero__caption {
    position: absolute;
    left: 0;
    bottom: 0;
    z-index: 2;
    max-width: 24rem;
    padding: var(--space-1) var(--space-2) 0 0;
    background: var(--color-white);
    font-size: var(--text-small);
    line-height: 1.45;
  }

  .v2-hero__progress {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
  }

  .v2-hero__stages li { display: none; }
  .v2-hero__stages li.is-active { display: block; }
  .v2-hero__stages strong { font-weight: 600; color: var(--color-bronze); }
  .v2-hero__stages span { display: none; }

  .v2-hero__scene canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
  }

  /* Al 100 %, la escena se funde con un render fotorrealista de la misma casa y desde la
     misma cámara (portada-render-*.webp, 4:5, cover): v2-hero3d.js sube su opacidad.
     Se descarga recién cuando el 3D arrancó (.has-render). */
  .v2-hero__render {
    position: absolute;
    inset: 0;
    z-index: 1;
    opacity: 0;
    background: 50% 50% / cover no-repeat;
    pointer-events: none;
  }

  .v2-hero.has-render .v2-hero__render {
    background-image: image-set(url("../img/portada-render-400.7aae74a8b56e.webp") 1x, url("../img/portada-render-800.87483608394a.webp") 2x);
  }

  /* Es una casa que no existe: se dice, para no hacerla pasar por una obra real. */
  .v2-hero__note {
    position: absolute;
    right: 0;
    bottom: 0;
    z-index: 2;
    opacity: 0;
    padding: var(--space-1) 0 0 var(--space-2);
    background: var(--color-white);
    font-size: var(--text-label);
    line-height: 1.4;
  }

  .v2-hero.is-3d .v2-plan { opacity: 0; }
  .v2-hero.is-3d .v2-hero__scene { opacity: 1; }
}

/* Celular bajo o con letra grande (las medidas en em siguen el tamaño de letra del
   teléfono): sin antetítulo (las regiones están en Zona de trabajo) y con título y
   bajada más chicos, para que la obra tenga espacio. Si aun así no cabe, v2.js deja
   el plano fijo (.no-3d). Caso real: Samsung de Claudia, 2026-10-25. */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) and (min-height: 34em) and (max-height: 46em) and (max-width: 63.99em) {
  .v2-hero:not(.no-3d) .v2-hero__where { display: none; }
  .v2-hero:not(.no-3d) .v2-hero__title { margin-top: 0; font-size: clamp(2rem, 9vw, 2.75rem); }
  .v2-hero:not(.no-3d) .v2-hero__lead { margin-top: var(--space-2); font-size: var(--text-body); line-height: 1.5; }
}

@media (scripting: enabled) and (prefers-reduced-motion: no-preference) and (min-height: 34em) and (min-width: 64em) {
  .v2-hero:not(.no-3d) { height: 260svh; }

  .v2-hero__stages strong { display: block; margin-top: var(--space-1); font-size: 1.5rem; font-weight: 300; line-height: 1.2; }
  .v2-hero__stages span { display: block; }

  .v2-hero:not(.no-3d) .v2-hero__grid { grid-template-rows: auto 1fr auto auto; }

  .v2-hero:not(.no-3d) .v2-plan,
  .v2-hero:not(.no-3d) .v2-hero__scene { margin: 0; }

  .v2-hero:not(.no-3d) .v2-plan {
    background-image: image-set(url("../img/portada-plano-720.8ad13fde5307.webp") 1x, url("../img/portada-plano-1440.d9c57134a946.webp") 2x);
  }

  .v2-hero.has-render .v2-hero__render {
    background-image: image-set(url("../img/portada-render-720.ca9951d4ef0f.webp") 1x, url("../img/portada-render-1440.ccff39f0822c.webp") 2x);
  }
}

/* Pantalla más ancha que la página: la obra no se corta en el borde de la hoja, pasa
   sobre la mitad de la franja antracita (Ariel, 2026-10-25; hasta el borde de la
   pantalla quedaba gigante en monitores muy anchos). La imagen
   fija y la escena crecen igual, así el cambio a 3D sigue sin notarse; el desborde por
   la barra de desplazamiento lo recorta site.css (html, overflow-x: clip). */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) and (min-height: 34em) and (min-width: 90.0625em) {
  .v2-hero:not(.no-3d) .v2-plan,
  .v2-hero:not(.no-3d) .v2-hero__scene {
    width: calc(100% + (100vw - var(--max-width)) / 4);
  }
}

/* Dibujo del plano: muros macizos en antracita, cotas en bronce (línea, no texto
   de cuerpo), ejes en cemento. */
.v2-plan__svg,
.v2-stage__svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

.v2-plan__svg text,
.v2-stage__svg text {
  fill: var(--color-anthracite);
  font-family: var(--font-sans);
  font-weight: 600;
  text-anchor: middle;
  font-variant-numeric: tabular-nums;
}

/* Tamaños en unidades del dibujo: se leen como cotas a cualquier ancho. */
.v2-plan__svg text { font-size: 20px; }
.v2-stage__svg text { font-size: 24px; }

/* Las líneas finas mantienen su grosor en pantalla; las que se "dibujan"
   (pathLength + dasharray) escalan con el dibujo. */
.v2-plan__svg path,
.v2-plan__svg circle,
.b-hatch,
.b-ground__line,
.b-line,
.b-stake,
.b-dash,
.b-axes circle,
.b-ghost path,
.b-mullion { vector-effect: non-scaling-stroke; }

.pl-axes path {
  fill: none;
  stroke: var(--color-cement);
  stroke-width: 1;
  stroke-dasharray: 10 6 2 6;
}

.pl-bubbles circle {
  fill: var(--color-white);
  stroke: var(--color-cement);
  stroke-width: 1.5;
}

.pl-bubbles text { font-size: 18px; }

.pl-dim path {
  fill: none;
  stroke: var(--color-bronze);
  stroke-width: 1.5;
}

.pl-walls { fill: var(--color-anthracite); }
.pl-cut { fill: var(--color-white); }

.pl-openings path {
  fill: none;
  stroke: var(--color-anthracite);
  stroke-width: 1.5;
}

.pl-openings .pl-swing {
  stroke: var(--color-cement);
  stroke-dasharray: 4 4;
}

/* ── Proceso: la obra se levanta ───────────────────────────────────────────
   --p (0 → 1) es el avance por los 6 pasos; lo escribe static/js/v2.js. Sin JS
   o con movimiento reducido queda en 1: el dibujo terminado. Cada --sN completa
   su capa al 60 % del paso N, para que se lea mientras el paso está en pantalla. */
.v2-build {
  --p: 1;
  --s1: clamp(0, var(--p) * 9.6, 1);
  --s2: clamp(0, (var(--p) * 6 - 1) * 1.6, 1);
  --s3: clamp(0, (var(--p) * 6 - 2) * 1.6, 1);
  --s4: clamp(0, (var(--p) * 6 - 3) * 1.6, 1);
  --s5: clamp(0, (var(--p) * 6 - 4) * 1.6, 1);
  --s6: clamp(0, (var(--p) * 6 - 5) * 1.6, 1);
  /* El paso 6 se reparte en la secuencia de una obra. */
  --found: clamp(0, var(--s6) * 4, 1);
  --rebar: clamp(0, (var(--s6) - 0.15) * 3, 1);
  --walls: clamp(0, (var(--s6) - 0.4) * 2.5, 1);
  --roof: clamp(0, (var(--s6) - 0.65) * 3.5, 1);
  --glass: clamp(0, (var(--s6) - 0.85) * 6.6, 1);
}

.home-grid > .v2-build__layout {
  grid-column: 1 / -1;
  padding-left: 0;
}

.v2-build__layout { display: grid; }

/* En el celular el dibujo queda fijo arriba y los pasos pasan por debajo. */
.v2-stage {
  position: sticky;
  top: var(--header-height);
  z-index: 1;
  display: flex;
  align-items: center;
  /* Ariel: en el celular el dibujo ocupa a lo más 1/6 de la pantalla. */
  height: calc(100svh / 6);
  padding-block: var(--space-1);
  background: var(--color-white);
  border-bottom: 1px solid var(--line);
}

.v2-stage__svg { height: 100%; }

.v2-steps { counter-reset: none; }

.v2-step {
  display: grid;
  align-content: center;
  gap: var(--space-2);
  min-height: 45svh;
  padding: var(--space-6) 0 var(--space-6) var(--space-3);
  border-left: 3px solid transparent;
}

.v2-step + .v2-step { border-top: 1px solid var(--line); }

.v2-step__number {
  color: var(--color-anthracite);
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 300;
  line-height: 0.9;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.v2-step__title {
  max-width: 22rem;
  font-size: var(--text-h3);
  font-weight: 600;
  line-height: 1.25;
}

.v2-step p { max-width: 30rem; }

/* El paso en curso: el canto y el número pasan a bronce (número ≥ 24 px). */
.v2-build.is-live .v2-step.is-active { border-left-color: var(--color-bronze); }
.v2-build.is-live .v2-step.is-active .v2-step__number { color: var(--color-bronze); }

@media (min-width: 64em) {
  .v2-build__layout {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    column-gap: var(--space-6);
    align-items: start;
  }

  .v2-steps { grid-column: 1 / 3; grid-row: 1; }

  .v2-stage {
    grid-column: 3 / 5;
    grid-row: 1;
    top: calc(var(--header-height) + 8vh);
    height: min(76vh, 42rem);
    padding: 0;
    background: none;
    border: 0;
  }

  .v2-step { min-height: 72vh; }
}

/* Capas del dibujo */
.b-hatch { stroke: var(--color-cement); stroke-width: 1; }
.b-ground__line { stroke: var(--color-anthracite); stroke-width: 2; }

.b-line,
.b-stake {
  fill: none;
  stroke: var(--color-bronze);
  stroke-width: 1.5;
}

.b-dash {
  fill: none;
  stroke: var(--color-cement);
  stroke-width: 1;
  stroke-dasharray: 10 6 2 6;
}

.b-axes circle {
  fill: var(--color-white);
  stroke: var(--color-cement);
  stroke-width: 1.5;
}

.b-text--start { text-anchor: start; }

/* Las líneas de proyecto se apagan cuando la obra está terminada. */
.b-site { opacity: calc(var(--s1) * (1 - var(--glass) * 0.6)); }
.b-axes { opacity: calc(var(--s2) * (1 - var(--glass) * 0.75)); }
.b-docs { opacity: calc(var(--s5) * (1 - var(--glass) * 0.6)); }

/* Ajustes: la alternativa aparece y se va dentro del paso 4. */
.b-ghost {
  fill: none;
  stroke: var(--color-cement);
  stroke-width: 2;
  stroke-dasharray: 8 6;
  opacity: calc(var(--s4) * (1 - var(--s4)) * 4);
}

.b-draft path {
  fill: none;
  stroke: var(--color-anthracite);
  stroke-width: 4;
  stroke-dasharray: 1;
  stroke-dashoffset: calc(1 - var(--s3));
}

/* Obra */
.b-found,
.b-walls {
  transform-box: fill-box;
  transform-origin: 50% 100%;
}

.b-found {
  fill: var(--color-bronze);
  transform: scaleY(var(--found));
}

.b-rebar {
  fill: none;
  stroke: var(--color-bronze);
  stroke-width: 8;
  stroke-dasharray: 1;
  stroke-dashoffset: calc(1 - var(--rebar));
}

.b-walls {
  fill: var(--color-anthracite);
  transform: scaleY(var(--walls));
}

.b-glass {
  fill: var(--color-white);
  opacity: var(--glass);
}

.b-mullion {
  fill: none;
  stroke: var(--color-cement);
  stroke-width: 1.5;
}

.b-roof {
  fill: none;
  stroke: var(--color-anthracite);
  stroke-width: 18;
  stroke-linecap: square;
  stroke-dasharray: 1;
  stroke-dashoffset: calc(1 - var(--roof));
}
