:root {
  --bg1: #e9f4ff;
  --bg2: #f7f0ff;
  --panel: rgba(255,255,255,0.92);
  --panel-border: rgba(99, 102, 241, 0.16);
  --ink: #172554;
  --muted: #64748b;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --warn: #ef4444;
  --shadow: 0 14px 30px rgba(61, 76, 172, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --game-width: min(100vw - 12px, 520px);
  --board-size: min(calc(var(--game-width) - 10px), 86vw);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  font-family: Inter, system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, #ffffff 0%, rgba(255,255,255,0) 32%),
    linear-gradient(160deg, var(--bg1), var(--bg2));
  overscroll-behavior: none;
}
body {
  min-height: 100vh;
  min-height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
button { font: inherit; }
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}
.app {
  width: var(--game-width);
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(4px + var(--safe-top)) 6px calc(4px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  margin: 0 auto;
}
.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.hud-card,
.board-wrap,
.targets-card {
  width: min(100%, calc(var(--board-size) + 8px));
  margin: 0 auto;
}
.logo-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 2px 6px 1px;
}
.logo {
  font-family: 'Luckiest Guy', cursive;
  letter-spacing: 0.04em;
  font-size: clamp(24px, 4vw, 34px);
  margin: 0;
  color: #4338ca;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.12);
}
.top-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.small-btn {
  border: 0;
  border-radius: 11px;
  background: rgba(99,102,241,0.12);
  color: #4338ca;
  padding: 7px 9px;
  font-weight: 800;
  min-height: 36px;
}
.header {
  padding: 4px 6px 5px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
.metric {
  background: rgba(255,255,255,0.78);
  border: 1px solid rgba(99,102,241,0.1);
  border-radius: 13px;
  padding: 4px 7px;
  min-width: 0;
}
.metric-label {
  display: block;
  font-size: 8px;
  line-height: 1;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 3px;
  font-weight: 800;
}
.metric-value {
  display: block;
  font-size: clamp(15px, 3vw, 22px);
  line-height: 1;
  font-weight: 800;
}
.metric-value.danger { color: var(--warn); }
.board-wrap { padding: 4px; }
.board {
  width: min(100%, var(--board-size));
  max-width: var(--board-size);
  margin: 0 auto;
  display: grid;
  gap: 2px;
  background: rgba(99,102,241,0.08);
  border-radius: 20px;
  padding: 4px;
}
.cell {
  aspect-ratio: 1 / 1;
  border-radius: 15px;
  border: 0;
  background: rgba(255,255,255,0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 -2px 0 rgba(99,102,241,0.06);
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
  touch-action: none;
  padding: 0;
  position: relative;
  overflow: hidden;
}
.cell::after {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease, box-shadow 120ms ease;
}
.cell.active {
  transform: scale(1.08);
  background: linear-gradient(180deg, #7c83ff, #6366f1);
  box-shadow: 0 8px 18px rgba(99,102,241,0.35);
}
.cell.active::after {
  opacity: 1;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.95), 0 0 0 2px rgba(99,102,241,0.32);
}
.cell.found {
  background: linear-gradient(180deg, #fbbf24, #f59e0b);
  box-shadow: inset 0 -2px 0 rgba(120, 53, 15, 0.25);
  opacity: 1;
}
.cell.just-found {
  animation: foundPop 320ms ease-out;
}
.cell.reveal {
  background: #fee2e2;
  animation: pulse 0.7s infinite alternate;
}
.cell.hint { background: linear-gradient(180deg, #fde68a, #fcd34d); }
.emoji-stack {
  width: 94%;
  height: 94%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.emoji-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  filter: saturate(1.02);
}
.emoji-fallback {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: clamp(18px, 4.6vw, 32px);
  line-height: 1;
}
.fallback-only .emoji-fallback,
.emoji-stack.fallback-only .emoji-fallback {
  display: inline-flex;
}
.emoji-inline {
  width: calc(var(--board-size) / 10 - 6px);
  height: calc(var(--board-size) / 10 - 6px);
}
.targets {
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.target-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}
.target {
  position: relative;
  background: rgba(99,102,241,0.07);
  border: 1px solid rgba(99,102,241,0.14);
  border-radius: 16px;
  padding: 5px 7px 4px;
  text-align: center;
  min-height: 48px;
}
.target.found {
  opacity: 0.86;
  background: rgba(245, 158, 11, 0.24);
}
.target-seq {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  line-height: 1.05;
}
.hint-btn {
  position: absolute;
  top: -8px;
  left: -6px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid #ef4444;
  background: white;
  color: #ef4444;
  font-weight: 900;
  box-shadow: 0 8px 16px rgba(239,68,68,0.18);
}
.hint-btn:disabled {
  opacity: 0.5;
  border-color: #94a3b8;
  color: #94a3b8;
  box-shadow: none;
}
.hint-tooltip {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.96);
  color: white;
  border-radius: 12px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.28);
  max-width: 160px;
}
.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(241,245,249,0.78);
  backdrop-filter: blur(6px);
}
.overlay-soft { background: rgba(30,41,59,0.34); }
.overlay-card {
  width: 100%;
  max-width: 440px;
  padding: 22px 18px;
  border-radius: 24px;
  text-align: center;
}
.compact-card { max-width: 340px; }
.rules-card { max-width: 480px; }
.overlay-title {
  margin: 0 0 6px;
  font-family: 'Luckiest Guy', cursive;
  color: #4338ca;
  font-size: clamp(28px, 7vw, 42px);
  letter-spacing: 0.04em;
}
.small-title { font-size: clamp(24px, 6vw, 34px); }
.overlay-subtitle {
  margin: 0 0 14px;
  color: var(--muted);
  font-weight: 700;
}
.overlay-copy {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.42;
  margin: 0 0 16px;
}
.overlay-list {
  margin: 0 0 18px;
  padding-left: 18px;
  text-align: left;
  color: var(--ink);
  font-weight: 600;
  line-height: 1.5;
}
.tight-list { line-height: 1.4; }
.primary-btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 12px 22px rgba(99,102,241,0.3);
}
@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.04); }
}
@keyframes foundPop {
  0% { transform: scale(0.88); }
  55% { transform: scale(1.14); }
  100% { transform: scale(1); }
}
@media (max-width: 430px) {
  .logo { font-size: 26px; }
  .small-btn { padding: 6px 8px; min-height: 34px; }
  .metric { padding: 4px 6px; }
  .emoji-inline { width: 24px; height: 24px; }
}

