/* =========================================================
   لغز الصورة المخفية — Arabian-Night Arcade RTL Design System
   Strict CSS Logical Properties & Responsive Layout
   ========================================================= */

:root {
  --bg-deep: #080d1a;
  --bg-navy: #0e1628;
  --surface-card: rgba(17, 26, 46, 0.8);
  --surface-card-hover: rgba(23, 35, 62, 0.92);
  --surface-elevated: rgba(20, 31, 56, 0.94);

  --gold-primary: #f5b942;
  --gold-bright: #ffd97d;
  --gold-deep: #c78312;
  --gold-glow: rgba(245, 185, 66, 0.34);

  --emerald: #22c55e;
  --emerald-soft: rgba(34, 197, 94, 0.16);
  --coral: #f43f5e;
  --coral-soft: rgba(244, 63, 94, 0.16);
  --sky: #38bdf8;
  --violet: #a855f7;

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --border-subtle: rgba(148, 163, 184, 0.16);
  --border-gold: rgba(245, 185, 66, 0.28);
  --border-gold-strong: rgba(255, 217, 125, 0.62);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-xl: 28px;
  --radius-pill: 999px;

  --shadow-card: 0 14px 36px rgba(2, 6, 18, 0.52);
  --shadow-gold: 0 0 28px rgba(245, 185, 66, 0.26);

  --font-arabic: 'Cairo', 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
  --transition-fast: 160ms cubic-bezier(0.22, 1, 0.36, 1);
  --transition-med: 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-arabic);
  color: var(--text-primary);
  background-color: var(--bg-deep);
  line-height: 1.65;
  text-align: start;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font-family: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* =========================================================
   Ambient Background (Starfield + Warm Gold & Indigo Orbs)
   ========================================================= */

.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 10%, rgba(30, 58, 138, 0.28), transparent 46%),
    radial-gradient(circle at 82% 88%, rgba(120, 53, 15, 0.22), transparent 50%),
    linear-gradient(180deg, #060a14 0%, #080d1a 55%, #0c1426 100%);
}

.ambient-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(72px);
  opacity: 0.42;
  will-change: transform;
}

.ambient-orb-gold {
  width: 380px;
  height: 380px;
  inset-block-start: -130px;
  inset-inline-start: -90px;
  background: radial-gradient(circle, rgba(245, 185, 66, 0.42), transparent 70%);
  animation: orbFloat 18s ease-in-out infinite alternate;
}

.ambient-orb-indigo {
  width: 440px;
  height: 440px;
  inset-block-end: -160px;
  inset-inline-end: -110px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.26), rgba(99, 102, 241, 0.22), transparent 72%);
  animation: orbFloat 22s ease-in-out infinite alternate-reverse;
}

.ambient-stars {
  position: absolute;
  inset: 0;
  opacity: 0.55;
  background-image:
    radial-gradient(1.5px 1.5px at 14% 22%, rgba(255, 240, 195, 0.9), transparent),
    radial-gradient(1.2px 1.2px at 31% 64%, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1.8px 1.8px at 49% 16%, rgba(255, 217, 125, 0.85), transparent),
    radial-gradient(1.2px 1.2px at 66% 42%, rgba(226, 232, 240, 0.75), transparent),
    radial-gradient(1.6px 1.6px at 84% 28%, rgba(255, 217, 125, 0.9), transparent),
    radial-gradient(1.2px 1.2px at 91% 71%, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1.4px 1.4px at 22% 83%, rgba(186, 230, 253, 0.75), transparent),
    radial-gradient(1.2px 1.2px at 74% 86%, rgba(255, 240, 195, 0.8), transparent),
    radial-gradient(1.1px 1.1px at 56% 74%, rgba(255, 255, 255, 0.6), transparent);
  background-size: 480px 480px;
  animation: starTwinkle 7s ease-in-out infinite alternate;
}

@keyframes orbFloat {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  100% { transform: translate3d(28px, 22px, 0) scale(1.08); }
}

@keyframes starTwinkle {
  0% { opacity: 0.38; }
  100% { opacity: 0.68; }
}

/* =========================================================
   Sticky Header & Persistent HUD
   ========================================================= */

.top-header {
  position: sticky;
  inset-block-start: 0;
  z-index: 40;
  background: rgba(8, 13, 26, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-block-end: 1px solid var(--border-subtle);
}

.header-inner {
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: 18px;
  padding-block: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px;
  padding-inline-end: 8px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-primary);
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.brand-btn:hover {
  transform: translateY(-1px);
}

.brand-emblem {
  position: relative;
  width: 50px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(245, 185, 66, 0.22), rgba(245, 185, 66, 0.06));
  border: 1px solid var(--border-gold);
  box-shadow: 0 0 18px rgba(245, 185, 66, 0.22);
  flex-shrink: 0;
  overflow: visible;
  direction: ltr;
}

.brand-emblem-morph {
  animation: emblemFrameMorph 8s ease-in-out infinite;
}

.emblem-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  will-change: transform, opacity;
}

.emblem-angel {
  gap: 0;
  animation: emblemAngelShow 8s ease-in-out infinite;
}

.emblem-evil {
  animation: emblemEvilShow 8s ease-in-out infinite;
}

.emblem-emoji {
  position: relative;
  z-index: 2;
  font-size: 1.38rem;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}

.emblem-wing {
  width: 17px;
  height: 16px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 5px rgba(255, 232, 160, 0.72));
}

.emblem-wing-start {
  margin-inline-end: -4px;
  transform-origin: 90% 65%;
  animation: emblemWingFlutterStart 0.85s ease-in-out infinite alternate;
}

.emblem-wing-end {
  margin-inline-start: -4px;
  transform-origin: 10% 65%;
  animation: emblemWingFlutterEnd 0.85s ease-in-out infinite alternate;
}

.emblem-horns {
  position: absolute;
  inset-block-start: -6px;
  inset-inline: 0;
  margin-inline: auto;
  width: 34px;
  height: 15px;
  z-index: 3;
  filter: drop-shadow(0 0 7px rgba(244, 63, 94, 0.78));
  animation: emblemHornsPulse 1.4s ease-in-out infinite alternate;
}

