/* ============================================
   Sparkle Runner — Side-Scrolling Platformer
   ============================================ */

.runner-world {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  contain: layout style paint;
}

/* ---- Parallax Background Layers ---- */

.runner-bg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;
  height: 100%;
  will-change: transform;
  pointer-events: none;
}

.runner-bg-layer[data-depth="0"] {
  z-index: 0;
}
.runner-bg-layer[data-depth="1"] {
  z-index: 1;
}
.runner-bg-layer[data-depth="2"] {
  z-index: 2;
}
.runner-bg-layer[data-depth="3"] {
  z-index: 3;
}

/* ---- Character ---- */

.runner-character {
  position: absolute;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--char-color, var(--color-mira));
  display: grid;
  place-items: center;
  transform: translate3d(var(--cx, 0px), var(--cy, 0px), 0);
  will-change: transform;
  z-index: 10;
  box-shadow: 0 0 12px 4px color-mix(in srgb, var(--char-color, var(--color-mira)) 40%, transparent);
  pointer-events: none;
}

.runner-char-initial {
  font-weight: var(--weight-heading);
  font-size: 1.25rem;
  color: var(--text-primary);
  text-shadow: 0 1px 2px var(--black-30);
  line-height: var(--leading-none);
}

/* ---- Ground ---- */