.secondary-btn {
  border: 1px solid rgba(99,102,241,0.22);
  border-radius: 14px;
  padding: 11px 18px;
  background: rgba(255,255,255,0.85);
  color: #4338ca;
  font-weight: 800;
  font-size: 15px;
  margin-top: 10px;
}
.primary-btn:disabled {
  opacity: 0.7;
  box-shadow: none;
}
.tiny-note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}


.music-btn { display:none; }

.top-actions { align-items: center; }

.small-btn {
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
}
.small-btn:active,
.small-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99,102,241,0.16);
}

.hud-celebrate {
  animation: celebrateGlow 900ms ease;
}
.board-wrap-celebrate {
  animation: boardPulse 820ms ease;
}

@keyframes celebrateGlow {
  0% { box-shadow: 0 0 0 rgba(255,215,80,0); }
  25% { box-shadow: 0 0 0 4px rgba(255,215,80,0.18), 0 14px 30px rgba(61, 76, 172, 0.16); }
  100% { box-shadow: var(--shadow); }
}

@keyframes boardPulse {
  0% { transform: scale(1); }
  30% { transform: scale(1.012); }
  100% { transform: scale(1); }
}

.celebration-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}
.celebration-layer::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.1), rgba(255,255,255,0) 55%);
  animation: flashFade 700ms ease-out;
}
.celebration-badge {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translate(-50%, -50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255,255,255,0.95);
  border: 2px solid rgba(251,191,36,0.9);
  box-shadow: 0 12px 30px rgba(0,0,0,0.16);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #7c2d12;
  animation: badgePop 850ms ease-out;
}
.confetti-piece {
  position: absolute;
  top: -12%;
  line-height: 1;
  will-change: transform, top, opacity;
  animation-name: confettiDrop;
  animation-timing-function: cubic-bezier(.2,.7,.2,1);
  animation-fill-mode: forwards;
  text-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
@keyframes confettiDrop {
  0% { top: -12%; opacity: 0; }
  10% { opacity: 1; }
  100% { top: 112%; opacity: 0; transform: translateX(24px) rotate(360deg); }
}
@keyframes badgePop {
  0% { opacity: 0; transform: translate(-50%, -60%) scale(0.75); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  100% { opacity: 0; transform: translate(-50%, -44%) scale(1); }
}
@keyframes flashFade {
  from { opacity: 1; }
  to { opacity: 0; }
}

.target.found {
  transform: translateY(-1px);
}

.tiny-note {
  margin-top: 10px;
}

@media (max-width: 640px) {
  .top-actions {
    justify-content: flex-end;
    gap: 4px;
  }
  .small-btn {
    min-height: 34px;
    padding: 7px 8px;
  }
  .celebration-badge {
    top: 18%;
    font-size: 14px;
  }
}
