/* Ridge & Friends toddler game — offline demo (visual polish pass) */
:root {
  --sky: #a8d5e5;
  --meadow: #e8f5e9;
  --autumn1: #f4a261;
  --autumn2: #e76f51;
  --autumn3: #e9c46a;
  --forest: #2a9d8f;
  --ink: #264653;
  --cream: #fff8f0;
  --card: #ffffff;
  --shadow: 0 8px 24px rgba(38, 70, 83, 0.18);
  --tap: 128px;
  --radius: 28px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* Soft meadow: blur + ~24% white baked into bg-meadow.jpg; light extra wash */
  --bg-overlay: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.10) 0%,
    rgba(255, 255, 255, 0.06) 45%,
    rgba(255, 248, 240, 0.12) 100%
  );
  --bg-meadow-url: url("../assets/bg-meadow.jpg");
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, var(--sky) 0%, #d4edda 45%, var(--meadow) 100%);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 1200px;
  margin: 0 auto;
  overflow: hidden;
}

.screen {
  display: none;
  position: absolute;
  inset: 0;
  padding: calc(10px + var(--safe-top)) 14px calc(12px + var(--safe-bottom));
  flex-direction: column;
  align-items: center;
  animation: fadeIn 0.35s ease;
}

.screen.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* Soft meadow backgrounds — image + light wash (size/pos set separately; custom props can't carry bg-size) */
#screen-start,
#screen-home,
.game-screen,
#screen-celeb {
  background-color: #cfe8d6;
  background-image: var(--bg-overlay), var(--bg-meadow-url);
  background-size: cover, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
}

#screen-start {
  justify-content: center;
}

.start-card {
  background: var(--cream);
  border-radius: 36px;
  padding: 20px 22px 28px;
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 420px;
  width: min(92vw, 420px);
}

.hero-art {
  width: 100%;
  border-radius: 24px;
  display: block;
  margin-bottom: 12px;
  aspect-ratio: 16/9;
  object-fit: cover;
}

.logo {
  margin: 4px 0 0;
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  color: var(--autumn2);
  letter-spacing: 0.02em;
}

.logo-sm {
  margin: 0;
  font-size: 1.25rem;
  color: var(--autumn2);
  text-align: center;
}
.topbar-spacer { width: var(--tap); height: 1px; }
.topbar-title { min-height: 1px; }

.tagline {
  margin: 4px 0 18px;
  font-size: 1.1rem;
  opacity: 0.85;
}

.big-btn {
  appearance: none;
  border: none;
  background: linear-gradient(180deg, #f4a261, #e76f51);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 800;
  padding: 18px 36px;
  min-height: var(--tap);
  min-width: 200px;
  border-radius: 999px;
  box-shadow: 0 6px 0 #c45c3e, var(--shadow);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 0.12s ease;
}

.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #c45c3e; }
.big-btn.secondary {
  background: linear-gradient(180deg, #2a9d8f, #1f7a6f);
  box-shadow: 0 6px 0 #165e56, var(--shadow);
}
.big-btn.secondary:active { box-shadow: 0 2px 0 #165e56; }

.btn-emoji { font-size: 1.2rem; }

.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

/* Top bar */
.topbar {
  width: 100%;
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-shrink: 0;
}

.game-topbar { margin-bottom: 4px; }

.icon-btn {
  width: var(--tap);
  height: calc(var(--tap) * 0.72);
  min-width: 72px;
  min-height: 72px;
  border: none;
  border-radius: 24px;
  background: rgba(255,255,255,0.9);
  box-shadow: var(--shadow);
  font-size: 2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active { transform: scale(0.94); }

/* ----- Big guide panel ----- */
.game-layout {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.guide-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  width: 100%;
  max-width: 520px;
  z-index: 2;
}

.guide-card {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(255, 248, 240, 0.88);
  border: 4px solid #fff;
  border-radius: 32px;
  box-shadow: var(--shadow);
  padding: 8px 16px 4px;
  /* ~28% of viewport height on desktop/landscape */
  height: clamp(150px, 30vh, 280px);
  width: min(92%, 340px);
}

.guide-hero {
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.18));
  border-radius: 12px;
  transform-origin: bottom center;
}

.guide-hero.sparkle-guide {
  /* Full-body Sparkle — keep all 4 legs visible */
  object-fit: contain;
  object-position: center bottom;
}

.guide-pet {
  position: absolute;
  right: 10px;
  bottom: 8px;
  width: clamp(48px, 8vh, 72px);
  height: clamp(48px, 8vh, 72px);
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  object-fit: cover;
}

/* Speech bubble from guide */
.speech-bubble {
  position: relative;
  margin: 2px 0 0;
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  font-weight: 800;
  text-align: center;
  background: rgba(255, 248, 240, 0.95);
  padding: 12px 20px;
  border-radius: 22px;
  box-shadow: var(--shadow);
  max-width: 94%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}

.speech-bubble::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 0 10px 10px 10px;
  border-style: solid;
  border-color: transparent transparent rgba(255, 248, 240, 0.95) transparent;
  filter: drop-shadow(0 -1px 0 rgba(38,70,83,0.06));
}

/* Guide bounce / wiggle when speaking or celebrating */
.guide-panel.speaking .guide-hero {
  animation: guideSpeak 0.7s ease-in-out infinite;
}
.guide-panel.celebrate .guide-hero {
  animation: guideCelebrate 0.65s ease;
}
.guide-panel.celebrate .guide-pet {
  animation: guideCelebrate 0.65s ease 0.08s;
}

@keyframes guideSpeak {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-6px) rotate(-2deg); }
  50% { transform: translateY(-2px) rotate(2deg); }
  75% { transform: translateY(-8px) rotate(-1deg); }
}

