:root {
  --bg: #0e1424;
  --card: #121a2f;
  --accent: #5cf0c1;
  --accent-2: #7aa7ff;
  --danger: #ff6b6b;
  --text: #f4f7ff;
  --muted: #b5bed3;
  --tile-1: #ffe8a3;
  --tile-2: #ffd3a3;
  --tile-3: #ffc5c5;
  --tile-4: #b5ffeb;
  --tile-5: #c3d4ff;
  --tile-6: #f6b3ff;
  --tile-7: #aff3ff;
  --tile-8: #d9ffa3;
  --tile-9: #f7c9ff;
  --tile-10: #ffbdbd;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  --radius-lg: 18px;
  --radius-sm: 12px;
  font-size: 16px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 20%, #172040, #0e1424 50%);
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  touch-action: manipulation;
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: 800; }
p { margin: 0; }

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
}

.screen { display: none; }
.screen.active { display: block; }

.hero { text-align: center; margin: 16px 0 12px; }
.hero h1 { font-size: 2.1rem; letter-spacing: 0.02em; }
.subtitle { color: var(--muted); margin-top: 6px; }

.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.progress-summary { display: grid; grid-template-columns: 1fr; gap: 10px; }
.stat { display: flex; justify-content: space-between; align-items: baseline; color: var(--muted); }
.stat strong { color: var(--text); font-size: 1.1rem; }

.button-stack { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
button {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 1rem;
  font-weight: 700;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  min-height: 52px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.2s;
}
button:active { transform: translateY(1px); }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #06111a; }
button.secondary { background: #1d2741; }
button.ghost { background: transparent; border: 1px solid #2c3652; box-shadow: none; width: auto; padding: 10px 16px; }
button.danger { background: var(--danger); color: #120808; }
button.full { width: 100%; }

.pill { width: auto; padding: 12px 16px; border-radius: 999px; font-weight: 800; }
.pill.danger { background: #ff8d8d; color: #1b0b0b; }

.header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }

.level-list { display: flex; flex-direction: column; gap: 12px; }
.level-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.level-info { display: flex; flex-direction: column; gap: 4px; }
.level-progress { color: var(--muted); font-size: 0.95rem; }

.game-top { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 10px; }
.level-info .small { color: var(--muted); }
.actions { display: flex; gap: 8px; }

.grid {
  background: #101728;
  border-radius: var(--radius-lg);
  padding: 10px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
}

.cell {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 14px;
  background: #0a1020;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1c273d;
  font-size: 1.4rem;
  font-weight: 800;
  position: relative;
  overflow: hidden;
}

.tile {
  width: 100%;
  height: 100%;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: #0f1321;
  transition: transform 0.16s ease;
}

.tile.spawn { animation: pop 0.2s ease; }
.tile.removed { animation: fadeOut 0.18s ease forwards; }

@keyframes pop {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes fadeOut {
  to { transform: scale(0.6); opacity: 0; }
}

.missions { margin-bottom: 12px; }
.mission {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #1f2944;
}
.mission:last-child { border-bottom: none; }

.collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.collection-cell {
  border-radius: 12px;
  background: #1a2239;
  color: var(--muted);
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  position: relative;
}
.collection-cell.open { background: var(--accent); color: #062016; box-shadow: 0 8px 16px rgba(92, 240, 193, 0.35); }
.collection-cell.dim { opacity: 0.35; }

.collection-popup {
  position: fixed;
  left: 50%;
  bottom: 16vh;
  transform: translateX(-50%);
  background: #0f1729;
  padding: 16px 20px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  font-size: 1.2rem;
  font-weight: 800;
  animation: pop 0.2s ease;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 20, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.overlay.hidden { display: none; }
.modal {
  background: #0f1629;
  padding: 18px;
  border-radius: 16px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
  text-align: center;
}

.toast {
  position: fixed;
  bottom: 14vh;
  left: 50%;
  transform: translateX(-50%);
  background: #0f1729;
  padding: 12px 18px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 9;
}
.toast.show { opacity: 1; }
.toast.sticker { background: var(--accent); color: #041912; }

.settings .setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.settings .label { font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 0.95rem; }

.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
}
.switch input { display: none; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #1f2944;
  transition: .2s;
  border-radius: 34px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
}
input:checked + .slider { background-color: var(--accent); }
input:checked + .slider:before { transform: translateX(22px); }

.hidden { display: none; }

@media (min-width: 700px) {
  #app { max-width: 520px; }
}