@keyframes emblemFrameMorph {
  0%, 46% {
    background: linear-gradient(145deg, rgba(255, 224, 130, 0.24), rgba(245, 185, 66, 0.08));
    border-color: rgba(255, 217, 125, 0.56);
    box-shadow: 0 0 18px rgba(245, 185, 66, 0.34);
    transform: scale(1);
  }
  48.5% {
    transform: scale(1.12);
  }
  51%, 96% {
    background: linear-gradient(145deg, rgba(244, 63, 94, 0.28), rgba(126, 34, 206, 0.22));
    border-color: rgba(244, 63, 94, 0.66);
    box-shadow: 0 0 20px rgba(244, 63, 94, 0.42);
    transform: scale(1);
  }
  98.5% {
    transform: scale(1.12);
  }
  100% {
    background: linear-gradient(145deg, rgba(255, 224, 130, 0.24), rgba(245, 185, 66, 0.08));
    border-color: rgba(255, 217, 125, 0.56);
    box-shadow: 0 0 18px rgba(245, 185, 66, 0.34);
    transform: scale(1);
  }
}

@keyframes emblemAngelShow {
  0%, 46% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
  48.5% {
    opacity: 0;
    transform: scale(0.55) rotate(-14deg);
  }
  50%, 96.5% {
    opacity: 0;
    transform: scale(0.55) rotate(12deg);
  }
  99% {
    opacity: 1;
    transform: scale(1.1) rotate(-3deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

@keyframes emblemEvilShow {
  0%, 46.5% {
    opacity: 0;
    transform: scale(0.55) rotate(-12deg);
  }
  49.5% {
    opacity: 1;
    transform: scale(1.12) rotate(4deg);
  }
  51%, 96% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
  98.5%, 100% {
    opacity: 0;
    transform: scale(0.55) rotate(14deg);
  }
}

@keyframes emblemWingFlutterStart {
  0% { transform: rotate(-10deg) translateY(0); }
  100% { transform: rotate(12deg) translateY(-1.5px); }
}

@keyframes emblemWingFlutterEnd {
  0% { transform: rotate(10deg) translateY(0); }
  100% { transform: rotate(-12deg) translateY(-1.5px); }
}

@keyframes emblemHornsPulse {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-1px) scale(1.06); }
}

.brand-title {
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, #fff5d6 0%, #ffd97d 52%, #f5b942 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
}

/* Golden Pieces Progress Pill */
.hud-progress-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding-inline: 14px;
  padding-block: 7px;
  border-radius: var(--radius-md);
  background: rgba(17, 26, 46, 0.88);
  border: 1px solid var(--border-gold);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: border-color var(--transition-med), box-shadow var(--transition-med);
}

.hud-progress-pill.is-complete {
  border-color: var(--gold-bright);
  box-shadow: 0 0 22px rgba(245, 185, 66, 0.32);
}

.hud-progress-top {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.hud-piece-icon {
  width: 18px;
  height: 18px;
  color: var(--gold-primary);
  display: inline-flex;
  filter: drop-shadow(0 0 6px rgba(245, 185, 66, 0.5));
}

.hud-piece-icon svg {
  width: 100%;
  height: 100%;
}

.hud-counter-ratio {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.hud-pips {
  display: flex;
  align-items: center;
  gap: 3px;
  direction: ltr;
}

.hud-pip {
  width: 8px;
  height: 5px;
  border-radius: 3px;
  background: rgba(148, 163, 184, 0.22);
  transition: background var(--transition-med), transform var(--transition-med), box-shadow var(--transition-med);
}

.hud-pip.is-filled {
  background: linear-gradient(180deg, #ffe799, #f5b942);
  box-shadow: 0 0 7px rgba(245, 185, 66, 0.72);
}

.hud-pip.just-lit {
  animation: pipPop 420ms ease-out;
}

@keyframes pipPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.55); }
  100% { transform: scale(1); }
}

/* Header Action Buttons */
.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding-inline: 12px;
  padding-block: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: rgba(17, 26, 46, 0.78);
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 700;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(30, 44, 78, 0.9);
  border-color: var(--border-gold);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.icon-btn-danger:hover {
  border-color: rgba(244, 63, 94, 0.55);
  color: #fda4af;
}

.icon-btn .icon-sound-off {
  display: none;
}

.icon-btn.is-muted .icon-sound-on {
  display: none;
}

.icon-btn.is-muted .icon-sound-off {
  display: inline-flex;
  color: var(--coral);
}

.icon-btn .icon-sound-on {
  display: inline-flex;
  color: var(--gold-primary);
}

/* =========================================================
   Main Layout & View Transitions
   ========================================================= */

.app-main {
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: 18px;
  padding-block: 24px 44px;
}

.view {
  animation: viewEnter 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes viewEnter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================================================
   Reusable Buttons
   ========================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding-inline: 18px;
  padding-block: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.94rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast), opacity var(--transition-fast);
}

.btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.98);
}

.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.btn-sm {
  padding-inline: 13px;
  padding-block: 8px;
  font-size: 0.85rem;
}

.btn-lg {
  padding-inline: 24px;
  padding-block: 13px;
  font-size: 1rem;
  border-radius: 13px;
}

.btn-gold {
  background: linear-gradient(135deg, #ffe08a 0%, #f5b942 52%, #d99116 100%);
  color: #161005;
  box-shadow: 0 6px 20px rgba(245, 185, 66, 0.32);
}

.btn-gold:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(245, 185, 66, 0.48);
}

.btn-primary {
  background: linear-gradient(135deg, rgba(245, 185, 66, 0.22), rgba(245, 185, 66, 0.1));
  border-color: var(--border-gold);
  color: var(--gold-bright);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #ffd97d, #f5b942);
  border-color: transparent;
  color: #161005;
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(245, 185, 66, 0.3);
}

.btn-outline {
  background: rgba(17, 26, 46, 0.72);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--border-gold);
  background: rgba(25, 38, 68, 0.9);
  color: var(--gold-bright);
}

.btn-ghost {
  background: rgba(148, 163, 184, 0.1);
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.2);
  color: var(--text-primary);
}

.btn-teletubby {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-teletubby-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.teletubby-head-icon {
  width: 28px;
  height: 30px;
  display: block;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

.btn-danger {
  background: linear-gradient(135deg, #fb7185, #e11d48);
  color: #fff;
  box-shadow: 0 6px 18px rgba(244, 63, 94, 0.3);
}

.btn-danger:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(244, 63, 94, 0.45);
}

/* =========================================================
   VIEW 1: HUB — Hero, 2x2 Game Cards & Final Stage Card
   ========================================================= */

.hub-hero {
  text-align: center;
  max-width: 660px;
  margin-inline: auto;
  margin-block-end: 28px;
}

.hero-kicker {
  display: inline-block;
  padding-inline: 14px;
  padding-block: 4px;
  margin-block-end: 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-gold);
  background: rgba(245, 185, 66, 0.1);
  color: var(--gold-bright);
  font-size: 0.82rem;
  font-weight: 700;
}

.hero-title {
  margin: 0 0 8px;
  font-size: clamp(1.65rem, 3.6vw, 2.35rem);
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -0.015em;
  color: var(--text-primary);
}

.hero-subtitle {
  margin: 0;
  font-size: 0.98rem;
  color: var(--text-secondary);
}

/* 2x2 Games Grid */
.games-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-block-end: 24px;
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--surface-card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: transform var(--transition-med), border-color var(--transition-med), background var(--transition-med), box-shadow var(--transition-med);
}

