/* =========================================================
   DUNIA CERIA — Game edutainment 4-6 tahun
   ========================================================= */

:root {
  --font: 'Fredoka', 'Baloo 2', 'Comic Sans MS', 'Trebuchet MS', system-ui, sans-serif;
  --emoji: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', 'Twemoji Mozilla', sans-serif;

  --ink: #2b2d42;
  --ink-soft: #656a80;
  --white: #ffffff;
  --cream: #fffdf6;

  --green: #22c55e;
  --green-d: #16a34a;
  --red: #ff6b6b;
  --yellow: #ffd166;

  --shadow-btn: 0 7px 0 rgba(0, 0, 0, .13);
  --shadow-soft: 0 12px 30px rgba(43, 45, 66, .13);
  --shadow-card: 0 10px 0 rgba(0, 0, 0, .1), 0 18px 34px rgba(43, 45, 66, .18);

  --r-lg: 30px;
  --r-md: 22px;
  --r-sm: 16px;

  --topbar-h: 66px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: #d9f2ff;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body.boot { visibility: hidden; }
body.ready { visibility: visible; }

.emoji { font-family: var(--emoji); font-style: normal; }

/* ---------- Latar ---------- */
.bg {
  position: fixed; inset: 0; z-index: 0; overflow: hidden;
  background: linear-gradient(180deg, #a9e4ff 0%, #cdefff 38%, #e7f9ff 66%, #f3ffe9 100%);
}
.sun {
  position: absolute; top: -70px; right: -60px;
  width: 320px; height: 320px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #fff4b8 0%, #ffe066 45%, rgba(255, 214, 102, 0) 72%);
  animation: sunPulse 6s ease-in-out infinite;
}
@keyframes sunPulse { 0%,100% { transform: scale(1); opacity: .95 } 50% { transform: scale(1.07); opacity: 1 } }

.cloud {
  position: absolute;
  background: #fff;
  border-radius: 100px;
  opacity: .85;
  filter: blur(.3px);
  box-shadow: 0 16px 30px rgba(120, 190, 230, .18);
}
.cloud::before, .cloud::after {
  content: ''; position: absolute; background: #fff; border-radius: 50%;
}
.cloud::before { width: 62%; height: 165%; left: 12%; top: -78%; }
.cloud::after { width: 44%; height: 130%; right: 10%; top: -54%; }

.c1 { width: 150px; height: 44px; top: 12%; left: -180px; animation: drift 48s linear infinite; }
.c2 { width: 110px; height: 34px; top: 26%; left: -160px; animation: drift 64s linear infinite 6s; opacity: .7; }
.c3 { width: 180px; height: 52px; top: 6%; left: -240px; animation: drift 78s linear infinite 16s; opacity: .6; }
.c4 { width: 96px; height: 30px; top: 38%; left: -140px; animation: drift 56s linear infinite 26s; opacity: .55; }

@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(calc(100vw + 320px)); }
}

.hills {
  position: absolute; left: -10%; right: -10%; bottom: -6%;
  height: 34vh;
  background:
    radial-gradient(120% 100% at 18% 100%, #b7ec9e 0%, #b7ec9e 56%, transparent 57%),
    radial-gradient(130% 100% at 74% 100%, #a3e58b 0%, #a3e58b 52%, transparent 53%),
    radial-gradient(150% 120% at 46% 120%, #cbf3b4 0%, #cbf3b4 50%, transparent 51%);
  opacity: .8;
}

/* ---------- Rangka ---------- */
#app {
  position: fixed; inset: 0; z-index: 1;
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
}

#topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 0 clamp(10px, 2.5vw, 26px);
  z-index: 20;
}

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

#btn-home { display: none; }

.instr-btn {
  border: none; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
  height: 40px; padding: 0 14px;
  border-radius: 13px;
  background: rgba(255,255,255,.86);
  box-shadow: 0 4px 0 rgba(21,110,150,.16), 0 8px 16px rgba(21,110,150,.10);
  color: #12688f; font-weight: 600; font-size: 13px;
  transition: transform .12s, box-shadow .12s;
  flex: 0 0 auto;
}
.instr-btn .emoji { font-size: 16px; }
.instr-btn:hover { background: #fff; transform: translateY(-2px); }
.instr-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(21,110,150,.16); }

.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: clamp(15px, 2.2vw, 21px);
  letter-spacing: .3px; color: #12688f;
  text-shadow: 0 2px 0 #fff;
}
.brand-emoji { font-family: var(--emoji); font-size: 1.4em; }

.icon-btn {
  border: none; cursor: pointer;
  width: 46px; height: 46px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .82);
  box-shadow: 0 4px 0 rgba(21, 110, 150, .18), 0 8px 18px rgba(21, 110, 150, .12);
  display: grid; place-items: center;
  font-size: 22px; line-height: 1;
  transition: transform .12s ease, box-shadow .12s ease, background .15s;
  color: var(--ink);
  flex: 0 0 auto;
}
.icon-btn span { font-family: var(--emoji); }
.icon-btn:hover { background: #fff; transform: translateY(-2px); }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(21, 110, 150, .18); }
.icon-btn.is-off { filter: grayscale(1); opacity: .65; }
.icon-btn.hidden { visibility: hidden; pointer-events: none; }

.star-pill {
  display: flex; align-items: center; gap: 6px;
  height: 46px; padding: 0 16px 0 10px;
  border-radius: 16px;
  background: linear-gradient(180deg, #fff9e0, #ffeaa3);
  box-shadow: 0 4px 0 #e6bf58, 0 8px 18px rgba(180, 140, 30, .16);
  font-weight: 700; font-size: 19px; color: #8a6200;
}
.star-ico { font-family: var(--emoji); font-size: 20px; }
.star-pill.bump { animation: bump .45s ease; }
@keyframes bump { 0%,100% { transform: scale(1) } 35% { transform: scale(1.18) rotate(-4deg) } 65% { transform: scale(1.1) rotate(3deg) } }

/* ---------- Skrin ---------- */
#screens { position: relative; flex: 1 1 auto; min-height: 0; z-index: 5; }

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
  padding: 4px clamp(12px, 3vw, 30px) calc(24px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.screen.active { display: flex; animation: screenIn .32s cubic-bezier(.3,1.3,.5,1); }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px) scale(.985) } to { opacity: 1; transform: none } }

