/* ===================================================================
   TUNJUK ANGKA — Preschool Number Matching Game
   =================================================================== */

:root {
  --sky-top: #6EC6FF;
  --sky-bottom: #CDEBFF;
  --grass-top: #8CE05A;
  --grass-bottom: #5FBF3E;
  --yellow: #FFD24C;
  --yellow-dark: #FFB627;
  --green: #58C24C;
  --white: #FFFFFF;
  --ink: #2D3142;
  --ink-soft: #5A5F73;
  --card-border: #E7E9EF;
  --shadow-soft: rgba(45, 49, 66, 0.16);
  --shadow-strong: rgba(45, 49, 66, 0.28);
  --font-display: 'Baloo 2', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, sans-serif;
  --radius-card: 24px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

body {
  position: fixed;
  inset: 0;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  outline: none;
  background: none;
}
button:focus-visible {
  outline: 3px solid #2D6FE0;
  outline-offset: 3px;
}

/* ============================================================
   SCREEN MANAGEMENT
   ============================================================ */
.screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 1;
}
.screen.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 2;
}

/* ============================================================
   OPENING SCREEN
   ============================================================ */
#opening-screen {
  align-items: center;
  justify-content: flex-end;
}

.sky {
  position: absolute;
  inset: 0;
  height: 72%;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 100%);
  overflow: hidden;
}

.cloud {
  position: absolute;
  background: #FFFFFF;
  border-radius: 50px;
  opacity: 0.92;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.05));
}
.cloud::before, .cloud::after {
  content: "";
  position: absolute;
  background: #FFFFFF;
  border-radius: 50%;
}
.c1 { width: 110px; height: 40px; top: 8%; left: 6%; animation: drift 26s linear infinite; }
.c1::before { width: 55px; height: 55px; top: -28px; left: 12px; }
.c1::after { width: 40px; height: 40px; top: -18px; left: 60px; }
.c2 { width: 90px; height: 34px; top: 16%; left: 55%; animation: drift 34s linear infinite reverse; }
.c2::before { width: 46px; height: 46px; top: -22px; left: 10px; }
.c2::after { width: 34px; height: 34px; top: -14px; left: 48px; }
.c3 { width: 70px; height: 28px; top: 5%; left: 78%; animation: drift 20s linear infinite; }
.c3::before { width: 36px; height: 36px; top: -18px; left: 8px; }
.c3::after { width: 26px; height: 26px; top: -10px; left: 36px; }

@keyframes drift {
  0% { transform: translateX(0); }
  50% { transform: translateX(18px); }
  100% { transform: translateX(0); }
}

.rainbow {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 620px;
  opacity: 0.95;
}
.rainbow-svg { width: 100%; height: auto; display: block; }

.butterfly {
  position: absolute;
  font-size: 22px;
  animation: flutter 6s ease-in-out infinite;
}
.b1 { top: 28%; left: 12%; animation-delay: 0s; }
.b2 { top: 20%; left: 82%; animation-delay: 1.2s; }
.b3 { top: 40%; left: 45%; animation-delay: 2.4s; }

@keyframes flutter {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  25% { transform: translate(14px, -18px) rotate(8deg); }
  50% { transform: translate(-6px, -30px) rotate(-6deg); }
  75% { transform: translate(-16px, -10px) rotate(6deg); }
}

#particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.particle {
  position: absolute;
  bottom: -10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.8);
  animation: floatUp linear infinite;
}
@keyframes floatUp {
  0% { transform: translateY(0) translateX(0); opacity: 0.9; }
  100% { transform: translateY(-420px) translateX(20px); opacity: 0; }
}

.grass {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 30%;
  background: linear-gradient(180deg, var(--grass-top) 0%, var(--grass-bottom) 100%);
  border-radius: 50% 50% 0 0 / 18% 18% 0 0;
}
.flower {
  position: absolute;
  bottom: 8px;
  font-size: 26px;
  animation: sway 3.2s ease-in-out infinite;
  transform-origin: bottom center;
}
.f1 { left: 5%; animation-delay: 0s; }
.f2 { left: 20%; animation-delay: 0.4s; }
.f3 { left: 38%; animation-delay: 0.8s; }
.f4 { left: 58%; animation-delay: 0.3s; }
.f5 { left: 76%; animation-delay: 0.6s; }
.f6 { left: 90%; animation-delay: 0.2s; }
@keyframes sway {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}

.opening-content {
  position: relative;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 8%;
  width: 100%;
}

.title-card {
  background: rgba(255, 255, 255, 0.96);
  border-radius: 28px;
  padding: 22px 30px 24px;
  margin: 0 16px 26px;
  max-width: 92vw;
  text-align: center;
  box-shadow: 0 4px 0 rgba(45,49,66,0.08), 0 18px 34px rgba(45,49,66,0.22);
  animation: popIn 0.8s ease;
}

