:root {
  --bg: #fff7e0;
  --card: #ffffff;
  --text: #3d3355;
  --accent: #ffd166;
  --shadow: 0 6px 0 rgba(61, 51, 85, 0.15);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe UI Rounded", system-ui, sans-serif;
  /* Toddler-proofing: no text selection, no long-press menus, no double-tap zoom */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

img { -webkit-user-drag: none; pointer-events: none; }

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

[hidden] { display: none !important; }

h1 {
  text-align: center;
  font-size: clamp(2rem, 8vw, 4rem);
  margin: 0.3em 0 0.6em;
}

/* ---------- Home ---------- */
.games {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 320px));
  justify-content: center;
  gap: 24px;
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  background: var(--card);
  border-radius: 32px;
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  transition: transform 0.12s;
}

.game-pics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  background: #caffbf;
  border-radius: 24px;
  padding: 16px;
}

.game-pics img { width: 100%; aspect-ratio: 1; }

.game-name { font-size: 2.2rem; font-weight: bold; }

.game-card:active { transform: scale(0.94); }

footer { text-align: center; margin-top: 40px; }
footer a { color: var(--text); opacity: 0.5; font-size: 0.9rem; }

/* ---------- Game screens ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 16px;
  margin: -16px -16px 16px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--accent);
  box-shadow: var(--shadow);
}

.bar h2 { margin: 0; font-size: clamp(1.6rem, 6vw, 2.4rem); }

.home-btn {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
}
.home-btn img { width: 38px; height: 38px; }
.home-btn:active { transform: scale(0.9); }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  padding: 12%;
  border: none;
  border-radius: 28px;
  background: var(--tile, #fff);
  box-shadow: var(--shadow);
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.tile img { width: 100%; height: 100%; object-fit: contain; }

/* Name label pops up when the name is spoken */
.tile .label {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  font-weight: bold;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}
.tile.named .label { opacity: 1; transform: none; }

/* Pressed feel */
.tile:active { transform: scale(0.92) translateY(4px); box-shadow: 0 2px 0 rgba(61, 51, 85, 0.15); }

.tile.bounce img { animation: bounce 0.5s ease; }
.tile.wiggle img { animation: wiggle 0.6s ease; }

@keyframes bounce {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.18); }
  60%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-12deg) scale(1.1); }
  40% { transform: rotate(12deg) scale(1.1); }
  60% { transform: rotate(-8deg) scale(1.05); }
  80% { transform: rotate(8deg); }
}

@media (prefers-reduced-motion: reduce) {
  .tile.bounce img, .tile.wiggle img { animation: none; }
}

/* ---------- Colors ---------- */
.game-pics .swatch { aspect-ratio: 1; border-radius: 50%; }

.colors .tile { border: 4px solid rgba(61, 51, 85, 0.12); }
.colors .tile.bounce { animation: bounce 0.5s ease; }

/* The thing of that color pops up on a white plate on the second tap */
.thing {
  position: absolute;
  inset: 10%;
  display: grid;
  place-items: center;
  padding: 14%;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 4px rgba(61, 51, 85, 0.1);
  transform: scale(0);
  transition: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.tile.show-thing .thing { transform: scale(1); }

/* Label sits on a white pill so it reads on every color */
.colors .label {
  left: 50%;
  right: auto;
  padding: 2px 14px;
  border-radius: 999px;
  background: #fff;
  translate: -50% 0;
}
.tile[aria-label="white"] .thing { background: #9bf6ff; }

/* ---------- Numbers ---------- */
.numeral-chip {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 20px;
  font-size: clamp(2.5rem, 12vw, 4rem);
  font-weight: bold;
}

.numbers .tile.bounce { animation: bounce 0.5s ease; }
.numbers .tile img { animation: none !important; }

.numeral {
  font-size: clamp(5rem, 22vw, 8rem);
  font-weight: bold;
  line-height: 1;
}

/* The counted pictures replace the numeral on the second tap */
.things {
  display: none;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  width: 100%;
  height: 100%;
}
.things img {
  width: calc(100% / var(--cols));
  height: auto;
  aspect-ratio: 1;
  padding: 3%;
  transform: scale(0);
  transition: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.things img.on { transform: scale(1); }

.tile.counting .numeral { display: none; }
.tile.counting .things { display: flex; }

/* ---------- Shapes ---------- */
.game-pics svg { width: 100%; aspect-ratio: 1; }
.shape { width: 100%; height: 100%; transition: opacity 0.2s; }
.show-thing .shape { opacity: 0; }
.shapes .tile.bounce { animation: bounce 0.5s ease; }
.shapes .thing { background: #fff7e0; }

/* ---------- Food: the second tap takes a bite out of the top-right corner ---------- */
.tile.bitten img {
  -webkit-mask-image: radial-gradient(circle at 90% 10%, transparent 0 22%, #000 23%),
                      radial-gradient(circle at 70% 4%, transparent 0 14%, #000 15%);
  -webkit-mask-composite: source-in;
  mask-image: radial-gradient(circle at 90% 10%, transparent 0 22%, #000 23%),
              radial-gradient(circle at 70% 4%, transparent 0 14%, #000 15%);
  mask-composite: intersect;
}
