/**
 * WHILE YOU WAIT — isolated overlay + HUD (Etapa 1).
 * All selectors use .wyw- prefix; no global styles outside scroll-lock helpers.
 */

html.wyw-scroll-lock {
  overflow: hidden;
  height: 100dvh;
  overscroll-behavior: none;
}

body.wyw-scroll-lock {
  overflow: hidden;
  overscroll-behavior: none;
}

/* ——— Overlay shell ——— */

.wyw-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  min-height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  pointer-events: none;
  color: var(--color-text, rgba(244, 239, 228, 0.88));
  font-family: var(--font-body, "Inter", system-ui, -apple-system, "Segoe UI", sans-serif);
}

.wyw-overlay:not([hidden]),
.wyw-overlay.is-open {
  pointer-events: auto;
}

.wyw-overlay[hidden] {
  display: none !important;
}

.wyw-overlay__backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: var(--color-bg, #000);
  opacity: 0;
  transition: opacity 0.55s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1));
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: default;
}

.wyw-overlay.is-open .wyw-overlay__backdrop {
  opacity: 1;
}

.wyw-overlay__shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  max-height: 100dvh;
  max-height: 100svh;
  width: 100%;
  overflow: hidden;
  touch-action: pan-y;
  padding:
    max(env(safe-area-inset-top, 0px), 0.35rem)
    max(var(--page-pad, clamp(1.25rem, 5vw, 3rem)), env(safe-area-inset-right, 0px))
    max(env(safe-area-inset-bottom, 0px), 0.75rem)
    max(var(--page-pad, clamp(1.25rem, 5vw, 3rem)), env(safe-area-inset-left, 0px));
  box-sizing: border-box;
}

/* ——— HUD ——— */

.wyw-hud {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: clamp(0.75rem, 3vw, 1.5rem);
  flex-shrink: 0;
  padding-top: max(calc(var(--header-height, 4.25rem) * 0.15), 0.25rem);
  padding-bottom: clamp(0.65rem, 2vh, 1rem);
}

.wyw-hud__cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: clamp(1rem, 4vw, 2.25rem);
  min-width: 0;
}

.wyw-hud__stat {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 3.5rem;
}

.wyw-hud__label {
  font-size: clamp(0.58rem, 1.6vw, 0.68rem);
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-transform: uppercase;
  color: var(--color-text-muted, rgba(244, 239, 228, 0.46));
}

.wyw-hud__value {
  font-family: var(--font-display, "Bebas Neue", "Arial Narrow", "Helvetica Neue", sans-serif);
  font-size: clamp(1.75rem, 6vw, 2.35rem);
  line-height: 1;
  letter-spacing: 0.06em;
  color: var(--color-text, rgba(244, 239, 228, 0.88));
}

.wyw-hud__title {
  font-family: var(--font-display, "Bebas Neue", "Arial Narrow", "Helvetica Neue", sans-serif);
  font-size: clamp(1.1rem, 3.2vw, 1.45rem);
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  text-transform: uppercase;
  color: var(--color-text-muted, rgba(244, 239, 228, 0.46));
  align-self: center;
  margin-right: auto;
}

.wyw-hud__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.wyw-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0.45rem 0.85rem;
  font-family: var(--font-body, "Inter", system-ui, sans-serif);
  font-size: clamp(0.62rem, 1.8vw, 0.72rem);
  font-weight: 300;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  text-indent: 0.28em;
  color: var(--color-text-muted, rgba(244, 239, 228, 0.46));
  background: transparent;
  border: 1px solid var(--color-border, rgba(168, 188, 148, 0.14));
  cursor: pointer;
  transition:
    color 0.35s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1)),
    border-color 0.35s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1)),
    background 0.35s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1));
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.wyw-btn:hover,
.wyw-btn:focus-visible {
  color: var(--color-accent-hover, rgba(210, 228, 192, 0.92));
  border-color: rgba(186, 204, 168, 0.35);
  outline: none;
}

.wyw-btn--close {
  min-width: 44px;
  padding: 0.35rem;
  font-size: 1.35rem;
  line-height: 1;
  letter-spacing: 0;
  text-indent: 0;
  text-transform: none;
  border-color: transparent;
}

.wyw-btn--close:hover,
.wyw-btn--close:focus-visible {
  border-color: var(--color-border, rgba(168, 188, 148, 0.14));
}

.wyw-btn--primary {
  border-color: rgba(186, 204, 168, 0.28);
  color: var(--color-accent, rgba(186, 204, 168, 0.78));
}

