.visualizer-shell {
  --ink: var(--marino);
  --muted: #5f6e70;
  --line: rgba(16, 37, 42, 0.14);
  --surface: #ffffff;
  --accent: var(--cian);
  --water-color: #8ee8e4;
  --water-deep: #0a7c8d;
  --water-highlight: rgba(255, 255, 255, 0.45);
  --surface-color: #efeee8;
  /* Fallback poligonal: se usa si no se carga la máscara PNG del agua. */
  --water-mask: polygon(
    0% 48.8%,
    8% 46.3%,
    19% 43.3%,
    33% 39.8%,
    48% 37.8%,
    62% 36.9%,
    72.2% 37.2%,
    77.8% 39.8%,
    83.6% 45%,
    89.6% 48.4%,
    95.2% 52.3%,
    100% 54.4%,
    100% 100%,
    0% 100%
  );
  color-scheme: light;
  color: var(--ink);
}

.visualizer-shell [hidden] {
  display: none !important;
}

.visualizer-shell button {
  font-family: inherit;
}

.visualizer-shell button:focus-visible,
.visualizer-shell summary:focus-visible,
.compare-handle:focus-visible {
  outline: 2px solid var(--water-deep);
  outline-offset: 2px;
}

.visualizer-shell {
  display: flex;
  flex-direction: column;
  width: min(100%, 1600px);
  margin: 0 auto;
  padding: 1.5rem 3vw 4rem;
}

/* ---------- Hero ---------- */
.visualizador-hero {
  display: grid;
  align-items: end;
  padding: 0.2rem 0 clamp(0.8rem, 1.6vw, 1.3rem);
}

.hero-copy {
  max-width: 62rem;
}

.visualizer-shell h1,
.visualizer-shell h2,
.visualizer-shell h3,
.visualizer-shell p {
  overflow-wrap: anywhere;
}

.visualizador-hero h1 {
  max-width: 58rem;
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 3rem);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.035em;
}

.hero-copy p:last-child {
  max-width: 48rem;
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
}

.viewer-section,
.controls-section {
  padding: clamp(0.7rem, 1.5vw, 1.2rem) 0;
}

.visualizer-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(17rem, 20rem);
  gap: clamp(1rem, 2.5vw, 2.5rem);
  align-items: start;
}

.viewer-section {
  min-width: 0;
}

.controls-section {
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: var(--palette-height);
  margin-top: var(--palette-offset);
  padding: 0;
}

.controls-section > .section-heading {
  flex-shrink: 0;
}

.controls-section .palette-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.controls-section .palette-head {
  flex-shrink: 0;
}

.viewer-section .section-heading {
  align-items: center;
}

.viewer-section .sobrelinea {
  margin: 0 0 0.4rem;
}

.controls-section .section-heading h2 {
  font-size: 1.45rem;
}

#fullscreenToggle {
  flex-shrink: 0;
}

.material-section {
  padding-top: 2rem;
  margin-top: 1rem;
  border-top: 1px solid var(--line);
}

.visualizer-workspace:fullscreen,
.visualizer-workspace.is-expanded {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: clamp(1rem, 3vw, 3rem);
  background: var(--niebla);
}

.visualizer-workspace.is-expanded {
  position: fixed;
  inset: 0;
  z-index: 100;
}

body.visualizador-ampliado {
  overflow: hidden;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin-bottom: 0.72rem;
}

.section-heading h2 {
  max-width: 46rem;
  margin: 0;
  font-size: clamp(1.45rem, 2.6vw, 2.6rem);
  font-weight: 620;
  line-height: 1.08;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem 1.4rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
}

.profile-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.9rem 0 0;
}