.game-card::before {
  content: '';
  position: absolute;
  inset-block-start: 0;
  inset-inline: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--card-accent, var(--gold-primary)), transparent);
  opacity: 0.65;
  transition: opacity var(--transition-med);
}

.game-card:hover {
  transform: translateY(-4px);
  background: var(--surface-card-hover);
  border-color: var(--border-gold);
  box-shadow: 0 18px 42px rgba(2, 6, 18, 0.62), 0 0 24px rgba(245, 185, 66, 0.14);
}

.game-card:hover::before {
  opacity: 1;
}

.game-card.is-completed {
  border-color: rgba(34, 197, 94, 0.34);
}

.game-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.game-card-identity {
  display: flex;
  align-items: center;
  gap: 14px;
}

.game-icon-box {
  width: 54px;
  height: 54px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.12), rgba(15, 23, 42, 0.65));
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--card-accent, var(--gold-primary));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.game-icon-box svg {
  width: 30px;
  height: 30px;
}

.game-card-title {
  margin: 0;
  font-size: 1.24rem;
  font-weight: 800;
  color: var(--text-primary);
}

.game-badges {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.reward-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding-inline: 10px;
  padding-block: 4px;
  border-radius: var(--radius-pill);
  background: rgba(245, 185, 66, 0.12);
  border: 1px solid rgba(245, 185, 66, 0.32);
  color: var(--gold-bright);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.reward-badge svg {
  width: 14px;
  height: 14px;
}

.complete-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding-inline: 10px;
  padding-block: 3px;
  border-radius: var(--radius-pill);
  background: var(--emerald-soft);
  border: 1px solid rgba(34, 197, 94, 0.45);
  color: #86efac;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.game-card-footer {
  display: flex;
  align-items: center;
  justify-content: stretch;
  padding-block-start: 12px;
  border-block-start: 1px solid rgba(148, 163, 184, 0.12);
}

.game-card-footer .btn {
  width: 100%;
  padding-block: 11px;
  font-size: 1rem;
}

/* Final Stage Card */
.final-card {
  position: relative;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, rgba(17, 26, 46, 0.9), rgba(14, 21, 38, 0.92));
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: border-color var(--transition-med), box-shadow var(--transition-med), transform var(--transition-med);
}

.final-card.is-locked {
  opacity: 0.88;
}

.final-card.is-unlocked {
  border-color: var(--border-gold-strong);
  box-shadow: var(--shadow-card), 0 0 38px rgba(245, 185, 66, 0.28);
  animation: finalGlowPulse 3.2s ease-in-out infinite;
}

@keyframes finalGlowPulse {
  0%, 100% { box-shadow: var(--shadow-card), 0 0 28px rgba(245, 185, 66, 0.24); }
  50% { box-shadow: var(--shadow-card), 0 0 46px rgba(245, 185, 66, 0.45); }
}

.final-card-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 80% 50%, rgba(245, 185, 66, 0.18), transparent 62%);
  transition: opacity var(--transition-med);
}

.final-card.is-unlocked .final-card-glow {
  opacity: 1;
}

.final-card-content {
  position: relative;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 24px 26px;
}

.final-card-icon-wrap {
  width: 68px;
  height: 68px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  transition: color var(--transition-med), border-color var(--transition-med), box-shadow var(--transition-med);
}

.final-card.is-unlocked .final-card-icon-wrap {
  color: var(--gold-bright);
  border-color: var(--border-gold-strong);
  background: radial-gradient(circle, rgba(245, 185, 66, 0.26), rgba(15, 23, 42, 0.8));
  box-shadow: 0 0 24px rgba(245, 185, 66, 0.34);
}

.final-card-icon-wrap svg {
  width: 38px;
  height: 38px;
}

.final-card.is-locked .final-icon-unlocked {
  display: none;
}

.final-card.is-unlocked .final-icon-locked {
  display: none;
}

.final-card-body {
  flex: 1;
  min-width: 0;
}

.final-card-header-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-block-end: 4px;
}

.final-card-title {
  margin: 0;
  font-size: 1.24rem;
  font-weight: 800;
  color: var(--text-primary);
}

.status-pill {
  padding-inline: 11px;
  padding-block: 2px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-pill-locked {
  background: rgba(148, 163, 184, 0.14);
  border: 1px solid rgba(148, 163, 184, 0.26);
  color: var(--text-muted);
}

.status-pill-unlocked {
  background: var(--emerald-soft);
  border: 1px solid rgba(34, 197, 94, 0.45);
  color: #86efac;
}

.final-card-desc {
  margin: 0 0 12px;
  font-size: 0.94rem;
  color: var(--text-secondary);
}

.final-progress-track {
  width: 100%;
  height: 8px;
  border-radius: var(--radius-pill);
  background: rgba(148, 163, 184, 0.16);
  overflow: hidden;
}

.final-progress-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, #d99116, #f5b942, #ffe394);
  box-shadow: 0 0 12px rgba(245, 185, 66, 0.55);
  transition: width 360ms cubic-bezier(0.22, 1, 0.36, 1);
}

.final-card-action {
  flex-shrink: 0;
}

/* =========================================================
   VIEW 2: MINI-GAME STAGE
   ========================================================= */

.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-inline: 16px;
  padding-block: 12px;
  margin-block-end: 16px;
  border-radius: var(--radius-md);
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(12px);
}

.stage-title-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.stage-title {
  margin: 0;
  font-size: 1.16rem;
  font-weight: 800;
  color: var(--text-primary);
}

.stage-status-badge {
  padding-inline: 11px;
  padding-block: 3px;
  border-radius: var(--radius-pill);
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #bae6fd;
  font-size: 0.82rem;
  font-weight: 700;
}

