.wun-sparky-game {
  --sparky-border-color: #B94CFF;
  --sparky-timer-bg: #FF5128;
  --sparky-pill-text: #1F123F;
  --sparky-accent: #FF5128;
  --sparky-modal-bg: #FFFFFF;
  --sparky-modal-text: #1F123F;

  position: relative;
  width: min(100%, 520px);
  margin: 0 auto;
  padding: 22px 22px 24px;

  border: 1.5px solid var(--sparky-border-color);
  border-radius: 18px;

  background:
    radial-gradient(
      ellipse at center,
      rgba(167, 56, 224, 0.12) 0%,
      rgba(31, 18, 63, 0.28) 55%,
      rgba(31, 18, 63, 0.55) 100%
    );

  box-shadow:
    0 0 38px rgba(167, 56, 224, 0.22),
    inset 0 0 24px rgba(167, 56, 224, 0.08);

  overflow: hidden;
  isolation: isolate;
}

/* Soft premium glow behind board */
.wun-sparky-game::before {
  content: "";
  position: absolute;
  inset: -40%;
  z-index: -1;
  pointer-events: none;

  background: radial-gradient(
    ellipse at center,
    rgba(167, 56, 224, 0.22) 0%,
    rgba(167, 56, 224, 0.08) 42%,
    rgba(167, 56, 224, 0) 72%
  );

  filter: blur(32px);
}

/* Score/best/time row */
.wun-game-top {
  position: relative;
  z-index: 4;

  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;

  margin-bottom: 10px;
}

/* Pills */
.wun-game-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  min-height: 24px;
  padding: 0 13px;
  border-radius: 999px;

  background: #ffffff;
  color: var(--sparky-pill-text);

  font-family: "Roc Grotesk", sans-serif;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;

  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
}

.wun-game-time {
  background: var(--sparky-timer-bg);
  color: #ffffff;
}

.wun-game-best {
  background: rgba(255, 255, 255, 0.9);
}

/* Grid */
.wun-sparky-grid {
  position: relative;

  display: grid;
  grid-template-columns: repeat(3, 1fr);

  border-radius: 12px;
  overflow: hidden;

  opacity: 0;
  transform: translateY(8px) scale(0.985);
  animation: wunBoardIn 0.55s cubic-bezier(.16,.84,.32,1) forwards;
}

/* Draw the tic-tac-toe gridlines as an overlay */
.wun-sparky-grid::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;

  background:
    linear-gradient(
      to right,
      transparent calc(33.333% - 0.75px),
      var(--sparky-border-color) calc(33.333% - 0.75px),
      var(--sparky-border-color) calc(33.333% + 0.75px),
      transparent calc(33.333% + 0.75px),
      transparent calc(66.666% - 0.75px),
      var(--sparky-border-color) calc(66.666% - 0.75px),
      var(--sparky-border-color) calc(66.666% + 0.75px),
      transparent calc(66.666% + 0.75px)
    ),
    linear-gradient(
      to bottom,
      transparent calc(33.333% - 0.75px),
      var(--sparky-border-color) calc(33.333% - 0.75px),
      var(--sparky-border-color) calc(33.333% + 0.75px),
      transparent calc(33.333% + 0.75px),
      transparent calc(66.666% - 0.75px),
      var(--sparky-border-color) calc(66.666% - 0.75px),
      var(--sparky-border-color) calc(66.666% + 0.75px),
      transparent calc(66.666% + 0.75px)
    );
  opacity: 0.9;
}

/* Cells */
.wun-sparky-cell {
  position: relative;
  aspect-ratio: 1 / 1;

  display: flex;
  align-items: center;
  justify-content: center;

  background: transparent !important;
  border: none !important;

  cursor: pointer;
  padding: 8px;

  transition:
    background 0.22s ease,
    transform 0.22s ease;
}

.wun-sparky-cell::before {
  display: none !important;
}

/* Sparkys */
.wun-sparky-cell img {
  position: relative;
  z-index: 2;

  width: 88%;
  height: 88%;
  object-fit: contain;
  pointer-events: none;

  transform-origin: center;
  transition:
    transform 0.24s cubic-bezier(.16,.84,.32,1),
    filter 0.24s ease;
}

.wun-sparky-cell:hover img {
  transform: translateY(-5px) scale(1.055) rotate(-1deg);
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.18));
}

.wun-sparky-cell.is-correct img {
  animation: wunCorrectPop 0.42s cubic-bezier(.16,.84,.32,1) forwards;
}

.wun-sparky-cell.is-wrong {
  animation: wunWrongShake 0.32s ease;
}

.wun-sparky-game.is-low-time .wun-game-time {
  animation: wunTimerPulse 0.65s ease-in-out infinite;
}

