/*
 * Decision field — Waterproofing (html/kiwitile-waterproofing-decision-field.html).
 *
 * Adds the interactive exploded tile assembly (five 3D layers driven by the
 * custom property --p, 0 = compressed … 1 = exploded) and, on phones, a single
 * tall visual stage in which the copy sits over the assembly, with the method
 * box moved below it (.method-panel). The document itself scrolls on phones.
 */

.decision-field--waterproofing {
  --df-columns: minmax(250px, 310px) minmax(410px, 1fr) minmax(500px, 1.28fr);
  --df-columns-narrow: 245px minmax(390px, .95fr) minmax(320px, 1.16fr);
  --df-mark-size: 98px;
  --df-mark-margin: -25px;
  --df-mark-shift: translate(-18px, -13px);
  --df-mark-filter: drop-shadow(0 8px 16px rgba(0, 0, 0, .34)) drop-shadow(0 0 10px rgba(217, 164, 94, .1));
  --df-tab-count: 5;
  --df-stagger-start: 80ms;
  --df-stagger-step: 50ms;
  --df-stage-shade:
    linear-gradient(90deg, rgba(3, 7, 6, .84) 0%, rgba(4, 8, 7, .69) 28%, rgba(4, 8, 7, .46) 49%, rgba(3, 7, 6, .25) 100%),
    linear-gradient(180deg, rgba(3, 7, 6, .16), transparent 58%, rgba(3, 7, 6, .38));
  --df-copy-bg: linear-gradient(90deg, rgba(4, 8, 7, .3), rgba(4, 8, 7, .09));
  --df-copy-title-size: clamp(37px, 3.45vw, 58px);
  --df-copy-rule-margin: 16px;
  --df-copy-text-color: rgba(244, 234, 216, .72);
  --df-copy-kicker-margin: 17px;
  --df-photo-position: center 54%;
  --df-photo-filter: saturate(.72) contrast(1.08) brightness(.64);
  --df-mobile-text-size: 20px;
  --df-mobile-text-leading: 1.45;
  --df-mobile-text-leading-landscape: 1.45;
  --df-mobile-method-size: 20px;
  --df-mobile-method-leading: 1.45;
  --df-mobile-method-leading-landscape: 1.45;
  --df-mobile-title-size-landscape: clamp(26px, 3.8vw, 32px);
  --df-mobile-copy-index-size: 110px;
  --df-mobile-copy-index-top: 12px;
}

.decision-field--waterproofing .backdrop { backdrop-filter: none; }

.decision-field--waterproofing .stage-photo {
  position: absolute;
  inset: 0;
}

.decision-field--waterproofing .image-stage::after { z-index: 1; }

.copy-title-or { font-size: .56em; }

/* Phone-only wrappers: transparent to the desktop grid. */
.mobile-visual-stage { display: contents; }
.mobile-field-bg { display: none; }

/* ── Exploded assembly ─────────────────────────────────────────────────── */

.assembly-wrap {
  position: absolute;
  z-index: 2;
  inset: 4% 1% 10% 54%;
  display: grid;
  place-items: center;
  perspective: 1100px;
  pointer-events: none;
}

.assembly-wrap::before {
  content: "";
  position: absolute;
  width: min(29vw, 420px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(241, 199, 125, .12), transparent 62%);
  filter: blur(4px);
}

.visual-status {
  position: absolute;
  top: 8px;
  right: 28px;
  z-index: 2;
  display: grid;
  gap: 7px;
  min-width: 170px;
  padding: 0 0 11px;
  border-bottom: 1px solid rgba(241, 199, 125, .27);
  color: rgba(244, 234, 216, .45);
  font-size: 8px;
  font-weight: 750;
  letter-spacing: .24em;
  text-align: right;
  text-transform: uppercase;
}

.visual-status strong {
  color: var(--pale-gold);
  font-size: 10px;
  letter-spacing: .2em;
}

.assembly {
  --p: 0;
  --assembly-tilt: rotateX(calc(61deg - var(--p) * 4deg)) rotateZ(calc(-43deg + var(--p) * 4deg)) translateX(clamp(-52px, -3.2vw, -24px)) translateY(calc(var(--p) * -20px));
  position: relative;
  width: clamp(220px, 21vw, 315px);
  aspect-ratio: 1;
  transform-style: preserve-3d;
  transform: var(--assembly-tilt);
  transition: transform .08s linear;
  pointer-events: auto;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
}

.layer {
  --z: 0px;
  --edge: #222;
  --layer-color: #999;
  --glow: transparent;
  position: absolute;
  inset: 0;
  opacity: 1;
  transform-style: preserve-3d;
  transform: translateZ(var(--z));
  filter: drop-shadow(0 42px 28px rgba(0, 0, 0, .22));
  transition: opacity .45s ease, filter .2s ease;
}

