/* ==========================================================================
   BERHITUNG CERIA — STYLE
   Palet pastel ceria untuk anak PAUD, dengan tipografi bulat & lembut,
   ilustrasi CSS (matahari, lebah, pegunungan, bunga) dan animasi lembut.
   ========================================================================== */

:root {
  /* Palet warna */
  --sky-top: #6EC3EA;
  --sky-bottom: #CDEEFB;
  --sun-color: #FFD34D;
  --sun-glow: #FFEA9E;
  --grass-back: #8ED97A;
  --grass-front: #6FCB57;
  --grass-dark: #4FAE3E;
  --pink: #FF9AC1;
  --pink-deep: #FF6FA0;
  --purple: #9B7BE0;
  --purple-deep: #7E5CD9;
  --cream: #FFFDF6;
  --text-dark: #3B3358;
  --text-soft: #6C6289;
  --success: #4CAF6D;
  --error: #FF6B6B;
  --shadow-soft: 0 12px 28px rgba(59, 51, 88, 0.16);
  --shadow-btn: 0 8px 0 rgba(0,0,0,0.12);
  --radius-lg: 32px;
  --radius-md: 22px;
  --radius-sm: 14px;
  --font-display: "Baloo 2", "Nunito", sans-serif;
  --font-body: "Nunito", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  font-family: var(--font-body);
  color: var(--text-dark);
  background: var(--sky-bottom);
}

button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  background: none;
}

/* ============================== BACKGROUND SCENE ============================== */
.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}

.sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 70%);
}

.sun {
  position: absolute;
  top: 6%;
  right: 8%;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #FFF3C4, var(--sun-color) 65%);
  box-shadow: 0 0 0 18px rgba(255, 211, 77, 0.28), 0 0 60px 10px var(--sun-glow);
  animation: sun-pulse 4s ease-in-out infinite;
}
.sun-face { position: relative; width: 100%; height: 100%; }
.sun-eye {
  position: absolute; top: 42%; width: 8px; height: 12px;
  background: #B8791F; border-radius: 50%;
}
.sun-eye.left { left: 34%; }
.sun-eye.right { right: 34%; }
.sun-smile {
  position: absolute; bottom: 30%; left: 50%; width: 26px; height: 13px;
  border-bottom: 5px solid #B8791F; border-radius: 0 0 20px 20px;
  transform: translateX(-50%);
}
@keyframes sun-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.rainbow {
  position: absolute;
  top: 4%;
  left: 50%;
  width: min(600px, 80vw);
  transform: translateX(-50%);
  opacity: 0.85;
  animation: rainbow-float 8s ease-in-out infinite;
}
.rainbow svg { width: 100%; height: auto; display: block; }
@keyframes rainbow-float {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(8px); }
}

.cloud {
  position: absolute;
  font-size: 46px;
  filter: drop-shadow(0 6px 6px rgba(0,0,0,0.06));
  animation: drift 30s linear infinite;
  opacity: 0.9;
}
.cloud-1 { top: 14%; left: -10%; font-size: 60px; animation-duration: 38s; }
.cloud-2 { top: 26%; left: -20%; font-size: 40px; animation-duration: 26s; animation-delay: -8s; }
.cloud-3 { top: 8%; left: -30%; font-size: 34px; animation-duration: 44s; animation-delay: -18s; }
@keyframes drift {
  0% { transform: translateX(0); }
  100% { transform: translateX(140vw); }
}

.butterfly {
  position: absolute;
  font-size: 26px;
  animation: butterfly-flit 9s ease-in-out infinite;
}
.bfly-1 { top: 40%; left: 12%; animation-delay: 0s; }
.bfly-2 { top: 55%; right: 15%; animation-delay: -3s; }
.bfly-3 { top: 68%; left: 30%; animation-delay: -6s; }
@keyframes butterfly-flit {
  0%, 100% { transform: translate(0,0) rotate(0deg); }
  25% { transform: translate(20px, -18px) rotate(8deg); }
  50% { transform: translate(0, -30px) rotate(-6deg); }
  75% { transform: translate(-18px, -10px) rotate(4deg); }
}

