/* =====================================================
   BASE — variabel, reset, layar, tombol, chip, topbar,
   keyframes umum, background per-bab
   (WAJIB dimuat paling pertama)
   ===================================================== */
:root {
  /* Colors */
  --merah: #c62e2e;
  --merah-tua: #8e1f1f;
  --emas: #f5a623;
  --emas-muda: #ffd27a;
  --tosca: #0fa3a3;
  --tosca-tua: #086868;
  --krem: #fff6e9;
  --coklat: #5b3a1e;
  --putih: #ffffff;
  --hijau: #4caf50;
  --abu: #b8ad9c;
  --radius: 20px;
  --shadow: 0 6px 0 rgba(91, 58, 30, 0.18);

  /* Fonts */
  --font-judul: "Baloo 2", cursive;
  --font-isi: "Nunito", sans-serif;

  /* Fluid Spacing */
  --gap-xs: clamp(4px, 1vw, 8px);
  --gap-sm: clamp(8px, 1.5vw, 12px);
  --gap-md: clamp(12px, 2.5vw, 16px);
  --gap-lg: clamp(16px, 3.5vw, 24px);
  --gap-xl: clamp(24px, 5vw, 40px);

  /* Fluid Typography */
  --text-xs: clamp(10px, 1.5vw, 12px);
  --text-sm: clamp(12px, 2vw, 14px);
  --text-base: clamp(14px, 2.5vw, 16px);
  --text-md: clamp(16px, 3vw, 20px);
  --text-lg: clamp(20px, 4vw, 28px);
  --text-xl: clamp(28px, 5vw, 40px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
}

body {
  font-family: var(--font-isi);
  color: var(--coklat);
  background-color: var(--krem);
  background-image: radial-gradient(rgba(198, 46, 46, 0.07) 2px, transparent 2px);
  background-size: 26px 26px;
  overflow: hidden;
  animation: bgMove 60s linear infinite;
}

@keyframes bgMove {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 520px 520px;
  }
}

/* --- Sistem layar (Explicit Full-Dimension & Scalable Cover) --- */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  min-height: 100%;
  max-width: 100vw;
  overflow: hidden;
  flex-direction: column;
  box-sizing: border-box;
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: scroll;
}
.screen:not(.active) {
  display: none !important;
}
.screen.active {
  display: flex;
  animation: masuk 0.35s ease;
}

/* --- Keyframes umum --- */
@keyframes masuk {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes ngambang {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}
@keyframes pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes goyang {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-8px);
  }
  75% {
    transform: translateX(8px);
  }
}
@keyframes naik {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-30px);
  }
}
@keyframes pulseGlow {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(245, 166, 35, 0.7);
  }
  50% {
    transform: scale(1.03);
    box-shadow: 0 0 0 10px rgba(245, 166, 35, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(245, 166, 35, 0);
  }
}
@keyframes floatDynamic {
  0% {
    transform: translateY(0) rotate(0deg);
  }
  25% {
    transform: translateY(-8px) rotate(1deg);
  }
  50% {
    transform: translateY(-12px) rotate(0deg);
  }
  75% {
    transform: translateY(-8px) rotate(-1deg);
  }
  100% {
    transform: translateY(0) rotate(0deg);
  }
}

/* --- Tombol --- */
.btn {
  font-family: var(--font-judul);
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  font-size: 2.5vmin;
  padding: 1.5vmin 3vmin;
  position: relative;
  overflow: hidden;
}
.btn:hover {
  transform: translateY(-4px) scale(1.02);
}
.btn:active {
  transform: translateY(4px) scale(0.95);
  box-shadow: 0 2px 0 rgba(91, 58, 30, 0.18);
}

.btn-primary {
  background: var(--emas);
  color: var(--coklat);
  box-shadow: var(--shadow);
  animation: pulseGlow 2.5s infinite;
}
.btn-primary:hover {
  filter: brightness(1.1);
  animation: none;
}

.btn-ghost {
  background: var(--putih);
  color: var(--coklat);
  box-shadow: var(--shadow);
}

.btn-big {
  font-size: 3.5vmin;
  padding: 2vmin 5vmin;
}
.btn-sm {
  font-size: 2vmin;
  padding: 1vmin 2vmin;
}

.btn-back {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: transform 0.12s ease;
  flex-shrink: 0;
}
.btn-back:hover {
  transform: translateY(-4px) scale(1.05);
}
.btn-back:active {
  transform: translateY(2px) scale(0.95);
}
.btn-back img {
  width: clamp(65px, 12vmin, 95px);
  height: auto;
  filter: drop-shadow(0 4px 0 rgba(91, 58, 30, 0.18));
}

/* --- Chip --- */
.chip {
  background: var(--putih);
  border-radius: 999px;
  padding: clamp(6px, 1.2vh, 10px) clamp(14px, 2.5vw, 22px);
  font-weight: 700;
  box-shadow: 0 3px 0 rgba(91, 58, 30, 0.12);
  font-size: clamp(1rem, 2.8vmin, 1.35rem);
  white-space: nowrap;
}

