/* ============================================================
   CRITTER CLUB v1.0 — Sunny Meadow theme
   A learning playground for 3–4 year olds
   British English throughout
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&family=Nunito:wght@600;700;800&display=swap');

:root {
  --sky: #9bdcf2;
  --sky-deep: #5fb6dd;
  --grass: #9be0b0;
  --grass-deep: #5fc486;
  --sun: #ffd166;
  --coral: #ff8fa3;
  --berry: #9b7ede;
  --ink: #33384f;
  --cream: #fffdf5;
  --shadow: rgba(51, 56, 79, .18);
  --display: 'Fredoka', 'Baloo 2', 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }

body {
  font-family: var(--body);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky) 0%, var(--sky-deep) 55%, var(--grass) 55%, var(--grass-deep) 100%);
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---- ambient sky ---- */
.sky-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.sun {
  position: absolute; top: 4vh; right: 6vw;
  width: 14vh; height: 14vh; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #fff3c4, var(--sun));
  box-shadow: 0 0 0 12px rgba(255, 209, 102, .25), 0 0 0 28px rgba(255, 209, 102, .12);
}
.cloud {
  position: absolute; background: #fff; border-radius: 50px; opacity: .85;
  filter: drop-shadow(0 6px 0 rgba(255, 255, 255, .5));
}
.cloud::before, .cloud::after { content: ''; position: absolute; background: #fff; border-radius: 50%; }
.cloud.c1 { top: 10vh; width: 120px; height: 38px; left: -160px; animation: drift 38s linear infinite; }
.cloud.c2 { top: 22vh; width: 90px; height: 30px; left: -140px; animation: drift 52s linear infinite; animation-delay: -12s; }
.cloud.c3 { top: 6vh; width: 70px; height: 24px; left: -120px; animation: drift 60s linear infinite; animation-delay: -30s; }
.cloud.c4 { top: 16vh; width: 100px; height: 34px; left: -170px; animation: drift 45s linear infinite; animation-delay: -20s; }
.cloud::before { width: 50px; height: 50px; top: -22px; left: 18px; }
.cloud::after { width: 38px; height: 38px; top: -14px; left: 54px; }
@keyframes drift { to { transform: translateX(115vw); } }

/* ---- top bar ---- */
.topbar {
  position: relative; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  flex-wrap: wrap;
}
.brand {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(18px, 4vw, 28px);
  color: #fff; text-shadow: 0 3px 0 var(--sky-deep), 0 4px 6px var(--shadow);
  display: flex; align-items: center; gap: 6px;
}
.spacer { flex: 1; }

.pill-btn {
  font-family: var(--display); font-weight: 600; border: none; cursor: pointer;
  background: #fff; color: var(--ink); border-radius: 999px;
  padding: 8px 14px; font-size: clamp(13px, 3vw, 17px);
  box-shadow: 0 4px 0 var(--shadow);
  display: flex; align-items: center; gap: 6px;
  transition: transform .08s;
}
.pill-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--shadow); }
.pill-btn:focus-visible { outline: 4px solid var(--berry); outline-offset: 3px; }

.seg {
  display: flex; background: #fff; border-radius: 999px; padding: 4px;
  box-shadow: 0 4px 0 var(--shadow);
}
.seg button {
  font-family: var(--display); font-weight: 600; border: none; cursor: pointer;
  background: transparent; color: var(--ink); border-radius: 999px;
  padding: 6px 12px; font-size: clamp(12px, 3vw, 16px); transition: .12s;
}
.seg button.on { background: var(--sun); box-shadow: 0 2px 0 rgba(0, 0, 0, .08); }
.seg button:focus-visible { outline: 3px solid var(--berry); outline-offset: 2px; }

/* ---- generic stage ---- */
.stage {
  position: relative; z-index: 3; flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 8px 16px 24px;
}

.prompt {
  font-family: var(--display); font-weight: 600;
  color: #fff; text-align: center;
  font-size: clamp(20px, 5.5vw, 38px);
  text-shadow: 0 3px 0 var(--sky-deep), 0 5px 8px var(--shadow);
  margin: 0 0 4px; min-height: 1.2em;
}

.subprompt {
  font-family: var(--body); font-weight: 700;
  color: rgba(255, 255, 255, .85); text-align: center;
  font-size: clamp(13px, 3vw, 18px);
  margin: 0 0 12px;
}

