/* ============================================================
   INDITEX — Insignias para colorear · prototipo Sensa (v3)
   Identidad editorial Inditex: base crema/casi-blanca, tipografía
   Gelion, chrome plano (sin cajas/sombras), iconos SVG (sin emoji).
   Fondo de vídeo en loop con crossfade tras una veladura clara.
   ============================================================ */

/* --- Tipografía de marca: Gelion ---------------------------- */
@font-face {
  font-family: 'Gelion';
  src: url('../../assets/font/gelion-thin.woff') format('woff');
  font-weight: 100; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Gelion';
  src: url('../../assets/font/gelion-light.woff') format('woff');
  font-weight: 300; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Gelion';
  src: url('../../assets/font/gelion-regular.woff') format('woff');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Gelion';
  src: url('../../assets/font/gelion-medium.woff') format('woff');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Gelion';
  src: url('../../assets/font/gelion-bold.woff') format('woff');
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  --cream:       #f4f1ec;
  --cream-2:     #ebe7e0;
  --paper:       #ffffff;
  --ink:         #15130f;
  --ink-2:       #4a463f;
  --ink-3:       #8a857c;
  --line:        rgba(21, 19, 15, 0.14);
  --line-strong: rgba(21, 19, 15, 0.30);
  --stroke:      #15130f;
  --export-bg:   #f4f1ec;
  --radius:      14px;
  --ease:        cubic-bezier(0.22, 1, 0.36, 1);
  --spring:      cubic-bezier(0.34, 1.56, 0.64, 1);
  --font:        'Gelion', system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

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

html, body {
  min-height: 100%;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* --- Fondo de vídeo en loop con crossfade ------------------- */
.bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: var(--cream); }
.bg__video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; opacity: 0; transform: scale(1.05);
  transition: opacity 1.5s var(--ease);
  filter: grayscale(1) contrast(1.02);
}
.bg__video.is-active { opacity: 0.5; }
/* Veladura clara para legibilidad del área crema + paleta */
.bg__scrim {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% -6%, rgba(255,255,255,0.55), transparent 55%),
    linear-gradient(180deg, rgba(244,241,236,0.82), rgba(244,241,236,0.70) 45%, rgba(235,231,224,0.88));
}

