:root {
  --page-bg: #ffffff;
  --page-ink: #050505;
  --footer-bg: #ffffff;
  --footer-ink: #050505;
  --panel-shadow: 0 22px 54px rgba(0, 0, 0, 0.16);
  --tap-size: 44px;
  --footer-panel-size: min(92vw, 420px);
  --toy-shadow-x: 0;
  --toy-shadow-y: 0;
  --toy-shadow-scale-x: 1;
  --toy-shadow-scale-y: 1;
  --toy-shadow-opacity: 0.28;
  --toy-glow: 0;
  --toy-secret-glow: 0;
  --toy-flare-opacity: 0.15;
  --secret-charge: 0;
  --secret-button-glow: 0;
  --joystick-x: 0;
  --joystick-y: 0;
  --joystick-tilt-x: 0;
  --joystick-tilt-y: 0;
  --joystick-wobble: 0;
  --joystick-scale: 1;
  --orb-shift-x: 0;
  --orb-shift-y: 0;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--page-ink);
  background: var(--page-bg);
  font-family: Arial, Helvetica, sans-serif;
}

a {
  color: inherit;
}

img,
video {
  display: block;
  max-width: 100%;
}

.portal-preview {
  min-height: clamp(520px, 68vh, 780px);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 20px;
  padding: clamp(20px, 3vw, 40px) 18px clamp(10px, 2vw, 24px);
  background: #ffffff;
}

.portal-kicker {
  margin: 0;
  color: #050505;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.orb-toy {
  width: min(76vw, 626px);
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.orb-toy__stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: clamp(348px, 54vw, 545px);
  perspective: 900px;
  animation: orb-idle-float 4.8s ease-in-out infinite;
}

.orb-toy__stage::before {
  content: "";
  position: absolute;
  z-index: 1;
  left: 42%;
  top: 54%;
  width: 38%;
  aspect-ratio: 1;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  /* Blue secret-charge ring deleted per Kenny 2026-05-17. Green flare (.orb-toy__flare)
     still carries the wiggle feedback via --toy-secret-glow driving its opacity + scale (see line ~186).
     Single-color cohesion; no competing blue layer. */
  opacity: 0;
  box-shadow: none;
}

.orb-toy__orb-wrap {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 675px;
  /* translate (not translate3d) + no will-change → no GPU layer promotion → no compositor edge. */
  transform:
    translate(calc(var(--orb-shift-x) * 1px), calc(var(--orb-shift-y) * 1px))
    rotate(calc(var(--orb-wobble, 0) * 1deg));
  transform-origin: 50% 54%;
}

.orb-toy__orb {
  width: 100%;
  height: auto;
  /* NO filter — structurally eliminates the WebKit GPU-compositor-layer that was creating the seam.
     Glow visual lives entirely on .orb-toy__stage::before (CSS box-shadow on a pseudo-element).
     Sources: WebKit #158807, agent research 2026-05-15. */
}

/* Safari-targeted sub-pixel fringe trim (Next.js issue #40615 fix pattern).
   Chops the 0.5px sub-pixel artifact that appears on 3x iPhone displays when
   fractional CSS pixels resolve into a single visible physical pixel. */
@supports (-webkit-touch-callout: none) {
  .orb-toy__orb {
    clip-path: inset(0.5px);
  }
}

.orb-toy__shadow {
  display: none;
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: clamp(18px, 5vw, 38px);
  width: clamp(120px, 30vw, 225px);
  height: clamp(20px, 4.5vw, 34px);
  border-radius: 999px;
  background:
    radial-gradient(ellipse at center,
      rgba(0, 0, 0, 0.28) 0%,
      rgba(0, 0, 0, 0.16) 38%,
      rgba(0, 0, 0, 0) 72%);
  filter: blur(8px);
  opacity: var(--toy-shadow-opacity);
  transform:
    translate3d(
      calc(-50% + (var(--toy-shadow-x) * 1px)),
      calc(var(--toy-shadow-y) * 1px),
      0
    )
    scaleX(var(--toy-shadow-scale-x))
    scaleY(var(--toy-shadow-scale-y));
  transform-origin: center;
  pointer-events: none;
  will-change: transform, opacity;
}

