* { margin: 0; padding: 0; box-sizing: border-box; }

/* semua tombol: tanpa jeda 300ms & tanpa zoom double-tap pas dipencet cepat */
button { touch-action: manipulation; }

html, body {
  height: 100%;
  overscroll-behavior: none; /* ga ada pull-to-refresh / rubber band pas main */
}

:root {
  --navy: #0c142e;
  --card: #101b3c;
  --card2: #17234e;
  --purple: #7c5cff;
  --purple-l: #9d7bff;
  --muted: #8f9cc9;
  --yellow: #ffc93c;
  /* lebar papan main: dipakai bareng canvas + kontrol sentuh biar selalu pas */
  --game-w: min(480px, 96vw, calc((100dvh - 130px) * 0.75));
}

body {
  height: 100vh; /* cadangan kalau 100dvh belum didukung */
  height: 100dvh;
  overflow: hidden; /* layar game ga bisa discroll (bengkel punya scroll sendiri) */
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0 max(16px, env(safe-area-inset-bottom));
  font-family: 'Poppins', 'Segoe UI', sans-serif;
  background: linear-gradient(155deg, #2fb39a 0%, #17607a 32%, #123057 62%, #0a1d3a 100%);
  -webkit-tap-highlight-color: transparent;
}

/* margin auto = tetap center, tapi ga kepotong di layar pendek.
   width dikunci ke papan main biar hint yang panjang ga melebarin wrapper
   (kalau melebar, tombol sentuh yang absolute ikut keluar dari canvas). */
#game-wrap {
  position: relative;
  margin-top: auto;
  width: var(--game-w);
  -webkit-user-select: none;
  user-select: none; /* HUD & tombol ga ketebol pas di-tahan lama */
}

#game {
  display: block;
  border-radius: clamp(16px, 5vw, 36px);
  box-shadow: 0 30px 80px rgba(3, 10, 30, 0.65);
  width: 100%;
  height: auto;
  touch-action: none;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: max(14px, env(safe-area-inset-top)); /* ga ketutup notch pas full-screen */
  left: 50%;
  transform: translateX(-50%);
  background: rgba(9, 16, 38, 0.55);
  border: 1px solid rgba(124, 92, 255, 0.35);
  border-radius: 999px;
  padding: 8px 20px;
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.6;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(3, 10, 30, 0.45);
}

#hint {
  width: var(--game-w);
  margin: 14px 0 auto; /* auto di bawah = pasangan margin-top:auto #game-wrap, tetap center & bisa discroll */
  text-align: center;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
  text-shadow: 0 2px 6px rgba(3, 10, 30, 0.5);
}

/* ---------- layar pembuka (splash) ---------- */
#splash {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #0c142e;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#splash.hidden { display: none; }

#splash-cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* petunjuk loncat: muncul pas intro, hilang begitu tombol kebuka */
#splash-skip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(20px, env(safe-area-inset-bottom));
  text-align: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 13.5px;
  font-weight: 600;
  animation: skipbob 1.6s ease-in-out infinite;
  pointer-events: none;
}

@keyframes skipbob {
  0%, 100% { transform: translateY(0); opacity: 0.55; }
  50% { transform: translateY(-6px); opacity: 0.95; }
}

#splash-skip.hidden { display: none; }

/* dua tombol pilihan: gede, ikon + teks, gampang diteken anak */
#splash-ui {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(22px, env(safe-area-inset-bottom));
  margin-inline: auto;
  width: min(330px, 88vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#splash-ui.hidden { display: none; }

.splash-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  padding: 12px 18px;
  border-radius: 22px;
  border: 2px solid rgba(124, 92, 255, 0.55);
  background: rgba(13, 21, 48, 0.78);
  color: #fff;
  font-family: inherit;
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(4px);
  box-shadow: 0 12px 30px rgba(3, 10, 30, 0.5);
  transition: transform 0.12s;
  animation: pop 0.35s ease-out backwards;
}

.splash-btn:nth-child(2) { animation-delay: 0.12s; }
.splash-btn:hover { transform: scale(1.03); }
.splash-btn:active { transform: scale(0.96); }

/* tombol utama: gaya poster kuning-oranye kayak judulnya */
.splash-btn.primary {
  font-family: 'Bowlby One SC', Impact, 'Arial Black', sans-serif;
  font-weight: 400;
  font-size: 20px;
  letter-spacing: 0.5px;
  color: #2e2378;
  background: linear-gradient(135deg, #ffd93b, #ff8a3c);
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 14px 34px rgba(255, 138, 60, 0.45);
}

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 9, 24, 0.75);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.modal.hidden, .modal .hidden { display: none; }