/* Every layer but the selected one recedes (the tile view shows all). */
.assembly:not([data-active="tile"]) .layer:not(.is-active) { opacity: .18; }

.plate {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .16);
  background: var(--layer-color);
  box-shadow: inset 0 1px rgba(255, 255, 255, .24), inset 0 -1px rgba(0, 0, 0, .22), 0 0 58px var(--glow);
}

.plate::before,
.plate::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.plate::before {
  background: linear-gradient(120deg, rgba(255, 255, 255, .35), transparent 30%, rgba(0, 0, 0, .13) 100%);
  mix-blend-mode: soft-light;
}

/* Quarter grid etched into each plate. */
.plate::after {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, .1) 1px, transparent 1px) 0 0 / 25% 100%,
    linear-gradient(180deg, rgba(255, 255, 255, .1) 1px, transparent 1px) 0 0 / 100% 25%;
  opacity: .28;
}

.layer.is-active .plate {
  border-color: rgba(255, 222, 159, .7);
  box-shadow: inset 0 1px rgba(255, 255, 255, .34), inset 0 -1px rgba(0, 0, 0, .22), 0 0 42px rgba(241, 199, 125, .28);
}

.edge {
  position: absolute;
  background: linear-gradient(180deg, color-mix(in srgb, var(--edge), white 18%), var(--edge));
  box-shadow: inset 0 0 24px rgba(0, 0, 0, .18);
  transform-style: preserve-3d;
}

.edge.front {
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--thick);
  transform-origin: 50% 100%;
  transform: rotateX(-90deg);
}

.edge.right {
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--thick);
  transform-origin: 100% 50%;
  transform: rotateY(90deg);
}

.tile-layer {
  --z: calc(228px * var(--p));
  --thick: 18px;
  --edge: #a49888;
  --layer-color: #cfc5b5;
  --glow: rgba(255, 255, 255, .04);
}

.tile-layer .plate {
  background:
    linear-gradient(120deg, rgba(255, 255, 255, .36), rgba(255, 255, 255, .02) 42%, rgba(0, 0, 0, .2)),
    url("../../images/kiwitile-stone-explode.webp") center / cover no-repeat;
}

.tile-layer .plate::after { opacity: calc(.28 + var(--p) * .5); }

.adhesive-layer {
  --z: calc(118px * var(--p));
  --thick: 22px;
  --edge: #7e6042;
  --layer-color: #aa8964;
  inset: 16px;
}

.adhesive-layer .plate {
  background:
    linear-gradient(120deg, rgba(255, 255, 255, .22), rgba(255, 255, 255, .02) 42%, rgba(0, 0, 0, .18)),
    url("../../images/kiwitile-adhesive-layer-waterproof-explode.webp") right top / 150% auto no-repeat;
}

.waterproofing-layer {
  --z: calc(4px * var(--p));
  --thick: 16px;
  --edge: #055c72;
  --layer-color: #109abb;
  --glow: rgba(91, 219, 245, .58);
  inset: 31px;
  filter: drop-shadow(0 42px 28px rgba(0, 0, 0, .22)) drop-shadow(0 0 calc(10px + var(--p) * 32px) rgba(86, 218, 244, .62));
}

.waterproofing-layer .plate {
  border-color: rgba(177, 247, 255, .66);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .34), rgba(255, 255, 255, 0) 34%),
    radial-gradient(circle at 72% 28%, rgba(211, 255, 255, .42), transparent 16%),
    linear-gradient(145deg, #28c3e1, #077fa0 54%, #075670);
}

.waterproofing-layer .plate::after,
.heating-layer .plate::after,
.substrate-layer .plate::after { display: none; }

.waterproof-pulse {
  position: absolute;
  inset: -4%;
  border: 2px solid rgba(153, 239, 255, .62);
  opacity: calc(.14 + var(--p) * .7);
  transform: translateZ(3px);
  box-shadow: 0 0 28px rgba(91, 219, 245, .56), inset 0 0 34px rgba(91, 219, 245, .26);
}

.heating-layer {
  --z: calc(-104px * var(--p));
  --thick: 18px;
  --edge: #8f3a20;
  --layer-color: #b8542d;
  --glow: rgba(255, 115, 55, .38);
  inset: 38px;
  filter: drop-shadow(0 42px 28px rgba(0, 0, 0, .22)) drop-shadow(0 0 calc(6px + var(--p) * 20px) rgba(255, 105, 45, .34));
}

.heating-layer .plate {
  border-color: rgba(255, 190, 137, .58);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .18), transparent 38%, rgba(70, 18, 10, .16)),
    url("../../images/kiwitile-underfloor-wire.webp") center / cover no-repeat;
}