.orb-toy__flare {
  position: absolute;
  z-index: 3;
  left: 42%;
  top: 58%;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 999px;
  background:
    radial-gradient(circle,
      rgba(198, 255, 207, 0.98) 0%,
      rgba(67, 255, 98, 0.72) 28%,
      rgba(67, 255, 98, 0.18) 52%,
      rgba(67, 255, 98, 0) 74%);
  filter: blur(2px);
  mix-blend-mode: screen;
  opacity: calc(var(--toy-flare-opacity) + (var(--toy-glow) * 0.22) + (var(--toy-secret-glow) * 0.92));
  transform: translate3d(-50%, -50%, 0) scale(calc(0.74 + (var(--toy-glow) * 0.2) + (var(--toy-secret-glow) * 1.8)));
  pointer-events: none;
  will-change: transform, opacity;
}

.orb-toy.is-flaring .orb-toy__flare {
  animation: orb-flare-pop 620ms ease-out;
}

.footer-isolation {
  min-height: clamp(12px, 3vw, 36px);
  background: #ffffff;
}

.footer-isolation--bottom {
  min-height: clamp(128px, 24vw, 220px);
}

.arcade-footer {
  position: relative;
  z-index: 1;
  padding: 22px 10px 22px;
  color: var(--footer-ink);
  background: var(--footer-bg);
}

.arcade-footer.footer--sticky {
  position: sticky;
  bottom: 0;
}