/* ---- splash ---- */
.splash {
  position: absolute; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  text-align: center;
  background: linear-gradient(180deg, var(--sky), var(--grass-deep));
}
.splash h1 {
  font-family: var(--display); font-weight: 700; color: #fff; margin: 0;
  font-size: clamp(40px, 12vw, 88px);
  text-shadow: 0 5px 0 var(--sky-deep), 0 8px 14px var(--shadow);
}
.splash .paws { font-size: clamp(44px, 14vw, 110px); animation: bob 1.6s ease-in-out infinite; }
.splash p {
  color: #fff; font-weight: 700; font-size: clamp(14px, 3.5vw, 20px);
  margin: 0 24px; text-shadow: 0 2px 4px var(--shadow);
}
.big-start {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(24px, 6vw, 40px);
  border: none; cursor: pointer; color: var(--ink);
  background: var(--sun); padding: 16px 40px;
  border-radius: 999px;
  box-shadow: 0 8px 0 #d9a93f, 0 12px 20px var(--shadow);
  animation: pulseBtn 1.8s ease-in-out infinite;
}
.big-start:active { transform: translateY(5px); box-shadow: 0 3px 0 #d9a93f; }
@keyframes pulseBtn { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-16px); } }

/* ---- hub menu cards ---- */
.hub {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px; width: min(960px, 100%);
  padding: 0 8px;
}
.game-card {
  position: relative; cursor: pointer; border: none; text-align: left;
  border-radius: 26px; padding: 20px; color: #fff;
  font-family: var(--display);
  box-shadow: 0 7px 0 var(--shadow), 0 10px 20px var(--shadow);
  transition: transform .1s; overflow: hidden;
  min-height: 140px;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 3px;
}
.game-card:active { transform: translateY(4px) scale(.99); }
.game-card:focus-visible { outline: 5px solid #fff; outline-offset: 3px; }
.game-card .ico { font-size: clamp(40px, 8vw, 62px); line-height: 1; filter: drop-shadow(0 4px 4px rgba(0,0,0,.15)); }
.game-card .ttl { font-weight: 700; font-size: clamp(18px, 4vw, 24px); }
.game-card .sub { font-family: var(--body); font-weight: 700; font-size: 13px; opacity: .9; }
.game-card.g0 { background: linear-gradient(140deg, #ff9a76, var(--coral)); }
.game-card.g1 { background: linear-gradient(140deg, #7fd6f2, var(--berry)); }
.game-card.g2 { background: linear-gradient(140deg, #86e0a4, var(--grass-deep)); }
.game-card.g3 { background: linear-gradient(140deg, #ffd166, #ff9a76); }
.game-card.g4 { background: linear-gradient(140deg, #c4b5fd, var(--berry)); }
.game-card.g5 { background: linear-gradient(140deg, #fda4af, var(--coral)); }
.game-card.g6 { background: linear-gradient(140deg, #a5f3fc, var(--sky-deep)); }
.game-card.g7 { background: linear-gradient(140deg, #fde68a, var(--sun)); }
.game-card.g8 { background: linear-gradient(140deg, #d8b4fe, #a78bfa); }

.hub-hint {
  color: #fff; text-align: center; font-weight: 700; margin-top: 4px;
  text-shadow: 0 2px 4px var(--shadow);
  font-size: clamp(12px, 3vw, 16px);
}

/* ---- choice tiles ---- */
.choices {
  display: flex; flex-wrap: wrap;
  gap: clamp(10px, 2.5vw, 22px);
  justify-content: center; align-items: center;
  width: min(960px, 100%); margin-top: 8px;
}
.tile {
  position: relative; cursor: pointer; border: none; background: var(--cream);
  border-radius: 28px;
  box-shadow: 0 7px 0 var(--shadow), 0 10px 18px var(--shadow);
  display: flex; align-items: center; justify-content: center;
  width: clamp(100px, 20vw, 170px); height: clamp(100px, 20vw, 170px);
  font-size: clamp(54px, 12vw, 100px); line-height: 1;
  transition: transform .1s;
  animation: popIn .35s cubic-bezier(.2, 1.3, .5, 1) backwards;
}
.tile.big-tile { width: clamp(120px, 22vw, 190px); height: clamp(120px, 22vw, 190px); }
.tile:active { transform: translateY(4px); }
.tile:focus-visible { outline: 5px solid var(--berry); outline-offset: 4px; }
.tile.num {
  font-family: var(--display); font-weight: 700; color: var(--coral);
  font-size: clamp(48px, 11vw, 88px);
}
.tile.idle { animation: popIn .35s backwards, sway 3s ease-in-out infinite; }
.tile.right { animation: winSpin .7s ease; }
.tile.wrong { animation: wiggle .45s ease; }
.tile.dim { opacity: .45; filter: saturate(.6); }
@keyframes popIn { from { opacity: 0; transform: scale(.3) translateY(20px); } to { opacity: 1; transform: scale(1); } }
@keyframes sway { 0%,100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes wiggle { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-10px) rotate(-4deg); } 40% { transform: translateX(10px) rotate(4deg); } 60% { transform: translateX(-7px); } 80% { transform: translateX(7px); } }
@keyframes winSpin { 0% { transform: scale(1); } 40% { transform: scale(1.3) rotate(8deg); } 100% { transform: scale(1.15); } }

/* ---- count row ---- */
.count-row {
  background: rgba(255, 255, 255, .35); border-radius: 32px;
  padding: 16px 20px;
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; align-items: center;
  width: min(900px, 100%);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .4);
}
.count-row .critter {
  font-size: clamp(40px, 9vw, 78px); line-height: 1;
  animation: popIn .35s backwards;
}
.count-row .critter.lit { animation: countPop .5s ease; }
@keyframes countPop { 0% { transform: scale(1); } 50% { transform: scale(1.45); } 100% { transform: scale(1); } }

/* ---- letter game ---- */
.letter-card {
  background: var(--cream); border-radius: 34px;
  padding: clamp(16px, 3.5vw, 36px);
  box-shadow: 0 9px 0 var(--shadow), 0 14px 26px var(--shadow);
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  animation: popIn .4s backwards; cursor: pointer;
}
.letter-card .animal { font-size: clamp(70px, 18vw, 150px); line-height: 1; animation: bob 2s ease-in-out infinite; }
.letter-card .glyph {
  font-family: var(--display); font-weight: 700; color: var(--berry);
  font-size: clamp(60px, 14vw, 120px); line-height: .9;
}
.letter-card .word {
  font-family: var(--display); font-weight: 600; color: var(--ink);
  font-size: clamp(18px, 4.5vw, 28px);
}

.key-hint { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.key {
  font-family: var(--display); font-weight: 700; background: #fff; color: var(--ink);
  border: none; border-radius: 12px;
  min-width: 48px; height: 54px; padding: 0 12px;
  font-size: 22px; cursor: pointer;
  box-shadow: 0 4px 0 var(--shadow); transition: transform .08s;
}
.key:active, .key.press { transform: translateY(4px); box-shadow: 0 1px 0 var(--shadow); background: var(--sun); }
.key.target { background: var(--sun); box-shadow: 0 4px 0 #d9a93f; }
.key:focus-visible { outline: 4px solid var(--berry); outline-offset: 3px; }

/* ---- colour game ---- */
.colour-tile {
  border-radius: 24px; cursor: pointer; border: 4px solid transparent;
  width: clamp(90px, 18vw, 150px); height: clamp(90px, 18vw, 150px);
  box-shadow: 0 6px 0 var(--shadow), 0 8px 16px var(--shadow);
  transition: transform .1s, border-color .2s;
  animation: popIn .35s backwards;
}
.colour-tile:active { transform: translateY(4px); }
.colour-tile.right { border-color: #fff; animation: winSpin .7s ease; }
.colour-tile.wrong { animation: wiggle .45s ease; }
.colour-tile:focus-visible { outline: 5px solid var(--berry); outline-offset: 4px; }

/* ---- shape game ---- */
.shape-tile {
  border-radius: 20px; cursor: pointer; border: 3px solid rgba(255,255,255,.5);
  background: var(--cream);
  width: clamp(90px, 18vw, 150px); height: clamp(90px, 18vw, 150px);
  box-shadow: 0 6px 0 var(--shadow), 0 8px 16px var(--shadow);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(50px, 12vw, 90px);
  transition: transform .1s;
  animation: popIn .35s backwards;
}
.shape-tile:active { transform: translateY(4px); }
.shape-tile.right { border-color: #fff; animation: winSpin .7s ease; }
.shape-tile.wrong { animation: wiggle .45s ease; }
.shape-tile:focus-visible { outline: 5px solid var(--berry); outline-offset: 4px; }

/* ---- memory game ---- */
.memory-grid {
  display: grid; gap: 10px; width: min(760px, 100%);
  justify-content: center; align-items: center;
}
.memory-card {
  aspect-ratio: 1;
  border-radius: 18px; border: 3px solid rgba(255,255,255,.4);
  background: linear-gradient(140deg, var(--berry), var(--sky-deep));
  cursor: pointer; font-size: clamp(32px, 8vw, 60px);
  display: flex; align-items: center; justify-content: center;
  transition: transform .2s, background .3s;
  box-shadow: 0 5px 0 var(--shadow);
}
.memory-card.flipped { background: var(--cream); }
.memory-card.matched { background: var(--grass-deep); border-color: #fff; cursor: default; }
.memory-card:active:not(.matched) { transform: scale(.94); }
.memory-card:focus-visible { outline: 4px solid var(--berry); outline-offset: 3px; }

/* ---- replay ---- */
.replay { position: relative; z-index: 4; }

/* ---- confetti ---- */
.confetti {
  position: fixed; top: -20px; width: 14px; height: 14px; border-radius: 3px;
  z-index: 60; pointer-events: none; animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: .9; } }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; top: 18%; transform: translateX(-50%) scale(.6);
  z-index: 65; font-family: var(--display); font-weight: 700; color: #fff;
  pointer-events: none;
  font-size: clamp(32px, 9vw, 64px);
  text-shadow: 0 4px 0 var(--coral), 0 6px 12px var(--shadow);
  opacity: 0;
}
.toast.show { animation: toastPop 1.4s ease forwards; }
@keyframes toastPop {
  0% { opacity: 0; transform: translateX(-50%) scale(.4); }
  20% { opacity: 1; transform: translateX(-50%) scale(1.1); }
  70% { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) scale(1); }
}

/* ---- settings panel ---- */
.settings-overlay {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.settings-panel {
  background: var(--cream); border-radius: 28px;
  padding: 28px 24px; width: min(420px, 90vw);
  box-shadow: 0 12px 0 var(--shadow), 0 20px 36px var(--shadow);
  font-family: var(--body);
  max-height: 80vh; overflow-y: auto;
}
.settings-panel h2 {
  font-family: var(--display); font-weight: 700; color: var(--ink);
  margin: 0 0 18px; font-size: clamp(22px, 5vw, 30px);
  text-align: center;
}
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 0; border-bottom: 2px solid rgba(0,0,0,.06);
}
.setting-row label { font-weight: 700; font-size: 15px; color: var(--ink); flex: 1; }
.setting-row select, .setting-row input[type=range] {
  font-family: var(--body); font-size: 14px; padding: 4px 8px;
  border-radius: 12px; border: 2px solid rgba(0,0,0,.12); background: #fff;
}
.settings-panel .pill-btn { margin-top: 16px; width: 100%; justify-content: center; }

/* ---- sticker book ---- */
.sticker-book {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .2s ease;
}
.sticker-inner {
  background: var(--cream); border-radius: 28px;
  padding: 24px; width: min(480px, 90vw);
  box-shadow: 0 12px 0 var(--shadow), 0 20px 36px var(--shadow);
  max-height: 80vh; overflow-y: auto;
}
.sticker-inner h2 {
  font-family: var(--display); font-weight: 700; text-align: center;
  color: var(--ink); margin: 0 0 14px; font-size: clamp(20px, 5vw, 28px);
}
.sticker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 10px; justify-items: center;
}
.sticker-slot {
  width: 60px; height: 60px; border-radius: 16px;
  background: rgba(0,0,0,.06); border: 2px dashed rgba(0,0,0,.12);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; transition: .2s;
}
.sticker-slot.earned { background: #fff; border: 3px solid var(--sun); box-shadow: 0 2px 6px var(--shadow); }

/* ---- progress bar ---- */
.progress-wrap {
  width: min(400px, 90%); margin: 0 auto 8px;
  background: rgba(255,255,255,.3); border-radius: 999px;
  height: 12px; overflow: hidden;
}
.progress-bar {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--sun), var(--coral));
  transition: width .4s ease;
  width: 0%;
}

/* ---- trace game ---- */
.trace-canvas {
  border-radius: 24px; background: var(--cream);
  box-shadow: 0 8px 0 var(--shadow), 0 12px 24px var(--shadow);
  touch-action: none;
}

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001s !important; animation-iteration-count: 1 !important; }
  .cloud, .sun { display: none; }
}
