/* =====================================================================
   FAR PIXEL KIDS — Hub Design System
   Palette: candy-sticker kawaii — cream paper base, bubblegum + sky +
   sunshine + mint + grape accents, thick soft outlines, puffy shadows.
   ===================================================================== */

:root {
  --cream:        #FFF8EE;
  --paper:        #FFFDF8;
  --ink:          #2D2140;
  --ink-soft:     #6B5C82;

  --bubblegum:    #FF6FA5;
  --bubblegum-dk: #E84C88;
  --sky:          #4FC3F7;
  --sky-dk:       #2AA3DE;
  --sunshine:     #FFD54F;
  --sunshine-dk:  #F5A623;
  --mint:         #6EE7B7;
  --mint-dk:      #34C495;
  --grape:        #B78DFF;
  --grape-dk:     #9560F0;
  --coral:        #FF8A65;

  --card-radius: 28px;
  --btn-radius: 999px;
  --outline: 3px solid rgba(45,33,64,0.10);
  --shadow-puffy: 0 10px 0 rgba(45,33,64,0.08), 0 14px 24px rgba(45,33,64,0.14);
  --shadow-soft: 0 6px 18px rgba(45,33,64,0.12);

  --f-main: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI Rounded',
            'Segoe UI', Verdana, Arial, sans-serif;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

html, body {
  margin: 0; padding: 0;
  width: 100%;
  overflow-x: hidden;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--f-main);
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

button { font-family: inherit; }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Decorative background: soft blobs, fixed, behind everything */
.bg-blobs {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
}
.bg-blobs span {
  position: absolute; border-radius: 50%; opacity: 0.35; filter: blur(2px);
}
.bg-blobs span:nth-child(1) { width: 220px; height: 220px; background: var(--sky); top: -60px; left: -60px; }
.bg-blobs span:nth-child(2) { width: 160px; height: 160px; background: var(--sunshine); top: 30%; right: -50px; }
.bg-blobs span:nth-child(3) { width: 260px; height: 260px; background: var(--grape); bottom: -80px; left: 10%; }
.bg-blobs span:nth-child(4) { width: 140px; height: 140px; background: var(--mint); bottom: 10%; right: 8%; }

/* =====================================================================
   SPLASH SCREEN
   ===================================================================== */
#splash-screen {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--bubblegum) 0%, var(--grape) 55%, var(--sky) 100%);
  color: #fff; text-align: center; padding: 24px;
  transition: opacity .5s ease, visibility .5s ease;
}
#splash-screen.fade-out { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-mascot {
  font-size: 96px; line-height: 1;
  animation: bounce-in .7s cubic-bezier(.34,1.56,.64,1), float 2.4s ease-in-out 0.7s infinite;
}
.splash-title {
  margin: 18px 0 4px; font-size: clamp(28px, 8vw, 44px); font-weight: 900;
  letter-spacing: 1px; text-shadow: 0 4px 0 rgba(0,0,0,0.15);
}
.splash-sub { font-size: 16px; opacity: 0.92; font-weight: 700; }
.splash-loader {
  margin-top: 28px; width: min(240px, 70vw); height: 14px; border-radius: 999px;
  background: rgba(255,255,255,0.28); overflow: hidden; border: 2px solid rgba(255,255,255,0.5);
}
.splash-loader-bar {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--sunshine), #fff);
  transition: width .25s ease;
}
.splash-loader-label { margin-top: 10px; font-size: 13px; font-weight: 800; opacity: 0.9; }

@keyframes bounce-in {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes float {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* =====================================================================
   APP SHELL / HEADER
   ===================================================================== */
#app {
  position: relative; z-index: 1;
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
}

.hub-header {
  padding: calc(14px + var(--safe-t)) max(16px, var(--safe-l)) 10px max(16px, var(--safe-l));
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.hub-greeting { flex: 1 1 auto; min-width: 0; }
.hub-greeting h1 {
  margin: 0; font-size: clamp(20px, 5.5vw, 28px); font-weight: 900; color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
.hub-greeting p { margin: 2px 0 0; font-size: 13px; color: var(--ink-soft); font-weight: 700; }

.stat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--paper); border: var(--outline); border-radius: var(--btn-radius);
  padding: 8px 14px; font-weight: 900; font-size: 15px; box-shadow: var(--shadow-soft);
  white-space: nowrap;
}
.stat-pill .ic { font-size: 18px; }
.stats-row { display: flex; gap: 8px; flex-wrap: wrap; }

.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; border: var(--outline);
  background: var(--paper); box-shadow: var(--shadow-soft); font-size: 20px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  flex: 0 0 auto;
}
.icon-btn:active { transform: translateY(2px); box-shadow: none; }