.particles {
  position: absolute;
  inset: 0;
}
.particle {
  position: absolute;
  bottom: -20px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.85);
  animation: particle-rise linear infinite;
}
@keyframes particle-rise {
  0% { transform: translateY(0) scale(0.6); opacity: 0; }
  10% { opacity: 0.9; }
  90% { opacity: 0.6; }
  100% { transform: translateY(-110vh) scale(1.1); opacity: 0; }
}

.ground {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 34%;
}
.hill {
  position: absolute;
  bottom: -10%;
  left: -10%;
  width: 120%;
  height: 100%;
  border-radius: 50% 50% 0 0 / 60% 60% 0 0;
}
.hill-back { background: var(--grass-back); bottom: -6%; opacity: 0.9; }
.hill-front { background: var(--grass-front); bottom: -14%; }
.tree { position: absolute; font-size: 54px; bottom: 8%; animation: sway 6s ease-in-out infinite; }
.tree-1 { left: 4%; animation-delay: 0s; }
.tree-2 { right: 6%; font-size: 46px; animation-delay: -2s; }
.flower { position: absolute; font-size: 28px; bottom: 2%; animation: sway 5s ease-in-out infinite; }
.flower-1 { left: 18%; animation-delay: -1s; }
.flower-2 { left: 34%; bottom: 4%; font-size: 22px; animation-delay: -2.5s; }
.flower-3 { left: 55%; animation-delay: -0.5s; }
.flower-4 { left: 70%; bottom: 5%; font-size: 20px; animation-delay: -3s; }
.flower-5 { left: 88%; animation-delay: -1.8s; }
@keyframes sway {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

/* ============================== SCREENS ============================== */
.screen {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  width: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 3vh, 24px) clamp(12px, 4vw, 24px);
  overflow-y: auto;
  box-sizing: border-box;
}
.screen.active { display: flex; }