.stage-bar-end {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.stage-pieces-tracker {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding-inline: 12px;
  padding-block: 6px;
  border-radius: var(--radius-pill);
  background: rgba(8, 13, 26, 0.65);
  border: 1px solid var(--border-gold);
}

.stage-piece-slots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.stage-slot {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  color: rgba(148, 163, 184, 0.3);
  transition: color var(--transition-med), transform var(--transition-med), filter var(--transition-med);
}

.stage-slot svg {
  width: 100%;
  height: 100%;
}

.stage-slot.is-collected {
  color: var(--gold-bright);
  filter: drop-shadow(0 0 8px rgba(245, 185, 66, 0.85));
  animation: slotPop 380ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes slotPop {
  0% { transform: scale(0.75); }
  55% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.stage-piece-ratio,
.puzzle-counter-ratio {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
}

/* Responsive Stage Frame */
.game-stage-frame {
  position: relative;
  width: 100%;
  max-width: 840px;
  min-height: clamp(360px, 56vh, 520px);
  margin-inline: auto;
  border-radius: var(--radius-lg);
  background: #0a1122;
  border: 1px solid var(--border-gold);
  box-shadow: var(--shadow-card), 0 0 32px rgba(8, 13, 26, 0.7);
  overflow: hidden;
}

.game-stage-frame.is-intro-active {
  overflow: hidden;
}

/* =========================================================
   Anime Hero Entrance & Golden Energy Aura Intro (2.45s)
   ========================================================= */

.stage-intro {
  --intro-duration: 2450ms;
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  pointer-events: none;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 54%, rgba(56, 36, 6, 0.56) 0%, rgba(10, 17, 34, 0.94) 64%, rgba(6, 10, 20, 0.98) 100%);
}

.stage-intro.is-playing {
  animation: introBackdropFade var(--intro-duration) ease-out both;
}

.hero-aura-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  overflow: hidden;
}

.hero-aura-glow {
  position: absolute;
  width: clamp(230px, 42vw, 350px);
  height: clamp(230px, 42vw, 350px);
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 245, 196, 0.88) 0%,
    rgba(251, 191, 36, 0.62) 32%,
    rgba(245, 158, 11, 0.28) 58%,
    rgba(245, 158, 11, 0) 76%
  );
  filter: blur(18px);
  opacity: 0;
  will-change: transform, opacity;
}

.stage-intro.is-playing .hero-aura-glow {
  animation: auraGlowPulse var(--intro-duration) ease-in-out both;
}

.hero-aura-ring {
  position: absolute;
  width: clamp(190px, 34vw, 290px);
  height: clamp(190px, 34vw, 290px);
  border-radius: 50%;
  border: 3px solid rgba(255, 224, 125, 0.92);
  box-shadow:
    0 0 24px rgba(251, 191, 36, 0.85),
    inset 0 0 20px rgba(255, 224, 125, 0.45);
  opacity: 0;
  will-change: transform, opacity;
}

.stage-intro.is-playing .hero-aura-ring.ring-1 {
  animation: auraRingExpand1 var(--intro-duration) cubic-bezier(0.22, 1, 0.36, 1) both;
}

.stage-intro.is-playing .hero-aura-ring.ring-2 {
  border-width: 2.5px;
  border-color: rgba(245, 185, 66, 0.88);
  animation: auraRingExpand2 var(--intro-duration) cubic-bezier(0.22, 1, 0.36, 1) both;
}

.hero-aura-ground {
  position: absolute;
  inset-block-end: 20%;
  width: clamp(200px, 38vw, 320px);
  height: 44px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 226, 130, 0.9);
  background: radial-gradient(ellipse at center, rgba(251, 191, 36, 0.55) 0%, rgba(245, 158, 11, 0.16) 55%, transparent 78%);
  box-shadow: 0 0 28px rgba(251, 191, 36, 0.72);
  opacity: 0;
  will-change: transform, opacity;
}

.stage-intro.is-playing .hero-aura-ground {
  animation: auraGroundFlare var(--intro-duration) cubic-bezier(0.22, 1, 0.36, 1) both;
}