.offline-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 800; padding: 6px 12px; border-radius: var(--btn-radius);
  background: rgba(110,231,183,0.25); color: var(--mint-dk); border: 2px solid rgba(52,196,149,0.4);
  margin: 0 max(16px, var(--safe-l)) 4px;
}
.offline-badge.not-ready { background: rgba(255,213,79,0.25); color: #a2760a; border-color: rgba(245,166,35,0.4); }
.offline-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* =====================================================================
   HUB GRID / GAME CARDS
   ===================================================================== */
.hub-main {
  flex: 1 1 auto; padding: 10px max(16px, var(--safe-l)) calc(28px + var(--safe-b));
  max-width: 920px; width: 100%; margin: 0 auto;
}

.game-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px; margin-top: 12px;
}

.game-card {
  position: relative; text-align: left; border: none; cursor: pointer;
  border-radius: var(--card-radius); padding: 18px 18px 20px;
  color: #fff; overflow: hidden;
  box-shadow: var(--shadow-puffy);
  display: flex; flex-direction: column; gap: 10px; min-height: 168px;
  transform: translateY(0) scale(1);
  transition: transform .15s ease, box-shadow .15s ease;
  animation: card-in .5s cubic-bezier(.34,1.56,.64,1) both;
}
.game-card:active { transform: translateY(4px) scale(0.99); box-shadow: 0 4px 0 rgba(45,33,64,0.10); }
.game-card:nth-child(1) { animation-delay: .02s; }
.game-card:nth-child(2) { animation-delay: .08s; }
.game-card:nth-child(3) { animation-delay: .14s; }
.game-card:nth-child(4) { animation-delay: .20s; }
.game-card:nth-child(5) { animation-delay: .26s; }

@keyframes card-in {
  0% { opacity: 0; transform: translateY(18px) scale(0.92); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.game-card.c-bahasa   { background: linear-gradient(145deg, var(--sky), var(--sky-dk)); }
.game-card.c-matematika { background: linear-gradient(145deg, var(--mint), var(--mint-dk)); }
.game-card.c-membaca  { background: linear-gradient(145deg, var(--grape), var(--grape-dk)); }
.game-card.c-restoran { background: linear-gradient(145deg, var(--coral), var(--bubblegum-dk)); }
.game-card.c-tatasurya{ background: linear-gradient(145deg, #4B3B8F, #1D1348); }

.game-card .emoji {
  font-size: 42px; filter: drop-shadow(0 3px 0 rgba(0,0,0,0.15));
}
.game-card h2 { margin: 0; font-size: 20px; font-weight: 900; }
.game-card .desc { margin: 0; font-size: 13px; font-weight: 700; opacity: 0.92; line-height: 1.35; }
.game-card .card-foot {
  margin-top: auto; display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 800;
}
.game-card .stars-earned { display: flex; align-items: center; gap: 4px; }
.game-card .play-chip {
  background: rgba(255,255,255,0.25); border-radius: var(--btn-radius);
  padding: 6px 12px; backdrop-filter: blur(2px);
}

.install-banner {
  margin-top: 18px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--paper); border: var(--outline); border-radius: var(--card-radius);
  padding: 14px 16px; box-shadow: var(--shadow-soft);
}
.install-banner .txt { flex: 1 1 200px; min-width: 0; }
.install-banner .txt strong { display: block; font-size: 15px; }
.install-banner .txt span { font-size: 12.5px; color: var(--ink-soft); font-weight: 700; }

.btn-primary, .btn-ghost, .btn-danger {
  border: none; border-radius: var(--btn-radius); font-weight: 900; cursor: pointer;
  padding: 12px 20px; font-size: 15px; min-height: 44px;
}
.btn-primary { background: var(--bubblegum); color: #fff; box-shadow: 0 5px 0 var(--bubblegum-dk); }
.btn-primary:active { transform: translateY(4px); box-shadow: none; }
.btn-ghost { background: rgba(45,33,64,0.06); color: var(--ink); }
.btn-ghost:active { transform: translateY(2px); }
.btn-danger { background: #FF5C5C; color: #fff; box-shadow: 0 5px 0 #C93E3E; }
.btn-danger:active { transform: translateY(4px); box-shadow: none; }

/* =====================================================================
   GAME VIEW (iframe host)
   ===================================================================== */
#game-view {
  position: fixed; inset: 0; z-index: 500; background: #000;
  display: flex; flex-direction: column;
}
.game-topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) max(10px, var(--safe-l)) 10px max(10px, var(--safe-l));
  background: linear-gradient(to bottom, rgba(0,0,0,0.45), transparent);
  pointer-events: none;
}
.game-topbar > * { pointer-events: auto; }
.game-topbar .back-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.92); font-size: 22px; display: flex; align-items: center;
  justify-content: center; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,0.3); flex: 0 0 auto;
}
.game-topbar .g-title {
  color: #fff; font-weight: 900; font-size: 15px; text-shadow: 0 2px 6px rgba(0,0,0,0.5);
}
#game-frame { flex: 1 1 auto; width: 100%; height: 100%; border: none; background: #fff; }

