:root {
  --purple-0: #1a0828;
  --purple-1: #2a0d40;
  --pink: #e9a8ff;
  --gold: #f0c040;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: Montserrat, system-ui, sans-serif;
  color: #fff;
  background: #1a0828 url("./assets/bg.jpg") center / cover no-repeat;
  user-select: none;
  overflow: hidden;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.app {
  width: min(100%, 640px);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 8px 14px 12px;
}

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

.logo {
  height: 56px;
  width: auto;
  max-width: 46vw;
  object-fit: contain;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,.45));
}

.wallet {
  background: rgba(12, 4, 22, .72);
  border: 2px solid rgba(233, 168, 255, .35);
  border-radius: 16px;
  padding: 8px 14px;
  min-width: 132px;
  text-align: right;
}

.wallet span {
  display: block;
  font-size: 10px;
  letter-spacing: .16em;
  color: rgba(255,255,255,.55);
}

#walletBalanceText {
  font-size: 18px;
  font-weight: 800;
  color: #fff;
}

.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 6px 0;
}

.board-wrap {
  position: relative;
  width: min(100%, 68dvh, 560px);
  aspect-ratio: 586 / 602;
  background: url("./assets/board-frame.png") center / 100% 100% no-repeat;
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 5.1% 5% 6.6%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 2.15%;
}

.tile {
  position: relative;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  overflow: visible;
}

.tile .art,
.tile .gem,
.tile .bomb-glow,
.tile .bomb,
.tile .boom-fx,
.tile .fuse-spark,
.tile .finger,
.tile .gold {
  position: absolute;
  pointer-events: none;
}

.tile .art {
  inset: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
}

.tile.is-closed .art { background-image: url("./assets/tile-closed.png"); }
.tile.is-gem .art { background-image: url("./assets/tile-gem.png"); }
.tile.is-mine .art,
.tile.is-boom .art { background-image: url("./assets/tile-boom.png"); }

.tile.is-boom .bomb,
.tile.is-boom .bomb-glow,
.tile.is-boom .fuse-spark {
  opacity: 0 !important;
  animation: none !important;
}

.tile.is-boom .art {
  animation: boomPop 0.28s ease-out;
}

@keyframes boomPop {
  0% { transform: scale(0.72); filter: brightness(2.2); }
  100% { transform: scale(1); filter: brightness(1); }
}

.tile .gem {
  inset: -4%;
  background: url("./assets/gem.png") center / contain no-repeat;
  opacity: 0;
}

.tile.is-gem .gem { opacity: 1; }

.tile .bomb-glow {
  inset: -55%;
  background: url("./assets/mine-fx.jpg") center / contain no-repeat;
  mix-blend-mode: screen;
  opacity: 0;
  z-index: 2;
}

.tile.is-mine .bomb-glow {
  opacity: 1;
  animation: burstPulse 0.5s ease-in-out infinite alternate;
}

.tile .bomb {
  inset: 6%;
  background: url("./assets/bomb.png") center / contain no-repeat;
  transform: rotate(90deg);
  opacity: 0;
  z-index: 3;
}

.tile.is-mine .bomb { opacity: 1; }

.tile .boom-fx {
  inset: -48%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  mix-blend-mode: screen;
  opacity: 0;
  z-index: 6;
}

.tile.is-exploding .boom-fx { opacity: 1; }