.hero-aura-sparks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hero-aura-sparks span {
  position: absolute;
  inset-block-end: 18%;
  width: 5px;
  height: 22px;
  border-radius: 999px;
  background: linear-gradient(180deg, #fffbe6 0%, #ffd97d 45%, rgba(245, 158, 11, 0) 100%);
  box-shadow: 0 0 12px rgba(255, 224, 125, 0.95);
  opacity: 0;
  will-change: transform, opacity;
}

.hero-aura-sparks span:nth-child(1)  { inset-inline-start: 24%; height: 18px; }
.hero-aura-sparks span:nth-child(2)  { inset-inline-start: 31%; height: 26px; width: 4px; }
.hero-aura-sparks span:nth-child(3)  { inset-inline-start: 38%; height: 22px; }
.hero-aura-sparks span:nth-child(4)  { inset-inline-start: 44%; height: 28px; width: 6px; }
.hero-aura-sparks span:nth-child(5)  { inset-inline-start: 50%; height: 24px; }
.hero-aura-sparks span:nth-child(6)  { inset-inline-start: 56%; height: 30px; width: 5px; }
.hero-aura-sparks span:nth-child(7)  { inset-inline-start: 62%; height: 20px; width: 4px; }
.hero-aura-sparks span:nth-child(8)  { inset-inline-start: 68%; height: 26px; }
.hero-aura-sparks span:nth-child(9)  { inset-inline-start: 74%; height: 19px; width: 4px; }
.hero-aura-sparks span:nth-child(10) { inset-inline-start: 47%; height: 25px; width: 5px; }

.stage-intro.is-playing .hero-aura-sparks span {
  animation-name: auraSparkRise;
  animation-duration: 980ms;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
  animation-fill-mode: both;
}

.stage-intro.is-playing .hero-aura-sparks span:nth-child(1)  { animation-delay: 420ms; }
.stage-intro.is-playing .hero-aura-sparks span:nth-child(2)  { animation-delay: 520ms; }
.stage-intro.is-playing .hero-aura-sparks span:nth-child(3)  { animation-delay: 460ms; }
.stage-intro.is-playing .hero-aura-sparks span:nth-child(4)  { animation-delay: 640ms; }
.stage-intro.is-playing .hero-aura-sparks span:nth-child(5)  { animation-delay: 500ms; }
.stage-intro.is-playing .hero-aura-sparks span:nth-child(6)  { animation-delay: 780ms; }
.stage-intro.is-playing .hero-aura-sparks span:nth-child(7)  { animation-delay: 580ms; }
.stage-intro.is-playing .hero-aura-sparks span:nth-child(8)  { animation-delay: 880ms; }
.stage-intro.is-playing .hero-aura-sparks span:nth-child(9)  { animation-delay: 700ms; }
.stage-intro.is-playing .hero-aura-sparks span:nth-child(10) { animation-delay: 980ms; }

.hero-intro-actor {
  position: relative;
  z-index: 3;
  display: grid;
  place-items: center;
  will-change: transform, opacity, filter;
}

.hero-intro-img {
  display: block;
  width: auto;
  max-width: min(82%, 340px);
  max-height: clamp(220px, 42vh, 330px);
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

.stage-intro.is-playing .hero-intro-actor {
  animation: heroJumpAndAura var(--intro-duration) cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes introBackdropFade {
  0% { opacity: 0; }
  8% { opacity: 1; }
  84% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes heroJumpAndAura {
  0% {
    opacity: 0;
    transform: translate3d(0, 130%, 0) scale(0.76);
    filter: drop-shadow(0 0 0 rgba(251, 191, 36, 0));
  }
  11% {
    opacity: 1;
    transform: translate3d(0, -24px, 0) scale(1.06);
    filter: drop-shadow(0 12px 20px rgba(251, 191, 36, 0.45));
  }
  18% {
    opacity: 1;
    transform: translate3d(0, 5px, 0) scaleX(1.07) scaleY(0.92);
    filter: drop-shadow(0 0 18px rgba(251, 191, 36, 0.8));
  }
  23% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
    filter: drop-shadow(0 0 20px rgba(251, 191, 36, 0.95)) drop-shadow(0 0 42px rgba(245, 158, 11, 0.72));
  }
  37% {
    opacity: 1;
    transform: translate3d(0, -6px, 0) scale(1.035);
    filter: brightness(1.12) drop-shadow(0 0 26px rgba(255, 224, 125, 1)) drop-shadow(0 0 54px rgba(245, 158, 11, 0.86));
  }
  52% {
    opacity: 1;
    transform: translate3d(0, -1px, 0) scale(1.015);
    filter: brightness(1.06) drop-shadow(0 0 18px rgba(251, 191, 36, 0.95)) drop-shadow(0 0 38px rgba(245, 158, 11, 0.7));
  }
  67% {
    opacity: 1;
    transform: translate3d(0, -6px, 0) scale(1.04);
    filter: brightness(1.18) drop-shadow(0 0 28px rgba(255, 232, 145, 1)) drop-shadow(0 0 58px rgba(245, 158, 11, 0.92));
  }
  80% {
    opacity: 1;
    transform: translate3d(0, -4px, 0) scale(1.03);
    filter: brightness(1.22) drop-shadow(0 0 24px rgba(251, 191, 36, 0.95)) drop-shadow(0 0 46px rgba(245, 158, 11, 0.8));
  }
  90% {
    opacity: 0.78;
    transform: translate3d(0, -16px, 0) scale(1.09);
    filter: brightness(1.75) drop-shadow(0 0 36px rgba(255, 243, 184, 1)) drop-shadow(0 0 68px rgba(245, 158, 11, 0.95));
  }
  100% {
    opacity: 0;
    transform: translate3d(0, -28px, 0) scale(1.14);
    filter: brightness(1.9) drop-shadow(0 0 44px rgba(255, 243, 184, 0));
  }
}

@keyframes auraGlowPulse {
  0%, 16% {
    opacity: 0;
    transform: scale(0.45);
  }
  24% {
    opacity: 0.92;
    transform: scale(1.06);
  }
  40% {
    opacity: 0.68;
    transform: scale(0.95);
  }
  56% {
    opacity: 1;
    transform: scale(1.16);
  }
  72% {
    opacity: 0.78;
    transform: scale(1.02);
  }
  82% {
    opacity: 0.96;
    transform: scale(1.22);
  }
  100% {
    opacity: 0;
    transform: scale(0.4);
  }
}

@keyframes auraRingExpand1 {
  0%, 18% {
    opacity: 0;
    transform: scale(0.45);
  }
  24% {
    opacity: 0.95;
    transform: scale(0.88);
  }
  48% {
    opacity: 0;
    transform: scale(1.62);
  }
  52% {
    opacity: 0;
    transform: scale(0.58);
  }
  60% {
    opacity: 0.88;
    transform: scale(0.95);
  }
  84% {
    opacity: 0;
    transform: scale(1.68);
  }
  100% {
    opacity: 0;
    transform: scale(1.75);
  }
}

@keyframes auraRingExpand2 {
  0%, 28% {
    opacity: 0;
    transform: scale(0.5);
  }
  36% {
    opacity: 0.9;
    transform: scale(0.92);
  }
  64% {
    opacity: 0;
    transform: scale(1.68);
  }
  68% {
    opacity: 0;
    transform: scale(0.62);
  }
  75% {
    opacity: 0.82;
    transform: scale(1.02);
  }
  94%, 100% {
    opacity: 0;
    transform: scale(1.75);
  }
}

@keyframes auraGroundFlare {
  0%, 15% {
    opacity: 0;
    transform: scale(0.3);
  }
  21% {
    opacity: 1;
    transform: scale(1.12);
  }
  35% {
    opacity: 0.78;
    transform: scale(0.96);
  }
  56% {
    opacity: 0.96;
    transform: scale(1.08);
  }
  78% {
    opacity: 0.75;
    transform: scale(1.02);
  }
  100% {
    opacity: 0;
    transform: scale(0.45);
  }
}

@keyframes auraSparkRise {
  0% {
    opacity: 0;
    transform: translate3d(0, 16px, 0) scaleY(0.5);
  }
  22% {
    opacity: 1;
    transform: translate3d(0, -34px, 0) scaleY(1.2);
  }
  75% {
    opacity: 0.85;
    transform: translate3d(0, -165px, 0) scaleY(1);
  }
  100% {
    opacity: 0;
    transform: translate3d(0, -230px, 0) scaleY(0.4);
  }
}

/* =========================================================
   Maze Victory Showcase (Giant Plankton Zoom-In + Shake + Soft Green Aura)
   ========================================================= */

.maze-win-showcase {
  --maze-win-duration: 2400ms;
  position: fixed;
  inset: 0;
  z-index: 950;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 50%, rgba(16, 185, 129, 0.18), rgba(6, 13, 24, 0.78) 72%);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  pointer-events: none;
}

.maze-win-showcase.is-playing {
  animation: mazeWinBackdropFade var(--maze-win-duration) ease-out both;
}

.plankton-win-aura {
  position: absolute;
  width: clamp(340px, 62vw, 620px);
  height: clamp(340px, 62vw, 620px);
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(74, 222, 128, 0.46) 0%,
    rgba(34, 197, 94, 0.28) 38%,
    rgba(16, 185, 129, 0.12) 62%,
    rgba(16, 185, 129, 0) 78%
  );
  filter: blur(28px);
  opacity: 0;
  will-change: transform, opacity;
}

.maze-win-showcase.is-playing .plankton-win-aura {
  animation: planktonAuraPulse var(--maze-win-duration) ease-in-out both;
}

.plankton-win-ring {
  position: absolute;
  width: clamp(280px, 50vw, 500px);
  height: clamp(280px, 50vw, 500px);
  border-radius: 50%;
  border: 2px solid rgba(74, 222, 128, 0.42);
  box-shadow:
    0 0 28px rgba(34, 197, 94, 0.35),
    inset 0 0 18px rgba(74, 222, 128, 0.18);
  opacity: 0;
  will-change: transform, opacity;
}

.maze-win-showcase.is-playing .plankton-win-ring {
  animation: planktonRingPulse var(--maze-win-duration) cubic-bezier(0.22, 1, 0.36, 1) both;
}

.plankton-win-actor {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  will-change: transform, opacity;
}

.maze-win-showcase.is-playing .plankton-win-actor {
  animation: planktonSlideIn var(--maze-win-duration) cubic-bezier(0.2, 0.9, 0.3, 1) both;
}

.plankton-win-img {
  display: block;
  width: min(84vw, 620px);
  max-height: min(76vh, 490px);
  height: auto;
  object-fit: contain;
  filter:
    drop-shadow(0 0 26px rgba(34, 197, 94, 0.56))
    drop-shadow(0 16px 32px rgba(0, 0, 0, 0.5));
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

@keyframes mazeWinBackdropFade {
  0% { opacity: 0; }
  10% { opacity: 1; }
  88% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes planktonSlideIn {
  0% {
    opacity: 0;
    transform: translate3d(0, 12px, 0) scale(0.42) rotate(-4deg);
  }
  13% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(0.95) rotate(2.6deg);
  }
  18% {
    opacity: 1;
    transform: translate3d(-10px, 3px, 0) scale(0.99) rotate(-3.2deg);
  }
  23% {
    opacity: 1;
    transform: translate3d(10px, -3px, 0) scale(1.02) rotate(3deg);
  }
  28% {
    opacity: 1;
    transform: translate3d(-7px, 2px, 0) scale(1.05) rotate(-2.4deg);
  }
  33% {
    opacity: 1;
    transform: translate3d(7px, -2px, 0) scale(1.07) rotate(2deg);
  }
  38% {
    opacity: 1;
    transform: translate3d(-4px, 1px, 0) scale(1.09) rotate(-1.2deg);
  }
  43% {
    opacity: 1;
    transform: translate3d(3px, 0, 0) scale(1.11) rotate(0.7deg);
  }
  64% {
    opacity: 1;
    transform: translate3d(0, -3px, 0) scale(1.17) rotate(-0.6deg);
  }
  86% {
    opacity: 1;
    transform: translate3d(0, -6px, 0) scale(1.23) rotate(0.6deg);
  }
  100% {
    opacity: 0;
    transform: translate3d(0, -10px, 0) scale(1.29) rotate(0deg);
  }
}

@keyframes planktonAuraPulse {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  18% {
    opacity: 0.75;
    transform: scale(1.02);
  }
  48% {
    opacity: 0.55;
    transform: scale(0.94);
  }
  74% {
    opacity: 0.72;
    transform: scale(1.08);
  }
  88% {
    opacity: 0.55;
    transform: scale(1.02);
  }
  100% {
    opacity: 0;
    transform: scale(0.72);
  }
}

@keyframes planktonRingPulse {
  0%, 10% {
    opacity: 0;
    transform: scale(0.55);
  }
  22% {
    opacity: 0.62;
    transform: scale(0.92);
  }
  58% {
    opacity: 0;
    transform: scale(1.42);
  }
  62% {
    opacity: 0;
    transform: scale(0.68);
  }
  74% {
    opacity: 0.45;
    transform: scale(0.98);
  }
  100% {
    opacity: 0;
    transform: scale(1.38);
  }
}

.game-mount {
  width: 100%;
  min-height: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.game-mount canvas {
  display: block;
  max-width: 100%;
  height: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.controls-hint-bar {
  max-width: 840px;
  margin-inline: auto;
  margin-block: 12px 0;
  padding-inline: 16px;
  padding-block: 9px;
  border-radius: var(--radius-sm);
  background: rgba(17, 26, 46, 0.6);
  border: 1px solid var(--border-subtle);
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

/* Maze Mobile On-Screen Directional Pad (.maze-dpad) */
.maze-dpad {
  direction: ltr;
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 7px;
  justify-content: center;
  align-items: center;
  margin-block: 14px 12px;
  margin-inline: auto;
  padding: 8px;
  border-radius: var(--radius-md);
  background: rgba(11, 18, 34, 0.78);
  border: 1px solid var(--border-subtle);
  user-select: none;
  touch-action: manipulation;
}

.maze-dpad button {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  border: 1px solid var(--border-gold);
  background: linear-gradient(180deg, rgba(28, 42, 74, 0.95), rgba(15, 24, 46, 0.95));
  color: var(--gold-bright);
  font-size: 1.25rem;
  font-weight: 800;
  display: inline-grid;
  place-items: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: transform 90ms ease, background 120ms ease, box-shadow 120ms ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.maze-dpad button:hover {
  background: linear-gradient(180deg, rgba(42, 62, 106, 0.95), rgba(22, 34, 62, 0.95));
  border-color: var(--gold-bright);
}

.maze-dpad button:active,
.maze-dpad button.is-pressed {
  transform: scale(0.92);
  background: linear-gradient(180deg, #ffd97d, #f5b942);
  color: #161005;
  box-shadow: 0 0 16px rgba(245, 185, 66, 0.55);
}

.maze-dpad [data-dir="up"]    { grid-column: 2; grid-row: 1; }
.maze-dpad [data-dir="left"]  { grid-column: 1; grid-row: 2; }
.maze-dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }
.maze-dpad [data-dir="down"]  { grid-column: 2; grid-row: 3; }

/* Stage Win / Lose Overlay */
.stage-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(6, 10, 20, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn 220ms ease-out;
}

.stage-overlay-card {
  width: 100%;
  max-width: 420px;
  padding: 28px 24px;
  border-radius: var(--radius-lg);
  background: var(--surface-elevated);
  border: 1px solid var(--border-gold);
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.65);
  text-align: center;
  animation: cardPop 260ms cubic-bezier(0.22, 1, 0.36, 1);
}

.stage-overlay.is-lose .stage-overlay-card {
  border-color: rgba(244, 63, 94, 0.45);
  padding-block: 18px 20px;
  padding-inline: 20px;
}

/* Lose Character Showcase ("مستوى مستوى") */
.lose-character-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-block-end: 8px;
}

.lose-speech-bubble {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-inline: 20px;
  padding-block: 7px;
  border-radius: 18px;
  background: #fffbeb;
  color: #be123c;
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.3;
  border: 2.5px solid #f43f5e;
  box-shadow: 0 8px 20px rgba(244, 63, 94, 0.28), 0 3px 0 rgba(244, 63, 94, 0.42);
  will-change: transform, opacity;
}

.lose-character-box.is-animated .lose-speech-bubble {
  animation: loseBubblePop 420ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.lose-character-stage {
  position: relative;
  display: grid;
  place-items: center;
  padding-block: 4px;
}

.lose-character-aura {
  position: absolute;
  width: 134px;
  height: 134px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(56, 189, 248, 0.34) 0%,
    rgba(244, 63, 94, 0.24) 52%,
    rgba(244, 63, 94, 0) 74%
  );
  filter: blur(14px);
  pointer-events: none;
  animation: loseAuraPulse 2s ease-in-out infinite;
}

.lose-character-img {
  position: relative;
  z-index: 2;
  display: block;
  height: clamp(138px, 24vh, 184px);
  width: auto;
  max-width: 100%;
  object-fit: cover;
  border-radius: 16px;
  border: 2px solid rgba(244, 63, 94, 0.55);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55), 0 0 22px rgba(56, 189, 248, 0.22);
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
  will-change: transform, opacity;
}

.lose-character-box.is-animated .lose-character-img {
  animation:
    loseHeroSprint 420ms cubic-bezier(0.22, 1, 0.36, 1) both,
    loseHeroWobble 960ms ease-in-out 420ms infinite;
}

.lose-character-box.is-still .lose-character-img {
  animation: fadeIn 240ms ease-out both;
}

@keyframes loseBubblePop {
  0% {
    opacity: 0;
    transform: translate3d(0, 12px, 0) scale(0.6);
  }
  70% {
    opacity: 1;
    transform: translate3d(0, -3px, 0) scale(1.07);
  }
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes loseHeroSprint {
  0% {
    opacity: 0;
    transform: translate3d(42px, 14px, 0) scale(0.78) rotate(-8deg);
  }
  65% {
    opacity: 1;
    transform: translate3d(-6px, -6px, 0) scale(1.05) rotate(4deg);
  }
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1) rotate(0deg);
  }
}

@keyframes loseHeroWobble {
  0%, 100% {
    transform: translate3d(0, 0, 0) rotate(-2.5deg);
  }
  25% {
    transform: translate3d(3px, -5px, 0) rotate(2.5deg);
  }
  50% {
    transform: translate3d(0, 1px, 0) rotate(-2deg);
  }
  75% {
    transform: translate3d(-3px, -4px, 0) rotate(3deg);
  }
}

@keyframes loseAuraPulse {
  0%, 100% {
    opacity: 0.72;
    transform: scale(0.94);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
}

.overlay-icon {
  width: 62px;
  height: 62px;
  margin-inline: auto;
  margin-block-end: 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.stage-overlay.is-win .overlay-icon {
  background: rgba(245, 185, 66, 0.16);
  border: 1px solid var(--border-gold-strong);
  color: var(--gold-bright);
  box-shadow: 0 0 24px rgba(245, 185, 66, 0.35);
}

.stage-overlay.is-lose .overlay-icon {
  background: var(--coral-soft);
  border: 1px solid rgba(244, 63, 94, 0.45);
  color: #fda4af;
}

.overlay-icon svg {
  width: 32px;
  height: 32px;
}

.overlay-title {
  margin: 0 0 8px;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-primary);
}

.overlay-message {
  margin: 0 0 20px;
  font-size: 0.94rem;
  color: var(--text-secondary);
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

/* =========================================================
   VIEW 3: FINAL 16-PIECE INTERLOCKING JIGSAW PUZZLE
   ========================================================= */

.puzzle-bar .stage-title-group {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.puzzle-subtitle {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.puzzle-counter-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-inline: 13px;
  padding-block: 7px;
  border-radius: var(--radius-pill);
  background: rgba(8, 13, 26, 0.72);
  border: 1px solid var(--border-gold);
}

.puzzle-mount {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Isolated LTR coordinate playfield so pointer X/Y & canvas math stay exact */
.puzzle-workspace {
  position: relative;
  direction: ltr;
  width: 100%;
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at 50% 45%, rgba(24, 38, 70, 0.65), rgba(9, 14, 28, 0.92));
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

.puzzle-board {
  position: absolute;
  border-radius: 12px;
  background: rgba(6, 10, 20, 0.72);
  border: 2px solid var(--border-gold);
  box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.65), 0 0 28px rgba(245, 185, 66, 0.14);
  overflow: hidden;
  transition: border-color 480ms ease, box-shadow 480ms ease;
}

.puzzle-board.is-completed {
  border-color: var(--gold-bright);
  box-shadow: 0 0 46px rgba(245, 185, 66, 0.48), 0 18px 44px rgba(0, 0, 0, 0.65);
}

.puzzle-grid-guides {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  pointer-events: none;
  transition: opacity 500ms ease;
}

.puzzle-board.is-completed .puzzle-grid-guides {
  opacity: 0;
}

.puzzle-guide-cell {
  border: 1px dashed rgba(245, 185, 66, 0.2);
  transition: background 320ms ease, box-shadow 320ms ease;
}

.puzzle-guide-cell.is-flash {
  animation: cellSnapFlash 520ms ease-out;
}

@keyframes cellSnapFlash {
  0% {
    background: rgba(255, 217, 125, 0.45);
    box-shadow: inset 0 0 18px rgba(255, 217, 125, 0.85);
  }
  100% {
    background: transparent;
    box-shadow: none;
  }
}

.puzzle-reveal-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
  z-index: 12;
  transition: opacity 650ms cubic-bezier(0.22, 1, 0.36, 1);
}

.puzzle-board.is-completed .puzzle-reveal-img {
  opacity: 1;
}

.puzzle-piece {
  position: absolute;
  top: 0;
  left: 0;
  touch-action: none;
  cursor: grab;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.55));
  will-change: transform;
  transition: filter 160ms ease, opacity 550ms ease;
}

.puzzle-piece:hover:not(.is-snapped) {
  filter: drop-shadow(0 8px 14px rgba(245, 185, 66, 0.35));
}

.puzzle-piece.is-dragging {
  cursor: grabbing;
  transition: none !important;
  filter: drop-shadow(0 16px 24px rgba(0, 0, 0, 0.68)) drop-shadow(0 0 12px rgba(245, 185, 66, 0.45));
}

.puzzle-piece.is-animating {
  transition: transform 170ms cubic-bezier(0.22, 1, 0.36, 1), filter 170ms ease;
}

.puzzle-piece.is-snapped {
  cursor: default;
  pointer-events: none;
  filter: none;
}

.puzzle-piece.is-cracking {
  cursor: not-allowed;
  pointer-events: none;
  animation: puzzlePieceCrack 180ms ease-in-out both;
}

.puzzle-piece.is-broken {
  cursor: not-allowed;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}

.puzzle-broken-group {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  user-select: none;
  cursor: not-allowed;
  z-index: 30;
}

.puzzle-shard {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.65));
  will-change: transform;
  transform: translate3d(0, 0, 0) rotate(0deg);
  transition: transform 440ms cubic-bezier(0.16, 1, 0.3, 1), filter 300ms ease;
}

