/* =========================================================================
   Pandai Cilik — KIDS design framework
   Mobile-first. Big rounded cards, bright per-subject palette, huge tap
   targets (64–80px), child text >= 24px, playful Baloo/Nunito fonts.
   ========================================================================= */

/* ---- Fonts (Google Fonts; self-host later if desired) ------------------ */
@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700;800&family=Nunito:wght@400;600;700;800&display=swap');

/* ---- Design tokens ----------------------------------------------------- */
:root {
  /* Per-subject palette */
  --math:        #2563eb;  /* blue   */
  --math-soft:   #dbeafe;
  --bm:          #f97316;  /* orange */
  --bm-soft:     #ffedd5;
  --bi:          #16a34a;  /* green  */
  --bi-soft:     #dcfce7;
  --sains:       #7c3aed;  /* purple */
  --sains-soft:  #ede9fe;

  --sun:         #facc15;  /* mascot / star yellow */
  --pink:        #ec4899;
  --sky:         #38bdf8;

  --ink:         #1f2937;
  --ink-soft:    #4b5563;
  --bg:          #fff7ed;
  --card:        #ffffff;
  --line:        #f1e7da;

  --ok:          #22c55e;
  --gentle:      #fb923c;

  --radius:      20px;
  --radius-lg:   26px;
  --tap:         66px;   /* default tap target (still big for kids) */
  --shadow:      0 10px 25px rgba(31, 41, 55, .12);
  --shadow-lg:   0 18px 40px rgba(31, 41, 55, .18);

  --font-head:   'Baloo 2', system-ui, sans-serif;
  --font-body:   'Nunito', system-ui, sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(250, 204, 21, .18), transparent 38%),
    radial-gradient(circle at 88% 12%, rgba(56, 189, 248, .18), transparent 40%),
    radial-gradient(circle at 75% 90%, rgba(236, 72, 153, .12), transparent 42%);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, .h { font-family: var(--font-head); font-weight: 800; line-height: 1.15; margin: 0 0 .35em; }
h1 { font-size: clamp(24px, 6vw, 32px); }
h2 { font-size: clamp(19px, 4.6vw, 26px); }
h3 { font-size: clamp(18px, 4.2vw, 22px); }

a { color: var(--bi); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { max-width: 100%; }

/* ---- Layout shell ------------------------------------------------------ */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 14px 88px;
}
.app--wide { max-width: 1040px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 2px 10px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 20px;
  color: var(--ink);
  white-space: nowrap;       /* never wrap the brand to 2 lines */
}
.brand .logo {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--sun);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 22px;
  flex: none;
}
.brand--sm { font-size: 18px; }
/* Let a long skill-name brand shrink/truncate instead of pushing the Stop
   button off-screen on the play header. */
.topbar .brand { flex: 1 1 auto; min-width: 0; }
.topbar .brand > span:not(.logo) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.topbar .pill { flex: none; }

/* ---- compact top actions + language toggle ---------------------------- */
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.icon-pill {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow);
  font-size: 18px; text-decoration: none; color: var(--ink); flex: none;
}
.icon-pill:active { transform: scale(.94); }
.lang-toggle {
  display: inline-flex; background: #eef1f6; border-radius: 999px;
  padding: 3px; gap: 2px; flex: none;
}
.lang-opt {
  border: 0; background: transparent; border-radius: 999px;
  padding: 7px 13px; font-family: var(--font-head); font-weight: 800;
  font-size: 14px; color: #64748b; cursor: pointer; min-height: 36px; line-height: 1;
}
.lang-opt.is-on { background: var(--sains); color: #fff; box-shadow: 0 2px 6px rgba(124,58,237,.35); }

/* ---- Cards ------------------------------------------------------------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.card-lg { border-radius: var(--radius-lg); padding: 18px; }

.stack > * + * { margin-top: 10px; }
.center { text-align: center; }
.muted { color: var(--ink-soft); }
.big-text { font-size: clamp(22px, 5.4vw, 28px); }   /* child-facing min */

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  --btn-bg: var(--bi);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 0 28px;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 22px;
  color: #fff;
  background: var(--btn-bg);
  border: none;
  border-radius: 999px;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-decoration: none;
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { text-decoration: none; filter: brightness(1.03); }
.btn:active { transform: translateY(2px) scale(.99); box-shadow: var(--shadow); }
.btn:focus-visible { outline: 4px solid rgba(37, 99, 235, .45); outline-offset: 3px; }
.btn--block { display: flex; width: 100%; }
.btn--lg { min-height: 80px; font-size: 26px; padding: 0 36px; }
.btn--math  { --btn-bg: var(--math); }
.btn--bm    { --btn-bg: var(--bm); }
.btn--bi    { --btn-bg: var(--bi); }
.btn--sains { --btn-bg: var(--sains); }
.btn--sun   { --btn-bg: var(--sun); color: var(--ink); }
.btn--ghost {
  background: #fff; color: var(--ink);
  box-shadow: inset 0 0 0 3px var(--line), var(--shadow);
}

/* Big round audio replay button */
.audio-btn {
  width: 80px; height: 80px;
  border-radius: 50%;
  border: none;
  background: var(--sun);
  color: var(--ink);
  font-size: 38px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: grid; place-items: center;
  touch-action: manipulation;
}
.audio-btn:active { transform: scale(.94); }
.audio-btn--sm { width: 48px; height: 48px; font-size: 24px; }

/* ---- level (Tahun) groups on the skill map ---------------------------- */
.level-group { margin-top: 18px; }
.level-group:first-of-type { margin-top: 8px; }
.level-head {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-head); font-weight: 800; font-size: 18px; color: var(--ink-soft);
  margin: 0 2px 10px; padding-bottom: 6px; border-bottom: 2px dashed var(--line);
}
.level-badge {
  font-size: 12px; font-weight: 800; color: #fff; background: var(--sains);
  padding: 3px 10px; border-radius: 999px;
}
.level-group.is-current-level .level-head { color: var(--ink); border-bottom-color: var(--sains); }
.level-group:not(.is-current-level) { opacity: .82; }

