:root {
  --pmb-font-display: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --pmb-font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --pmb-font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

body {
  font-family: var(--pmb-font-body);
  background-color: #F0F7FF;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(56, 189, 248, 0.14) 0%, transparent 28%),
    radial-gradient(circle at 88% 12%, rgba(251, 191, 36, 0.16) 0%, transparent 30%),
    radial-gradient(circle at 80% 85%, rgba(167, 139, 250, 0.14) 0%, transparent 32%);
  color: #1E293B;
  min-height: 100vh;
  overflow-x: hidden;
}

.font-display {
  font-family: var(--pmb-font-display);
}

.font-mono-num {
  font-family: var(--pmb-font-mono);
  font-variant-numeric: tabular-nums;
}

/* Sembunyikan scrollbar horizontal pada tab level mobile */
.no-scrollbar::-webkit-scrollbar {
  display: none;
}
.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Tekstur Kertas Buku Berpetak (Graph Paper) */
.notebook-grid {
  background-color: #FFFDF9;
  background-image:
    linear-gradient(to right, rgba(148, 197, 235, 0.28) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(148, 197, 235, 0.28) 1px, transparent 1px);
  background-size: 24px 24px;
  box-shadow:
    inset 0 2px 8px rgba(15, 23, 42, 0.04),
    0 10px 25px -5px rgba(59, 130, 246, 0.12);
}

/* Tombol 3D Taktil Ramah Anak */
.btn-3d {
  transition: transform 0.1s ease, box-shadow 0.1s ease, background-color 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn-3d:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18) !important;
}