@keyframes wunBoardIn {
  0% { opacity: 0; transform: translateY(10px) scale(0.985); filter: blur(4px); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

@keyframes wunCorrectPop {
  0% { transform: scale(1); }
  42% {
    transform: scale(1.2) rotate(5deg);
    filter:
      drop-shadow(0 0 12px rgba(255, 81, 40, 0.75))
      drop-shadow(0 0 22px rgba(167, 56, 224, 0.45));
  }
  72% { transform: scale(0.96) rotate(-2deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes wunWrongShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@keyframes wunTimerPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 6px 18px rgba(255, 81, 40, 0.2); }
  50% { transform: scale(1.08); box-shadow: 0 8px 22px rgba(255, 81, 40, 0.45); }
}

/* ----------------------------- */
/* MODAL */
/* ----------------------------- */

.wun-game-modal {
  position: absolute;
  inset: 0;
  z-index: 20;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 20px;

  background: radial-gradient(
    ellipse at center,
    rgba(167, 56, 224, 0.58) 0%,
    rgba(31, 18, 63, 0.68) 58%,
    rgba(31, 18, 63, 0.9) 100%
  );

  opacity: 0;
  visibility: hidden;
  pointer-events: none;

  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.wun-game-modal.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ----------------------------- */
/* START SCREEN */
/* ----------------------------- */

.wun-game-start {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  padding: 40px 24px;

  min-height: 260px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(185, 76, 255, 0.4);
}

.wun-game-start.is-visible {
  display: flex;
}

.wun-game-start h4 {
  margin: 0 0 2px;
  color: #ffffff;
  font-family: "Roc Grotesk", sans-serif;
  font-size: 22px;
  font-weight: 700;
}

.wun-game-start p {
  margin: 0 0 18px;
  max-width: 300px;
  color: rgba(255, 255, 255, 0.78);
  font-family: "Lato", sans-serif;
  font-size: 13px;
  line-height: 140%;
}

.wun-start-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;

  min-height: 46px;
  padding: 0 28px;

  border: none;
  border-radius: 999px;

  background: var(--sparky-accent);
  color: #ffffff;

  font-family: "Roc Grotesk", sans-serif;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;

  cursor: pointer;
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  animation: wunStartPulse 2.2s ease-in-out infinite;
}

.wun-start-button svg {
  flex-shrink: 0;
}

.wun-start-button:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 12px 26px rgba(255, 81, 40, 0.4);
}

@keyframes wunStartPulse {
  0%, 100% { box-shadow: 0 6px 18px rgba(255, 81, 40, 0.25); }
  50% { box-shadow: 0 6px 26px rgba(255, 81, 40, 0.5); }
}

/* ----------------------------- */
/* MILESTONE TOAST */
/* ----------------------------- */

.wun-game-toast {
  position: absolute;
  top: 70px;
  left: 50%;
  z-index: 16;
  transform: translate(-50%, -6px);

  padding: 6px 16px;
  border-radius: 999px;

  background: #1F123F;
  color: #ffffff;

  font-family: "Roc Grotesk", sans-serif;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;

  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.wun-game-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  animation: wunToastPop 0.9s ease forwards;
}

@keyframes wunToastPop {
  0% { opacity: 0; transform: translate(-50%, 6px) scale(0.9); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  30% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -8px) scale(0.95); }
}

/* ----------------------------- */
/* +1 POPUP */
/* ----------------------------- */

.wun-plus-one {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 5;

  color: var(--sparky-accent);
  font-family: "Roc Grotesk", sans-serif;
  font-size: 15px;
  font-weight: 800;

  pointer-events: none;
  animation: wunPlusOneFloat 0.6s ease forwards;
}

@keyframes wunPlusOneFloat {
  0% { opacity: 0; transform: translateY(0) scale(0.8); }
  20% { opacity: 1; transform: translateY(-6px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-28px) scale(1); }
}

/* ----------------------------- */
/* NEW BEST BADGE + CONFETTI */
/* ----------------------------- */

.wun-new-best-badge {
  display: none;
  margin: 0 auto 8px;
  padding: 4px 14px;
  border-radius: 999px;

  background: linear-gradient(90deg, #FFD166, #FF5128);
  color: #ffffff;

  font-family: "Roc Grotesk", sans-serif;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.wun-new-best-badge.is-visible {
  display: inline-block;
  animation: wunBadgeBounce 0.5s cubic-bezier(.16,.84,.32,1);
}

@keyframes wunBadgeBounce {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); }
}

.wun-confetti-piece {
  position: absolute;
  top: -10px;
  width: 7px;
  height: 12px;
  z-index: 30;
  pointer-events: none;
  animation: wunConfettiFall 1.4s ease-in forwards;
}

@keyframes wunConfettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(320px) rotate(280deg); opacity: 0; }
}

