:root {
  --bg-top: #ffdce8;
  --bg-bot: #ffe9c7;
  --panel-bg: #ffffff;
  --panel-text: #3a2340;
  --text-dim: #7a6a85;
  --accent: #ff5fa2;
  --accent-2: #7b4fff;
  --board-bg: #ffffff;
  --cell-bg: #f6edf9;
  --hud-bg: rgba(255,255,255,0.85);
  --shadow: 0 10px 30px rgba(123,79,255,0.18);
  --ring-glow: #ffd54a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-top: #1c1230;
    --bg-bot: #2a1a3a;
    --panel-bg: #241733;
    --panel-text: #f2e9ff;
    --text-dim: #b8a8cc;
    --accent: #ff6fb0;
    --accent-2: #9b7bff;
    --board-bg: #1b1228;
    --cell-bg: #2c1e3f;
    --hud-bg: rgba(28,18,48,0.85);
    --shadow: 0 10px 30px rgba(0,0,0,0.5);
    --ring-glow: #ffe07a;
  }
}

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

html, body {
  margin: 0;
  height: 100%;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bot));
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--panel-text);
  overscroll-behavior: none;
  touch-action: manipulation;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) 0;
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  padding: 16px;
}
.screen.active { display: flex; }

/* overlay screens (start/levelup/gameover) sit above the game screen */
#screen-start, #screen-levelup, #screen-gameover {
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  z-index: 10;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bot));
}
#screen-start.active, #screen-levelup.active, #screen-gameover.active { display: flex; }

.panel {
  background: var(--panel-bg);
  border-radius: 24px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 340px;
}

.logo { font-size: 28px; font-weight: 800; margin-bottom: 8px; }
.logo span { color: var(--accent); }
.tag { color: var(--text-dim); font-size: 14px; line-height: 1.5; margin-bottom: 24px; }
.ring-emoji { filter: drop-shadow(0 0 4px var(--ring-glow)); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  font-size: 17px;
  font-weight: 700;
  padding: 14px 32px;
  border-radius: 999px;
  width: 100%;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(255,95,162,0.35);
}
.btn-primary:active { transform: scale(0.97); }

.btn-ghost {
  background: transparent;
  border: 1.5px solid var(--text-dim);
  color: var(--text-dim);
  font-size: 13px;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
}

.best { margin-top: 16px; font-size: 13px; color: var(--text-dim); }
.big-emoji { font-size: 48px; margin-bottom: 8px; }
.stat-row { font-size: 15px; margin: 6px 0 18px; color: var(--text-dim); }
.stat-row span { font-weight: 800; color: var(--panel-text); }
#lu-ring-row { display: none; }
#lu-ring-row.show { display: block; }

#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--hud-bg);
  border-radius: 18px;
  padding: 10px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
.hud-item { text-align: center; flex: 1; }
.hud-goal { flex: 1.4; }
.hud-label { display: block; font-size: 10px; letter-spacing: 0.08em; color: var(--text-dim); font-weight: 700; }
.hud-item > span:not(.hud-label) { font-size: 18px; font-weight: 800; }
#hud-moves { color: var(--accent); }

#board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  position: relative;
  background: var(--board-bg);
  border-radius: 18px;
  box-shadow: var(--shadow);
  touch-action: none;
}

.cell {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  will-change: transform;
  transition: transform 160ms cubic-bezier(.4,0,.2,1), opacity 140ms linear;
}

.cell .emoji {
  width: 82%;
  height: 82%;
  border-radius: 50%;
  background: var(--cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6em;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.08);
}

.cell .emoji { position: relative; overflow: hidden; }

.cell.selected .emoji {
  transform: scale(1.12);
  box-shadow: 0 0 0 3px #fff, 0 0 14px var(--accent);
}

.cell.striped-h .emoji::after,
.cell.striped-v .emoji::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(180deg, rgba(255,255,255,0.7) 0 12%, transparent 12% 30%);
}
.cell.striped-v .emoji::after {
  background: repeating-linear-gradient(90deg, rgba(255,255,255,0.7) 0 12%, transparent 12% 30%);
}

.cell.wrapped .emoji {
  box-shadow: 0 0 0 3px #ffd24a, 0 0 10px #ffb300, inset 0 -3px 0 rgba(0,0,0,0.06);
}

.cell.bomb .emoji {
  background: conic-gradient(from 0deg, #ff5fa2, #ffd54a, #4fd1ff, #7b4fff, #ff5fa2);
  color: #fff;
  font-weight: 900;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  animation: ring-pulse 0.9s ease-in-out infinite;
}

.cell.ring .emoji {
  background: radial-gradient(circle, #fff7d6, var(--ring-glow));
  box-shadow: 0 0 14px var(--ring-glow), inset 0 -2px 0 rgba(0,0,0,0.08);
  animation: ring-pulse 1.1s ease-in-out infinite;
}

@keyframes ring-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.cell.popping {
  transform: scale(0.2) !important;
  opacity: 0;
}

.cell.shake { animation: shake 160ms; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

#bottom-bar { text-align: center; margin-top: 12px; }

#toast-layer {
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.toast {
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 999px;
  animation: toast-float 1100ms ease-out forwards;
  white-space: nowrap;
}

.toast.ring-toast {
  background: linear-gradient(135deg, #ffb300, #ff6fb0);
}

@keyframes toast-float {
  0% { opacity: 0; transform: translateY(10px); }
  15% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-28px); }
}