/* --- Layout: todo en una pantalla --------------------------- */
.app {
  position: relative; z-index: 1;
  margin: 0 auto;
  min-height: 100vh; min-height: 100dvh;
  padding: clamp(64px, 12vw, 96px) clamp(14px, 3vw, 32px) clamp(20px, 4vw, 36px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(18px, 3vw, 30px);
}

/* --- Coreografía de entrada (gradiente → vídeo → dibujo) ----- */
.bg__scrim { opacity: 0; transition: opacity 0.9s var(--ease); }
body.ph-grad .bg__scrim { opacity: 1; }
.stage__svg { opacity: 0; transition: opacity 0.5s var(--ease); }
body.ph-draw .stage__svg { opacity: 1; }
/* Redraw: al cambiar de insignia (random/dots) la actual se desvanece y la
   nueva entra; el line-draw vuelve a trazarse, así el cambio es intencional. */
body.ph-draw .stage__svg.is-swapping { opacity: 0; transform: scale(0.985); transition: opacity .26s var(--ease), transform .26s var(--ease); }
.palette, .corner { opacity: 0; transition: opacity 0.6s var(--ease) 0.1s, transform 0.6s var(--ease) 0.1s; }
.palette { transform: translateY(12px); }
body.ph-draw .palette, body.ph-draw .corner { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .bg__scrim, .stage__svg, .palette, .corner { opacity: 1 !important; transform: none !important; transition: none; }
}

/* --- Escenario de la insignia (plano, marco mínimo) --------- */
.stage {
  position: relative; flex: 0 1 auto;
  display: flex; align-items: center; justify-content: center;
  padding: 0 clamp(8px, 3vw, 20px); width: 100%;
}
.stage__svg {
  width: 100%; max-width: 360px;
  display: flex; align-items: center; justify-content: center;
}
.stage__svg svg { width: 100%; height: auto; max-height: 64vh; display: block; }
.stage__err { color: var(--ink-2); font-size: 14px; text-align: center; }

/* Regiones coloreables */
.stage__svg .region {
  cursor: pointer;
  transition: opacity .12s var(--ease), fill .28s var(--ease);
  transform-box: fill-box; transform-origin: center;
}
.stage__svg .region:hover { opacity: 0.82; }
.stage__svg .region:focus { outline: none; }
.stage__svg .region.is-focus { stroke: var(--ink); stroke-width: 3.4; opacity: 0.9; }
.stage__svg .frame { pointer-events: none; }
/* Paint = the fill INKS IN with a subtle spring pop (scale overshoot). */
.stage__svg .region.is-painted { animation: regionInk .34s var(--spring) both; }
@keyframes regionInk {
  0%   { transform: scale(0.985); }
  55%  { transform: scale(1.02); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .stage__svg .region { transition: opacity .12s var(--ease); }
  .stage__svg .region.is-painted { animation: none; }
}

/* Line-draw: se dibujan los trazos (ease in/out) y luego entran los rellenos */
.stage__svg.is-drawing .region,
.stage__svg.is-drawing .frame {
  stroke-dasharray: var(--len);
  animation: inkDraw 1.25s cubic-bezier(0.65, 0, 0.35, 1) var(--d) both;
}
.stage__svg.is-drawing .region {
  animation: inkDraw 1.25s cubic-bezier(0.65, 0, 0.35, 1) var(--d) both,
             inkFill 0.55s var(--ease) calc(var(--d) + 0.9s) both;
}
@keyframes inkDraw { from { stroke-dashoffset: var(--len); } to { stroke-dashoffset: 0; } }
@keyframes inkFill { from { fill-opacity: 0; } to { fill-opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .stage__svg.is-drawing .region, .stage__svg.is-drawing .frame { animation: none; stroke-dasharray: none; }
}

/* --- Controles en esquina: SOLO el icono (sin burbuja/contenedor) --- */
.corner {
  position: fixed; top: clamp(16px, 3vw, 28px); z-index: 3;
  font-family: var(--font); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 0; background: none; padding: 0;
  border-radius: 0; -webkit-backdrop-filter: none; backdrop-filter: none;
  color: var(--ink);
  transition: transform .24s var(--spring), opacity .2s var(--ease);
}
.corner svg { width: 24px; height: 24px; flex: 0 0 auto;
  transition: transform .3s var(--spring); }
.corner:hover { transform: translateY(-2px); }
.corner:active { transform: scale(0.96); transition-duration: .12s; }
.corner:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
/* RANDOM: the insignia "redraw" feels intentional — the dice icon spins once. */
.corner--tl.is-shuffling svg { animation: diceSpin .5s var(--spring) both; }
@keyframes diceSpin {
  from { transform: rotate(0); }
  to   { transform: rotate(180deg); }
}
@media (prefers-reduced-motion: reduce) {
  .corner { transition: opacity .2s var(--ease); }
  .corner:hover, .corner:active { transform: none; }
  .corner svg { transition: none; }
  .corner--tl.is-shuffling svg { animation: none; }
}
.corner--tl { left: clamp(16px, 3vw, 28px); }
.corner--tr { right: clamp(16px, 3vw, 28px); }
/* El de descargar ya no es una pastilla sólida; mismo tratamiento de icono. */

/* --- Paleta: una sola línea horizontal con scroll ----------- */
.palette {
  display: flex; flex-wrap: nowrap; gap: 10px; align-items: center;
  width: -webkit-fit-content; width: fit-content; max-width: 94vw;
  margin: 0 auto; padding: 8px 12px;
  overflow: visible;  /* colapsada = 3 colores + stack: cabe sin scroll */
  border-radius: 28px;
  background: rgba(255,255,255,0.55);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.palette::-webkit-scrollbar { height: 0; }
/* Expandida: la paleta completa en DOS LÍNEAS (no en una sola). */
.palette.is-expanded {
  flex-wrap: wrap; justify-content: center; overflow: visible;
  max-width: min(94vw, 360px); row-gap: 10px;
}
.swatch {
  position: relative; cursor: pointer; flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 999px; border: 0;
  padding: 0;
  /* Sin borde oscuro: una sombra MUY suave da el borde a los colores claros sin
     el contorno negro. El anillo de selección lo añade aria-pressed. */
  box-shadow: 0 1px 2px rgba(21,19,15,0.12);
  /* Tactile spring on hover/select; quick decel on press. */
  transition: transform .26s var(--spring), box-shadow .24s var(--spring);
}
.swatch:hover { transform: translateY(-2px) scale(1.04); }
.swatch:active { transform: scale(0.96); transition-duration: .12s; }
.swatch:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
/* The selected ring SPRINGS in (animated ring radius + a brief pop). */
.swatch[aria-pressed="true"] {
  box-shadow: 0 0 0 2px rgba(255,255,255,0.9), 0 0 0 4px var(--ink);
}
.swatch.is-justpicked { animation: swatchPick .42s var(--spring) both; }
@keyframes swatchPick {
  0%   { box-shadow: 0 0 0 2px rgba(255,255,255,0.9), 0 0 0 2px var(--ink); transform: scale(0.92); }
  55%  { box-shadow: 0 0 0 2px rgba(255,255,255,0.9), 0 0 0 6px var(--ink); transform: scale(1.12); }
  100% { box-shadow: 0 0 0 2px rgba(255,255,255,0.9), 0 0 0 4px var(--ink); transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .swatch { transition: box-shadow .15s var(--ease); }
  .swatch:hover, .swatch:active { transform: none; }
  .swatch.is-justpicked { animation: none; }
}

/* --- Magic-move: los colores extra colapsan/crecen suavemente ---
   EXPAND (default) uses a spring so the row "pops" open; COLLAPSE uses a
   smooth decel so it settles quietly. */
.swatch--extra {
  transition: width .46s var(--spring), opacity .3s var(--ease), transform .46s var(--spring),
              margin-left .46s var(--spring), border-width .3s var(--ease);
}
.palette.is-collapsed .swatch--extra {
  width: 0; opacity: 0; transform: scale(0.3); margin-left: -10px;
  border-width: 0; pointer-events: none; overflow: hidden;
  transition: width .4s var(--ease), opacity .26s var(--ease), transform .4s var(--ease),
              margin-left .4s var(--ease), border-width .26s var(--ease);
}
/* Stack "más colores": MISMO tamaño que un swatch (38px); muestra varios
   colores ocultos APILADOS dentro del mismo diámetro. Al pulsarlo se
   despliega la paleta completa. NO hay flecha de volver: la paleta se
   auto-colapsa tras unos segundos de inactividad. */
.pstack {
  position: relative; flex: 0 0 auto; cursor: pointer; padding: 0;
  order: 9999;  /* los solapados van SIEMPRE como último elemento de la paleta */
  /* SIN círculo contenedor: los colores ocultos se muestran como discos del
     MISMO tamaño que un swatch (38px), simplemente PISADOS entre sí. */
  height: 38px; border: 0; background: none; overflow: visible;
  display: inline-flex; align-items: center; justify-content: center;
  max-width: 220px;
  transition: max-width .46s var(--spring), opacity .3s var(--ease), transform .26s var(--spring),
              margin-left .46s var(--spring);
}
.pstack__pile { display: inline-flex; align-items: center; transition: transform .26s var(--spring); }
.pstack__dot {
  /* Mismo diámetro que un swatch; se solapan ~16px (pisados). Aro fino del
     color papel para separarlos visualmente, sin contorno negro. */
  width: 38px; height: 38px; border-radius: 999px; border: 2px solid var(--paper);
  margin-left: -16px; box-shadow: 0 1px 3px rgba(21,19,15,0.18);
}
.pstack__dot:first-child { margin-left: 0; }
.pstack:hover { transform: translateY(-2px) scale(1.04); }
.pstack:hover .pstack__pile { transform: scale(1.04); }
.pstack:active { transform: scale(0.96); transition-duration: .12s; }
/* Expandido → todos los colores ya son visibles, así que el stack se oculta
   suavemente (magic-move): se funde, encoge y colapsa su espacio. */
.palette.is-expanded .pstack {
  max-width: 0; opacity: 0; transform: scale(0.3); margin-left: -10px;
  pointer-events: none; overflow: hidden;
}
@media (prefers-reduced-motion: reduce) {
  .swatch--extra, .palette.is-collapsed .swatch--extra, .pstack, .pstack__pile { transition: none; }
  .pstack:hover, .pstack:active { transform: none; }
}

/* --- Responsive fino ---------------------------------------- */
@media (max-width: 420px) {
  .stage { padding: 6px clamp(40px, 12vw, 52px); }
  .stage__svg { max-width: 300px; }
  .stage__svg svg { max-height: 58vh; }
  .palette { gap: 8px; }
}
@media (max-width: 360px) {
  .stage { padding: 4px 40px; }
  .stage__svg { max-width: 264px; }
}