/* ---------- Menu utama ---------- */
.home-inner {
  width: 100%; max-width: 1040px; margin: 0 auto;
  display: flex; flex-direction: column; gap: clamp(12px, 2vw, 20px);
  padding-bottom: 20px;
}

.hero {
  display: flex; align-items: center; gap: clamp(8px, 2vw, 20px);
  padding: 4px 6px 0;
}
.mascot {
  flex: 0 0 auto;
  width: clamp(78px, 12vw, 112px); height: clamp(78px, 12vw, 112px);
  border-radius: 50%;
  background: linear-gradient(160deg, #fff3c4, #ffd166 60%, #ffb703);
  display: grid; place-items: center;
  font-size: clamp(40px, 6.4vw, 62px);
  box-shadow: 0 10px 0 #e0a300, 0 18px 28px rgba(224, 163, 0, .28);
  animation: bob 3.4s ease-in-out infinite;
  position: relative;
}
.mascot::after {
  content: ''; position: absolute; inset: 6px;
  border-radius: 50%; border: 3px dashed rgba(255,255,255,.6);
  animation: spinSlow 22s linear infinite;
}
.mascot span { font-family: var(--emoji); }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-2deg) } 50% { transform: translateY(-8px) rotate(2deg) } }
@keyframes spinSlow { to { transform: rotate(360deg) } }

.hero-text { min-width: 0; }
.hero-text h1 {
  margin: 0;
  font-size: clamp(24px, 4.4vw, 44px);
  line-height: 1.05;
  color: #0e5f86;
  text-shadow: 0 3px 0 #ffffff, 0 6px 14px rgba(14, 95, 134, .16);
  letter-spacing: .4px;
}
.hero-text p {
  margin: 6px 0 0;
  font-size: clamp(12px, 1.9vw, 17px);
  color: #2f7c9c; font-weight: 500;
}

.bubble {
  position: relative;
  background: #fff;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: clamp(12px, 1.8vw, 16px);
  font-weight: 500;
  color: var(--ink-soft);
  box-shadow: var(--shadow-soft);
  margin-top: 10px;
  display: inline-block;
  max-width: 100%;
}
.bubble::before {
  content: ''; position: absolute; left: 26px; top: -8px;
  width: 16px; height: 16px; background: #fff;
  transform: rotate(45deg); border-radius: 3px;
}

/* Grid kad permainan */
.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(10px, 1.8vw, 18px);
}