/* Animasi Muncul Modal */
@keyframes modalPop {
  0% { opacity: 0; transform: scale(0.94) translateY(8px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-card {
  animation: modalPop 0.2s ease-out;
}

/* Animasi Kotak Aktif Menyala */
@keyframes pulseGlow {
  0%, 100% {
    box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.75), 0 4px 14px rgba(59, 130, 246, 0.35);
    transform: scale(1.04);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(56, 189, 248, 0.65), 0 6px 18px rgba(59, 130, 246, 0.45);
    transform: scale(1.07);
  }
}
.cell-active {
  position: relative;
  animation: pulseGlow 1.5s infinite ease-in-out;
  background-color: #FEF9C3 !important;
  border-color: #EAB308 !important;
  color: #1E3A8A !important;
  z-index: 10;
}

/* Animasi Getar Lembut Saat Jawaban Keliru */
@keyframes gentleShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.cell-error {
  position: relative;
  animation: gentleShake 0.38s ease-in-out;
  background-color: #FEE2E2 !important;
  border-color: #EF4444 !important;
  color: #B91C1C !important;
}

/* Animasi Pop Saat Jawaban Benar */
@keyframes popSuccess {
  0% { transform: scale(0.85); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.cell-done {
  position: relative;
  animation: popSuccess 0.28s ease-out;
  background-color: #DCFCE7 !important;
  border-color: #22C55E !important;
  color: #15803D !important;
}

/* Garis Coretan untuk Angka yang Dipinjam pada Pengurangan */
.digit-crossed {
  position: relative;
  color: #94A3B8 !important;
}
.digit-crossed::after {
  content: '';
  position: absolute;
  left: 14%;
  right: 14%;
  top: 50%;
  height: 3px;
  background-color: #EF4444;
  border-radius: 999px;
  transform: rotate(-28deg);
}

/* Animasi Balon Panduan */
@keyframes floatSoft {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-4px); }
}
.mascot-float {
  animation: floatSoft 3s ease-in-out infinite;
}

/* ===== PWA: aman untuk notch / gesture bar ===== */
body {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  overscroll-behavior-y: contain; /* cegah pull-to-refresh tak sengaja saat anak menekan tombol */
}
/* Cegah seleksi teks & callout long-press saat dipakai sebagai aplikasi */
@media (display-mode: standalone) {
  body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}
@keyframes toastIn {
  0% { opacity: 0; transform: translate(-50%, 12px); }
  100% { opacity: 1; transform: translate(-50%, 0); }
}
.pwa-toast { animation: toastIn 0.22s ease-out; }

/* Kanvas Konfeti di Atas Layar */
#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

/* Tombol di Tailwind v4 tidak lagi pointer secara bawaan */
button, [role="button"], .btn-3d { cursor: pointer; }
button:disabled { cursor: not-allowed; }

/* Indikator status yang tidak hanya bergantung pada warna (aksesibilitas) */
.cell-done::after,
.cell-error::after {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  font-family: var(--pmb-font-body);
  font-size: 10px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  color: #fff;
}
.cell-done::after { content: '\2713'; background: #22C55E; }
.cell-error::after { content: '!'; background: #EF4444; }

/* Fokus terlihat jelas untuk pengguna keyboard */
:focus-visible { outline: 3px solid #0EA5E9; outline-offset: 2px; }

/* Hormati preferensi "kurangi gerakan" */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================================
   SISTEM KARTU: satu format & ukuran untuk seluruh kartu.
   Dibungkus @layer components agar utilitas Tailwind (warna border/bg) tetap menang.
   ============================================================================ */
@layer components {
  /* Kartu besar (panel): header, bar operasi, papan, keypad */
  .panel {
    background-color: #fff;
    border: 2px solid #e0f2fe;
    border-radius: 1.5rem;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    padding: 0.875rem;
  }
  .panel-bar { padding: 0.75rem; }
  @media (min-width: 640px) {
    .panel { padding: 1.5rem; }
    .panel-bar { padding: 1rem; }
  }

  /* Kartu dalam (sub-kartu): panduan, legenda, misi, target, cadangan, dll. */
  .subcard {
    border-width: 2px;
    border-style: solid;
    border-radius: 1rem;
    padding: 0.75rem;
  }
  @media (min-width: 640px) { .subcard { padding: 1rem; } }

  /* Kartu lipat: riwayat langkah & bantuan tabel */
  .subcard-collapse {
    border-width: 2px;
    border-style: solid;
    border-radius: 1rem;
    overflow: hidden;
  }
  .collapse-head {
    width: 100%;
    min-height: 2.75rem;
    padding: 0 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
  }
  .collapse-body {
    padding: 0.5rem 0.75rem 0.75rem;
    border-top-width: 2px;
    border-top-style: solid;
  }
  @media (min-width: 640px) {
    .collapse-head { padding: 0 1rem; }
    .collapse-body { padding: 0.5rem 1rem 1rem; }
  }

  /* Kartu statistik: ukuran seragam */
  .stat-card {
    min-height: 4.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-width: 2px;
    border-style: solid;
    border-radius: 1rem;
    padding: 0.5rem;
  }

  /* Chip header: tinggi seragam 44px (target sentuh minimum) */
  .chip {
    height: 2.75rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0 0.75rem;
    border-width: 2px;
    border-style: solid;
    border-radius: 1rem;
  }
  .chip-icon { width: 2.75rem; padding: 0; justify-content: center; }

  /* Kartu lencana */
  .badge-card {
    min-height: 8.5rem;
    border-width: 2px;
    border-style: solid;
    border-radius: 1rem;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  /* Modal: ukuran dan padding sama untuk ketiganya */
  .modal-card {
    background-color: #fff;
    border-width: 2px;
    border-style: solid;
    border-radius: 1.5rem;
    box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
    width: 100%;
    max-width: 28rem;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  @media (min-width: 640px) { .modal-card { padding: 1.5rem; } }

  /* Tombol aksi: ukuran seragam di semua modal */
  .btn-action,
  .btn-action-ghost {
    min-height: 2.75rem;
    padding: 0 1.25rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
  }
  .btn-action { font-family: var(--pmb-font-display); color: #fff; }
  .btn-action-ghost { border-width: 2px; border-style: solid; transition: background-color 0.15s ease; }
  @media (min-width: 640px) { .btn-action { font-size: 1rem; } }

  /* Tombol operasi & level: tinggi seragam */
  .op-btn { min-height: 3rem; }
  .lvl-btn { min-height: 2.75rem; display: inline-flex; align-items: center; }
  #btn-toggle-mission, #btn-open-custom { min-height: 2.75rem; }
}


/* ===== Ikon & chip header seragam: cyan, tanpa border ===== */
.chip-ic { width: 1.35rem; height: 1.35rem; color: #20CEE2; flex-shrink: 0; fill: currentColor; }
@media (min-width: 640px) { .chip-ic { width: 1.6rem; height: 1.6rem; } }
.logo-mark { color: #20CEE2; }
.chip.chip-cyan {
  background: #ECFEFF !important;
  border: 0 !important;
  box-shadow: none !important;
  color: #0E7490 !important;
}
.chip.chip-cyan.chip-btn:hover { background: #CFFAFE !important; }
.chip.chip-cyan.chip-btn { box-shadow: 0 3px 0 #A5F3FC !important; }
.chip.chip-cyan.chip-btn:active { box-shadow: 0 0 0 #A5F3FC !important; }
.chip-label { font-size: 10px; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: #0891B2; }
.chip-value { color: #164E63; }

/* ===== Layar pembuka pertama kali: ikon cyan, latar hitam ===== */
#splash {
  position: fixed; inset: 0; z-index: 9999; background: #000;
  display: flex; align-items: center; justify-content: center;
  animation: splash-out 0.45s ease 1.1s forwards;
}
html.no-splash #splash { display: none; }
@keyframes splash-out { to { opacity: 0; visibility: hidden; } }
