:root {
  --gold: #f0c84a;
  --gold-deep: #c9a227;
  --magenta: #e879f9;
  --purple-deep: #3b1468;
  --panel: linear-gradient(180deg, #6a2a9a 0%, #3a1468 55%, #2a0f52 100%);
  --text: #fff6e8;
  --win: #ffe566;
  --rose: #f472b6;
  --lavender: #c4b5fd;
  --cream: #fff7ed;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(120, 40, 180, 0.45) 0%, transparent 55%),
    linear-gradient(180deg, #2a1048 0%, #1a0a36 45%, #140828 100%);
  color: var(--text);
  font-family: "Nunito", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
}

html.embed,
html.embed body {
  background: transparent;
  height: auto;
  min-height: 0;
}

html.embed .stage {
  min-height: 0;
  height: auto;
  justify-content: flex-start;
  gap: 8px;
  padding: 10px 10px 8px;
}

html.embed .hint {
  display: none;
}

html.embed .hud,
html.embed .board-wrap {
  width: min(96%, 560px);
}

html.embed .board-wrap {
  --board-w: min(96%, 560px);
}

.stage {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 12px 20px;
}

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: min(92vw, 560px);
  z-index: 5;
}

.hud-card {
  background: var(--panel);
  border: 2.5px solid var(--gold);
  border-radius: 999px;
  padding: 8px 14px;
  text-align: center;
  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.35),
    0 0 18px rgba(240, 200, 74, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.hud-label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #fff;
  opacity: 0.95;
  font-weight: 800;
}

.hud-value {
  display: block;
  font-family: "Baloo 2", "Nunito", sans-serif;
  font-weight: 800;
  font-size: clamp(1rem, 3.6vw, 1.35rem);
  color: var(--gold);
  text-shadow: 0 0 12px rgba(240, 200, 74, 0.45);
  margin-top: 2px;
}

.hud-win {
  color: var(--win);
  text-shadow: 0 0 12px rgba(255, 229, 102, 0.45);
}

.bet-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 2px;
}

.bet-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  background: linear-gradient(180deg, #f9a8d4, #c084fc);
  color: var(--gold);
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.bet-btn:active {
  transform: scale(0.92);
}

.bet-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.combo-wrap {
  height: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  z-index: 6;
  overflow: visible;
  pointer-events: none;
}

.combo-wrap.active {
  height: 42px;
}

.combo-badge {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  letter-spacing: 0.08em;
  color: #fff;
  padding: 6px 18px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff2d8a, #ffb000 50%, #ff2d8a);
  background-size: 200% 100%;
  box-shadow:
    0 0 24px rgba(255, 80, 180, 0.7),
    0 4px 0 #8a0048;
  animation: comboPulse 0.55s ease, comboShine 1.2s linear infinite;
}

@keyframes comboPulse {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes comboShine {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

.board-wrap {
  --board-w: min(92vw, 560px);
  width: var(--board-w);
  aspect-ratio: 975 / 860;
  position: relative;
  filter: drop-shadow(0 16px 28px rgba(190, 24, 93, 0.22));
  z-index: 2;
}

.board-wrap.shake {
  animation: boardShake 0.45s ease;
}

@keyframes boardShake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 2px) rotate(-0.6deg); }
  40% { transform: translate(7px, -3px) rotate(0.7deg); }
  60% { transform: translate(-4px, 3px) rotate(-0.4deg); }
  80% { transform: translate(3px, -2px); }
}

.board-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  border-radius: 4%;
}

.board {
  position: absolute;
  left: 4.92%;
  top: 5.12%;
  width: 90.26%;
  height: 88.37%;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 0;
}

.fx-layer {
  position: absolute;
  left: 4.92%;
  top: 5.12%;
  width: 90.26%;
  height: 88.37%;
  pointer-events: none;
  overflow: hidden;
  z-index: 4;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.cell.selected::after {
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 18%;
  border: 2.5px solid #f9a8d4;
  box-shadow:
    0 0 10px rgba(244, 114, 182, 0.75),
    inset 0 0 8px rgba(255, 255, 255, 0.55);
  pointer-events: none;
  z-index: 3;
}

.gem {
  width: 82%;
  height: 82%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35));
  z-index: 1;
  position: relative;
}

.gem.swapping {
  transition: transform 0.16s ease;
  z-index: 5;
}

.gem.falling {
  animation: fallIn 0.22s cubic-bezier(0.2, 0.85, 0.3, 1);
}

.gem.spawn {
  animation: spawnIn 0.28s ease;
}

.gem.matched {
  animation: pop 0.28s ease forwards;
}

.gem-special-badge {
  position: absolute;
  inset: 8%;
  border-radius: 16%;
  pointer-events: none;
  z-index: 2;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55);
}

.gem-wrap {
  position: relative;
  width: 82%;
  height: 82%;
  display: grid;
  place-items: center;
}

.gem-wrap .gem {
  width: 100%;
  height: 100%;
}

.special-stripe-h,
.special-stripe-v,
.special-bomb {
  filter: drop-shadow(0 0 6px rgba(255, 210, 80, 0.85));
}

.special-stripe-h::before,
.special-stripe-v::before,
.special-bomb::before,
.special-stripe-h::after,
.special-stripe-v::after,
.special-bomb::after {
  content: "";
  position: absolute;
  pointer-events: none;
  z-index: 2;
}

.special-stripe-h::after,
.special-stripe-v::after,
.special-bomb::after {
  inset: -2%;
  border-radius: 22%;
  box-shadow: 0 0 0 2px rgba(255, 220, 100, 0.9), 0 0 12px rgba(255, 180, 40, 0.7);
}