.modal-box {
  background: var(--card);
  border: 1px solid rgba(124, 92, 255, 0.3);
  border-radius: 32px;
  padding: 34px 36px;
  width: min(360px, 90vw);
  text-align: center;
  color: #fff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  animation: pop 0.25s ease-out;
}

.modal-emoji { font-size: 54px; }
.modal-box h2 { margin: 6px 0 4px; font-size: 23px; }
.modal-box p { margin: 4px 0; color: var(--muted); font-size: 14px; }
.modal-box .modal-sub { color: #c7d1f5; }

#player-name, #math-answer {
  display: block;
  width: 100%;
  margin: 18px 0 14px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(124, 92, 255, 0.4);
  background: #0a1226;
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  text-align: center;
  outline: none;
}

#player-name:focus, #math-answer:focus { border-color: var(--purple-l); }

#restart-btn, .primary-btn {
  width: 100%;
  padding: 14px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--purple-l), var(--purple));
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(124, 92, 255, 0.4);
  transition: transform 0.12s;
}

#restart-btn:hover, .primary-btn:hover { transform: scale(1.04); }

.secondary-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1.5px solid rgba(124, 92, 255, 0.4);
  border-radius: 999px;
  cursor: pointer;
}

.secondary-btn:hover { color: #fff; border-color: var(--purple-l); }

/* soal matematika buat nyawa tambahan */
#revive-actions .primary-btn { margin-top: 14px; }
.revive-hearts { font-size: 26px; margin: 10px 0 2px !important; }
.modal-box .math-feedback { color: #ffe08a; font-weight: 600; min-height: 1.4em; }
.modal-box .math-count { margin-top: 10px; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; }
.modal-box .math-q { color: #fff; font-size: 34px; font-weight: 800; margin: 4px 0 0; }
#math-answer { font-size: 22px; font-weight: 700; margin: 12px 0; }
.math-timer { margin-top: 10px; }
.math-timer-track { height: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
#math-timer-bar { height: 100%; width: 100%; border-radius: inherit; background: linear-gradient(90deg, #66bb6a, #ffd93b); transition: width 0.1s linear; }
.modal-box #math-timer-text { margin: 6px 0 0; font-size: 13px; font-weight: 700; color: #c7d1f5; }
.math-timer.low #math-timer-bar { background: #ff5252; }
.modal-box .math-timer.low #math-timer-text { color: #ff8a80; }
.modal-box .revive-note { margin-top: 12px; color: #c7d1f5; font-weight: 600; }

@keyframes pop {
  from { transform: scale(0.75); opacity: 0; }
}

/* ---------- kartu kenalan (fakta planet & ISS) ---------- */
.info-box {
  width: min(344px, 92vw);
  padding: 16px 18px 18px;
  border-radius: 26px;
}

.info-eyebrow {
  margin: 0 0 6px !important;
  color: var(--yellow);
  font-size: 12px !important;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

#info-cv {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 16px;
  border: 1px solid rgba(124, 92, 255, 0.3);
}

#info-title { font-size: 24px; margin: 10px 0 2px !important; }
.modal-box .info-sub { color: #c7d1f5; font-size: 13px; margin: 0 0 10px; }

#info-facts {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 0 0 4px;
}

.info-fact {
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  background: rgba(124, 92, 255, 0.13);
  border: 1px solid rgba(124, 92, 255, 0.28);
  border-radius: 14px;
  padding: 7px 12px;
}

.info-fact .info-emoji { flex: none; font-size: 23px; }
.info-fact p { margin: 0 !important; color: #fff !important; font-size: 13px; line-height: 1.45; font-weight: 600; }
.info-fact b { color: var(--yellow); font-weight: 800; }

.info-actions {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 10px;
  margin-top: 14px;
}

.info-actions .secondary-btn { margin-top: 0; }

#info-next:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ---------- bengkel roket ---------- */
#builder {
  --cyan: #35e6ff;
  --poster-yellow: #ffd93b;
  --poster-orange: #ff8a3c;
  --poster-deep: #2e2378;
  position: fixed;
  inset: 0;
  z-index: 20;
  /* latar baja hangar: gradasi gelap + iga diagonal samar */
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.02) 0 2px, transparent 2px 26px),
    radial-gradient(700px 360px at 18% 30%, rgba(124, 92, 255, 0.14), transparent 70%),
    linear-gradient(180deg, #1b2440 0%, #141d33 55%, #0d1424 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #fff;
  /* bisa discroll di layar pendek, tapi scrollnya ga merambat ke body */
  overflow-y: auto;
  overscroll-behavior: contain;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

#builder.hidden { display: none; }

.builder-head {
  margin-top: auto; /* auto margin = center pas muat, tapi tetap bisa discroll di layar pendek */
  text-align: center;
}

/* strip hazard di bawah judul, aksen hangar */
.builder-head::after {
  content: '';
  display: block;
  height: 6px;
  width: min(340px, 70vw);
  margin: -10px auto 14px;
  border-radius: 3px;
  background: repeating-linear-gradient(-45deg, #ffc93c 0 14px, #1d2238 14px 28px);
  opacity: 0.85;
}

/* judul ala poster action, satu gaya dengan sapaan waktu meluncur */
.builder-title {
  font-family: 'Bowlby One SC', Impact, 'Arial Black', sans-serif;
  font-weight: 400;
  font-size: clamp(34px, 7vw, 56px);
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--poster-yellow);
  text-shadow: 3px 3px 0 var(--poster-orange), 6px 6px 0 var(--poster-deep);
  transform: rotate(-3deg);
  margin: 6px 0 10px;
}

.builder-sub {
  color: #b7c2ea;
  font-size: 15px;
  margin-bottom: 22px;
}

.builder-row {
  display: grid;
  grid-template-columns: 300px minmax(0, 400px);
  grid-template-areas:
    "bay parts"
    "actions parts";
  grid-template-rows: auto 1fr;
  column-gap: 28px;
  row-gap: 16px;
  margin-bottom: auto; /* berpasangan dengan margin-top auto di judul */
  padding-bottom: 8px;
}

.bay { grid-area: bay; }
.parts { grid-area: parts; }
.bay-actions { grid-area: actions; }

#preview {
  display: block;
  width: 100%;
  height: auto;
  background: var(--navy);
  border: 2px solid rgba(255, 201, 60, 0.3); /* bingkai baja-kuning ala hangar */
  border-radius: 28px;
  box-shadow: 0 24px 60px rgba(3, 10, 30, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.part-label {
  display: block;
  margin: 16px 0 8px;
  color: #b7c2ea;
  font-size: 14px;
  font-weight: 600;
}

.part-panel > .part-label:first-child { margin-top: 4px; }

/* ---- tab bagian roket ---- */
.parts {
  position: relative;
  background: rgba(16, 27, 60, 0.85);
  border: 1px solid rgba(124, 92, 255, 0.3);
  border-radius: 24px;
  padding: 10px 16px 18px;
}

/* strip hazard tipis di atas panel, nyambung sama latar hangar */
.parts::before {
  content: '';
  display: block;
  height: 4px;
  margin: -10px -16px 10px;
  border-radius: 24px 24px 0 0;
  background: repeating-linear-gradient(-45deg, #ffc93c 0 10px, #232b4d 10px 20px);
  opacity: 0.4;
}

.part-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 10px;
  background: #0a1226;
  border-radius: 16px;
}

.part-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px 7px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 18px;
  cursor: pointer;
}

.part-tab span { font-size: 12px; font-weight: 600; }
.part-tab:hover { color: #fff; }

/* tab yang masih dikunci: selesaikan langkahnya dulu */
.part-tab.locked { opacity: 0.45; cursor: not-allowed; }
.part-tab.locked:hover { color: var(--muted); }

.part-tab.sel {
  background: linear-gradient(135deg, var(--purple-l), var(--purple));
  color: #fff;
  box-shadow: 0 6px 16px rgba(124, 92, 255, 0.35);
}

/* ---- gambar mini bentuk ---- */
.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 8px;
}

.thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 4px 8px;
  border: 2px solid rgba(124, 92, 255, 0.25);
  border-radius: 16px;
  background: #0a1226;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
}

.thumb canvas { width: 100%; max-width: 84px; height: auto; border-radius: 10px; }
.thumb:hover { border-color: var(--purple-l); color: #fff; }

.thumb.sel {
  border-color: var(--cyan);
  background: radial-gradient(circle at 50% 40%, rgba(53, 230, 255, 0.16), #0a1226 70%);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(53, 230, 255, 0.18);
}

.thumb:active, .swatch:active { transform: scale(0.94); }

/* ---- warna ---- */
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }

.swatch {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  border: 3px solid rgba(10, 18, 38, 0.9);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(3, 10, 30, 0.45);
  transition: transform 0.1s;
}

.swatch:hover { transform: scale(1.1); }
.swatch.sel { border-color: #fff; box-shadow: 0 0 0 3px var(--cyan); }

/* ---- nama pilot + tombol ---- */
#pilot-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(124, 92, 255, 0.4);
  background: #0a1226;
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  outline: none;
}

#pilot-input:focus { border-color: var(--cyan); }
.bay-actions .part-label { margin-top: 0; }

.bay-buttons {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  margin-top: 12px;
}

.bay-buttons .secondary-btn { width: auto; margin-top: 0; padding: 0 16px; color: #dfe5ff; }

#launch-btn {
  width: 100%;
  padding: 15px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--purple-l), var(--purple));
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 14px 30px rgba(124, 92, 255, 0.45);
  transition: transform 0.12s;
}

#launch-btn:hover { transform: scale(1.03); }

#launch-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

#builder button:focus-visible,
#builder input:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 2px;
}

/* HP: satu kolom — roket, pilihan, lalu nama & tombol meluncur */
@media (max-width: 760px) {
  .builder-row {
    grid-template-columns: minmax(0, 420px);
    grid-template-areas: "bay" "parts" "actions";
    grid-template-rows: auto;
    width: 100%;
    justify-content: center;
  }
  .bay { width: min(200px, 52vw); justify-self: center; }
  .builder-sub { margin-bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .thumb, .swatch, #launch-btn, .splash-btn { transition: none; animation: none; }
  #splash-skip { animation: none; }
}

/* ---------- tombol jeda ---------- */
#btn-pause {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 6;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(124, 92, 255, 0.45);
  background: rgba(9, 16, 38, 0.6);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(4px);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#btn-pause:hover { border-color: var(--purple-l); }
#btn-pause:active { transform: scale(0.92); }

/* ---------- layar jeda (di atas kanvas, selalu di tengah) ---------- */
#pause-menu {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-radius: clamp(16px, 5vw, 36px);
  background: rgba(6, 11, 30, 0.66);
  backdrop-filter: blur(2px);
}

#pause-menu.hidden { display: none; }

.pause-box {
  width: min(280px, 100%);
  text-align: center;
  color: #fff;
  animation: pop 0.2s ease-out;
}

.pause-title {
  color: #ffd93b;
  font-size: clamp(30px, calc(var(--game-w) * 0.085), 40px);
  font-weight: 800;
  line-height: 1.2;
}

#pause-hint { margin: 6px 0 18px; color: #c9d6ff; font-size: 14px; }

/* ---------- kontrol sentuh (HP/tablet) ---------- */
/* kolom kiri bawah: TURBO, TEMBAK, lalu JEDA */
#touch-controls {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom)); /* ga ketutup home indicator */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  z-index: 5;
}

#touch-controls.hidden { display: none; }

#touch-controls button {
  pointer-events: auto;
  /* ikut lebar papan: di tablet kecil / HP jangan makan setengah layar */
  width: clamp(62px, calc(var(--game-w) * 0.19), 86px);
  height: clamp(62px, calc(var(--game-w) * 0.19), 86px);
  border-radius: 50%;
  border: 2px solid rgba(124, 92, 255, 0.65);
  background: rgba(9, 16, 38, 0.55);
  color: #fff;
  font-family: inherit;
  font-size: clamp(10px, calc(var(--game-w) * 0.027), 12.5px);
  font-weight: 700;
  line-height: 1.3;
  backdrop-filter: blur(4px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#touch-controls #btn-pause {
  position: static;
  width: 46px;
  height: 46px;
  border-width: 1px;
  font-size: 18px;
}

#touch-controls button:active {
  background: rgba(124, 92, 255, 0.55);
  transform: scale(0.94);
}

/* layar lega: hint boleh lebih lebar dari papan biar muat satu baris */
@media (min-width: 760px) {
  #hint { width: auto; max-width: 90vw; }
}

@media (max-width: 520px) {
  #hud { font-size: 12px; padding: 6px 12px; top: max(8px, env(safe-area-inset-top)); }
  #btn-pause { top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); width: 32px; height: 32px; font-size: 13px; }
  #hint { font-size: 11.5px; }
}