.game-loading {
  position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: var(--cream); transition: opacity .3s ease, visibility .3s ease;
}
.game-loading.hidden-fade { opacity: 0; visibility: hidden; }
.spinner {
  width: 54px; height: 54px; border-radius: 50%;
  border: 6px solid rgba(45,33,64,0.12); border-top-color: var(--bubblegum);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =====================================================================
   SETTINGS SHEET
   ===================================================================== */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 800; background: rgba(45,33,64,0.42);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; visibility: hidden; transition: opacity .25s ease, visibility .25s ease;
}
.sheet-overlay.open { opacity: 1; visibility: visible; }
.sheet {
  width: 100%; max-width: 520px; background: var(--paper);
  border-radius: 28px 28px 0 0; padding: 8px 20px calc(22px + var(--safe-b));
  box-shadow: 0 -10px 30px rgba(0,0,0,0.2);
  transform: translateY(24px); transition: transform .25s cubic-bezier(.34,1.56,.64,1);
  max-height: 82vh; overflow-y: auto;
}
.sheet-overlay.open .sheet { transform: translateY(0); }
.sheet-handle { width: 44px; height: 5px; border-radius: 999px; background: rgba(45,33,64,0.18); margin: 10px auto 12px; }
.sheet h2 { margin: 4px 0 14px; font-size: 20px; font-weight: 900; }

.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 4px; border-bottom: 2px solid rgba(45,33,64,0.06);
}
.setting-row:last-of-type { border-bottom: none; }
.setting-row .lbl { font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.setting-row .lbl small { display: block; font-weight: 700; color: var(--ink-soft); font-size: 12px; }

.toggle {
  width: 56px; height: 32px; border-radius: 999px; background: rgba(45,33,64,0.15);
  border: none; position: relative; cursor: pointer; flex: 0 0 auto;
}
.toggle .knob {
  position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.3); transition: left .18s ease;
}
.toggle.on { background: var(--mint-dk); }
.toggle.on .knob { left: 27px; }

.sheet-section { margin-top: 6px; }
.about-line { font-size: 12.5px; color: var(--ink-soft); font-weight: 700; margin-top: 14px; text-align: center; }

/* =====================================================================
   TOAST
   ===================================================================== */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b));
  transform: translate(-50%, 20px); z-index: 3000;
  background: var(--ink); color: #fff; font-weight: 800; font-size: 14px;
  padding: 12px 20px; border-radius: var(--btn-radius); box-shadow: var(--shadow-soft);
  opacity: 0; visibility: hidden; transition: all .25s ease; max-width: 88vw; text-align: center;
}
#toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (min-width: 720px) {
  .hub-header { padding-top: calc(22px + var(--safe-t)); }
  .game-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 380px) {
  .game-card { min-height: 150px; padding: 14px; }
  .game-card .emoji { font-size: 34px; }
}

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