* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(160deg, #1b1033 0%, #2a1450 45%, #120a26 100%);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  touch-action: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  max-width: 520px;
  margin: 0 auto;
}

#topbar {
  position: relative;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 14px 10px 6px;
  flex-shrink: 0;
}

#muteBtn {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 12px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.2);
  background: linear-gradient(180deg, #3fd67a, #1f9d52);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 3px 8px rgba(31,157,82,0.4);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

#muteIcon {
  font-size: 15px;
}

#muteBtn:active {
  transform: scale(0.92);
}

#muteBtn.muted {
  background: linear-gradient(180deg, #8a8a99, #55555e);
  box-shadow: 0 3px 8px rgba(0,0,0,0.35);
}

.stat {
  text-align: center;
  color: #fff;
  min-width: 70px;
}

.stat .label {
  font-size: 12px;
  opacity: 0.6;
  letter-spacing: 1px;
  margin-bottom: 2px;
}

.stat .value {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(180deg, #ffe9a8, #ffb347);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  transition: transform 0.15s ease;
}

.stat .value.bump {
  transform: scale(1.25);
}

#boardWrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 6px 10px;
}

#board {
  position: relative;
  display: grid;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  padding: 6px;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.4), 0 10px 30px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.08);
}

.cell {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  transition: transform 0.16s ease, left 0.18s ease, top 0.18s ease, opacity 0.16s ease;
  will-change: transform, left, top;
}

.gem {
  width: 82%;
  height: 82%;
  border-radius: 30% 70% 65% 35% / 40% 40% 60% 60%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  position: relative;
  box-shadow: inset -3px -4px 6px rgba(0,0,0,0.35), inset 3px 3px 6px rgba(255,255,255,0.5), 0 3px 8px rgba(0,0,0,0.4);
  cursor: pointer;
}

.gem::after {
  content: "";
  position: absolute;
  top: 12%;
  left: 18%;
  width: 30%;
  height: 22%;
  background: rgba(255,255,255,0.55);
  border-radius: 50%;
  filter: blur(1px);
}

.gem.type-0 { background: radial-gradient(circle at 35% 30%, #7ff7ff, #0aa6c9 70%, #076f8c); }
.gem.type-1 { background: radial-gradient(circle at 35% 30%, #ffd0e6, #ff4d8d 70%, #b5215c); }
.gem.type-2 { background: radial-gradient(circle at 35% 30%, #dfffb0, #6fd94a 70%, #2f8f16); }
.gem.type-3 { background: radial-gradient(circle at 35% 30%, #fff2b0, #ffc93c 70%, #c98a06); }
.gem.type-4 { background: radial-gradient(circle at 35% 30%, #e2c8ff, #a259ff 70%, #6414c9); }
.gem.type-5 { background: radial-gradient(circle at 35% 30%, #e35555, #a3111a 65%, #5c0008); }

.cell.selected .gem {
  transform: scale(1.12);
  box-shadow: 0 0 0 3px #fff, inset -3px -4px 6px rgba(0,0,0,0.35), inset 3px 3px 6px rgba(255,255,255,0.5), 0 3px 10px rgba(0,0,0,0.5);
}

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

.cell.falling-in {
  opacity: 0;
}

@keyframes pop {
  0% { transform: scale(1); opacity: 1; }
  60% { transform: scale(1.3); opacity: 0.7; }
  100% { transform: scale(0.1); opacity: 0; }
}

#bottombar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px calc(14px + env(safe-area-inset-bottom));
}

#bottomLeft {
  display: flex;
  align-items: center;
  gap: 12px;
}

#levelLabel {
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  letter-spacing: 1px;
}

#audioDebug {
  color: rgba(255,255,255,0.35);
  font-size: 10px;
}

#restartBtn {
  background: linear-gradient(180deg, #7a5cff, #4b2fd6);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 10px rgba(75,47,214,0.5);
}

#restartBtn:active {
  transform: scale(0.95);
}

#overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 5, 25, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity 0.2s ease;
}

#overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#overlayCard {
  background: linear-gradient(160deg, #2c1a55, #1a0f38);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 18px;
  padding: 30px 36px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
}

#overlayTitle {
  color: #ffd76b;
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 8px;
}

#overlaySub {
  color: rgba(255,255,255,0.8);
  font-size: 15px;
  margin-bottom: 20px;
}

#overlayBtn {
  background: linear-gradient(180deg, #ffcf5c, #ff9d1e);
  border: none;
  padding: 12px 26px;
  border-radius: 22px;
  font-size: 15px;
  font-weight: 700;
  color: #4a2a00;
  box-shadow: 0 6px 14px rgba(255,159,30,0.4);
}

#overlayBtn:active {
  transform: scale(0.95);
}

#app.shake {
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