.badge-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}
.badge-num {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 15px;
  color: #FFFFFF;
  box-shadow: 0 2px 0 rgba(0,0,0,0.12);
}
.badge-num.n1 { background: #FF5D5D; }
.badge-num.n2 { background: #FF9F45; }
.badge-num.n3 { background: #FFD24C; color: #7A4A00; }
.badge-num.n4 { background: #7ED957; }
.badge-num.n5 { background: #5DB1FF; }

.game-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(28px, 8vw, 48px);
  color: var(--ink);
  margin: 0;
  text-align: center;
  line-height: 1.15;
}
.title-emoji {
  display: inline-block;
  animation: wiggle 2.4s ease-in-out infinite;
}
@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-10deg); }
  75% { transform: rotate(10deg); }
}
@keyframes popIn {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); }
}

.game-subtitle {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: clamp(14px, 3.4vw, 18px);
  color: #7A4A00;
  background: var(--yellow);
  display: inline-block;
  padding: 6px 18px;
  border-radius: 999px;
  margin: 10px 0 0;
  text-align: center;
}

.opening-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.opening-buttons-row {
  display: flex;
  gap: 16px;
}

.btn {
  font-family: var(--font-display);
  font-weight: 700;
  border-radius: 999px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.94); }

.btn-primary {
  font-size: clamp(20px, 5vw, 28px);
  color: #7A4A00;
  background: linear-gradient(180deg, #FFE58A 0%, var(--yellow) 55%, var(--yellow-dark) 100%);
  padding: 16px 46px;
  box-shadow: 0 6px 0 #D98F1E, 0 14px 24px var(--shadow-strong);
  animation: bounceIn 1s ease 0.2s both, floatBtn 2.4s ease-in-out 1.2s infinite;
}
@keyframes bounceIn {
  0% { transform: translateY(40px) scale(0.7); opacity: 0; }
  60% { transform: translateY(-8px) scale(1.05); opacity: 1; }
  100% { transform: translateY(0) scale(1); }
}
@keyframes floatBtn {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.btn-round {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 24px;
  background: rgba(255,255,255,0.9);
  box-shadow: 0 4px 0 rgba(45,49,66,0.25), 0 8px 14px var(--shadow-soft);
}
.btn-round[aria-pressed="false"] { opacity: 0.5; }

/* ============================================================
   GAME SCREEN
   ============================================================ */
#game-screen {
  background: linear-gradient(180deg, #EAF6FF 0%, #FDFDFF 60%);
  align-items: center;
  padding: 10px 14px 16px;
  gap: 6px;
}

.topbar {
  width: 100%;
  max-width: 640px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.topbar-center {
  display: flex;
  gap: 8px;
}
.pill {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(13px, 3.4vw, 17px);
  background: var(--white);
  color: var(--ink);
  padding: 6px 16px;
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--card-border), 0 6px 10px var(--shadow-soft);
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--white);
  font-size: 20px;
  box-shadow: 0 3px 0 var(--card-border), 0 6px 10px var(--shadow-soft);
}
.icon-btn[aria-pressed="false"] { opacity: 0.5; }
.icon-btn:active { transform: scale(0.9); }

.instruction-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.speaker-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #FFFFFF, #EAF3FF);
  font-size: 30px;
  box-shadow: 0 4px 0 #C9DEF5, 0 8px 16px var(--shadow-soft);
  animation: pulseSpeaker 1.8s ease-in-out infinite;
}
@keyframes pulseSpeaker {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
.instruction-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(16px, 4.4vw, 22px);
  color: var(--ink-soft);
  margin: 4px 0 0;
}
.target-number {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(34px, 10vw, 56px);
  color: #2D6FE0;
  line-height: 1;
  margin-top: -2px;
}

.cards-row {
  flex: 1;
  width: 100%;
  max-width: 680px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 3.4vw, 26px);
  min-height: 0;
}