.runner-ground {
  position: absolute;
  left: 0;
  height: 120px;
  background: linear-gradient(180deg, #3a2580 0%, var(--bg-secondary) 8%, #1e1250 100%);
  transform: translate3d(var(--gx, 0px), var(--gy, 0px), 0);
  will-change: transform;
  z-index: 4;
}

/* ---- Platforms ---- */

.runner-platform {
  position: absolute;
  height: 16px;
  border-radius: 8px;
  background: linear-gradient(180deg, #5a3db8 0%, #3a2580 40%, var(--bg-secondary) 100%);
  box-shadow: 0 2px 6px var(--black-40);
  transform: translate3d(var(--px, 0px), var(--py, 0px), 0);
  will-change: transform;
  z-index: 5;
}

/* ---- Decorations ---- */

.runner-decoration {
  position: absolute;
  transform: translate3d(var(--dx, 0px), var(--dy, 0px), 0);
  will-change: transform;
  z-index: 5;
  pointer-events: none;
}

/* Flower — small circle on a thin stem */
.runner-deco-flower {
  border-radius: 50%;
  background: var(--deco-color, #ff85c8);
  box-shadow: 0 0 6px 2px rgba(255, 133, 200, 0.3);
}

.runner-deco-flower::after {
  content: "";
  position: absolute;
  bottom: -60%;
  left: 50%;
  width: 2px;
  height: 60%;
  background: #4a9e6a;
  transform: translateX(-50%);
}

/* Bush — wide rounded blob */
.runner-deco-bush {
  border-radius: 50% 50% 40% 40%;
  background: var(--deco-color, #2e7d4a);
  box-shadow: inset 0 -4px 8px var(--black-20);
}

/* Tree — triangle canopy on trunk */
.runner-deco-tree {
  background: none;
}

.runner-deco-tree::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 20%;
  height: 40%;
  background: #5a3d2b;
  transform: translateX(-50%);
  border-radius: 2px;
}

.runner-deco-tree::after {
  content: "";
  position: absolute;
  top: 0;
  left: 10%;
  width: 80%;
  height: 65%;
  background: var(--deco-color, #2a6e3f);
  border-radius: 50% 50% 30% 30%;
  box-shadow: inset 0 -6px 10px var(--black-15);
}

/* Mushroom — round cap on short stem */
.runner-deco-mushroom {
  background: none;
}

.runner-deco-mushroom::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 30%;
  height: 40%;
  background: #e8dcc8;
  transform: translateX(-50%);
  border-radius: 2px;
}

.runner-deco-mushroom::after {
  content: "";
  position: absolute;
  top: 0;
  left: 5%;
  width: 90%;
  height: 55%;
  background: var(--deco-color, #e74c6f);
  border-radius: 50% 50% 20% 20%;
  box-shadow: inset 0 -4px 6px var(--black-15);
}

/* ---- Collectible Sparkles ---- */

.runner-sparkle {
  position: absolute;
  width: 20px;
  height: 20px;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  background: var(--sparkle-color, #ffd700);
  box-shadow: 0 0 8px 3px var(--gold-40);
  transform: translate3d(var(--sx, 0px), var(--sy, 0px), 0);
  will-change: transform;
  z-index: 7;
  pointer-events: none;
  animation: runner-sparkle-float 2s ease-in-out infinite alternate;
}

.runner-big-sparkle {
  width: 32px;
  height: 32px;
  box-shadow: 0 0 14px 5px var(--gold-60);
  animation:
    runner-sparkle-float 2s ease-in-out infinite alternate,
    runner-sparkle-pulse 1.5s ease-in-out infinite;
}

.runner-sparkle.collected {
  animation: runner-sparkle-burst 400ms ease-out forwards;
}

@keyframes runner-sparkle-float {
  from {
    transform: translate3d(var(--sx, 0px), var(--sy, 0px), 0);
  }
  to {
    transform: translate3d(var(--sx, 0px), calc(var(--sy, 0px) - 4px), 0);
  }
}

@keyframes runner-sparkle-pulse {
  0%,
  100% {
    box-shadow: 0 0 14px 5px var(--gold-60);
  }
  50% {
    box-shadow: 0 0 20px 8px var(--gold-80);
  }
}

@keyframes runner-sparkle-burst {
  0% {
    transform: translate3d(var(--sx, 0px), var(--sy, 0px), 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--sx, 0px), var(--sy, 0px), 0) scale(2.5);
    opacity: 0;
  }
}

/* ---- HUD ---- */

.runner-hud {
  position: absolute;
  top: 64px; /* 48px mobile header + 16px gap */
  right: 12px;
  z-index: 20;
  pointer-events: none;
}

@media (min-width: 600px) {
  .runner-hud {
    top: 72px; /* 56px tablet header + 16px gap */
    right: 16px;
  }
}

.runner-sparkle-counter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: var(--weight-heading);
  font-size: var(--text-lg);
  color: var(--text-gold);
  text-shadow: 0 1px 3px var(--black-50);
}

.runner-sparkle-icon {
  width: 20px;
  height: 20px;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  background: var(--text-gold);
  flex-shrink: 0;
}

.runner-sparkle-counter.bump {
  animation: runner-counter-bump 300ms ease-out;
}

@keyframes runner-counter-bump {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
  }
}

/* ---- Demons ---- */

.runner-demon {
  position: absolute;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--demon-color, #e74c3c);
  display: grid;
  place-items: center;
  box-shadow: 0 0 16px 6px color-mix(in srgb, var(--demon-color, #e74c3c) 50%, transparent);
  transform: translate3d(var(--demon-x, 0px), var(--demon-y, 0px), 0);
  will-change: transform;
  z-index: 8;
  pointer-events: none;
  animation: runner-demon-idle 1s ease-in-out infinite alternate;
}

.runner-demon-initial {
  font-weight: var(--weight-heading);
  font-size: 1.5rem;
  color: var(--text-primary);
  text-shadow: 0 1px 2px var(--black-30);
  line-height: var(--leading-none);
}

@keyframes runner-demon-idle {
  from {
    transform: translate3d(var(--demon-x, 0px), var(--demon-y, 0px), 0) scale(1);
  }
  to {
    transform: translate3d(var(--demon-x, 0px), var(--demon-y, 0px), 0) scale(1.08);
  }
}

/* ---- Level Complete ---- */

.runner-complete-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-primary-88);
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  animation: runner-fade-in 0.4s ease-out;
}

.runner-complete-banner {
  font-weight: var(--weight-heading);
  font-size: var(--text-2xl);
  color: var(--text-gold);
  letter-spacing: var(--tracking-wide);
  text-shadow:
    0 0 24px var(--gold-70),
    0 0 48px var(--gold-30),
    0 2px 8px var(--black-50);
  animation: runner-banner-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.runner-sparkle-tally {
  font-weight: var(--weight-body);
  font-size: var(--text-lg);
  color: var(--text-gold);
  text-shadow: 0 1px 4px var(--black-40);
  animation: runner-fade-in 0.4s 0.5s ease-out both;
}

.runner-xp-line {
  font-weight: var(--weight-body);
  font-size: var(--text-md);
  color: var(--color-mint);
  animation: runner-fade-in 0.4s 0.7s ease-out both;
}

.runner-levelup-line {
  font-weight: var(--weight-heading);
  font-size: var(--text-lg);
  color: var(--color-mira);
  animation: runner-banner-in 0.6s 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.runner-complete-btn {
  font-weight: var(--weight-heading);
  font-size: var(--text-md);
  color: var(--bg-primary);
  background: linear-gradient(135deg, var(--color-mira), var(--color-rumi));
  border: none;
  border-radius: var(--border-radius-lg);
  padding: var(--space-md) var(--space-xl);
  min-height: 44px;
  min-width: 44px;
  box-shadow:
    0 0 16px rgba(255, 105, 180, 0.4),
    0 4px 12px var(--black-30);
  animation: runner-fade-in 0.4s 1s ease-out both;
}

@keyframes runner-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes runner-banner-in {
  from {
    transform: scale(0.3);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ---- Particles ---- */

.runner-dust {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--white-50);
  transform: translate3d(var(--px, 0px), var(--py, 0px), 0);
  z-index: 9;
  pointer-events: none;
  animation: runner-dust-fade 400ms ease-out forwards;
}

@keyframes runner-dust-fade {
  0% {
    transform: translate3d(var(--px, 0px), var(--py, 0px), 0) scale(1);
    opacity: 0.6;
  }
  100% {
    transform: translate3d(var(--px, 0px), calc(var(--py, 0px) - 12px), 0) scale(0.3);
    opacity: 0;
  }
}

.runner-burst-particle {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-gold);
  box-shadow: 0 0 4px 1px var(--gold-50);
  transform: translate3d(var(--px, 0px), var(--py, 0px), 0);
  z-index: 9;
  pointer-events: none;
  animation: runner-burst-out 400ms ease-out forwards;
}

@keyframes runner-burst-out {
  0% {
    transform: translate3d(var(--px, 0px), var(--py, 0px), 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate3d(calc(var(--px, 0px) + var(--burst-x, 0px)), calc(var(--py, 0px) + var(--burst-y, 0px)), 0)
      scale(0.3);
    opacity: 0;
  }
}

.runner-land-ring {
  position: absolute;
  width: 40px;
  height: 40px;
  margin-left: -20px;
  margin-top: -20px;
  border-radius: 50%;
  border: 2px solid var(--white-50);
  transform: translate3d(var(--px, 0px), var(--py, 0px), 0) scale(0.5);
  z-index: 9;
  pointer-events: none;
  animation: runner-ring-fade 400ms ease-out forwards;
}

@keyframes runner-ring-fade {
  0% {
    transform: translate3d(var(--px, 0px), var(--py, 0px), 0) scale(0.5);
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--px, 0px), var(--py, 0px), 0) scale(1.3);
    opacity: 0;
  }
}

/* ---- Ambient Sparkles ---- */

.runner-ambient-sparkles {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.runner-ambient-particle {
  position: absolute;
  left: var(--x, 50%);
  top: var(--y, 50%);
  width: var(--size, 3px);
  height: var(--size, 3px);
  border-radius: 50%;
  background: var(--gold-60);
  pointer-events: none;
  opacity: 0;
  animation: runner-ambient-float var(--duration, 6s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

@keyframes runner-ambient-float {
  0% {
    transform: translate(0, 0);
    opacity: 0;
  }
  15% {
    opacity: 0.7;
  }
  85% {
    opacity: 0.7;
  }
  100% {
    transform: translate(var(--drift-x, 0px), -40px);
    opacity: 0;
  }
}

/* ---- Animation States ---- */

.runner-character.running {
  animation: runner-bob 0.4s ease-in-out infinite alternate;
}

.runner-character.jumping {
  animation: none;
}

.runner-character.falling {
  animation: none;
}

@keyframes runner-bob {
  from {
    transform: translate3d(var(--cx, 0px), var(--cy, 0px), 0);
  }
  to {
    transform: translate3d(var(--cx, 0px), calc(var(--cy, 0px) - 2px), 0);
  }
}

/* ---- Squash & Stretch ---- */

.runner-character.squash {
  animation: runner-squash 150ms ease-out forwards;
}

.runner-character.stretch {
  animation: runner-stretch 150ms ease-out forwards;
}

@keyframes runner-squash {
  0% {
    transform: translate3d(var(--cx, 0px), var(--cy, 0px), 0) scale(1, 1);
  }
  50% {
    transform: translate3d(var(--cx, 0px), var(--cy, 0px), 0) scale(1.2, 0.85);
  }
  100% {
    transform: translate3d(var(--cx, 0px), var(--cy, 0px), 0) scale(1, 1);
  }
}

@keyframes runner-stretch {
  0% {
    transform: translate3d(var(--cx, 0px), var(--cy, 0px), 0) scale(1, 1);
  }
  50% {
    transform: translate3d(var(--cx, 0px), var(--cy, 0px), 0) scale(0.85, 1.2);
  }
  100% {
    transform: translate3d(var(--cx, 0px), var(--cy, 0px), 0) scale(1, 1);
  }
}

/* ---- Level Select ---- */

.level-select-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  padding: var(--space-lg) var(--space-md);
  max-width: 480px;
  margin: 0 auto;
}

.level-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-height: 84px;
  padding: var(--space-md);
  border-radius: var(--border-radius-md);
  border: 2px solid var(--white-20);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-weight: 800;
  font-size: var(--text-lg);
  text-align: left;
}

.level-card:active {
  transform: scale(0.97);
}

.level-card.level-locked {
  opacity: 0.4;
  pointer-events: none;
  filter: grayscale(0.6);
}

.level-card.level-completed {
  border-color: var(--gold-40);
  box-shadow: 0 0 16px var(--gold-20);
}

.level-card-number {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--white-15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
  flex-shrink: 0;
}

.level-card-info {
  flex: 1;
  min-width: 0;
}

.level-card-name {
  display: block;
}

.level-card-sparkles {
  display: block;
  font-size: var(--text-sm);
  color: var(--text-gold);
  margin-top: 2px;
}

.level-card-status {
  font-size: var(--text-lg);
  flex-shrink: 0;
}

/* ── Phase 8: Double Jump ── */

.runner-double-burst {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-double-jump);
  box-shadow: 0 0 6px 2px color-mix(in srgb, var(--color-double-jump) 60%, transparent);
  transform: translate3d(var(--px, 0px), var(--py, 0px), 0);
  z-index: 9;
  pointer-events: none;
  animation: runner-burst-out 400ms ease-out forwards;
}

.runner-dj-indicator {
  font-weight: var(--weight-heading);
  font-size: var(--text-xs);
  color: var(--color-double-jump);
  background: color-mix(in srgb, var(--color-double-jump) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-double-jump) 40%, transparent);
  border-radius: var(--border-radius-sm);
  padding: 2px 8px;
  margin-top: 6px;
  text-align: center;
  transition: opacity var(--duration-fast) var(--ease-out-quart);
}

.runner-dj-indicator.used {
  opacity: 0.3;
}

/* ── Phase 8: Purification Zones ── */

.runner-purified-zone {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--zone-w, 1000px);
  height: 100%;
  transform: translate3d(var(--zone-x, 0px), 0, 0);
  will-change: transform;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(
    ellipse 50% 80% at 50% 60%,
    rgba(168, 230, 207, 0.18) 0%,
    rgba(255, 182, 255, 0.1) 40%,
    transparent 70%
  );
  mix-blend-mode: screen;
}

.runner-purified-zone.appearing {
  animation: runner-purify-in 0.8s ease-out;
}

@keyframes runner-purify-in {
  0% {
    opacity: 0;
    transform: translate3d(var(--zone-x, 0px), 0, 0) scale(0.8);
  }
  100% {
    opacity: 1;
    transform: translate3d(var(--zone-x, 0px), 0, 0) scale(1);
  }
}

.runner-purified-sparkle {
  position: absolute;
  left: var(--zs-x, 50%);
  top: var(--zs-y, 50%);
  width: var(--zs-size, 3px);
  height: var(--zs-size, 3px);
  border-radius: 50%;
  background: rgba(168, 230, 207, 0.7);
  pointer-events: none;
  opacity: 0;
  animation: runner-purified-float var(--zs-duration, 5s) ease-in-out infinite;
  animation-delay: var(--zs-delay, 0s);
}

@keyframes runner-purified-float {
  0% {
    transform: translate(0, 0);
    opacity: 0;
  }
  20% {
    opacity: 0.8;
  }
  80% {
    opacity: 0.8;
  }
  100% {
    transform: translate(0, -30px);
    opacity: 0;
  }
}

/* ---- Level Select — Responsive ---- */

@media (min-width: 600px) {
  .level-select-container {
    max-width: 560px;
    padding: var(--space-xl) var(--space-lg);
  }

  .level-card {
    min-height: 96px;
  }

  .level-card-number {
    width: 60px;
    height: 60px;
  }
}

@media (min-width: 900px) {
  .level-select-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    max-width: 760px;
    gap: var(--space-md);
  }
}