.puzzle-broken-group.is-shattered .puzzle-shard {
  transform: translate3d(var(--shard-dx, 0px), var(--shard-dy, 0px), 0) rotate(var(--shard-rot, 0deg));
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.72)) saturate(0.76) brightness(0.9);
}

.puzzle-shard-dust {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 2px;
  background: linear-gradient(135deg, #fff5d6, #f59e0b);
  pointer-events: none;
  box-shadow: 0 0 8px rgba(245, 185, 66, 0.7);
  animation: puzzleDustBurst 520ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes puzzlePieceCrack {
  0% {
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.55));
  }
  25% {
    filter: drop-shadow(0 0 12px rgba(248, 113, 113, 0.7)) brightness(1.18);
  }
  55% {
    filter: drop-shadow(0 0 16px rgba(255, 255, 255, 0.85)) brightness(1.3);
  }
  100% {
    filter: drop-shadow(0 0 14px rgba(248, 113, 113, 0.65)) brightness(1.1);
  }
}

@keyframes puzzleDustBurst {
  0% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--dust-dx, 0px), var(--dust-dy, 0px), 0) scale(0.25) rotate(140deg);
  }
}

.puzzle-workspace.is-completed .puzzle-piece {
  opacity: 0;
}

.puzzle-loading {
  padding: 48px 20px;
  text-align: center;
  color: var(--gold-bright);
  font-weight: 700;
}