.profile-controls p {
  flex-basis: 100%;
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.seg button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.finish-gallery {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.finish-purchase-link {
  background: #fff;
  color: var(--ink);
}

.finish-purchase-link:hover {
  background: var(--ink);
  color: #fff;
}

.finish-gallery-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.75rem 1.2rem;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

.finish-gallery-link:hover {
  background: #fff;
  color: var(--ink);
}

.finish-gallery-link:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.seg {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.seg button,
.toggle {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 650;
  padding: 0.42rem 0.9rem;
  transition: background 0.25s ease, color 0.25s ease;
}

.seg button:hover,
.toggle:hover {
  background: rgba(16, 37, 42, 0.07);
}

.seg button[aria-pressed="true"],
.toggle[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
}

.toggle {
  border: 1px solid var(--line);
  background: #fff;
}

/* ---------- Escenario ---------- */
.pool-stage {
  position: relative;
  overflow: hidden;
  width: 100%;
  margin: 0 auto;
  aspect-ratio: var(--pool-ratio, 3 / 2); /* proporción de la foto del modelo activo */
  border: 1px solid rgba(16, 37, 42, 0.12);
  border-radius: 8px;
  background: #d9e7ea;
  box-shadow: 0 0.8rem 2.4rem rgba(3, 47, 85, 0.07);
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
}

.pool-stage[data-compare="on"] {
  cursor: ew-resize;
  touch-action: pan-y;
}

/* La escena lleva el filtro de luz; así "antes" y "después" comparten iluminación */
.scene {
  position: absolute;
  inset: 0;
  filter: var(--scene-filter, none);
  transition: filter 0.6s ease, opacity 0.22s ease;
}

/* Cambio de modelo: fundido corto mientras se cargan foto, máscaras y motor */
.pool-stage.is-switching .scene {
  opacity: 0;
}

.pool-stage[aria-busy="true"] {
  cursor: progress;
}

.model-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  filter: var(--scene-filter, none);
  pointer-events: none;
}

.pool-photo {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  filter: contrast(1.02) saturate(1.02);
  pointer-events: none;
}

/* Lado "después": se recorta desde la izquierda según el deslizador */
.sim {
  position: absolute;
  inset: 0;
  isolation: isolate;
  clip-path: inset(0 0 0 var(--split, 0%));
}

.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Máscaras: poligonal de reserva → PNG alpha precisa cuando existe */
.m-water {
  clip-path: var(--water-mask);
}

.m-walls,
.m-steps {
  display: none;
}

.has-mask-walls .m-walls,
.has-mask-steps .m-steps {
  display: block;
}

.has-mask-water .m-water {
  clip-path: none;
  -webkit-mask-image: var(--mask-water);
  mask-image: var(--mask-water);
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

.has-mask-walls .m-walls {
  -webkit-mask-image: var(--mask-walls);
  mask-image: var(--mask-walls);
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

.has-mask-steps .m-steps {
  -webkit-mask-image: var(--mask-steps);
  mask-image: var(--mask-steps);
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

/* Motor de recoloreado por píxel (conserva ondas y brillos reales) */
.recolor {
  display: none;
}

.engine-ready .recolor {
  display: block;
}

.recolor-transition {
  opacity: 0;
}

/* Capas de reserva (tinte CSS) cuando no se pueden leer píxeles */
.engine-ready .tint,
.engine-ready .shade {
  display: none;
}

.tint {
  background:
    radial-gradient(circle at 26% 64%, rgba(255, 255, 255, 0.38), transparent 18%),
    linear-gradient(115deg, rgba(255, 255, 255, 0.18), transparent 28%),
    linear-gradient(165deg, var(--water-color), var(--water-deep));
  mix-blend-mode: color;
  opacity: var(--op, 0.68);
  filter: var(--flt, none);
  transition: filter 0.5s ease, opacity 0.5s ease, background 0.5s ease;
}

.water-canvas {
  mix-blend-mode: screen;
  opacity: var(--op, 0.34);
  transition: opacity 0.5s ease;
}

.shade {
  background:
    linear-gradient(90deg, rgba(3, 20, 24, 0.28), transparent 22%, transparent 78%, rgba(4, 30, 37, 0.15)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 31%, rgba(2, 35, 46, 0.16));
  mix-blend-mode: multiply;
  opacity: var(--op, 0.58);
  transition: opacity 0.5s ease;
}

/* Luz de piscina nocturna */
.glow {
  background: radial-gradient(ellipse at 45% 66%, var(--water-color), transparent 72%);
  mix-blend-mode: screen;
  opacity: var(--op, 0);
  transition: opacity 0.6s ease;
}

/* Brillo en la línea de agua, limitado por la misma máscara */
.highlight {
  background: linear-gradient(180deg, transparent 33%, var(--water-highlight) 37%, transparent 49%);
  mix-blend-mode: overlay;
  opacity: var(--op, 0.56);
  transition: opacity 0.5s ease;
}

.light-overlay {
  position: absolute;
  inset: 0;
  background: var(--light-overlay, none);
  mix-blend-mode: var(--light-blend, normal);
  pointer-events: none;
}

/* ---------- Comparación antes / después ---------- */
.compare-handle,
.compare-label {
  display: none;
}

.pool-stage[data-compare="on"] .compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--split);
  display: block;
  width: 3rem;
  margin-left: -1.5rem;
  cursor: ew-resize;
  touch-action: none;
}

.compare-handle::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% - 1px);
  width: 2px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(16, 37, 42, 0.25);
}

.compare-handle::after {
  content: "‹ ›";
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0.3rem 1rem rgba(16, 37, 42, 0.35);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  transform: translate(-50%, -50%);
}

.pool-stage[data-compare="on"] .compare-label {
  position: absolute;
  top: 0.7rem;
  display: block;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: rgba(16, 37, 42, 0.72);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 650;
  pointer-events: none;
}

.compare-before {
  left: 0.7rem;
}

.compare-after {
  right: 0.7rem;
}

/* ---------- Panel de revestimiento ---------- */
.material-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  width: 100%;
  margin: 0;
}