/* ============================== OPENING SCREEN ============================== */
.opening-card {
  background: rgba(255, 253, 246, 0.92);
  backdrop-filter: blur(6px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: clamp(18px, 4vh, 40px) clamp(20px, 5vw, 36px) clamp(16px, 3.5vh, 34px);
  max-width: 460px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  text-align: center;
  animation: card-pop 0.6s cubic-bezier(.3,1.4,.5,1);
  border: 4px solid #fff;
  margin: auto;
}
@keyframes card-pop {
  0% { opacity: 0; transform: scale(0.85) translateY(20px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.badge {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--purple-deep);
  margin: 0 0 6px;
  letter-spacing: 0.5px;
}
.opening-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.4rem, 5vh, 2.1rem);
  line-height: 1.15;
  color: var(--text-dark);
  margin: 0 0 clamp(6px, 1.5vh, 10px);
}
.opening-subtitle {
  font-size: clamp(0.9rem, 2.4vh, 1.05rem);
  font-weight: 700;
  color: var(--text-soft);
  margin: 0 0 clamp(10px, 2vh, 18px);
}

/* Hero showcase — menampilkan aset gambar hitung asli (bukan ikon CSS)
   sebagai kartu-kartu kecil yang tersebar rapi di layar pembuka. */
.hero-showcase {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 0;
  margin: 4px 0 10px;
  height: clamp(70px, 14vh, 108px);
}
.asset-card {
  position: relative;
  width: clamp(50px, 10vh, 76px);
  height: clamp(50px, 10vh, 76px);
  background: #fff;
  border-radius: 18px;
  border: 3px solid #fff;
  box-shadow: 0 10px 18px rgba(59,51,88,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 -10px;
  animation: asset-bob 3.4s ease-in-out infinite;
  transition: transform 0.2s ease;
}
.asset-card:hover { transform: translateY(-6px) scale(1.05) !important; z-index: 10; }
.asset-card img {
  width: 82%;
  height: 82%;
  object-fit: contain;
  border-radius: 12px;
}
.asset-badge {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  color: #fff;
  box-shadow: 0 3px 6px rgba(0,0,0,0.2);
  border: 2px solid #fff;
}
.ac-1 { transform: rotate(-14deg) translateY(6px); z-index: 1; }
.ac-1 .asset-badge { background: var(--pink-deep); }
.ac-2 { transform: rotate(-7deg) translateY(-2px); z-index: 2; }
.ac-2 .asset-badge { background: #F2A93B; }
.ac-3 { transform: rotate(0deg) translateY(-8px); z-index: 3; width: clamp(56px, 11vh, 84px); height: clamp(56px, 11vh, 84px); }
.ac-3 .asset-badge { background: var(--success); }
.ac-4 { transform: rotate(7deg) translateY(-2px); z-index: 2; }
.ac-4 .asset-badge { background: #4AA9D9; }
.ac-5 { transform: rotate(14deg) translateY(6px); z-index: 1; }
.ac-5 .asset-badge { background: var(--purple-deep); }
.asset-card.ac-1 { animation-delay: -0.2s; }
.asset-card.ac-2 { animation-delay: -1.1s; }
.asset-card.ac-3 { animation-delay: -0.6s; }
.asset-card.ac-4 { animation-delay: -1.8s; }
.asset-card.ac-5 { animation-delay: -0.9s; }
@keyframes asset-bob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -8px; }
}
.hero-caption {
  font-size: clamp(0.8rem, 2.1vh, 0.92rem);
  font-weight: 700;
  color: var(--text-soft);
  margin: 0 0 clamp(10px, 2vh, 18px);
}

.loading-note {
  margin-top: clamp(8px, 2vh, 16px);
  font-size: 0.85rem;
  color: var(--text-soft);
  min-height: 1.2em;
  transition: opacity 0.4s ease;
}
.loading-note.hidden { opacity: 0; }

/* ============================== BUTTONS ============================== */
.btn {
  font-family: var(--font-display);
  font-weight: 700;
  border-radius: 999px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: none !important; }
.btn:focus-visible { outline: 3px solid var(--purple); outline-offset: 3px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; filter: grayscale(0.2); }
.btn:disabled:hover { transform: none; }

.btn-primary {
  background: linear-gradient(180deg, #FFB05C, #FF8A3D);
  color: #fff;
  box-shadow: 0 6px 0 #E06A1F, 0 10px 20px rgba(224,106,31,0.3);
}
.btn-primary:hover { filter: brightness(1.06); transform: translateY(-2px); }

.btn-secondary {
  background: linear-gradient(180deg, #B7A6F0, var(--purple));
  color: #fff;
  box-shadow: 0 6px 0 var(--purple-deep), 0 10px 20px rgba(126,92,217,0.3);
}
.btn-secondary:hover { filter: brightness(1.06); transform: translateY(-2px); }

.btn-large {
  font-size: clamp(1rem, 2.6vh, 1.2rem);
  padding: clamp(12px, 2.4vh, 16px) clamp(22px, 5vw, 34px);
  min-height: clamp(46px, 8vh, 56px);
}

.btn-pill {
  background: #fff;
  color: var(--text-dark);
  font-size: 0.95rem;
  padding: 10px 18px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08), 0 6px 12px rgba(0,0,0,0.08);
  border: 2px solid #F0ECFF;
}
.btn-pill:hover { transform: translateY(-2px); }
.btn-pill[aria-pressed="false"] { opacity: 0.55; }

.opening-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 18px;
  flex-wrap: wrap;
}

@keyframes bounce-in {
  0% { transform: scale(0.9); }
  40% { transform: scale(1.05); }
  100% { transform: scale(1); }
}
.btn-start-anim { animation: bounce-in 0.5s ease; }

/* ============================== GAME SCREEN ============================== */
#game-screen {
  max-width: 640px;
  width: 100%;
  margin: auto;
  max-height: 100%;
  overflow-y: auto;
}

.game-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: clamp(8px, 2vh, 18px);
}