@keyframes guideCelebrate {
  0%, 100% { transform: scale(1) rotate(0deg); }
  30% { transform: scale(1.08) rotate(-4deg); }
  55% { transform: scale(1.12) rotate(4deg); }
  75% { transform: scale(1.04) rotate(-2deg); }
}

.prompt-text,
.home-prompt {
  margin: 4px 0 12px;
  font-size: clamp(1.15rem, 4.5vw, 1.55rem);
  font-weight: 800;
  text-align: center;
  background: rgba(255,248,240,0.92);
  padding: 12px 18px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  max-width: 92%;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.play-area {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Home grid — bigger cards + portraits */
.home-grid {
  flex: 1;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  align-content: center;
  padding: 8px 8px;
  max-width: 1000px;
}

.char-card {
  position: relative;
  appearance: none;
  border: 5px solid #fff;
  background: var(--cream);
  border-radius: var(--radius);
  padding: 18px 12px 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 280px;
  transition: transform 0.12s ease;
}

.char-card:active { transform: scale(0.96); }

.char-card > img:first-child {
  width: min(220px, 24vw);
  height: min(220px, 24vw);
  min-width: 150px;
  min-height: 150px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 12px;
  border: 4px solid #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
}

.char-name {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--ink);
}

.char-game {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--forest);
  margin-top: 2px;
}

.char-card .sidekick {
  position: absolute;
  right: 12px;
  bottom: 64px;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* Choices */
.choices {
  flex: 1;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 18px;
  padding: 8px;
  min-height: 0;
}

.choice {
  appearance: none;
  border: 5px solid #fff;
  background: #fff;
  border-radius: 28px;
  width: min(42vw, 200px);
  height: min(42vw, 200px);
  min-width: var(--tap);
  min-height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  overflow: hidden;
}

.choice:active { transform: scale(0.94); }

.choice.correct {
  animation: bounceOk 0.55s ease;
  border-color: #2a9d8f;
  box-shadow: 0 0 0 6px rgba(42,157,143,0.35), var(--shadow);
}

.choice.wrong {
  animation: shake 0.4s ease;
  border-color: #e9c46a;
}

@keyframes bounceOk {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.12); }
  70% { transform: scale(0.96); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.shape-svg {
  width: 70%;
  height: 70%;
}

.choice img.item-img {
  width: 78%;
  height: 78%;
  object-fit: contain;
  pointer-events: none;
}

.choice.color-choice {
  background: var(--swatch, #fff);
}

/* Progress dots */
.progress {
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 8px 0 4px;
  min-height: 28px;
  flex-shrink: 0;
}

.progress .dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255,255,255,0.7);
  border: 2px solid rgba(38,70,83,0.25);
}

.progress .dot.done {
  background: var(--forest);
  border-color: var(--forest);
}

.progress .dot.current {
  background: var(--autumn1);
  border-color: var(--autumn2);
  transform: scale(1.2);
}