.number-card {
  width: min(27vw, 180px);
  height: min(27vw, 180px);
  max-height: 40vh;
  background: var(--white);
  border-radius: var(--radius-card);
  border: 1px solid var(--card-border);
  box-shadow: 0 10px 0 var(--card-border), 0 18px 30px var(--shadow-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10%;
  animation: idleFloat 3.4s ease-in-out infinite;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.number-card:nth-of-type(1) { animation-delay: 0s; }
#card-middle { animation-delay: 0.3s; }
#card-right { animation-delay: 0.6s; }

.number-img {
  width: 80%;
  height: 80%;
  object-fit: contain;
  pointer-events: none;
}

@keyframes idleFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.number-card.touch-bounce {
  animation: none;
  transform: scale(0.9);
}

.number-card.correct {
  animation: none;
  box-shadow: 0 0 0 6px rgba(88, 194, 76, 0.35), 0 10px 0 var(--green), 0 18px 34px rgba(88,194,76,0.4);
  transform: scale(1.06);
}

.number-card.wrong {
  animation: shakeCard 0.5s ease;
}
@keyframes shakeCard {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-14px) rotate(-4deg); }
  40% { transform: translateX(12px) rotate(4deg); }
  60% { transform: translateX(-10px) rotate(-3deg); }
  80% { transform: translateX(8px) rotate(3deg); }
}

.number-card.disabled {
  pointer-events: none;
}
.number-card.faded {
  opacity: 0.5;
}

.feedback-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(16px, 4.6vw, 24px);
  min-height: 1.4em;
  margin: 2px 0 0;
  text-align: center;
  flex-shrink: 0;
}
.feedback-text.wrong-msg { color: #E0693C; }
.feedback-text.correct-msg { color: var(--green); }

.btn-next {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(18px, 5vw, 24px);
  color: #7A4A00;
  background: linear-gradient(180deg, #FFE58A 0%, var(--yellow) 55%, var(--yellow-dark) 100%);
  padding: 14px 44px;
  border-radius: 999px;
  box-shadow: 0 6px 0 #D98F1E, 0 12px 20px var(--shadow-strong);
  flex-shrink: 0;
  margin-top: 4px;
  animation: nextBounce 1.1s ease-in-out infinite;
}
@keyframes nextBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.btn-next:active { transform: scale(0.94); }

#fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 20;
}
.fx-star, .fx-sparkle, .fx-confetti {
  position: absolute;
  font-size: 26px;
  pointer-events: none;
}
.fx-star { animation: starPop 0.9s ease forwards; }
@keyframes starPop {
  0% { transform: translate(0,0) scale(0.3) rotate(0deg); opacity: 1; }
  70% { transform: translate(var(--dx), var(--dy)) scale(1.2) rotate(180deg); opacity: 1; }
  100% { transform: translate(var(--dx), calc(var(--dy) - 30px)) scale(0.9) rotate(240deg); opacity: 0; }
}
.fx-confetti {
  width: 10px;
  height: 16px;
  border-radius: 3px;
  animation: confettiFall 1.4s ease-in forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(240px) rotate(400deg); opacity: 0; }
}

/* ============================================================
   ENDING SCREEN
   ============================================================ */
#ending-screen {
  background: linear-gradient(180deg, #FFE9B8 0%, #FFD24C 45%, #FFB627 100%);
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
#ending-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.balloon {
  position: absolute;
  bottom: -60px;
  font-size: 42px;
  animation: balloonRise linear infinite;
}
@keyframes balloonRise {
  0% { transform: translateY(0) translateX(0); opacity: 0.95; }
  100% { transform: translateY(-115vh) translateX(30px); opacity: 0.2; }
}
.firework {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  animation: fireworkPop 1s ease-out forwards;
}
@keyframes fireworkPop {
  0% { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--fx), var(--fy)) scale(0.3); opacity: 0; }
}

.ending-content {
  position: relative;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,0.85);
  border-radius: 32px;
  padding: 34px 38px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
  animation: popIn 0.7s ease;
}
.ending-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(30px, 8vw, 46px);
  color: var(--ink);
  margin: 0;
}
.ending-stars {
  font-size: clamp(26px, 7vw, 40px);
  color: var(--yellow-dark);
  letter-spacing: 4px;
  margin: 10px 0;
  animation: starsWiggle 1.6s ease-in-out infinite;
}
@keyframes starsWiggle {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
.ending-praise {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(16px, 4.4vw, 22px);
  color: var(--green);
  margin: 2px 0 14px;
  text-align: center;
  min-height: 1.4em;
}

.ending-score-label {
  font-family: var(--font-body);
  font-weight: 700;
  color: var(--ink-soft);
  margin: 0;
  font-size: clamp(14px, 3.6vw, 18px);
}
.ending-score {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(40px, 11vw, 64px);
  color: #2D6FE0;
  margin: 0 0 18px;
}

/* ============================================================
   RESPONSIVE / TABLET
   ============================================================ */
@media (min-width: 700px) {
  .number-card { width: 190px; height: 190px; }
}

@media (max-height: 480px) {
  .instruction-label { font-size: 14px; }
  .target-number { font-size: 30px; }
  .speaker-btn { width: 46px; height: 46px; font-size: 22px; }
  .number-card { max-height: 38vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