/* ---- Landscape / Short Viewports ---- */

@media (orientation: landscape) and (max-height: 500px) {
  .runner-hud {
    top: 56px; /* 48px header + 8px gap — tighter in landscape */
    right: calc(env(safe-area-inset-right) + 12px);
  }

  .runner-complete-overlay {
    gap: 8px;
  }

  .runner-complete-banner {
    font-size: var(--text-xl);
  }

  .runner-complete-btn {
    padding: 8px 24px;
  }

  .runner-sparkle-tally,
  .runner-xp-line,
  .runner-levelup-line {
    font-size: var(--text-sm);
  }
}

/* ---- Reduced Motion ---- */

@media (prefers-reduced-motion: reduce) {
  .runner-character.running {
    animation: none;
  }
  .runner-sparkle {
    animation: none;
  }
  .runner-big-sparkle {
    animation: none;
  }
  .runner-sparkle.collected {
    animation: none;
    opacity: 0;
  }
  .runner-sparkle-counter.bump {
    animation: none;
  }
  .runner-demon {
    animation: none;
  }
  .runner-complete-overlay,
  .runner-complete-banner,
  .runner-complete-btn,
  .runner-levelup-line {
    animation: none;
  }
  .runner-dust,
  .runner-burst-particle,
  .runner-land-ring {
    display: none;
  }
  .runner-character.squash,
  .runner-character.stretch {
    animation: none;
  }
  .runner-ambient-particle {
    display: none;
  }
  .runner-double-burst {
    display: none;
  }
  .runner-purified-zone.appearing {
    animation: none;
  }
  .runner-purified-sparkle {
    display: none;
  }
}