/* ----- Counting scene ----- */
.counting-play {
  gap: 4px;
}

.leaf-scene {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 720px;
  min-height: 180px;
  border-radius: 28px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(168, 213, 229, 0.15) 0%, rgba(255,255,255,0) 35%),
    linear-gradient(180deg, transparent 55%, rgba(90, 140, 70, 0.35) 100%);
  border: 3px solid rgba(255,255,255,0.7);
  box-shadow: var(--shadow);
}

/* decorative branch */
.leaf-scene::before {
  content: "";
  position: absolute;
  top: 8%;
  left: 5%;
  right: 5%;
  height: 14px;
  border-radius: 20px;
  background: linear-gradient(90deg, #8b5a2b, #a67c52, #6b4226);
  box-shadow: 0 4px 0 rgba(0,0,0,0.12);
  opacity: 0.85;
  pointer-events: none;
}

.leaf-scene::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 28%;
  background: linear-gradient(180deg, transparent, rgba(76, 140, 60, 0.45));
  pointer-events: none;
}

.leaf-tap {
  position: absolute;
  width: min(22vw, 120px);
  height: min(22vw, 120px);
  min-width: 92px;
  min-height: 92px;
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  transition: transform 0.35s ease, opacity 0.35s ease, filter 0.25s ease;
  animation: fallIn 0.7s ease backwards;
  z-index: 2;
}

.leaf-tap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.25));
  pointer-events: none;
}

.leaf-tap .leaf-num {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.45);
  pointer-events: none;
}

.leaf-tap.counted {
  pointer-events: none;
  z-index: 5;
  filter: drop-shadow(0 0 12px rgba(255, 220, 80, 0.95));
  animation: leafGlow 0.35s ease;
}

.leaf-tap.counted .leaf-num {
  display: flex;
}

.leaf-tap.to-basket {
  transition: transform 0.55s cubic-bezier(0.4, 0.0, 0.2, 1), opacity 0.55s ease;
  opacity: 0.92;
}

@keyframes leafGlow {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes fallIn {
  from { transform: translateY(-50px) rotate(-14deg); opacity: 0; }
  to { transform: rotate(var(--rot, 0deg)); opacity: 1; }
}

.basket-row {
  position: relative;
  width: 100%;
  max-width: 720px;
  height: 72px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  margin-top: -8px;
  flex-shrink: 0;
}

.basket-img {
  width: 100px;
  height: 100px;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
  z-index: 3;
}

.basket-catch {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  z-index: 4;
  pointer-events: none;
}

.basket-catch img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  margin: 0 -4px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

.count-display {
  font-size: clamp(2rem, 10vw, 3.5rem);
  font-weight: 900;
  color: var(--autumn2);
  min-height: 1.2em;
  text-shadow: 0 2px 0 rgba(255,255,255,0.8);
  margin-bottom: 2px;
}

.number-choices .choice {
  width: min(28vw, 140px);
  height: min(28vw, 140px);
  font-size: clamp(2.2rem, 10vw, 3.2rem);
  font-weight: 900;
  color: var(--ink);
  background: var(--cream);
}

/* Celebration */
#screen-celeb {
  justify-content: center;
}

.celeb-card {
  position: relative;
  background: var(--cream);
  border-radius: 36px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 420px;
  width: min(92vw, 420px);
  overflow: hidden;
}

.celeb-face {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 12px;
  display: block;
  animation: bounceOk 0.8s ease infinite;
  border: 5px solid #fff;
  box-shadow: var(--shadow);
}

.celeb-card h2 {
  margin: 0;
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  color: var(--autumn2);
}

.celeb-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 18px;
  align-items: center;
}

.confetti {
  pointer-events: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.confetti i {
  position: absolute;
  top: -12px;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0.2; }
}

/* ----- Desktop / landscape: guide beside play area ----- */
@media (orientation: landscape) and (min-height: 420px), (min-width: 900px) {
  .game-layout {
    flex-direction: row;
    align-items: stretch;
    gap: 16px;
    padding: 0 4px;
  }
  .guide-panel {
    width: clamp(200px, 28vw, 320px);
    max-width: 320px;
    justify-content: center;
    align-self: center;
  }
  .guide-card {
    height: clamp(180px, 34vh, 300px);
    width: 100%;
  }
  .play-area {
    flex: 1;
  }
  .speech-bubble {
    font-size: clamp(1rem, 2.2vw, 1.35rem);
  }
}