/* ---- compact greeting row (child home) -------------------------------- */
.greet-row {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 18px; padding: 8px 12px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.greet-row .sinar { font-size: 34px; flex: none; animation: bob 2.4s ease-in-out infinite; }
.greet-text {
  flex: 1; margin: 0; font-family: var(--font-head); font-weight: 800;
  font-size: 18px; line-height: 1.2; color: var(--ink);
}
.greet-row .audio-btn { flex: none; }

/* ---- Forms ------------------------------------------------------------- */
.field { margin-bottom: 16px; }
.label { display: block; font-weight: 700; margin-bottom: 6px; color: var(--ink-soft); }
.input {
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  font-size: 18px;
  font-family: var(--font-body);
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 16px;
}
.input:focus { outline: none; border-color: var(--bi); box-shadow: 0 0 0 4px var(--bi-soft); }

.alert {
  padding: 14px 16px;
  border-radius: 16px;
  font-weight: 700;
  margin-bottom: 16px;
}
.alert--err { background: #fee2e2; color: #991b1b; }
.alert--ok  { background: var(--bi-soft); color: #166534; }

/* ---- Subject tiles (child home) --------------------------------------- */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.subject-tile {
  --c: var(--math);
  --c-soft: var(--math-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 150px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--c-soft);
  box-shadow: var(--shadow);
  color: var(--ink);
  text-align: center;
  cursor: pointer;
  border: 4px solid #fff;
  transition: transform .12s ease, box-shadow .12s ease;
}
.subject-tile:hover { text-decoration: none; transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.subject-tile:active { transform: translateY(1px) scale(.98); }
.subject-tile .emoji { font-size: 56px; line-height: 1; }
.subject-tile .name { font-family: var(--font-head); font-weight: 800; font-size: 24px; color: var(--c); }
.subject-tile--math  { --c: var(--math);  --c-soft: var(--math-soft); }
.subject-tile--bm    { --c: var(--bm);    --c-soft: var(--bm-soft); }
.subject-tile--bi    { --c: var(--bi);    --c-soft: var(--bi-soft); }
.subject-tile--sains { --c: var(--sains); --c-soft: var(--sains-soft); }

/* ---- Child avatar picker ---------------------------------------------- */
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 18px;
}
.avatar-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 12px;
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 4px solid #fff;
}
.avatar-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.avatar-tile .face {
  width: 96px; height: 96px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 56px;
  background: var(--sun);
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.06);
}
.avatar-tile .who { font-family: var(--font-head); font-weight: 800; font-size: 22px; }

/* ---- Option cards (pick_one renderer) --------------------------------- */
.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
  margin-top: 20px;
}
.option-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 20px 14px;
  border-radius: var(--radius);
  background: #fff;
  border: 4px solid var(--line);
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: transform .1s ease, border-color .1s ease, box-shadow .1s ease;
}
.option-card:hover { transform: translateY(-2px); }
.option-card:active { transform: scale(.97); }
.option-card .emoji { font-size: 60px; line-height: 1; }
.option-card .label { font-family: var(--font-head); font-weight: 700; font-size: 24px; }
.option-card.is-selected { border-color: var(--sky); }
.option-card.is-correct  { border-color: var(--ok); background: var(--bi-soft); animation: pop .4s ease; }
.option-card.is-wrong    { border-color: var(--gentle); animation: wobble .4s ease; }