.game-card {
  position: relative;
  border: none; cursor: pointer;
  font-family: inherit; color: #fff;
  border-radius: var(--r-lg);
  padding: clamp(14px, 2.2vw, 22px);
  min-height: clamp(128px, 19vw, 168px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; text-align: center;
  box-shadow: var(--shadow-card);
  transition: transform .16s cubic-bezier(.3,1.4,.5,1), box-shadow .16s;
  overflow: hidden;
  isolation: isolate;
  outline: none;
}
.game-card::before {
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: radial-gradient(120% 90% at 50% -10%, rgba(255,255,255,.42), transparent 60%);
}
.game-card::after {
  content: ''; position: absolute;
  width: 140px; height: 140px; border-radius: 50%;
  background: rgba(255,255,255,.14);
  right: -46px; bottom: -56px;
}
.game-card:hover { transform: translateY(-5px) scale(1.015); }
.game-card:active { transform: translateY(3px) scale(.985); box-shadow: 0 4px 0 rgba(0,0,0,.1), 0 8px 16px rgba(43,45,66,.16); }
.game-card:focus-visible { outline: 4px solid #fff; outline-offset: 3px; }

.game-card .card-emoji {
  font-family: var(--emoji);
  font-size: clamp(38px, 6vw, 54px);
  line-height: 1;
  filter: drop-shadow(0 5px 8px rgba(0,0,0,.22));
  transition: transform .25s;
}
.game-card:hover .card-emoji { transform: scale(1.1) rotate(-6deg); }
.game-card .card-title { font-size: clamp(15px, 2.2vw, 21px); font-weight: 600; letter-spacing: .3px; text-shadow: 0 2px 4px rgba(0,0,0,.15); }
.game-card .card-sub { font-size: clamp(10px, 1.5vw, 13px); font-weight: 400; opacity: .92; line-height: 1.25; }
.game-card .card-badge {
  position: absolute; top: 10px; right: 12px;
  font-size: 12px; background: rgba(0,0,0,.18); color: #fff;
  padding: 3px 9px; border-radius: 20px; font-weight: 600;
  display: flex; align-items: center; gap: 3px;
  backdrop-filter: blur(4px);
}
.game-card .card-badge .emoji { font-size: 11px; }

/* Tema warna */
.t-math    { background: linear-gradient(150deg, #ffc247, #ff8a00); }
.t-reading { background: linear-gradient(150deg, #9b7bff, #6a4cff); }
.t-puzzle  { background: linear-gradient(150deg, #ff8fb1, #ff4d80); }
.t-animals { background: linear-gradient(150deg, #35d6c4, #00a896); }
.t-stories { background: linear-gradient(150deg, #ffa46b, #ff6b35); }
.t-adventure { background: linear-gradient(150deg, #56ccf2, #2f80ed); }

/* Panel kemajuan */
.panel {
  background: rgba(255,255,255,.86);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-soft);
  padding: 14px clamp(14px, 2vw, 20px);
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap;
}
.panel .panel-title { font-weight: 600; font-size: 14px; color: var(--ink-soft); }
.progress { flex: 1 1 160px; height: 16px; border-radius: 20px; background: #e7eef3; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,.08); }
.progress > i { display: block; height: 100%; width: 0; border-radius: 20px; background: linear-gradient(90deg, #ffd166, #ffa600); transition: width .7s cubic-bezier(.2,1,.3,1); }
.panel .panel-num { font-weight: 700; font-size: 15px; color: #a57100; }

/* ---------- Skrin permainan ---------- */
.game-inner {
  width: 100%; max-width: 880px; margin: 0 auto;
  display: flex; flex-direction: column; gap: clamp(10px, 2vh, 18px);
  min-height: 100%;
}
.game-head {
  display: flex; align-items: center; gap: 10px;
  padding-top: 2px;
}
.game-head .gtitle {
  font-weight: 600; font-size: clamp(14px, 2vw, 18px);
  color: #12688f; text-shadow: 0 2px 0 #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ghead-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.dots { display: flex; gap: 6px; align-items: center; }
.dots > i {
  width: 10px; height: 10px; border-radius: 50%;
  background: #ffffff; box-shadow: inset 0 0 0 2px #b9d9e8;
  transition: all .25s;
}
.dots > i.on { background: #ffc247; box-shadow: inset 0 0 0 2px #e8a300; transform: scale(1.15); }
.dots > i.done { background: #22c55e; box-shadow: inset 0 0 0 2px #16a34a; }

.board {
  flex: 1 1 auto;
  background: rgba(255,255,255,.96);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-soft);
  padding: clamp(14px, 3vw, 28px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(8px, 1.8vh, 16px);
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}
.board.flush { padding: 0; }

.prompt {
  text-align: center;
  font-size: clamp(18px, 3.1vw, 28px);
  font-weight: 600;
  line-height: 1.25;
  max-width: 22ch;
  color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.prompt .prompt-emoji { font-family: var(--emoji); font-size: clamp(30px, 5vw, 46px); line-height: 1; }
.prompt small { font-size: .62em; font-weight: 500; color: var(--ink-soft); }

/* Pilihan jawapan */
.options {
  display: grid; gap: clamp(8px, 1.6vw, 14px);
  width: 100%;
  justify-content: center;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
  max-width: 640px;
}
.opt {
  border: none; cursor: pointer; font-family: inherit;
  background: linear-gradient(180deg, #ffffff, #f2f8fc);
  border-radius: var(--r-md);
  box-shadow: 0 6px 0 #d6e6ef, 0 12px 20px rgba(43,45,66,.10);
  min-height: clamp(78px, 13vh, 116px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  font-size: clamp(22px, 4vw, 34px); font-weight: 700; color: #23405a;
  transition: transform .12s, box-shadow .12s, background .2s;
  position: relative;
  padding: 8px;
}
.opt .emoji { font-size: 1.25em; }
.opt small { font-size: 12px; font-weight: 500; color: var(--ink-soft); }
.opt:hover { transform: translateY(-3px); background: #fff; }
.opt:active { transform: translateY(2px); box-shadow: 0 3px 0 #d6e6ef; }
.opt.selected { background: linear-gradient(180deg, #fff6d8, #ffe9a8); box-shadow: 0 6px 0 #e8b93c, 0 0 0 4px #ffd166; transform: translateY(-2px); }
.opt.correct {
  background: linear-gradient(180deg, #b6f5c9, #52dd7f);
  color: #064d22;
  box-shadow: 0 6px 0 #1a9e4b, 0 0 0 5px rgba(34,197,94,.35);
  animation: popCorrect .5s cubic-bezier(.3,1.5,.5,1);
}
.opt.wrong {
  background: linear-gradient(180deg, #ffd7d7, #ffb1b1);
  box-shadow: 0 6px 0 #d96a6a;
  animation: shake .42s;
}
.opt.dim { opacity: .42; pointer-events: none; }
.opt .tick {
  position: absolute; top: -8px; right: -6px;
  font-size: 26px; font-family: var(--emoji);
  animation: popCorrect .45s cubic-bezier(.3,1.6,.5,1);
}
@keyframes popCorrect { 0% { transform: scale(.8) } 55% { transform: scale(1.07) } 100% { transform: scale(1) } }
@keyframes shake { 0%,100% { transform: translateX(0) } 20% { transform: translateX(-7px) rotate(-1.5deg) } 40% { transform: translateX(7px) rotate(1.5deg) } 60% { transform: translateX(-5px) } 80% { transform: translateX(5px) } }

/* Bintang kecil maklum balas */
.feedback {
  position: absolute; inset: 0; pointer-events: none;
  display: grid; place-items: center; z-index: 5;
}
.feedback .big {
  font-size: clamp(80px, 18vw, 150px);
  font-family: var(--emoji);
  animation: feedbackPop .9s cubic-bezier(.2,1.4,.4,1) forwards;
  filter: drop-shadow(0 10px 20px rgba(0,0,0,.25));
}
@keyframes feedbackPop {
  0% { transform: scale(.3) rotate(-18deg); opacity: 0 }
  40% { transform: scale(1.12) rotate(6deg); opacity: 1 }
  70% { transform: scale(1) rotate(0); opacity: 1 }
  100% { transform: scale(1.25) translateY(-16px); opacity: 0 }
}

/* Butang umum */
.btn {
  border: none; cursor: pointer; font-family: inherit; font-weight: 600;
  border-radius: 18px;
  padding: 12px 24px;
  font-size: clamp(15px, 2.2vw, 19px);
  background: linear-gradient(180deg, #ffffff, #eaf4fa);
  color: #175b7c;
  box-shadow: 0 6px 0 #cfe2ec, 0 10px 20px rgba(43,45,66,.10);
  display: inline-flex; align-items: center; gap: 8px;
  transition: transform .12s, box-shadow .12s;
  line-height: 1.2;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #cfe2ec; }
.btn .emoji { font-size: 1.15em; }
.btn.primary { background: linear-gradient(180deg, #ffe27a, #ffc247); color: #6b4a00; box-shadow: 0 6px 0 #d99b00, 0 12px 22px rgba(217,155,0,.25); }
.btn.primary:active { box-shadow: 0 2px 0 #d99b00; }
.btn.green { background: linear-gradient(180deg, #7ef0a5, #34d26b); color: #04501f; box-shadow: 0 6px 0 #1a9e4b; }
.btn.green:active { box-shadow: 0 2px 0 #1a9e4b; }
.btn.blue { background: linear-gradient(180deg, #7cd8ff, #38a8ec); color: #043a56; box-shadow: 0 6px 0 #1a7db4; }
.btn.blue:active { box-shadow: 0 2px 0 #1a7db4; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.big { padding: 16px 34px; font-size: clamp(17px, 2.6vw, 22px); border-radius: 22px; }
.btn.hidden { display: none; }

/* Kaunter / paparan objek */
.count-row {
  display: flex; flex-wrap: wrap; gap: clamp(4px, 1vw, 10px);
  justify-content: center; align-items: center;
  padding: 6px;
  max-width: 640px;
}
.count-item {
  font-family: var(--emoji);
  font-size: clamp(28px, 5.4vw, 50px);
  line-height: 1;
  animation: dropIn .45s cubic-bezier(.3,1.5,.5,1) backwards;
  filter: drop-shadow(0 4px 5px rgba(0,0,0,.12));
}
@keyframes dropIn { from { transform: translateY(-26px) scale(.6); opacity: 0 } to { transform: none; opacity: 1 } }

.groups { display: flex; gap: clamp(10px, 3vw, 28px); align-items: center; justify-content: center; flex-wrap: wrap; }
.group-box {
  background: #f4fbff; border-radius: 22px;
  padding: clamp(8px, 1.6vw, 16px);
  min-width: 110px;
  display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; align-items: center;
  box-shadow: inset 0 0 0 3px #e0f0f8;
}
.group-box .count-item { font-size: clamp(24px, 4.2vw, 38px); }
.op-sign { font-size: clamp(30px, 5vw, 46px); font-weight: 700; color: #ff8a00; }

/* ---------- Papan teka-teki ---------- */
.puzzle-stage { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.puzzle-frame {
  position: relative;
  width: min(74vw, 340px); aspect-ratio: 1;
  border-radius: 22px;
  background: #e8f4fb;
  box-shadow: inset 0 0 0 5px #cfe7f3, 0 10px 24px rgba(43,45,66,.14);
  overflow: hidden;
  touch-action: none;
}
.puzzle-frame.size-lg { width: min(82vw, 400px); }
.pgrid { position: absolute; inset: 0; display: grid; }
.pcell {
  position: relative; overflow: hidden;
  margin: 0; border-radius: 0;
  background: #dcecf6;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.pcell .scene { position: absolute; pointer-events: none; }
.pcell.placed { box-shadow: inset 0 0 0 2px rgba(34,197,94,.5); }
.pcell.sel { z-index: 4; transform: scale(.94); box-shadow: 0 0 0 5px #ffc247, 0 8px 18px rgba(0,0,0,.22); }
.pcell .num {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 700; color: rgba(255,255,255,.85); font-size: 22px;
  text-shadow: 0 2px 4px rgba(0,0,0,.25);
}
.pcell.hint { animation: hintGlow .9s ease 2; }
@keyframes hintGlow { 0%,100% { box-shadow: inset 0 0 0 2px rgba(34,197,94,.2) } 50% { box-shadow: 0 0 0 5px #34d26b, 0 0 22px #34d26b } }
.pcell.bad { animation: shake .4s; }
.pcell.good { animation: popCorrect .45s; }

.scene { position: absolute; overflow: hidden; }
.scene .s-item { position: absolute; transform: translate(-50%, -50%); line-height: 1; font-family: var(--emoji); filter: drop-shadow(0 6px 10px rgba(0,0,0,.18)); }
.scene .s-sun { position: absolute; border-radius: 50%; }

.puzzle-bar { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.hint-note { font-size: 13px; color: var(--ink-soft); font-weight: 500; text-align: center; }

/* ---------- Memori ---------- */
.mem-grid {
  display: grid;
  gap: clamp(6px, 1.4vw, 12px);
  width: min(92vw, 520px);
  grid-template-columns: repeat(4, 1fr);
  perspective: 800px;
}
.mem-card {
  aspect-ratio: 1 / 1.12;
  border: none; cursor: pointer; padding: 0;
  border-radius: 16px;
  background: transparent;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.4,1.2,.5,1);
}
.mem-card .face {
  position: absolute; inset: 0;
  border-radius: 16px;
  display: grid; place-items: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-family: var(--emoji);
  box-shadow: 0 6px 0 rgba(0,0,0,.12), 0 10px 18px rgba(43,45,66,.14);
}
.mem-card .back {
  background: linear-gradient(150deg, #9b7bff, #6a4cff);
  color: #fff; font-size: clamp(22px, 4vw, 34px);
}
.mem-card .back::after {
  content: ''; position: absolute; inset: 8px; border-radius: 11px;
  border: 2px dashed rgba(255,255,255,.4);
}
.mem-card .front {
  background: linear-gradient(180deg, #ffffff, #eef8ff);
  transform: rotateY(180deg);
  font-size: clamp(30px, 6vw, 48px);
}
.mem-card.flipped { transform: rotateY(180deg); }
.mem-card.matched { animation: matchedCard .55s ease; }
.mem-card.matched .front { box-shadow: 0 0 0 4px #34d26b, 0 8px 18px rgba(34,197,94,.35); background: linear-gradient(180deg,#eafff1,#c9ffdb); }
@keyframes matchedCard { 0%,100% { transform: rotateY(180deg) scale(1) } 50% { transform: rotateY(180deg) scale(1.08) } }

/* ---------- Bunyi haiwan ---------- */
.speaker-zone {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.big-speaker {
  width: clamp(96px, 16vw, 132px); height: clamp(96px, 16vw, 132px);
  border-radius: 50%; border: none; cursor: pointer;
  background: radial-gradient(circle at 35% 28%, #fff, #ffe9a8 45%, #ffc247 100%);
  box-shadow: 0 10px 0 #d99b00, 0 20px 34px rgba(217,155,0,.32);
  font-size: clamp(38px, 7.4vw, 56px);
  display: grid; place-items: center;
  transition: transform .15s;
  position: relative;
  color: #6b4a00;
}
.big-speaker span { font-family: var(--emoji); }
.big-speaker:active { transform: translateY(4px) scale(.97); box-shadow: 0 5px 0 #d99b00; }
.big-speaker.playing { animation: speakerPulse .7s ease infinite; }
@keyframes speakerPulse { 0%,100% { box-shadow: 0 10px 0 #d99b00, 0 0 0 0 rgba(255,194,71,.6) } 50% { box-shadow: 0 10px 0 #d99b00, 0 0 0 22px rgba(255,194,71,0) } }
.speaker-ring {
  position: absolute; inset: -14px; border-radius: 50%;
  border: 3px solid rgba(255,194,71,.55);
  animation: ringOut 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes ringOut { 0% { transform: scale(.9); opacity: .8 } 100% { transform: scale(1.35); opacity: 0 } }

.animal-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: clamp(8px,1.8vw,14px); width: 100%; max-width: 620px; }
.animal-opt {
  border: none; cursor: pointer; font-family: inherit;
  border-radius: 22px;
  background: linear-gradient(180deg, #ffffff, #eef8ff);
  box-shadow: 0 6px 0 #d6e6ef, 0 10px 20px rgba(43,45,66,.10);
  padding: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: transform .13s, box-shadow .13s;
  min-height: clamp(78px, 11.5vh, 102px);
  justify-content: center;
}
.animal-opt .emoji { font-size: clamp(32px, 5.6vw, 46px); line-height: 1.1; transition: transform .2s; }
.animal-opt .name { font-weight: 600; font-size: clamp(13px, 2vw, 17px); color: #23405a; }
.animal-opt:hover { transform: translateY(-3px); }
.animal-opt:hover .emoji { transform: scale(1.1) rotate(-5deg); }
.animal-opt:active { transform: translateY(2px); }
.animal-opt.correct { background: linear-gradient(180deg,#b6f5c9,#52dd7f); box-shadow: 0 6px 0 #1a9e4b, 0 0 0 5px rgba(34,197,94,.3); animation: popCorrect .45s; }
.animal-opt.wrong { background: linear-gradient(180deg,#ffd7d7,#ffb1b1); box-shadow: 0 6px 0 #d96a6a; animation: shake .4s; }
.animal-opt.dim { opacity: .35; pointer-events: none; }

/* ---------- Cerita ---------- */
.story-card {
  width: 100%; max-width: 680px;
  display: flex; flex-direction: column; align-items: center; gap: clamp(10px, 2vh, 18px);
  text-align: center;
}
.story-art {
  width: 100%;
  border-radius: 26px;
  background: linear-gradient(160deg, #fff3c4, #ffe6a7 50%, #d8f3ff 100%);
  min-height: clamp(150px, 30vh, 260px);
  display: grid; place-items: center;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.7);
}
.story-art .big-emoji {
  font-family: var(--emoji);
  font-size: clamp(70px, 16vw, 130px);
  line-height: 1;
  animation: bob 3.6s ease-in-out infinite;
  filter: drop-shadow(0 14px 18px rgba(0,0,0,.18));
  z-index: 2;
}
.story-art .deco { position: absolute; font-family: var(--emoji); opacity: .85; }
.story-text {
  font-size: clamp(15px, 2.5vw, 21px);
  font-weight: 500;
  line-height: 1.5;
  max-width: 46ch;
  background: #fff;
  border-radius: 20px;
  padding: 14px 20px;
  box-shadow: var(--shadow-soft);
}
.story-nav { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
.story-dots { display: flex; gap: 6px; }
.story-dots i { width: 9px; height: 9px; border-radius: 50%; background: #cfe2ec; }
.story-dots i.on { background: #ffb703; }
.story-dots i.done { background: #34d26b; }

/* ---------- Pengembaraan ---------- */
.adv-wrap {
  position: relative;
  width: 100%; max-width: 700px;
  margin: 0 auto;
  flex: 1;
  min-height: 380px;
  border-radius: 28px;
  background: linear-gradient(180deg, #bfeeff 0%, #d9f7ff 26%, #e9fcdf 42%, #b7e9a2 100%);
  box-shadow: inset 0 0 0 5px #fff, var(--shadow-soft);
  overflow: hidden;
}
.adv-wrap .adv-cloud { position: absolute; font-family: var(--emoji); font-size: 34px; opacity: .9; animation: driftSlow 26s linear infinite; }
@keyframes driftSlow { from { transform: translateX(-60px) } to { transform: translateX(720px) } }

.adv-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.adv-node {
  position: absolute; transform: translate(-50%, -50%);
  width: clamp(42px, 6.6vw, 56px); height: clamp(42px, 6.6vw, 56px);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 5px 0 rgba(0,0,0,.15), 0 8px 16px rgba(0,0,0,.14);
  display: grid; place-items: center;
  font-size: clamp(20px, 3.4vw, 27px);
  font-family: var(--emoji);
  transition: transform .3s, box-shadow .3s, background .3s;
  z-index: 2;
}
.adv-node.reached { background: #b9f8cb; box-shadow: 0 5px 0 #16a34a, 0 0 0 4px rgba(34,197,94,.25); }
.adv-node.current { animation: nodePulse 1.6s ease-in-out infinite; background: #fff3c4; box-shadow: 0 5px 0 #e0a300, 0 0 0 5px rgba(255,183,3,.35); }
.adv-node.goal { background: #ffe0b2; }
@keyframes nodePulse { 0%,100% { transform: translate(-50%,-50%) scale(1) } 50% { transform: translate(-50%,-50%) scale(1.12) } }

.adv-hero {
  position: absolute; transform: translate(-50%, -100%);
  font-family: var(--emoji);
  font-size: clamp(34px, 6vw, 48px);
  z-index: 4;
  transition: left .7s cubic-bezier(.4,1.2,.5,1), top .7s cubic-bezier(.4,1.2,.5,1);
  filter: drop-shadow(0 8px 8px rgba(0,0,0,.2));
  animation: heroBob 1.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes heroBob { 0%,100% { margin-top: 0 } 50% { margin-top: -7px } }

.adv-fruit {
  position: absolute; transform: translate(-50%,-50%);
  font-family: var(--emoji); font-size: clamp(20px,3.4vw,28px);
  z-index: 3;
  animation: fruitFloat 2.4s ease-in-out infinite;
  filter: drop-shadow(0 5px 6px rgba(0,0,0,.15));
}
@keyframes fruitFloat { 0%,100% { margin-top: 0 } 50% { margin-top: -8px } }

.adv-quest {
  position: absolute; left: 12px; top: 12px;
  background: rgba(255,255,255,.94);
  border-radius: 18px; padding: 8px 16px;
  font-weight: 600; font-size: clamp(12px,1.8vw,15px);
  box-shadow: var(--shadow-soft);
  z-index: 6; white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}
.adv-quest .emoji { font-size: 1.25em; }
.adv-bottom { display: flex; flex-direction: column; gap: 10px; width: 100%; align-items: center; }
.adv-q {
  background: #fff; border-radius: 20px; padding: 12px 18px;
  box-shadow: var(--shadow-soft);
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center;
  font-size: clamp(16px,2.6vw,22px); font-weight: 600;
}
.adv-q .qtext { color: var(--ink); }
.adv-opts { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.adv-opts .opt { min-height: 62px; min-width: 74px; font-size: clamp(20px,3vw,26px); padding: 6px 18px; }

/* ---------- Overlay / modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(20, 60, 85, .35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 16px;
  animation: fadeIn .25s ease;
}
.overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.modal {
  background: linear-gradient(180deg, #ffffff, #f6fcff);
  border-radius: 30px;
  box-shadow: 0 26px 60px rgba(10, 50, 75, .3), 0 0 0 6px rgba(255,255,255,.5);
  width: min(480px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: clamp(20px, 4vw, 32px);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
  animation: modalIn .42s cubic-bezier(.3,1.4,.5,1);
  position: relative;
}
@keyframes modalIn { from { transform: scale(.8) translateY(24px); opacity: 0 } to { transform: none; opacity: 1 } }

.modal h2 { margin: 0; font-size: clamp(22px, 3.6vw, 30px); color: #0e5f86; }
.modal p { margin: 0; font-size: clamp(14px, 2vw, 17px); color: var(--ink-soft); line-height: 1.45; font-weight: 500; }
.modal .modal-emoji { font-family: var(--emoji); font-size: clamp(54px, 11vw, 76px); line-height: 1; animation: bob 2.6s ease-in-out infinite; }
.modal .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

.stars-row { display: flex; gap: 8px; justify-content: center; margin: 4px 0; }
.stars-row .star-slot {
  font-family: var(--emoji); font-size: clamp(38px, 8vw, 54px); line-height: 1;
  filter: grayscale(1) opacity(.28);
  transform: scale(.85);
  transition: none;
}
.stars-row .star-slot.lit {
  filter: none; transform: scale(1);
  animation: starPop .6s cubic-bezier(.3,1.6,.5,1) both;
}
@keyframes starPop { 0% { transform: scale(.2) rotate(-40deg); opacity: 0 } 60% { transform: scale(1.25) rotate(8deg) } 100% { transform: scale(1) rotate(0); opacity: 1 } }

/* Sticker */
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: 100%; }
.sticker {
  aspect-ratio: 1; border-radius: 18px;
  display: grid; place-items: center;
  font-family: var(--emoji); font-size: clamp(26px, 5vw, 36px);
  background: linear-gradient(160deg, #fff9e0, #ffeaa3);
  box-shadow: inset 0 0 0 3px #f0d488;
  position: relative;
}
.sticker.locked { filter: grayscale(1); opacity: .35; background: #eef3f6; box-shadow: inset 0 0 0 3px #dde8ee; }
.sticker.new::after {
  content: 'BARU!'; position: absolute; top: -6px; right: -6px;
  background: #ff4d80; color: #fff; font-family: var(--font);
  font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 8px;
  box-shadow: 0 3px 6px rgba(0,0,0,.2);
}
.sticker-count { font-weight: 600; color: var(--ink-soft); font-size: 14px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 50, 70, .92); color: #fff;
  padding: 10px 20px; border-radius: 30px;
  font-size: 14px; font-weight: 500; z-index: 80;
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
  display: flex; align-items: center; gap: 8px;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast .emoji { font-size: 1.2em; }

/* Confetti */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; }

/* Skrin kecil */
@media (max-width: 620px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { align-items: flex-start; }
  .bubble { display: none; }
  .brand-text { display: none; }
  .game-card { min-height: 118px; border-radius: 24px; }
  .animal-grid { grid-template-columns: repeat(2, 1fr); }
  .mem-grid { grid-template-columns: repeat(4, 1fr); }
  .sticker-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 400px) {
  :root { --topbar-h: 58px; }
  .icon-btn { width: 40px; height: 40px; border-radius: 13px; font-size: 19px; }
  .star-pill { height: 40px; padding: 0 12px 0 8px; font-size: 16px; border-radius: 13px; }
  .game-card .card-sub { display: none; }
}

/* Lanskap pendek */
@media (max-height: 560px) {
  .hero-text h1 { font-size: clamp(20px, 4vw, 30px); }
  .game-card { min-height: 100px; }
  .board { padding: 10px; gap: 8px; }
}

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

/* =========================================================
   TAMBAHAN KOMPONEN
   ========================================================= */

/* objek yang "hilang" dalam soalan tolak */
.count-item.gone { opacity: .22; filter: grayscale(1); transform: scale(.8); }

/* ejaan */
.spell-boxes { display: flex; gap: clamp(6px, 1.4vw, 12px); justify-content: center; flex-wrap: wrap; }
.spell-box {
  width: clamp(40px, 8vw, 58px); height: clamp(48px, 9vw, 68px);
  border-radius: 14px;
  background: #eef7fc;
  box-shadow: inset 0 0 0 3px #cfe7f3;
  display: grid; place-items: center;
  font-size: clamp(22px, 4vw, 32px); font-weight: 700; color: #23405a;
  transition: all .2s;
}
.spell-box.filled { background: linear-gradient(180deg,#fff6d8,#ffe9a8); box-shadow: inset 0 0 0 3px #ffc247; animation: popCorrect .3s cubic-bezier(.3,1.5,.5,1); }
.spell-boxes.complete .spell-box { background: linear-gradient(180deg,#eafff1,#c9ffdb); box-shadow: inset 0 0 0 3px #34d26b; }

.tile-tray { display: flex; gap: clamp(6px, 1.4vw, 12px); justify-content: center; flex-wrap: wrap; }
.tile {
  border: none; cursor: pointer; font-family: inherit; font-weight: 700;
  width: clamp(46px, 9vw, 62px); height: clamp(52px, 10vw, 70px);
  border-radius: 16px;
  background: linear-gradient(180deg, #ffffff, #e7f3fb);
  box-shadow: 0 5px 0 #cfe2ec, 0 8px 16px rgba(43,45,66,.12);
  font-size: clamp(22px, 4vw, 30px); color: #23405a;
  transition: transform .12s, box-shadow .12s, opacity .2s;
  display: grid; place-items: center;
}
.tile:hover { transform: translateY(-3px); }
.tile:active { transform: translateY(2px); box-shadow: 0 2px 0 #cfe2ec; }
.tile.used { opacity: .18; pointer-events: none; transform: scale(.9); }
.tile.bad { animation: shake .4s; background: linear-gradient(180deg,#ffd7d7,#ffb1b1); box-shadow: 0 5px 0 #d96a6a; }

/* pemilih mod */
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(10px, 2vw, 16px); }
.mode-btn {
  border: none; cursor: pointer; font-family: inherit;
  border-radius: 24px; padding: 18px 14px;
  background: linear-gradient(180deg, #ffffff, #eff8ff);
  box-shadow: 0 7px 0 #d6e6ef, 0 12px 22px rgba(43,45,66,.12);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  color: #23405a; transition: transform .14s, box-shadow .14s;
  min-height: 150px; justify-content: center;
}
.mode-btn .emoji { font-size: clamp(38px, 7vw, 52px); line-height: 1; }
.mode-btn b { font-size: clamp(15px, 2.4vw, 19px); }
.mode-btn small { font-size: clamp(10px, 1.6vw, 12px); color: var(--ink-soft); font-weight: 500; line-height: 1.3; }
.mode-btn:hover { transform: translateY(-4px); }
.mode-btn:active { transform: translateY(2px); box-shadow: 0 3px 0 #d6e6ef; }

/* senarai cerita */
.story-list { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 560px; }
.story-pick {
  border: none; cursor: pointer; font-family: inherit;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px 12px 12px;
  border-radius: 22px;
  background: linear-gradient(180deg, #ffffff, #f2f9ff);
  box-shadow: 0 6px 0 #dcebf4, 0 10px 20px rgba(43,45,66,.1);
  color: #23405a; text-align: left;
  transition: transform .13s, box-shadow .13s;
}
.story-pick:hover { transform: translateY(-3px); }
.story-pick:active { transform: translateY(2px); box-shadow: 0 3px 0 #dcebf4; }
.story-pick .emoji { font-size: clamp(28px, 5vw, 38px); line-height: 1; }
.story-pick .sp-title { font-weight: 600; font-size: clamp(14px, 2.2vw, 18px); flex: 1; }
.story-pick .sp-arrow { color: #98c3d8; font-size: 14px; }

/* pemilih wira */
.hero-pick { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.hero-btn {
  border: none; cursor: pointer;
  width: clamp(80px, 16vw, 110px); height: clamp(80px, 16vw, 110px);
  border-radius: 28px;
  background: linear-gradient(180deg, #ffffff, #e8f6ff);
  box-shadow: 0 7px 0 #cfe2ec, 0 12px 22px rgba(43,45,66,.14);
  font-family: var(--emoji); font-size: clamp(40px, 8vw, 58px);
  display: grid; place-items: center;
  transition: transform .15s;
}
.hero-btn:hover { transform: translateY(-5px) rotate(-4deg); }
.hero-btn:active { transform: translateY(2px) scale(.96); }

/* pengembaraan */
.adv-wrap { flex: 1 1 auto; min-height: 300px; }
.adv-bottom { flex: 0 0 auto; padding-bottom: 2px; }
.adv-q { min-height: 58px; }
.adv-opts .opt { min-width: 64px; }
@media (max-height: 700px) {
  .adv-wrap { min-height: 250px; }
  .adv-q { padding: 8px 12px; font-size: 16px; }
}

/* papan cerita lebih besar */
.story-art .story-dots {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,.7); padding: 5px 10px; border-radius: 20px;
  z-index: 3;
}

/* modal koleksi lebih padat supaya muat di skrin kecil */
.modal .sticker-grid { max-width: 330px; gap: 8px; margin: 0 auto; }
.modal .sticker { font-size: clamp(24px, 4.6vw, 32px); border-radius: 14px; }
.modal .modal-emoji { font-size: clamp(46px, 9vw, 64px); }

.node-num {
  font-family: var(--font); font-weight: 700;
  font-size: clamp(14px, 2.3vw, 19px);
  color: #6f8f7c;
}
.adv-node.reached { font-size: clamp(18px, 3vw, 24px); }
.adv-node.goal { background: linear-gradient(180deg, #fff6d8, #ffd98a); box-shadow: 0 5px 0 #d6a63a, 0 10px 20px rgba(180, 130, 30, .28); }
.node-fruit {
  position: absolute; top: -12px; right: -12px;
  width: clamp(26px, 4.4vw, 32px); height: clamp(26px, 4.4vw, 32px);
  border-radius: 50%; background: #fff;
  display: grid; place-items: center;
  font-family: var(--emoji);
  font-size: clamp(15px, 2.5vw, 19px);
  line-height: 1;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .10), 0 6px 12px rgba(0, 0, 0, .16);
  animation: fruitFloat 2.2s ease-in-out infinite;
  z-index: 3;
}

/* Dalam permainan, toast dipaparkan di atas supaya tidak menutup pilihan jawapan */
body.playing .toast {
  top: calc(92px + var(--safe-top));
  bottom: auto;
  transform: translateX(-50%) translateY(-14px);
}
body.playing .toast.show { transform: translateX(-50%) translateY(0); }

/* butang tutup (X) pada modal */
.modal-close {
  position: absolute; top: 12px; right: 12px;
  width: 42px; height: 42px; border-radius: 50%;
  border: none; cursor: pointer; font-family: inherit;
  background: #eaf6fd; color: #12688f;
  font-size: 18px; font-weight: 700; line-height: 1;
  box-shadow: 0 3px 0 #cfe2ec, 0 6px 12px rgba(43,45,66,.10);
  display: grid; place-items: center;
  transition: transform .12s, box-shadow .12s, background .12s;
  z-index: 2;
}
.modal-close:hover { background: #dff0fa; transform: translateY(-1px); }
.modal-close:active { transform: translateY(2px); box-shadow: 0 1px 0 #cfe2ec; }