.arcade-footer__inner {
  width: min(100%, 560px);
  min-height: auto;
  margin: 0 auto;
  display: grid;
  grid-template-areas:
    "panel panel"
    "joystick coin";
  grid-template-columns: minmax(110px, 1fr) minmax(120px, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  justify-content: center;
  gap: 8px 22px;
}

.arcade-control {
  display: grid;
  place-items: center;
  min-width: var(--tap-size);
  min-height: var(--tap-size);
  border-radius: 8px;
  text-decoration: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.arcade-control:focus-visible,
.ArcadeButton:focus-visible {
  outline: 3px solid #ffce31;
  outline-offset: 5px;
}

.coin-slot {
  grid-area: coin;
  position: relative;
  justify-self: end;
  align-self: center;
  width: min(32.13vw, 118px);
  grid-template-rows: auto auto;
  margin-bottom: 0;
}

.coin-slot__insert {
  width: 94%;
  filter: drop-shadow(0 8px 15px rgba(0, 0, 0, 0.11)) saturate(1.33) brightness(1.04);
}

.coin-slot__crab {
  position: absolute;
  left: 17%;
  bottom: 18%;
  width: 66%;
  max-width: none;
  filter: drop-shadow(0 5px 0 rgba(0, 0, 0, 0.05));
}

button.joystick-control {
  background: none;
  border: none;
  padding: 0;
  cursor: default;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: none;
}

.joystick-control {
  grid-area: joystick;
  justify-self: start;
  align-self: center;
  width: min(39.6vw, 145px);
  margin-top: 0;
  touch-action: none;
}

.joystick-control__image {
  width: 100%;
  transform-origin: 48% 70%;
  filter: drop-shadow(0 8px 15px rgba(0, 0, 0, 0.11)) saturate(1.05);
  transform:
    translate3d(calc(var(--joystick-x) * 1px), calc(var(--joystick-y) * 1px), 0)
    rotateX(calc(var(--joystick-tilt-x) * 1deg))
    rotateY(calc(var(--joystick-tilt-y) * 1deg))
    rotateZ(calc(var(--joystick-wobble) * 1deg))
    scale(var(--joystick-scale))
    rotate(0deg);
  transition: filter 160ms ease;
  will-change: transform, filter;
}

.button-panel {
  grid-area: panel;
  position: relative;
  justify-self: center;
  align-self: start;
  width: var(--footer-panel-size);
  aspect-ratio: 1;
  margin-top: 0;
  filter: drop-shadow(var(--panel-shadow));
}

.button-panel__base {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.button-panel__buttons {
  position: absolute;
  inset: 0;
}

.ArcadeButton {
  /* B8 press-dip mechanics locked 2026-05-17 — see /v/button-led-stage/ history */
  --dip: 6px;
  --scl: 0.96;
  --shadow-a: 0.44;
  --overshoot: 3px;
  --press-dur: 62ms;
  --return-dur: 130ms;
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 999px;
  transform-origin: 50% 50%;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.ArcadeButton img {
  width: var(--image-w, 100%);
  height: auto;
  max-width: none;
  pointer-events: none;
  transform-origin: center;
}

/* B8 press: cap dips into recess via inset shadow + slight scale shrink */
.ArcadeButton:active {
  transition: transform var(--press-dur) ease-out, box-shadow var(--press-dur) ease-out;
  transform: translateY(var(--dip)) scale(var(--scl));
  box-shadow: inset 0 var(--dip) calc(var(--dip) * 2) rgba(0, 0, 0, var(--shadow-a));
}

/* B8 release: bounce-back snap (overshoots 3px UP then settles) */
.ArcadeButton.releasing {
  animation: ArcadeButton-bounce-release var(--return-dur) cubic-bezier(0.3, 0.9, 0.4, 1) forwards;
}
@keyframes ArcadeButton-bounce-release {
  0%   { transform: translateY(var(--dip)) scale(var(--scl)); box-shadow: inset 0 var(--dip) calc(var(--dip) * 2) rgba(0,0,0,var(--shadow-a)); }
  55%  { transform: translateY(calc(var(--overshoot) * -1)) scale(1.01); box-shadow: inset 0 0 0 rgba(0,0,0,0); }
  100% { transform: translateY(0) scale(1); box-shadow: inset 0 0 0 rgba(0,0,0,0); }
}

/* Coin slot keeps its existing hover effect */
.coin-slot:hover img {
  transform: scale(1.06);
}

.ArcadeButton--secret {
  border-radius: 999px;
}

.ArcadeButton--secret::before,
.ArcadeButton--secret::after {
  position: absolute;
  inset: -12%;
  border-radius: inherit;
  content: "";
  opacity: 0;
  pointer-events: none;
}

.ArcadeButton--secret::before {
  background:
    radial-gradient(circle,
      rgba(188, 255, 205, 0.78) 0%,
      rgba(64, 255, 112, 0.45) 36%,
      rgba(64, 255, 112, 0) 72%);
  filter: blur(4px);
  opacity: 0;
  transform: scale(0.78);
}

.ArcadeButton--secret::after {
  inset: 18%;
  background: #5cff7a;
  box-shadow:
    0 0 4px rgba(79, 255, 117, 0.75),
    0 0 0px rgba(79, 255, 117, 0.35);
  opacity: 0;
  transform: scale(0.2);
}

.ArcadeButton--secret.is-secret-locked {
  cursor: default;
  pointer-events: none;
}

.ArcadeButton--secret.is-secret-unlocked {
  cursor: pointer;
  pointer-events: auto;
}

.ArcadeButton--secret.is-secret-unlocked::before {
  animation: secret-button-flash 0.18s ease-out 1 forwards;  /* Kenny 2026-05-18: imperceptible level — duration 0.35→0.18s */
}

.ArcadeButton--secret.is-secret-unlocked::after {
  animation: secret-button-flash-after 0.18s ease-out 1 forwards;
}

/* Kenny 2026-05-18 imperceptible-spec (5/5 quietest): sound carries the unlock entirely.
   Visual exists code-wise for accessibility / state-change semantics only. Peak opacity 0.06/0.03,
   NO scale growth — same-size flash at near-zero intensity. "Did I see something?" effect. */
@keyframes secret-button-flash {
  0%   { opacity: 0;    transform: scale(1); }
  35%  { opacity: 0.06; transform: scale(1); }
  100% { opacity: 0;    transform: scale(1); }
}

@keyframes secret-button-flash-after {
  0%   { opacity: 0;    transform: scale(0.5); }
  35%  { opacity: 0.03; transform: scale(0.5); }
  100% { opacity: 0;    transform: scale(0.5); }
}

.is-tilting {
  animation: arcade-tilt 420ms ease;
}

.is-tilting img {
  filter: saturate(1.14) contrast(1.04);
}

.is-bouncing {
  animation: arcade-bounce 580ms ease;
}

.is-pressing img {
  animation: arcade-press 580ms ease;
}

.arcade-footer__meta {
  display: grid;
  place-items: center;
  padding-top: 0;
  padding-bottom: 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  text-align: center;
}

.arcade-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.arcade-status.is-live {
  animation: readout-pulse 360ms ease;
}

@keyframes arcade-tilt {
  0% { transform: rotate(0deg) scale(1); }
  22% { transform: rotate(5deg) scale(0.99); }
  48% { transform: rotate(-5deg) scale(1.01); }
  72% { transform: rotate(2deg) scale(1); }
  100% { transform: rotate(0deg) scale(1); }
}

@keyframes arcade-bounce {
  0%, 100% { transform: translateY(0); }
  24% { transform: translateY(-12px); }
  48% { transform: translateY(0); }
  72% { transform: translateY(-6px); }
}

@keyframes arcade-press {
  0%, 100% { transform: scale(1) rotate(0deg); }
  20% { transform: scale(0.86) rotate(3deg); }
  50% { transform: scale(1.08) rotate(-5deg); }
  76% { transform: scale(0.98) rotate(2deg); }
}

@keyframes readout-pulse {
  0%, 100% { color: #00f090; box-shadow: none; }
  45% { color: #ffffff; box-shadow: 0 0 18px rgba(0, 240, 144, 0.45); }
}

@keyframes orb-idle-float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  35% { transform: translateY(-3px) rotate(0.2deg); }
  70% { transform: translateY(2px) rotate(-0.15deg); }
}

@keyframes orb-flare-pop {
  0% { opacity: 0.15; transform: translate3d(-50%, -50%, 0) scale(0.65); }
  28% { opacity: 0.95; transform: translate3d(-50%, -50%, 0) scale(1.32); }
  100% { opacity: 0; transform: translate3d(-50%, -50%, 0) scale(1.75); }
}

@keyframes secret-button-awake {
  0%, 100% { transform: scale(0.9); filter: blur(4px); }
  50% { transform: scale(1.12); filter: blur(5px); }
}

@media (min-width: 861px) {
  :root {
    /* Path C 2026-05-16: button panel -5% (519 → 493) as first step; JS scaler handles the rest. */
    --footer-panel-size: min(54vw, 660px);
  }

  /* Path C desktop layout:
     - body flex-centers vertically so tall viewports get breathing room above + below
     - portal-preview top padding bumped (Kenny wants more room above orb)
     - JS scaler (script.js fitDesktop) auto-shrinks page to viewport with floor 0.82 */
  body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
  }

  .portal-preview {
    padding: 24px 18px 8px;
    min-height: auto;
  }

  .orb-toy__stage {
    min-height: auto;
  }

  .footer-isolation {
    min-height: 4px;
  }

  .footer-isolation--bottom {
    min-height: 20px;
  }

  .arcade-footer {
    padding: 10px 16px 14px;
  }

  .arcade-footer__inner {
    /* Right-cluster cockpit layout: joystick alone on LEFT (breathing room),
       panel + coin tight on RIGHT (action cluster). Mimics real arcade
       cabinet where coin slot sits adjacent to action buttons, not spaced apart.
       Composition: orb hero centered above, asymmetric controls below. */
    width: min(1200px, 100%);
    min-height: auto;
    grid-template-areas: "joystick panel coin";
    grid-template-columns: minmax(170px, 280px) var(--footer-panel-size) minmax(120px, 200px);
    grid-template-rows: auto;
    align-items: center;
    justify-content: end;
    column-gap: 0;
  }

  .coin-slot {
    grid-area: coin;
    justify-self: start;  /* hug panel on the left */
    align-self: center;
    width: clamp(107px, 14.54vw, 146px);
    margin-left: clamp(8px, 1vw, 20px);
  }

  .coin-slot__insert {
    width: 100%;
    filter: drop-shadow(0 8px 15px rgba(0, 0, 0, 0.11)) saturate(1.33) brightness(1.04);
  }

  .coin-slot__crab {
    left: 17%;
    bottom: 18%;
    width: 66%;
    max-width: none;
  }

  .joystick-control {
    grid-area: joystick;
    justify-self: end;  /* push joystick toward panel side */
    align-self: center;
    width: clamp(141px, 21.45vw, 252px);
    margin-right: clamp(28px, 5vw, 78px);  /* −12px from prior (Kenny: nudge joystick right) */
  }

  .button-panel {
    grid-area: panel;
    justify-self: center;
    align-self: center;
    margin-left: 6px;  /* Kenny: nudge panel ~6px right */
  }

  .arcade-footer__meta {
    padding-top: 26px;
    padding-bottom: 10px;
  }
}

@media (max-width: 860px) {
  .portal-preview {
    min-height: 0;
    padding-top: 12px;
    padding-bottom: 8px;
  }

  .arcade-footer {
    padding: 12px 10px 14px;
  }

  .orb-toy {
    width: min(78vw, 362px);
  }

  .orb-toy__stage {
    min-height: clamp(220px, 60vw, 310px);
  }

  .arcade-footer__inner {
    width: min(78vw, 306px);
    grid-template-columns: 60fr 40fr;
    gap: 10px 0;
    align-items: center;
  }

  .joystick-control {
    justify-self: end;
    align-self: center;
  }

  .coin-slot {
    justify-self: end;
    align-self: center;
  }
}

@media (max-width: 430px) {
  .portal-preview {
    min-height: 0;
    padding-top: 6px;  /* −4px per Kenny 2026-05-17 — tighter mobile comp */
    padding-bottom: 2px;
  }

  .arcade-footer {
    padding: 4px 10px 8px;
  }

  .footer-isolation {
    min-height: 2px;  /* −4px per Kenny — tighten pokeball→panel gap */
  }

  .footer-isolation--bottom {
    min-height: 24px;  /* Kenny 2026-05-17: was clamp(128px, 24vw, 220px) — reclaimed ~104px of dead space on mobile to kill scroll */
  }

  .orb-toy {
    width: min(80vw, 306px);
  }

  .orb-toy__stage {
    min-height: 190px;  /* −60px from 250 per Kenny 2026-05-17 — tighter mobile comp (was 210) */
  }

  .arcade-footer {
    padding-inline: 10px;
  }

  .arcade-footer__inner {
    gap: 15px 10px;  /* +5% (14→15) to scale with panel +5% — Kenny 2026-05-17 */
  }

  .coin-slot {
    width: min(26.03vw, 95px);
    margin-bottom: 0;
    margin-top: 0;
    margin-right: 4px;  /* −4px left per Kenny */
  }

  .coin-slot__crab {
    left: 17%;
    bottom: 18%;
    width: 66%;
  }

  .joystick-control {
    width: min(35vw, 130px);
    margin-top: 0;
    justify-self: start;  /* Kenny 2026-05-18: override inherited "end" — was eating all margin-left shifts */
    margin-left: 10px;    /* light inset — joystick.left ~10px right of panel.left for breathing room (Kenny 2026-05-18) */
    align-self: start;
  }

  .button-panel {
    width: min(89.25vw, 352px);  /* +5% per Kenny 2026-05-17 (was 85vw/335px) */
    margin-top: 2px;  /* −4px per Kenny — tighten pokeball→panel gap */
  }
}

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