.special-stripe-h::before {
  inset: 0;
  border-radius: 18%;
  background: linear-gradient(
    180deg,
    transparent 38%,
    rgba(255, 255, 255, 0.85) 47%,
    #ffe566 50%,
    rgba(255, 255, 255, 0.85) 53%,
    transparent 62%
  );
}

.special-stripe-v::before {
  inset: 0;
  border-radius: 18%;
  background: linear-gradient(
    90deg,
    transparent 38%,
    rgba(255, 255, 255, 0.85) 47%,
    #ffe566 50%,
    rgba(255, 255, 255, 0.85) 53%,
    transparent 62%
  );
}

.special-bomb::before {
  inset: 16%;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, #ffd060 35%, transparent 70%);
  box-shadow: 0 0 16px 6px rgba(255, 200, 60, 0.75);
  animation: bombGlow 0.9s ease-in-out infinite alternate;
}

@keyframes bombGlow {
  from { transform: scale(0.92); opacity: 0.75; }
  to { transform: scale(1.08); opacity: 1; }
}

@keyframes pop {
  0% { transform: scale(1); opacity: 1; filter: brightness(1); }
  40% { transform: scale(1.35); opacity: 1; filter: brightness(1.8); }
  100% { transform: scale(0); opacity: 0; filter: brightness(2.5); }
}

@keyframes fallIn {
  from { transform: translateY(-110%); opacity: 0.5; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes spawnIn {
  from { transform: scale(0.2); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.flash-line {
  position: absolute;
  background: linear-gradient(90deg, transparent, #fff, #ffe680, #fff, transparent);
  box-shadow: 0 0 18px 4px rgba(255, 230, 120, 0.9);
  z-index: 6;
  pointer-events: none;
  animation: flashFade 0.35s ease forwards;
}

.flash-line.row {
  left: 0;
  right: 0;
  height: 18%;
  border-radius: 8px;
}

.flash-line.col {
  top: 0;
  bottom: 0;
  width: 18%;
  border-radius: 8px;
}

.flash-bomb {
  position: absolute;
  width: 40%;
  height: 40%;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, #ffd060 30%, transparent 70%);
  box-shadow: 0 0 30px 12px rgba(255, 200, 80, 0.7);
  transform: translate(-50%, -50%) scale(0.2);
  animation: bombFlash 0.4s ease forwards;
  z-index: 6;
  pointer-events: none;
}

@keyframes flashFade {
  0% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes bombFlash {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.2); }
  40% { opacity: 1; transform: translate(-50%, -50%) scale(1.4); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(2.2); }
}

.hint {
  font-size: clamp(0.75rem, 2.5vw, 0.95rem);
  color: #9333ea;
  text-align: center;
  max-width: 560px;
  opacity: 0.85;
}

.win-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(74, 25, 66, 0.35);
  backdrop-filter: blur(2px);
  animation: overlayIn 0.2s ease;
}

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

.win-banner {
  text-align: center;
  padding: 28px 40px;
  border-radius: 24px;
  border: 3px solid var(--gold);
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.65), transparent 50%),
    linear-gradient(160deg, #fce7f3, #ede9fe 55%, #fff7ed);
  box-shadow:
    0 0 50px rgba(244, 114, 182, 0.45),
    0 20px 40px rgba(190, 24, 93, 0.18);
  animation: bannerPop 0.55s cubic-bezier(0.2, 1.2, 0.4, 1);
  min-width: min(86vw, 360px);
}

.win-title {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: clamp(1.8rem, 8vw, 3rem);
  letter-spacing: 0.06em;
  background: linear-gradient(180deg, #fff8c8, #ffd040 40%, #ff8a00);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 #8a4000);
  animation: titleGlow 0.8s ease infinite alternate;
}

.win-banner.mega .win-title {
  background: linear-gradient(180deg, #ffe0ff, #ff60d0 45%, #ff2080);
  -webkit-background-clip: text;
  background-clip: text;
}

.win-banner.epic .win-title {
  background: linear-gradient(180deg, #fff, #7dffb0 40%, #00e0ff 80%, #ffd040);
  -webkit-background-clip: text;
  background-clip: text;
  font-size: clamp(2rem, 9vw, 3.4rem);
}

.win-amount {
  margin-top: 10px;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: clamp(1.4rem, 5vw, 2.2rem);
  color: var(--win);
  text-shadow: 0 0 20px rgba(34, 197, 94, 0.55);
}

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

@keyframes bannerPop {
  0% { transform: scale(0.3) rotate(-8deg); opacity: 0; }
  70% { transform: scale(1.08) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

@keyframes titleGlow {
  from { filter: drop-shadow(0 2px 0 #8a4000) drop-shadow(0 0 8px rgba(255, 200, 60, 0.4)); }
  to { filter: drop-shadow(0 2px 0 #8a4000) drop-shadow(0 0 22px rgba(255, 220, 80, 0.9)); }
}

.coin-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 40;
}

@media (max-width: 420px) {
  .stage {
    gap: 8px;
    padding: 8px 8px 14px;
    justify-content: flex-start;
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .hud {
    gap: 6px;
  }

  .hud-card {
    padding: 6px 6px;
    border-radius: 12px;
  }

  .board-wrap {
    --board-w: min(96vw, 560px);
  }

  .hint {
    padding: 0 8px;
  }
}

@media (max-height: 700px) {
  .combo-wrap.active {
    height: 34px;
  }

  .hint {
    display: none;
  }
}
