:root {
  --bg-1: #081126;
  --bg-2: #0f1f45;
  --surface: rgba(14, 26, 59, 0.85);
  --surface-strong: rgba(10, 20, 48, 0.92);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f4f8ff;
  --text-muted: #b4c2e8;
  --accent: #53f2ff;
  --accent-2: #5cffb3;
  --danger: #ff6f8f;
  --board-size: min(82vw, 520px);
  --cell-gap: 6px;
  --tile-radius: 16px;
  --transition-fast: 140ms cubic-bezier(0.3, 0.6, 0.3, 1);
  --transition-smooth: 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  background: radial-gradient(circle at 20% 10%, #1c3a81 0%, transparent 35%),
    radial-gradient(circle at 80% 85%, #1f6f78 0%, transparent 40%),
    linear-gradient(130deg, var(--bg-1), var(--bg-2));
  color: var(--text);
  font-family: "Noto Sans SC", "PingFang SC", sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  display: grid;
  place-items: center;
  padding: clamp(14px, 2vh, 22px);
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(56px);
  opacity: 0.25;
  z-index: 0;
}

.orb-a {
  width: 32vmax;
  height: 32vmax;
  left: -10vmax;
  top: -8vmax;
  background: #29f0ff;
}

.orb-b {
  width: 36vmax;
  height: 36vmax;
  right: -14vmax;
  bottom: -14vmax;
  background: #2fffab;
}

.orb-c {
  width: 24vmax;
  height: 24vmax;
  right: 24vmax;
  top: 10vmax;
  background: #ff6f8f;
}

.app {
  position: relative;
  z-index: 1;
  width: min(100%, 620px);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  border-radius: 24px;
  padding: clamp(16px, 2.3vw, 24px);
  box-shadow: 0 20px 55px rgba(4, 7, 17, 0.48);
}

.panel-start {
  text-align: center;
  display: grid;
  gap: 14px;
}

.title {
  margin: 8px 0 0;
  font-family: "Baloo 2", cursive;
  font-size: clamp(2rem, 6.5vw, 3.2rem);
  letter-spacing: 1px;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
}

.best-score {
  margin-top: 8px;
  font-weight: 700;
  color: var(--accent);
}

.hidden {
  display: none !important;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.hud-item {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  display: grid;
  gap: 2px;
}

.hud-label {
  font-size: 12px;
  color: var(--text-muted);
}

.hud-value {
  font-weight: 800;
  font-size: 1.1rem;
  font-family: "Baloo 2", cursive;
}

.combo-wrap {
  position: relative;
}

.combo-wrap.active {
  animation: comboPulse 420ms ease;
}

@keyframes comboPulse {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.stage-line {
  margin: -2px 0 12px;
  color: var(--accent);
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.2px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.03));
  color: var(--text);
  font-family: "Noto Sans SC", sans-serif;
  font-weight: 700;
  min-height: 42px;
  padding: 10px 16px;
  cursor: pointer;
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.btn:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.33);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.22);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  border-color: transparent;
  background: linear-gradient(120deg, #21e1ff, #44f4a4 65%, #67d8ff);
  color: #06213f;
}

.board-shell {
  position: relative;
  width: var(--board-size);
  margin: 0 auto;
  border-radius: 22px;
  padding: 10px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.03));
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(6, 15, 40, 0.95), rgba(9, 25, 59, 0.94));
  overflow: hidden;
  touch-action: none;
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: calc(100% / 8) calc(100% / 8);
  pointer-events: none;
}

.particles {
  position: absolute;
  inset: 10px;
  width: calc(100% - 20px);
  height: calc(100% - 20px);
  pointer-events: none;
}

.tile {
  position: absolute;
  border: 0;
  margin: 0;
  border-radius: var(--tile-radius);
  display: grid;
  place-items: center;
  font-size: clamp(22px, 2.7vw, 28px);
  line-height: 1;
  color: rgba(255, 255, 255, 0.94);
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.3), inset 0 -6px 12px rgba(0, 0, 0, 0.2),
    0 8px 16px rgba(0, 0, 0, 0.28);
  user-select: none;
  transition: transform var(--transition-smooth), opacity var(--transition-fast), filter var(--transition-fast);
}

.tile.selected {
  filter: brightness(1.2);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.45), inset 0 2px 4px rgba(255, 255, 255, 0.3),
    inset 0 -6px 12px rgba(0, 0, 0, 0.2);
}

.tile.pop {
  animation: popOut 200ms ease forwards;
}

@keyframes popOut {
  to {
    transform: scale(0.15) rotate(12deg);
    opacity: 0;
  }
}

.tile.spawn {
  animation: spawnIn 230ms ease;
}

@keyframes spawnIn {
  from {
    transform: scale(0.7);
    opacity: 0.3;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.tile.special::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 11px;
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.tile.rainbow {
  background: conic-gradient(
    from 90deg,
    #ff758f,
    #ffdc65,
    #47e0ff,
    #6dff8f,
    #be82ff,
    #ff758f
  );
}

.tile.row::before,
.tile.col::before,
.tile.bomb::before {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 999px;
}

.tile.row::before {
  width: 72%;
  height: 5px;
}

.tile.col::before {
  width: 5px;
  height: 72%;
}

.tile.bomb::before {
  width: 34%;
  height: 34%;
  border: 2px solid rgba(255, 255, 255, 0.75);
  background: transparent;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.45);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 23, 0.7);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 20px;
}

.overlay-card {
  width: min(100%, 360px);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.44);
}

.end-score,
.end-best {
  margin: 8px 0;
}

.end-status {
  margin: 8px 0;
  color: var(--accent-2);
  font-weight: 700;
}

@media (max-width: 680px) {
  :root {
    --board-size: min(94vw, 520px);
    --cell-gap: 4px;
    --tile-radius: 12px;
  }

  body {
    padding: 8px;
  }

  .panel {
    border-radius: 18px;
    padding: 12px;
  }

  .controls {
    gap: 8px;
  }

  .btn {
    flex: 1;
    min-width: 96px;
    min-height: 44px;
  }

  .hud-value {
    font-size: 1rem;
  }
}