/* Celebratory Card BELOW Revealed Image (never covering artwork!) */
.puzzle-celebration-card {
  direction: rtl;
  width: 100%;
  max-width: 620px;
  padding: 24px 26px;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, rgba(22, 34, 62, 0.94), rgba(14, 22, 42, 0.96));
  border: 1px solid var(--border-gold-strong);
  box-shadow: var(--shadow-card), 0 0 34px rgba(245, 185, 66, 0.28);
  text-align: center;
  animation: cardPop 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

.celebration-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-inline: 14px;
  padding-block: 5px;
  margin-block-end: 10px;
  border-radius: var(--radius-pill);
  background: rgba(245, 185, 66, 0.16);
  border: 1px solid var(--border-gold);
  color: var(--gold-bright);
  font-size: 0.84rem;
  font-weight: 800;
}

.celebration-title {
  margin: 0 0 6px;
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  font-weight: 800;
  background: linear-gradient(135deg, #fff5d6, #ffd97d, #f5b942);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.celebration-subtitle {
  margin: 0 0 18px;
  font-size: 0.96rem;
  color: var(--text-secondary);
}

.celebration-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

/* Full-Viewport Confetti Layer */
.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 999;
}

/* =========================================================
   In-App Confirmation Modal & Toast
   ========================================================= */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 8, 18, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn 180ms ease-out;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  padding: 26px 24px;
  border-radius: var(--radius-lg);
  background: var(--surface-elevated);
  border: 1px solid rgba(244, 63, 94, 0.32);
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.68);
  text-align: center;
  animation: cardPop 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-icon-danger {
  width: 54px;
  height: 54px;
  margin-inline: auto;
  margin-block-end: 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--coral-soft);
  border: 1px solid rgba(244, 63, 94, 0.42);
  color: #fda4af;
}