.icon-btn {
  width: clamp(36px, 7vh, 48px); height: clamp(36px, 7vh, 48px);
  border-radius: 50%;
  background: #fff;
  font-size: 1.3rem;
  box-shadow: var(--shadow-soft);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.icon-btn:hover { transform: scale(1.08); }
.icon-btn[aria-pressed="false"] { opacity: 0.5; }

.hud-center { flex: 1; text-align: center; }
.question-counter {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-dark);
  margin-bottom: 6px;
}

.progress-track {
  position: relative;
  height: 16px;
  background: rgba(255,255,255,0.7);
  border-radius: 999px;
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.12);
  overflow: visible;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #FF9AA2, #FFD98A, #B4EFC9, #A6DDF0, #C6B4F0);
  transition: width 0.6s cubic-bezier(.4,1.4,.4,1);
}
.progress-mascot {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  font-size: 1.4rem;
  transition: left 0.6s cubic-bezier(.4,1.4,.4,1);
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.25));
}

.score-pill {
  background: #fff;
  border-radius: 999px;
  padding: 10px 16px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-dark);
  box-shadow: var(--shadow-soft);
  flex-shrink: 0;
}

.question-card {
  background: rgba(255,253,246,0.94);
  border-radius: var(--radius-lg);
  padding: clamp(12px, 2.6vh, 22px) clamp(14px, 3vw, 20px) clamp(14px, 3vh, 26px);
  text-align: center;
  width: 100%;
  box-shadow: var(--shadow-soft);
  border: 4px solid #fff;
  margin-bottom: clamp(10px, 2.6vh, 22px);
  animation: card-pop 0.5s cubic-bezier(.3,1.4,.5,1);
}
.question-prompt {
  font-size: clamp(0.9rem, 2.4vh, 1.05rem);
  font-weight: 700;
  color: var(--text-soft);
  margin: 0 0 6px;
}
.target-number {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.6rem, 8vh, 5rem);
  line-height: 1;
  color: var(--purple-deep);
  text-shadow: 3px 3px 0 rgba(255,255,255,0.8);
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: clamp(10px, 2.2vh, 18px);
  width: 100%;
  max-width: min(380px, 92vw, 46vh);
  margin: 0 auto;
}
@media (min-width: 520px) {
  .cards-grid { max-width: min(460px, 92vw, 50vh); gap: clamp(10px, 2.2vh, 22px); }
}

.answer-card {
  background: #fff;
  border-radius: var(--radius-md);
  border: 4px solid #F0ECFF;
  box-shadow: 0 6px 0 rgba(0,0,0,0.06), var(--shadow-soft);
  padding: 8px;
  aspect-ratio: 1 / 1;
  min-height: 48px;
  min-width: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.answer-card img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.answer-card:hover:not(.disabled) { transform: translateY(-4px) scale(1.04); }
.answer-card:active:not(.disabled) { transform: scale(0.96); }
.answer-card.disabled { cursor: default; }

.answer-card.correct {
  border-color: var(--success);
  box-shadow: 0 0 0 6px rgba(76,175,109,0.25), 0 6px 0 rgba(0,0,0,0.06);
  animation: card-correct 0.5s ease;
}
@keyframes card-correct {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1.04); }
}
.answer-card.wrong {
  border-color: var(--error);
  animation: card-shake 0.45s ease;
}
@keyframes card-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.answer-card.dimmed { opacity: 0.45; filter: grayscale(0.3); }