.substrate-layer {
  --z: calc(-214px * var(--p));
  --thick: 34px;
  --edge: #383d38;
  --layer-color: #606761;
  inset: 44px;
}

.substrate-layer .plate {
  background:
    linear-gradient(120deg, rgba(255, 255, 255, .18), rgba(255, 255, 255, .01) 42%, rgba(0, 0, 0, .2)),
    url("../../images/kiwitile-concrete-image.webp") center / cover no-repeat;
}

.shadow-plane {
  position: absolute;
  inset: 36% 4% -7%;
  transform: translateZ(-300px);
  background: radial-gradient(ellipse, rgba(0, 0, 0, .46), transparent 68%);
  filter: blur(8px);
}

/* Compress ↔ explode slider with the auto-motion toggle. */
.explode-console {
  position: absolute;
  left: calc(50% - 54px);
  bottom: -34px;
  z-index: 5;
  width: min(280px, calc(100% - 42px));
  padding: 10px 12px 11px;
  border: 1px solid rgba(241, 199, 125, .2);
  background: rgba(5, 10, 8, .72);
  backdrop-filter: blur(12px);
  transform: translateX(-50%);
  pointer-events: auto;
}

.explode-console-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: rgba(244, 234, 216, .47);
  font-size: 7px;
  font-weight: 760;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.motion-toggle {
  padding: 0;
  border: 0;
  color: var(--pale-gold);
  background: transparent;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.explode-range {
  display: block;
  width: 100%;
  height: 12px;
  margin: 0;
  accent-color: var(--pale-gold);
  cursor: ew-resize;
}

@media (max-width: 1180px) {
  .assembly-wrap { inset: 5% 1% 10% 55%; }
  .assembly { width: clamp(205px, 20vw, 275px); }
}

/* ── Phones: one tall visual stage, document scrolls ───────────────────── */
@media (max-width: 860px), (max-width: 1000px) and (max-height: 600px) and (orientation: landscape) {
  body { overflow: auto; }

  .decision-field--waterproofing {
    position: relative;
    min-height: 100svh;
    display: block;
  }

  .decision-field--waterproofing .shell {
    min-height: 100svh;
    height: auto;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .decision-field--waterproofing .frame {
    height: auto;
    min-height: 100%;
    /* brand · topic · visual stage · method box · footer */
    grid-template-rows: auto auto auto auto auto;
    overflow: visible;
  }

  .mobile-visual-stage {
    display: grid;
    grid-column: 1;
    grid-row: 3;
    grid-template-rows: auto minmax(0, 1fr);
    position: relative;
    z-index: 1;
    min-height: min(118vh, 1040px);
    overflow: visible;
    isolation: isolate;
  }

  .mobile-field-bg {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image:
      linear-gradient(180deg, rgba(3, 7, 6, .72) 0%, rgba(3, 7, 6, .52) 42%, rgba(3, 7, 6, .58) 100%),
      url("../../images/waterproofing/precision-waterproofing-system-large-format-ensuite-kiwitile-auckland.webp");
    background-size: cover;
    background-position: 65% center;
  }

  /* Copy sits at the top of the shared stage, over the assembly. */
  .decision-field--waterproofing .copy {
    grid-column: 1;
    grid-row: 1;
    height: auto;
    padding: 28px 22px 18px;
    overflow: visible;
    background: linear-gradient(180deg, rgba(3, 7, 6, .34), rgba(3, 7, 6, .1) 78%, transparent);
  }

  /* The method box moves below the assembly. */
  .decision-field--waterproofing .copy .copy-method { display: none; }

  .decision-field--waterproofing .image-stage {
    grid-column: 1;
    grid-row: 1 / -1;
    z-index: 1;
    width: 100%;
    height: auto;
    min-height: 100%;
    overflow: visible;
    background: transparent;
  }

  .decision-field--waterproofing .stage-photo,
  .visual-status { display: none; }

  .decision-field--waterproofing .image-stage::after {
    background: linear-gradient(180deg, transparent 0%, rgba(3, 7, 6, .14) 58%, rgba(3, 7, 6, .4) 100%);
  }

  .assembly-wrap {
    inset: 0;
    padding-top: 56px;
    perspective: 1000px;
    overflow: visible;
  }

  .assembly-wrap::before {
    width: min(70vw, 300px);
    top: 48%;
  }

  .assembly {
    --assembly-tilt: rotateX(calc(58deg - var(--p) * 4deg)) rotateZ(calc(-40deg + var(--p) * 4deg)) translateY(calc(48px + var(--p) * -22px));
    width: min(68vw, 280px);
    left: -7%;
  }

  .explode-console {
    left: 50%;
    bottom: 18px;
    width: min(260px, 88%);
  }

  .method-panel {
    grid-column: 1;
    grid-row: 4;
    display: block;
    padding: 16px 22px 8px;
  }

  .method-panel[hidden] { display: none; }

  .method-panel .copy-method {
    display: block;
    margin: 0;
    max-width: none;
  }

  .decision-field--waterproofing .footer {
    grid-row: 5;
    align-self: auto;
    min-height: auto;
    gap: normal;
  }
}

/* Mobile landscape: copy left, interactive assembly right. */
@media (max-width: 1000px) and (max-height: 600px) and (orientation: landscape) {
  .decision-field--waterproofing { min-height: 100dvh; }

  .decision-field--waterproofing .shell {
    height: 100dvh;
    min-height: 100dvh;
  }

  .decision-field--waterproofing .frame {
    grid-template-rows: auto auto minmax(320px, 1fr) auto;
    align-content: stretch;
  }

  .mobile-visual-stage {
    grid-template-columns: minmax(0, 47%) minmax(0, 53%);
    grid-template-rows: minmax(320px, 1fr);
    min-height: 320px;
  }

  .mobile-field-bg {
    grid-column: 1 / -1;
    background-position: center;
  }

  .decision-field--waterproofing .copy {
    min-height: 320px;
    padding: 20px 20px 22px;
    overflow-x: hidden;
    overflow-y: auto;
    border-right: 1px solid rgba(217, 164, 94, .2);
    background: linear-gradient(90deg, rgba(3, 7, 6, .78), rgba(3, 7, 6, .55));
  }

  .decision-field--waterproofing .copy-text { font-size: 18px; }

  .decision-field--waterproofing .copy .copy-method {
    display: block;
    margin-top: 16px;
  }

  .decision-field--waterproofing .copy-method,
  .decision-field--waterproofing .copy-method b,
  .decision-field--waterproofing .copy-method .copy-method-emphasis { font-size: 18px; }

  .method-panel { display: none; }

  .decision-field--waterproofing .image-stage {
    grid-column: 2;
    grid-row: 1;
    min-height: 320px;
    overflow: hidden;
  }

  .decision-field--waterproofing .image-stage::after {
    background: linear-gradient(90deg, rgba(3, 7, 6, .22), transparent 24%), linear-gradient(180deg, transparent 55%, rgba(3, 7, 6, .28));
  }

  .assembly-wrap { padding: 0 0 44px; }

  .assembly-wrap::before {
    width: min(38vw, 270px);
    top: 50%;
  }

  .assembly {
    --assembly-tilt: rotateX(calc(58deg - var(--p) * 4deg)) rotateZ(calc(-40deg + var(--p) * 4deg)) translateY(calc(24px + var(--p) * -20px));
    width: min(31vw, 240px);
    left: 0;
  }

  .explode-console {
    bottom: 8px;
    width: min(250px, 90%);
  }

  .decision-field--waterproofing .footer { grid-row: 4; }
}

@media (max-width: 460px) {
  .decision-field--waterproofing .copy {
    padding-top: 22px;
    padding-bottom: 18px;
  }

  .mobile-visual-stage { min-height: min(112vh, 960px); }
  .assembly-wrap { padding-top: 52px; }

  .assembly {
    --assembly-tilt: rotateX(calc(58deg - var(--p) * 4deg)) rotateZ(calc(-40deg + var(--p) * 4deg)) translateY(calc(44px + var(--p) * -20px));
    width: min(72vw, 250px);
    left: -7%;
  }
}

/* ── Tablet landscape ──────────────────────────────────────────────────── */
@media (min-width: 861px) and (max-width: 1180px) and (orientation: landscape),
       (min-width: 1181px) and (max-width: 1366px) and (orientation: landscape) and (pointer: coarse) {
  .decision-field--waterproofing .brand h1 { font-size: clamp(28px, 3vw, 35px); }

  .assembly-wrap {
    inset: 0;
    padding: 0 0 46px;
    perspective: 1000px;
    overflow: visible;
  }

  .assembly-wrap::before { width: min(38vw, 330px); }

  .assembly {
    --assembly-tilt: rotateX(calc(58deg - var(--p) * 4deg)) rotateZ(calc(-40deg + var(--p) * 4deg)) translateY(calc(20px + var(--p) * -20px));
    width: min(25vw, 285px);
  }

  .explode-console {
    left: 50%;
    bottom: 8px;
    width: min(280px, 86%);
  }

  .visual-status { right: 40px; }
}

/* High-resolution type: the layer rail inherits the site-wide .tab span size. */
@media (min-width: 1921px) and (min-height: 1081px) {
  .decision-field--waterproofing .tab span { font-size: clamp(12px, min(.625vw, 1.111111vh), 18.6px); }
}