.modal-icon-danger svg {
  width: 26px;
  height: 26px;
}

.modal-title {
  margin: 0 0 20px;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-primary);
}

.modal-body {
  margin: 0 0 22px;
  font-size: 0.94rem;
  color: var(--text-secondary);
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toast-region {
  position: fixed;
  inset-block-end: 20px;
  inset-inline-start: 20px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  padding-inline: 16px;
  padding-block: 10px;
  border-radius: var(--radius-sm);
  background: rgba(17, 26, 46, 0.96);
  border: 1px solid var(--border-gold);
  color: var(--gold-bright);
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.52);
  animation: viewEnter 220ms ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes cardPop {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* =========================================================
   Responsive Breakpoints (Tablet & Mobile)
   ========================================================= */

@media (max-width: 820px) {
  .header-inner {
    flex-wrap: wrap;
    padding-inline: 14px;
    padding-block: 10px;
    gap: 10px;
  }

  .hud-progress-pill {
    order: 3;
    width: 100%;
    flex-direction: row;
    justify-content: space-between;
    padding-inline: 14px;
    padding-block: 7px;
  }

  .icon-btn-label {
    display: none;
  }

  .icon-btn {
    padding-inline: 10px;
  }

  .final-card-content {
    flex-direction: column;
    text-align: center;
    padding: 22px 18px;
  }

  .final-card-header-row {
    justify-content: center;
  }

  .final-card-action,
  .final-card-action .btn {
    width: 100%;
  }
}

@media (max-width: 680px) {
  .app-main {
    padding-inline: 12px;
    padding-block: 18px 34px;
  }

  .games-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .game-card {
    padding: 16px;
  }

  .stage-bar {
    padding-inline: 12px;
    padding-block: 10px;
  }

  .stage-bar-end {
    width: 100%;
    justify-content: space-between;
  }

  .game-mount {
    min-height: 360px;
  }

  .hud-pip {
    width: 7px;
    height: 5px;
  }

  .puzzle-celebration-card {
    padding: 20px 16px;
  }
}

@media (max-width: 600px) {
  .hero-intro-img {
    max-height: clamp(190px, 38vh, 270px);
    max-width: 84%;
  }

  .hero-aura-glow {
    width: 240px;
    height: 240px;
  }

  .hero-aura-ring {
    width: 200px;
    height: 200px;
  }

  .hero-aura-ground {
    width: 210px;
    height: 36px;
    inset-block-end: 22%;
  }

  .plankton-win-img {
    width: 90vw;
    max-height: 58vh;
  }

  .plankton-win-aura {
    width: 310px;
    height: 310px;
  }

  .plankton-win-ring {
    width: 260px;
    height: 260px;
  }

  .lose-character-img {
    height: clamp(92px, 18vh, 124px);
  }

  .lose-speech-bubble {
    font-size: 1.02rem;
    padding-inline: 16px;
    padding-block: 6px;
  }

  .lose-character-aura {
    width: 110px;
    height: 110px;
  }
}