/* Phone landscape (short) */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --tap: 88px; }
  .guide-card {
    height: clamp(110px, 42vh, 180px);
    width: min(100%, 200px);
    padding: 4px 8px 2px;
  }
  .guide-pet { width: 40px; height: 40px; right: 6px; bottom: 4px; }
  .speech-bubble { font-size: 0.95rem; padding: 8px 12px; min-height: 36px; }
  .choice {
    width: min(26vw, 140px);
    height: min(36vh, 140px);
  }
  .home-grid { gap: 10px; }
  .char-card { min-height: 120px; padding: 8px; }
  .char-card > img:first-child {
    width: 84px; height: 84px; min-width: 84px; min-height: 84px; margin-bottom: 4px;
  }
  .char-name { font-size: 1.05rem; }
  .char-game { font-size: 0.9rem; }
  .start-card { padding: 12px 16px 16px; max-height: 96vh; overflow: auto; }
  .hero-art { max-height: 28vh; }
  .big-btn { min-height: 64px; padding: 10px 24px; font-size: 1.1rem; }
  .celeb-face { width: 100px; height: 100px; }
  .leaf-tap {
    width: min(18vw, 90px);
    height: min(18vw, 90px);
    min-width: 72px;
    min-height: 72px;
  }
  .basket-img { width: 72px; height: 72px; }
  .basket-row { height: 56px; }
  .icon-btn { min-width: 64px; min-height: 56px; font-size: 1.5rem; }
}

/* Portrait phone */
@media (max-width: 600px) and (orientation: portrait) {
  .home-grid {
    grid-template-columns: 1fr;
    gap: 14px;
    overflow-y: auto;
  }
  .char-card {
    flex-direction: row;
    gap: 16px;
    min-height: 112px;
    padding: 12px 18px;
    text-align: left;
  }
  .char-card > img:first-child {
    width: 96px; height: 96px; min-width: 96px; min-height: 96px; margin: 0;
  }
  .char-card .sidekick {
    right: 14px; bottom: 14px; width: 48px; height: 48px;
  }
  .char-name, .char-game { align-self: flex-start; }
  .char-name { font-size: 1.35rem; }
  .guide-card {
    height: clamp(150px, 26vh, 220px);
    width: min(88%, 280px);
  }
}

@media (min-width: 900px) {
  .home-grid { max-width: 1000px; }
  .choice {
    width: 180px;
    height: 180px;
  }
  .char-card {
    min-height: 300px;
  }
  .char-card > img:first-child {
    width: 230px;
    height: 230px;
    min-width: 190px;
    min-height: 190px;
  }
}

/* v2: picture choices for Kensli + Chadlee */
.pic-choices .choice{display:flex;align-items:center;justify-content:center}
.pic-choices .pic-img{width:72%;height:72%;object-fit:contain;pointer-events:none}
/* v2: 5 friends on home (3 + 2 centered) */
.home-grid{grid-template-columns:repeat(6,1fr)}
.home-grid .char-card{grid-column:span 2;min-height:0;padding:12px 10px 14px}
.home-grid .char-card:nth-child(4){grid-column:2 / span 2}
.home-grid .char-card > img:first-child{width:min(150px,15vw,22vh);height:min(150px,15vw,22vh);min-width:84px;min-height:84px;margin-bottom:6px}
.home-grid .char-card .sidekick{width:52px;height:52px;bottom:48px}
@media (max-width: 600px) and (orientation: portrait){
  .home-grid{grid-template-columns:1fr;gap:10px}
  .home-grid .char-card,.home-grid .char-card:nth-child(4){grid-column:auto;min-height:92px;padding:8px 16px;align-items:center}
  .home-grid .char-card > img:first-child{width:76px;height:76px;min-width:76px;min-height:76px;margin:0}
  .home-grid .char-name,.home-grid .char-game{align-self:center}
  .home-grid .char-card .sidekick{bottom:10px;width:40px;height:40px}
}
@media (orientation: landscape) and (max-height: 520px){
  .home-grid{grid-template-columns:repeat(5,1fr);gap:8px}
  .home-grid .char-card,.home-grid .char-card:nth-child(4){grid-column:auto;padding:8px 4px}
  .home-grid .char-card .sidekick{width:36px;height:36px;right:6px;bottom:44px}
}