.wyw-stage-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(0.45rem, 1.5vh, 0.75rem);
  position: relative;
}

/* ——— Opening message ——— */

.wyw-opening {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.55rem, 2.2vh, 0.85rem);
  padding: var(--page-pad, clamp(1.25rem, 5vw, 3rem));
  text-align: center;
  background: #000000;
  pointer-events: auto;
}

.wyw-opening[hidden] {
  display: none !important;
}

.wyw-opening__title {
  margin: 0;
  max-width: 18ch;
  font-family: var(--font-display, "Bebas Neue", "Arial Narrow", "Helvetica Neue", sans-serif);
  font-size: clamp(1.85rem, 7.2vw, 2.85rem);
  line-height: 1.05;
  letter-spacing: 0.14em;
  text-indent: 0.14em;
  text-transform: uppercase;
  color: var(--color-text, rgba(244, 239, 228, 0.88));
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 0.65s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1)),
    transform 0.65s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1));
}

.wyw-opening__subtitle {
  margin: 0 0 clamp(0.35rem, 1.5vh, 0.65rem);
  max-width: 22ch;
  font-family: var(--font-body, "Inter", system-ui, -apple-system, "Segoe UI", sans-serif);
  font-size: clamp(0.72rem, 2.1vw, 0.92rem);
  font-weight: 300;
  line-height: 1.45;
  letter-spacing: 0.04em;
  color: var(--color-text-muted, rgba(244, 239, 228, 0.42));
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 0.65s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1)),
    transform 0.65s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1));
}

.wyw-opening__start {
  margin-top: clamp(0.35rem, 1.8vh, 0.85rem);
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 0.55s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1)),
    transform 0.55s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1));
}

.wyw-overlay.is-opening .wyw-opening__title {
  opacity: 1;
  transform: none;
  transition-delay: 0.1s;
}

.wyw-overlay.is-opening .wyw-opening__subtitle {
  opacity: 1;
  transform: none;
  transition-delay: 0.28s;
}

.wyw-overlay.is-opening .wyw-opening__start {
  opacity: 1;
  transform: none;
  transition-delay: 0.46s;
}

.wyw-controls {
  --wyw-nav-icon-size: clamp(1.35rem, 5vw, 1.75rem);
  display: flex;
  justify-content: center;
  gap: clamp(1.25rem, 6vw, 2.5rem);
  flex-shrink: 0;
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 0.15rem);
  touch-action: manipulation;
}

.wyw-controls__btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  width: clamp(3.25rem, 14vw, 4.25rem);
  height: clamp(3.25rem, 14vw, 4.25rem);
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.wyw-controls__btn::after {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--wyw-nav-icon-size);
  height: var(--wyw-nav-icon-size);
  margin: auto;
  pointer-events: none;
  background-color: var(--color-text-muted, rgba(244, 239, 228, 0.46));
  -webkit-mask-image: url("/IMAGENES/flecha%201.png");
  mask-image: url("/IMAGENES/flecha%201.png");
  -webkit-mask-mode: luminance;
  mask-mode: luminance;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  mix-blend-mode: screen;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.wyw-controls__btn--next::after {
  transform: scaleX(-1);
}

.wyw-controls__btn--prev:hover::after,
.wyw-controls__btn--prev:focus-visible::after {
  transform: translateX(-2px);
}

.wyw-controls__btn--next:hover::after,
.wyw-controls__btn--next:focus-visible::after {
  transform: scaleX(-1) translateX(-2px);
}

.wyw-controls__btn:hover::after,
.wyw-controls__btn:focus-visible::after {
  background-color: var(--color-accent-hover, rgba(210, 228, 192, 0.92));
}

.wyw-controls__btn:focus-visible {
  outline: 1px solid color-mix(in srgb, var(--color-text, #f4efe4) 35%, transparent);
  outline-offset: 4px;
}

.wyw-controls__btn:active::after {
  background-color: var(--color-accent, rgba(186, 204, 168, 0.78));
}

@media (min-width: 900px) and (hover: hover) {
  .wyw-controls {
    opacity: 0.72;
  }
}

/* ——— Stage + canvas ——— */

.wyw-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  max-height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  border: 1px solid var(--color-border, rgba(168, 188, 148, 0.14));
  background: #000000;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  contain: strict;
}

.wyw-character {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  width: auto;
  height: auto;
  pointer-events: none;
  overflow: visible;
}

.wyw-canvas {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  max-height: 100%;
  touch-action: none;
  cursor: default;
  background: transparent;
}

.wyw-stage__hint {
  position: absolute;
  left: 50%;
  bottom: clamp(1rem, 4vh, 2rem);
  transform: translateX(-50%);
  font-size: clamp(0.58rem, 1.6vw, 0.68rem);
  letter-spacing: 0.38em;
  text-indent: 0.38em;
  text-transform: uppercase;
  color: var(--color-text-faint, rgba(244, 239, 228, 0.28));
  pointer-events: none;
  transition: opacity 0.4s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1));
}