.material-panel figure {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.material-panel img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: contain;
  background: var(--surface-color);
}

.material-panel figure.is-missing img {
  visibility: hidden;
}

.material-panel figcaption {
  padding: 0.65rem 0.85rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.disclaimer {
  max-width: 48rem;
  margin: 0.8rem auto 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
  text-align: center;
}

.mask-status {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.7rem;
  opacity: 0.7;
  text-align: center;
}

/* ---------- Selector ---------- */
.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(17rem, 23rem);
  gap: clamp(0.7rem, 1.4vw, 1.2rem);
  align-items: start;
}

.palette-panel,
.color-card {
  border: 0;
  background: transparent;
}

.palette-panel {
  padding: 0;
}

.palette-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.panel-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 760;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.chip {
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 650;
}

.chip[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  min-height: 0;
  flex: 1;
  align-content: start;
  overflow-y: auto;
  padding: 0.3rem 0.15rem;
  scrollbar-width: thin;
}

.color-item {
  min-width: 0;
}

.color-button {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  height: 100%;
  padding: 0.4rem 0.4rem 0.65rem;
  border: 1px solid rgba(16, 37, 42, 0.12);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

.color-button:hover {
  border-color: var(--ink);
  box-shadow: 0 0.25rem 0.75rem rgba(16, 37, 42, 0.06);
}

.color-button[aria-selected="true"] {
  border-color: var(--ink);
  background: #fff;
  box-shadow: 0 0 0 1px var(--ink);
}

.swatch {
  display: block;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 7px;
  background: var(--surface-color);
  box-shadow: inset 0 0 0 1px rgba(16, 37, 42, 0.1);
}

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

.color-meta {
  display: grid;
  gap: 0.1rem;
  padding: 0 0.2rem;
}

.color-name {
  font-size: 0.86rem;
  font-weight: 720;
  line-height: 1.2;
}

.color-family {
  color: var(--muted);
  font-size: 0.72rem;
}

.check {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.color-button[aria-selected="true"] .check {
  opacity: 1;
  transform: scale(1);
}

/* ---------- Ficha ---------- */
.color-card {
  padding: 0;
}

.color-card h3 {
  margin: 0 0 0.9rem;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.color-card dl,
.color-card dd {
  margin: 0;
}

.color-card dl {
  display: grid;
  gap: 0.7rem;
}

.color-card dl > div {
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--line);
}

.color-card dl > div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.color-card dt {
  margin-bottom: 0.2rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 760;
}

.color-card dd {
  color: var(--ink);
  font-size: 0.93rem;
  line-height: 1.45;
}

.selected-finish {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.selected-swatch {
  flex: 0 0 3.2rem;
  width: 3.2rem;
  height: 3.2rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-color);
}

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

.model-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.model-picker button {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0.75rem 0.35rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.model-picker button[aria-pressed="true"] {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.model-picker img {
  width: 3.5rem;
  height: 2.6rem;
  border-radius: 4px;
  object-fit: cover;
}

.model-picker span {
  font-size: 0.8rem;
  font-weight: 650;
}

.model-picker small {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 400;
}

.ambience-panel,
.simulation-panel {
  padding: 0.75rem 0;
  border-top: 1px solid var(--line);
}

.simulation-panel {
  margin-bottom: 0.7rem;
  border-bottom: 1px solid var(--line);
}

.ambience-panel summary,
.simulation-panel summary {
  cursor: pointer;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 600;
}

.ambience-panel summary span,
.simulation-panel summary span {
  margin-left: 0.65rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
}

.ambience-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.5rem;
  margin-top: 1rem;
}

.ambience-note {
  margin: 0.75rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.5;
}

.model-status {
  color: var(--ink);
  font-size: 0.8rem;
  line-height: 1.5;
}

.model-status:empty {
  display: none;
}

.technical-details {
  margin-top: 0.65rem;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

.technical-details summary {
  cursor: pointer;
}

.material-section .section-heading h2 {
  font-size: clamp(1.5rem, 2vw, 2rem);
}

.color-card .sobrelinea,
.controls-section .sobrelinea {
  margin: 0 0 0.5rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .visualizer-workspace {
    grid-template-columns: 1fr;
  }

  .viewer-section {
    position: static;
  }

  .controls-section {
    height: auto;
    margin-top: 0;
    position: static;
  }

  .controls-section .palette-head {
    display: none;
  }

  .controls-section .color-grid {
    display: flex;
    gap: 0.7rem;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
    padding: 0.3rem 0.15rem 0.75rem;
    scroll-snap-type: x proximity;
  }

  .controls-section .color-item {
    flex: 0 0 7.25rem;
    scroll-snap-align: start;
  }

  .controls-section .color-item[hidden] {
    display: none;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .color-card {
    position: static;
  }
}

@media (max-width: 620px) {
  .visualizer-shell {
    padding: 0.85rem;
  }

  .model-picker {
    width: 100%;
    flex-wrap: nowrap;
  }

  .model-picker button {
    flex: 1;
    min-width: 0;
    gap: 0.4rem;
    padding-right: 0.35rem;
  }

  .model-picker img {
    width: 2.5rem;
    height: 2.2rem;
  }

  .seg {
    max-width: 100%;
    flex-wrap: wrap;
  }

  .seg button,
  .toggle,
  .chip {
    min-height: 44px;
  }

  .ambience-panel summary,
  .simulation-panel summary,
  .technical-details summary {
    padding: 0.4rem 0;
  }

  .pool-stage,
  .material-panel {
    width: 100%;
  }

  .material-panel {
    gap: 0.65rem;
  }

  .viewer-section .section-heading {
    flex-wrap: wrap;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .toolbar-group {
    flex-wrap: wrap;
  }

}

@media (prefers-reduced-motion: reduce) {
  .visualizer-shell *,
  .visualizer-shell *::before,
  .visualizer-shell *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
