:root {
  --bg-deep: #1a1a2e;
  --bg-panel: rgba(255, 255, 255, 0.06);
  --accent: #e94560;
  --accent-soft: rgba(233, 69, 96, 0.35);
  --text: #eaeaea;
  --muted: #8892a6;
  --cell-bg: rgba(255, 255, 255, 0.08);
  --board-gap: 4px;
  --gem-size: min(10vw, 52px);
  --radius: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(165deg, #16213e 0%, #0f3460 45%, #1a1a2e 100%);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 12px;
}

.app {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 24px);
}

.header {
  text-align: center;
  padding: 8px 0 12px;
}

.title {
  margin: 0 0 12px;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-shadow: 0 2px 12px rgba(233, 69, 96, 0.4);
}

.stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.stat {
  background: var(--bg-panel);
  border-radius: var(--radius);
  padding: 8px 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  min-width: 88px;
}

.stat-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
}

.toolbar {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #c73e54);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-soft);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px var(--accent-soft);
}

.btn:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.18);
}

.btn-icon {
  padding: 10px 14px;
  font-size: 1.1rem;
  line-height: 1;
}

.btn-large {
  padding: 14px 28px;
  font-size: 1.05rem;
  margin-top: 8px;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.board-wrap {
  position: relative;
  padding: 12px;
  background: var(--bg-panel);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  overflow: visible;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, var(--gem-size));
  grid-template-rows: repeat(8, var(--gem-size));
  gap: var(--board-gap);
  user-select: none;
  overflow: visible;
  touch-action: none;
}

.cell {
  width: var(--gem-size);
  height: var(--gem-size);
  border-radius: 10px;
  background: var(--cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  overflow: visible;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.cell:active {
  transform: scale(0.95);
}

.cell.selected {
  box-shadow: 0 0 0 3px #fff, 0 0 16px var(--accent);
  z-index: 2;
}

.cell.hint-pulse {
  animation: hintPulse 0.9s ease-in-out infinite;
}

@keyframes hintPulse {
  0%,
  100% {
    box-shadow: 0 0 0 2px rgba(255, 200, 100, 0.8);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(255, 200, 100, 0.4);
  }
}

.gem {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  box-shadow:
    inset 0 -4px 8px rgba(0, 0, 0, 0.35),
    inset 0 4px 8px rgba(255, 255, 255, 0.25),
    0 4px 8px rgba(0, 0, 0, 0.25);
  transform-origin: center center;
  will-change: transform, opacity, filter;
}

.gem.eliminating {
  animation: gemEliminate 0.42s cubic-bezier(0.33, 0.82, 0.43, 1) forwards;
  pointer-events: none;
  z-index: 5;
}

@keyframes gemEliminate {
  0% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
    filter: brightness(1) saturate(1);
  }
  35% {
    transform: scale(1.18) rotate(10deg);
    filter: brightness(1.35) saturate(1.3);
  }
  100% {
    transform: scale(0) rotate(-28deg);
    opacity: 0;
    filter: brightness(1.6);
  }
}

.gem.refill-enter {
  animation: gemRefillDrop 0.38s cubic-bezier(0.25, 0.82, 0.35, 1.05) forwards;
}

@keyframes gemRefillDrop {
  from {
    opacity: 0.2;
    transform: translateY(calc(-1 * (var(--gem-size) + var(--board-gap)) * 2.2)) scale(0.65);
    filter: blur(2px);
  }
  70% {
    opacity: 1;
    filter: blur(0);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

.gem-0 {
  background: radial-gradient(circle at 30% 30%, #ff8a8a, #e63946);
}
.gem-1 {
  background: radial-gradient(circle at 30% 30%, #ffe066, #f4a261);
}
.gem-2 {
  background: radial-gradient(circle at 30% 30%, #a8e6cf, #2a9d8f);
}
.gem-3 {
  background: radial-gradient(circle at 30% 30%, #89c2ff, #4361ee);
}
.gem-4 {
  background: radial-gradient(circle at 30% 30%, #e0b0ff, #9b5de5);
}
.gem-5 {
  background: radial-gradient(circle at 30% 30%, #ffd6e8, #f15bb5);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 24, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(6px);
}

.overlay.hidden {
  display: none;
}

.modal {
  background: linear-gradient(180deg, #252542 0%, #1e1e36 100%);
  border-radius: 20px;
  padding: 28px 24px;
  max-width: 360px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal h2 {
  margin-top: 0;
  font-size: 1.35rem;
}

.modal p {
  color: var(--muted);
  line-height: 1.6;
  font-size: 0.95rem;
  text-align: left;
}

.hint-text {
  min-height: 1.5em;
  margin: 12px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  text-align: center;
}

.footer {
  text-align: center;
  padding: 12px;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.35);
}

@media (max-width: 380px) {
  :root {
    --gem-size: min(11vw, 44px);
  }
}