.wyw-stage__hint[hidden] {
  display: none;
}

.wyw-overlay.is-game-over .wyw-stage__hint {
  opacity: 0;
}

.wyw-overlay__message {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: var(--page-pad, clamp(1.25rem, 5vw, 3rem));
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.45s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1));
  background: rgba(0, 0, 0, 0.42);
}

.wyw-overlay.is-game-over .wyw-overlay__message {
  opacity: 1;
  pointer-events: auto;
}

.wyw-overlay__message-title {
  font-family: var(--font-display, "Bebas Neue", "Arial Narrow", sans-serif);
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text, rgba(244, 239, 228, 0.88));
}

.wyw-overlay__message-kicker {
  font-size: clamp(0.58rem, 1.6vw, 0.68rem);
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-transform: uppercase;
  color: var(--color-text-muted, rgba(244, 239, 228, 0.46));
}

.wyw-overlay__try-again {
  margin-top: 0.5rem;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
}

.wyw-perfect-stack {
  position: absolute;
  top: clamp(1.5rem, 12vh, 3rem);
  left: 50%;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  pointer-events: none;
  opacity: 0;
  transform: translate3d(-50%, -6px, 0);
  transition: opacity 0.28s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1)),
    transform 0.28s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1));
}

.wyw-perfect-stack.is-visible {
  opacity: 1;
  transform: translate3d(-50%, 0, 0);
}

.wyw-perfect-stack__title {
  margin: 0;
  font-size: clamp(0.58rem, 1.6vw, 0.68rem);
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-transform: uppercase;
  color: var(--color-text-muted, rgba(244, 239, 228, 0.56));
}

.wyw-perfect-stack__bonus {
  margin: 0;
  font-family: var(--font-display, "Bebas Neue", "Arial Narrow", sans-serif);
  font-size: clamp(1.35rem, 4.5vw, 1.8rem);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(186, 204, 168, 0.92);
}

/* ——— Reduced motion ——— */

@media (prefers-reduced-motion: reduce) {
  .wyw-overlay__backdrop,
  .wyw-overlay__message,
  .wyw-stage__hint,
  .wyw-opening__title,
  .wyw-opening__subtitle,
  .wyw-opening__start,
  .wyw-perfect-stack {
    transition: none;
    opacity: 1;
    transform: none;
  }

  .wyw-perfect-stack {
    transform: translate3d(-50%, 0, 0);
  }
}

/* ——— Small screens ——— */

@media (max-width: 540px) {
  .wyw-hud {
    flex-wrap: wrap;
  }

  .wyw-hud__title {
    order: -1;
    width: 100%;
    text-align: center;
    margin-right: 0;
    margin-bottom: 0.15rem;
  }

  .wyw-hud__cluster {
    flex: 1;
  }

  .wyw-hud__actions {
    margin-left: auto;
  }
}

@media (orientation: landscape) and (max-height: 500px) and (hover: none) {
  .wyw-hud {
    padding-top: 0.15rem;
    padding-bottom: 0.35rem;
    gap: 0.5rem;
  }

  .wyw-hud__title {
    font-size: clamp(0.85rem, 2.5vw, 1rem);
  }

  .wyw-hud__value {
    font-size: clamp(1.35rem, 4.5vw, 1.75rem);
  }

  .wyw-stage-wrap {
    gap: 0.35rem;
  }

  .wyw-controls__btn {
    width: clamp(2.75rem, 10vw, 3.25rem);
    height: clamp(2.75rem, 10vw, 3.25rem);
    min-width: 44px;
    min-height: 44px;
  }

  .wyw-stage__hint {
    bottom: clamp(0.65rem, 2.5dvh, 1rem);
    font-size: clamp(0.52rem, 1.4vw, 0.62rem);
  }
}

@media (max-width: 390px) {
  .wyw-hud__cluster {
    gap: 0.75rem;
  }

  .wyw-btn--primary {
    padding-inline: 0.65rem;
    letter-spacing: 0.22em;
    text-indent: 0.22em;
  }
}