/* --- Topbar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(8px, 1.8vh, 16px) clamp(16px, 3.5vw, 32px);
  gap: 14px;
  position: relative;
  min-height: clamp(52px, 10vh, 70px);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar h2 {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-judul);
  font-weight: 800;
  font-size: clamp(1.4rem, 4.5vmin, 2.2rem);
  color: var(--putih);
  letter-spacing: 1px;
  text-shadow:
    -3px -3px 0 var(--merah-tua),
    3px -3px 0 var(--merah-tua),
    -3px 3px 0 var(--merah-tua),
    3px 3px 0 var(--merah-tua),
    -3px 0px 0 var(--merah-tua),
    3px 0px 0 var(--merah-tua),
    0px -3px 0 var(--merah-tua),
    0px 3px 0 var(--merah-tua),
    0px 5px 0 var(--merah-tua),
    0px 8px 10px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  pointer-events: none;
}

/* Tambahan efek ripple pada tombol saat diklik */
.ripple {
  position: absolute;
  border-radius: 50%;
  transform: scale(0);
  animation: rippleAnim 0.6s linear;
  background: rgba(255, 255, 255, 0.4);
  pointer-events: none;
}
@keyframes rippleAnim {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

.screen.has-bg,
.screen.bg-bahasa,
.screen.bg-budaya,
.screen.bg-agama,
.screen.bg-adab,
.screen.bg-boss-dark {
  background-size: cover !important;
  background-position: center center !important;
  background-repeat: no-repeat !important;
  background-attachment: scroll !important;
}

.screen.bg-bahasa {
  background-image: url("../assets/images/backgrounds/bg-bahasa.webp");
}
.screen.bg-budaya {
  background-image: url("../assets/images/backgrounds/bg-budaya.webp");
}
.screen.bg-agama {
  background-image: url("../assets/images/backgrounds/bg-agama.webp");
}
.screen.bg-adab {
  background-image: url("../assets/images/backgrounds/bg_adab.webp");
}

/* Final Boss Background */
.screen.bg-boss-dark {
  background-image: url("../assets/images/backgrounds/bg-agama.webp");
  position: relative;
}

.screen.bg-boss-dark::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6); /* Dark dramatic overlay */
  z-index: 1;
}
/* Ensure HUD stays above the dark overlay */
.screen.bg-boss-dark > header,
.screen.bg-boss-dark > main {
  position: relative;
  z-index: 2;
}

/* --- Custom Confirm Popup --- */
.confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  animation: masuk 0.3s ease;
}
.confirm-popup {
  background: var(--krem);
  padding: 30px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 400px;
  width: 90%;
}
.confirm-popup p {
  font-family: var(--font-judul);
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 25px;
  color: var(--coklat);
}
.confirm-actions {
  display: flex;
  justify-content: center;
  gap: 15px;
}
.confirm-actions button {
  min-width: 100px;
}

/* --- Portrait Blocker (Wajib Landscape di HP / Layar Portrait) --- */
#portrait-warning {
  display: none;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(33, 17, 7, 0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 99999999;
  color: var(--krem);
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 24px;
  pointer-events: all;
  touch-action: none;
}
.portrait-warning-content {
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: masuk 0.4s ease;
}
.portrait-warning-content h2 {
  font-family: var(--font-judul);
  font-size: clamp(22px, 6vw, 30px);
  color: var(--emas);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
  margin-bottom: 2px;
  line-height: 1.2;
}
.portrait-warning-content p {
  font-family: var(--font-isi);
  font-size: clamp(14px, 3.8vw, 17px);
  line-height: 1.5;
  opacity: 0.92;
  color: #fff2df;
}

/* Animasi Putar HP yang Halus & Elegan */
.rotate-icon {
  width: 68px;
  height: 110px;
  border: 4px solid var(--emas);
  border-radius: 16px;
  position: relative;
  margin-bottom: 16px;
  animation: rotatePhoneAnim 2.4s ease-in-out infinite;
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.5),
    inset 0 0 12px rgba(245, 166, 35, 0.2);
  background: rgba(0, 0, 0, 0.3);
}
.rotate-icon::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 4px;
  border-radius: 4px;
  background: var(--emas);
}
.rotate-icon::after {
  content: "";
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--emas);
}

@keyframes rotatePhoneAnim {
  0%,
  15% {
    transform: rotate(0deg) scale(1);
  }
  50%,
  75% {
    transform: rotate(-90deg) scale(1.08);
  }
  95%,
  100% {
    transform: rotate(0deg) scale(1);
  }
}

/* Portrait diblokir karena seluruh game menggunakan layout landscape. */
@media screen and (orientation: portrait) and (max-width: 1024px), screen and (max-aspect-ratio: 1/1) and (max-width: 1024px) {
  #portrait-warning {
    display: flex !important;
  }
}

/* Kondisi Landscape (HP / Desktop) */
@media screen and (orientation: landscape) and (min-aspect-ratio: 1/1), screen and (min-width: 1025px) {
  #portrait-warning {
    display: none !important;
  }
  .screen.active {
    pointer-events: auto !important;
    filter: none !important;
  }
  #btn-fullscreen {
    display: flex !important;
  }
}

/* =====================================================
   RESPONSIF BACKGROUND IMAGE (Landscape & Mobile)
   ===================================================== */
@media (max-height: 600px) and (orientation: landscape), (max-width: 900px) {
  .screen,
  .screen.has-bg,
  .screen.bg-bahasa,
  .screen.bg-budaya,
  .screen.bg-agama,
  .screen.bg-adab,
  .screen.bg-boss-dark {
    background-size: cover !important;
    background-position: center center !important;
    background-repeat: no-repeat !important;
    background-attachment: scroll !important;
  }
}