/* ---- Categorize bins --------------------------------------------------- */
.bin-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-top: 16px; }
.bin {
  min-height: 140px;
  border-radius: var(--radius);
  border: 4px dashed var(--line);
  background: #fff;
  padding: 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.bin.is-over { border-color: var(--sky); background: #f0f9ff; }
.bin .bin-title { font-family: var(--font-head); font-weight: 800; font-size: 20px; text-align: center; }

/* ---- Sequence slots ---------------------------------------------------- */
.seq-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
.seq-slot {
  width: 96px; height: 96px;
  border-radius: var(--radius);
  border: 4px dashed var(--line);
  display: grid; place-items: center;
  font-size: 48px;
  background: #fff;
}
.seq-slot.is-over { border-color: var(--sky); }

/* ---- World map (skill nodes) ------------------------------------------ */
.world-map {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 10px 6px;
}
.world-row { display: flex; justify-content: center; }
.world-row:nth-child(even) { justify-content: flex-end; }
.world-row:nth-child(odd)  { justify-content: flex-start; }
.world-node {
  position: relative;
  width: 110px; height: 110px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: #fff;
  border: 6px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 44px;
  cursor: pointer;
  color: var(--ink);
  text-align: center;
}
.world-node .node-name { position: absolute; bottom: -26px; font-size: 15px; font-weight: 700; white-space: nowrap; }
.world-node.is-locked { filter: grayscale(.7); opacity: .6; cursor: not-allowed; }
.world-node.is-mastered { border-color: var(--sun); }
.world-node.is-mastered::after { content: "⭐"; position: absolute; top: -10px; right: -6px; font-size: 28px; }
.world-node.is-progress { border-color: var(--sky); }
.world-node.is-needswork { border-color: var(--gentle); }

/* ---- Taman Bintang (reward jar / garden) ------------------------------ */
.jar {
  position: relative;
  width: 200px; height: 240px;
  margin: 0 auto;
  border: 8px solid var(--line);
  border-top: none;
  border-radius: 0 0 60px 60px / 0 0 40px 40px;
  background: linear-gradient(180deg, transparent 0%, var(--bi-soft) 100%);
  overflow: hidden;
}
.jar-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, var(--sky), var(--bi));
  transition: height .6s ease;
}
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; }
.sticker { font-size: 44px; text-align: center; }

/* ---- Mascot ------------------------------------------------------------ */
.mascot {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.mascot .bubble {
  background: #fff;
  border-radius: 18px;
  padding: 9px 14px;
  box-shadow: var(--shadow);
  font-weight: 700;
  font-size: 16px;
  line-height: 1.25;
  position: relative;
}
.mascot .sinar { font-size: 48px; animation: bob 2.4s ease-in-out infinite; }
.mascot--sm .sinar { font-size: 34px; }
.mascot--sm .bubble { font-size: 15px; padding: 8px 12px; }

/* ---- Progress bar ------------------------------------------------------ */
.round-progress {
  height: 18px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.round-progress > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--sun), var(--bm));
  transition: width .4s ease;
}

/* ---- Confetti ---------------------------------------------------------- */
.confetti {
  position: fixed;
  top: -12px;
  width: 12px; height: 18px;
  border-radius: 3px;
  pointer-events: none;
  z-index: 60;
  animation: confetti-fall 1.6s linear forwards;
}

/* ---- Animations -------------------------------------------------------- */
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes wobble {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}
@keyframes bob {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes cheer {
  0% { transform: scale(.6) rotate(-8deg); opacity: 0; }
  60% { transform: scale(1.15) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: .9; }
}
.cheer { animation: cheer .5s ease both; }

/* ---- Utilities --------------------------------------------------------- */
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.hidden { display: none !important; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 999px;
  background: #fff; box-shadow: var(--shadow);
  font-weight: 700; font-size: 16px;
}

/* ---- Responsive -------------------------------------------------------- */
@media (min-width: 560px) {
  .tile-grid { gap: 20px; }
  .option-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}
@media (max-width: 380px) {
  .subject-tile { min-height: 130px; }
  .subject-tile .emoji { font-size: 46px; }
  .world-node { width: 92px; height: 92px; font-size: 38px; }
}

/* ---- Reduce motion ----------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .mascot .sinar { animation: none; }
  .confetti { display: none; }
}