.feedback-text {
  margin-top: clamp(8px, 2vh, 18px);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1rem, 2.6vh, 1.15rem);
  min-height: 1.6em;
  color: var(--text-dark);
}
.feedback-text.correct { color: var(--success); }
.feedback-text.wrong { color: #D9534F; }

.btn-next {
  margin-top: clamp(6px, 2vh, 18px);
  margin-bottom: env(safe-area-inset-bottom, 0px);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.btn-next.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Sparkle burst for correct answers */
.sparkle {
  position: fixed;
  font-size: 1.4rem;
  pointer-events: none;
  animation: sparkle-pop 0.8s ease-out forwards;
  z-index: 50;
}
@keyframes sparkle-pop {
  0% { transform: translate(0,0) scale(0.4) rotate(0deg); opacity: 1; }
  100% { transform: var(--sparkle-move) scale(1.2) rotate(120deg); opacity: 0; }
}

/* ============================== RESULT SCREEN ============================== */
#result-screen { position: relative; }
#fx-canvas {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}
.result-card {
  position: relative;
  z-index: 3;
  background: rgba(255,253,246,0.95);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: clamp(20px, 5vh, 40px) clamp(20px, 5vw, 32px);
  max-width: 440px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  text-align: center;
  border: 4px solid #fff;
  animation: card-pop 0.6s cubic-bezier(.3,1.4,.5,1);
  margin: auto;
}
.result-emoji { font-size: clamp(2rem, 6vh, 3rem); margin: 0 0 4px; }
.result-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.4rem, 5vh, 2rem);
  color: var(--purple-deep);
  margin: 0 0 8px;
}
.result-message {
  font-size: clamp(0.9rem, 2.4vh, 1.05rem);
  font-weight: 700;
  color: var(--text-soft);
  margin: 0 0 clamp(10px, 2vh, 18px);
}
.result-score {
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 3vh, 1.3rem);
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 12px;
}
.stars {
  font-size: clamp(1.6rem, 4.5vh, 2.2rem);
  letter-spacing: 6px;
  margin-bottom: clamp(14px, 3vh, 24px);
}
.result-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ============================== ACCESSIBILITY / RESPONSIVE ============================== */
@media (max-width: 400px) {
  .opening-title { font-size: clamp(1.4rem, 5vh, 1.7rem); }
  .target-number { font-size: clamp(2.6rem, 8vh, 3.8rem); }
  .opening-card, .result-card { padding: clamp(18px, 4vh, 28px) 20px clamp(16px, 3.5vh, 24px); }
}

/* Tablet & laptop: layar lebih lebar sekaligus lebih pendek dari HP.
   Batasi tinggi elemen dekoratif & perbesar sedikit lebar kartu supaya
   semua konten (termasuk tombol Selanjutnya) selalu tampil utuh tanpa scroll. */
@media (min-width: 700px) {
  .opening-card { max-width: 500px; }
  .cards-grid { max-width: min(480px, 42vw, 50vh); }
}

/* Layar pendek (tablet/laptop landscape, atau HP landscape):
   perketat semua jarak vertikal supaya kartu jawaban + tombol tidak terpotong. */
@media (max-height: 560px) {
  .screen { padding-top: 6px; padding-bottom: 6px; }
  .hero-showcase { height: clamp(50px, 12vh, 80px); margin: 2px 0 6px; }
  .opening-subtitle, .hero-caption { margin-bottom: 8px; }
  .opening-actions { margin-top: 10px; }
  .game-top { margin-bottom: 8px; }
  .question-card { padding: 10px 14px 12px; margin-bottom: 10px; }
  .target-number { font-size: clamp(2rem, 7vh, 3.2rem); }
  .cards-grid { max-width: min(360px, 90vw, 40vh); gap: 10px; }
  .feedback-text { margin-top: 6px; min-height: 1.3em; }
  .btn-next { margin-top: 6px; }
  .btn-large { padding: 10px 22px; min-height: 42px; font-size: 1rem; }
  .result-card { padding: 16px 24px; }
  .stars { margin-bottom: 10px; font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