.tile .fuse-spark {
  left: 50%;
  top: 10%;
  width: 34%;
  height: 34%;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(circle, #fff 0 18%, #ffe566 28%, #ff7a00 52%, transparent 70%);
  mix-blend-mode: screen;
  opacity: 0;
  z-index: 4;
  filter: drop-shadow(0 0 6px #ff9000);
}

.tile.is-mine .fuse-spark {
  opacity: 1;
  animation: fuseFlicker 0.11s linear infinite;
}

@keyframes burstPulse {
  from { transform: scale(0.9); opacity: 0.82; }
  to { transform: scale(1.12); opacity: 1; }
}

@keyframes fuseFlicker {
  0% { transform: translate(-50%, -50%) scale(0.85) rotate(-8deg); opacity: 0.75; }
  40% { transform: translate(-50%, -40%) scale(1.25) rotate(10deg); opacity: 1; }
  100% { transform: translate(-50%, -55%) scale(0.9) rotate(-4deg); opacity: 0.8; }
}

.tile .finger {
  left: 50%;
  top: 54%;
  width: 44%;
  height: 60%;
  transform: translate(-50%, -50%);
  background: url("./assets/finger.png") center / contain no-repeat;
  opacity: 0;
}

.tile.is-picked .finger { opacity: 1; }

.tile .gold {
  inset: -4%;
  background: url("./assets/gold-frame.png") center / 100% 100% no-repeat;
  opacity: 0;
}

.tile.is-gold .gold { opacity: 1; }

.tile:disabled { cursor: default; }

.hint {
  position: absolute;
  inset: 22% 7%;
  z-index: 4;
  background: rgba(40, 16, 64, .86);
  border: 2px solid rgba(255,255,255,.28);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px 14px;
  font-weight: 800;
  font-size: clamp(12px, 2.4vw, 17px);
  line-height: 1.35;
  letter-spacing: .02em;
  text-transform: uppercase;
  pointer-events: none;
}

.hint.hide { display: none; }

.count {
  position: absolute;
  right: 3.4%;
  bottom: 2.4%;
  background: rgba(20, 8, 36, .82);
  border-radius: 10px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 800;
  color: #d8c4ff;
  z-index: 3;
  pointer-events: none;
}

.dock {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1.35fr 64px;
  grid-template-areas:
    "mines gems rand"
    "play play play";
  gap: 8px;
  align-items: stretch;
}

.dock .panel:nth-child(1) { grid-area: mines; }
.dock .panel:nth-child(2) { grid-area: gems; }
.rand { grid-area: rand; }
.play { grid-area: play; min-height: 52px; }

.panel {
  background: rgba(28, 8, 48, .92);
  border: 2px solid #c07ae0;
  border-radius: 18px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.panel label {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #e9a8ff;
  font-weight: 700;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.val {
  font-size: 20px;
  font-weight: 800;
}

.arrow {
  width: 28px;
  height: 28px;
  border: 0;
  background: url("./assets/arrows.png") no-repeat;
  background-size: 200% 100%;
  cursor: pointer;
}

.arrow.prev { background-position: 0 50%; }
.arrow.next { background-position: 100% 50%; }
.arrow:disabled { opacity: .35; cursor: default; }

.play {
  border: 0;
  border-radius: 18px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  color: #2a1040;
  background: linear-gradient(180deg, #f6d15a, #e0a020);
  box-shadow: 0 6px 0 #9a6a10;
}

.play.cash {
  background: linear-gradient(180deg, #7af07a, #2db82d);
  box-shadow: 0 6px 0 #1a7a1a;
  color: #073007;
}

.play:disabled { opacity: .45; cursor: default; box-shadow: none; }

.rand {
  width: 64px;
  border: 2px solid #c07ae0;
  border-radius: 16px;
  background: rgba(28, 8, 48, .92) url("./assets/random.png") center 58% / 42px auto no-repeat;
  cursor: pointer;
}

.rand:disabled { opacity: .4; cursor: default; }

.toast {
  position: fixed;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  background: rgba(20, 6, 36, .92);
  border: 2px solid #f0c040;
  color: #ffe9a0;
  font-weight: 800;
  padding: 10px 16px;
  border-radius: 14px;
  z-index: 20;
  display: none;
}

@media (max-width: 720px) {
  .play { min-height: 48px; font-size: 16px; }
}

@media (max-height: 740px) {
  .logo { height: 40px; }
  .board-wrap { width: min(100%, 52dvh, 420px); }
  .play { min-height: 44px; }
}