.wun-game-result-line {
  margin: 0 auto 4px !important;
  max-width: 340px;

  color: var(--sparky-modal-text) !important;
  font-family: "Roc Grotesk", sans-serif !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  line-height: 130% !important;
}

.wun-game-result-best {
  margin-bottom: 14px !important;
  color: var(--sparky-modal-text) !important;
  opacity: 0.7;
  font-family: "Lato", sans-serif !important;
  font-size: 13px !important;
  font-weight: 400 !important;
}

.wun-game-modal-card {
  position: relative;
  width: min(100%, 420px);
  padding: 30px 32px 28px;

  border-radius: 18px;
  background: var(--sparky-modal-bg);
  color: var(--sparky-modal-text);
  text-align: center;

  box-shadow:
    0 18px 60px rgba(0, 0, 0, 0.28),
    0 0 60px rgba(167, 56, 224, 0.35);

  animation: wunModalIn 0.42s cubic-bezier(.16,.84,.32,1) forwards;
}

.wun-game-close {
  position: absolute;
  top: 12px;
  right: 14px;

  border: none;
  background: transparent;
  color: var(--sparky-modal-text);

  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.wun-game-modal-sparky {
  display: block;
  width: 76px;
  height: auto;
  margin: 0 auto 14px;

  animation: wunModalSparkyFloat 2.8s ease-in-out infinite;
}

.wun-game-modal-card h3 {
  margin: 0 0 12px;

  color: var(--sparky-modal-text);
  font-family: "Roc Grotesk", sans-serif;
  font-size: 26px;
  font-weight: 700;
  line-height: 110%;
}

.wun-game-modal-card p {
  margin: 0 auto 18px;
  max-width: 340px;

  color: var(--sparky-modal-text);
  font-family: "Lato", sans-serif;
  font-size: 13px;
  font-weight: 400;
  line-height: 140%;
}

/* Save-score row */
.wun-game-save-row {
  display: flex;
  gap: 8px;
  max-width: 340px;
  margin: 0 auto 8px;
}

.wun-game-name-input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 14px;

  border: 1.5px solid rgba(31, 18, 63, 0.18);
  border-radius: 999px;

  color: var(--sparky-modal-text);
  font-family: "Lato", sans-serif;
  font-size: 13px;

  outline: none;
  transition: border-color 0.2s ease;
}

.wun-game-name-input:focus {
  border-color: var(--sparky-accent);
}

.wun-save-score {
  background: var(--sparky-accent) !important;
  flex-shrink: 0;
}

.wun-game-save-status {
  min-height: 16px;
  margin: 0 auto 14px;
  max-width: 340px;

  color: var(--sparky-modal-text);
  opacity: 0.75;
  font-family: "Lato", sans-serif;
  font-size: 12px;
}

.wun-play-again {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;

  min-height: 38px;
  padding: 0 22px;

  border: none;
  border-radius: 999px;

  background: var(--sparky-accent);
  color: #ffffff;

  font-family: "Roc Grotesk", sans-serif;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;

  cursor: pointer;
  transition: transform 0.22s ease, box-shadow 0.22s ease, opacity 0.2s ease;
}

.wun-play-again:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none !important;
  box-shadow: none !important;
}

.wun-play-again:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 22px rgba(255, 81, 40, 0.32);
}

@keyframes wunModalIn {
  0% { opacity: 0; transform: translateY(16px) scale(0.96); filter: blur(4px); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

@keyframes wunModalSparkyFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-5px) rotate(-2deg); }
}

/* ----------------------------- */
/* TABLET */
/* ----------------------------- */

@media (max-width: 1024px) {
  .wun-sparky-game {
    width: min(100%, 480px);
  }
}

/* ----------------------------- */
/* MOBILE */
/* ----------------------------- */

@media (max-width: 767px) {
  .wun-sparky-game {
    width: min(100%, 340px);
    padding: 16px;
    border-radius: 16px;
  }

  .wun-game-top {
    margin-bottom: 10px;
    flex-wrap: wrap;
  }

  .wun-game-pill {
    min-height: 23px;
    padding: 0 10px;
    font-size: 10px;
  }

  .wun-sparky-cell {
    padding: 6px;
  }

  .wun-sparky-cell img {
    width: 90%;
    height: 90%;
  }

  .wun-game-modal {
    padding: 14px;
  }

  .wun-game-modal-card {
    padding: 26px 22px 24px;
    border-radius: 14px;
  }

  .wun-game-modal-sparky {
    width: 68px;
  }

  .wun-game-modal-card h3 {
    font-size: 22px;
  }

  .wun-game-modal-card p {
    font-size: 12px;
  }

  .wun-game-save-row {
    flex-direction: column;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .wun-sparky-grid,
  .wun-sparky-cell img,
  .wun-game-time,
  .wun-game-modal-card,
  .wun-game-modal-sparky {
    animation: none !important;
    transition: none !important;
  }
}
