/* --- STYLE.CSS FINAL V7 (ANTI WHITE SCREEN) --- */

/* Pastikan HTML dan Body penuh */
html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  background-color: #0f172a; /* Warna dasar paling bawah */
}

body {
  font-family: "Fredoka", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  transition: background 0.5s ease;

  /* Padding safe area untuk HP berponi */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ANIMASI GLOBAL BACKGROUND */
@keyframes moveGradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* --- DAFTAR TEMA (DIPERKUAT DENGAN !IMPORTANT) --- */

/* 1. TEMA OCEAN */
body.theme-ocean {
  background-color: #38bdf8 !important;
  background: linear-gradient(-45deg, #38bdf8, #7dd3fc, #0ea5e9) !important;
  background-size: 400% 400% !important;
  animation: moveGradient 15s ease infinite;
  color: #0f172a;
}
.theme-ocean #start-screen {
  background: linear-gradient(180deg, #0284c7, #38bdf8);
}

/* 2. TEMA SAKURA */
body.theme-sakura {
  background-color: #fce7f3 !important;
  background-image: radial-gradient(#f472b6 15%, transparent 16%),
    radial-gradient(#f472b6 15%, transparent 16%) !important;
  background-size: 60px 60px !important;
  background-position: 0 0, 30px 30px !important;
  color: #9d174d;
}
.theme-sakura #start-screen {
  background: linear-gradient(135deg, #fbcfe8, #be185d);
}

/* 3. TEMA CYBERPUNK */
body.theme-cyberpunk {
  background-color: #050505 !important;
  background-image: linear-gradient(rgba(6, 182, 212, 0.2) 1px, transparent 1px),
    linear-gradient(90deg, rgba(6, 182, 212, 0.2) 1px, transparent 1px) !important;
  background-size: 40px 40px !important;
  color: #e2e8f0;
}
.theme-cyberpunk #start-screen {
  background: linear-gradient(135deg, #312e81, #db2777);
}

/* 4. TEMA GALAXY */
body.theme-galaxy {
  background-color: #020617 !important;
  background-image: radial-gradient(white 1px, transparent 1px),
    radial-gradient(white 1px, transparent 1px),
    radial-gradient(ellipse at bottom, #1e293b 0%, #020617 100%) !important;
  background-size: 50px 50px, 50px 50px, 100% 100% !important;
  background-position: 0 0, 25px 25px, center !important;
  color: #f8fafc;
}
.theme-galaxy #start-screen {
  background: linear-gradient(to bottom, #0f172a, #4338ca);
}

/* 5. TEMA FOREST */
body.theme-forest {
  background-color: #86efac !important;
  background: linear-gradient(120deg, #86efac 0%, #bbf7d0 100%) !important;
  color: #14532d;
}
.theme-forest #start-screen {
  background: linear-gradient(135deg, #15803d, #4ade80);
}

/* 6. TEMA CANDY */
body.theme-candy {
  background-color: #fef3c7 !important;
  background: repeating-linear-gradient(
    45deg,
    #fef3c7,
    #fef3c7 10px,
    #fde68a 10px,
    #fde68a 20px
  ) !important;
  color: #92400e;
}
.theme-candy #start-screen {
  background: linear-gradient(to right, #fbbf24, #f472b6);
}

/* 7. TEMA ROYAL */
body.theme-royal {
  background-color: #1c1917 !important;
  background: linear-gradient(to right, #1c1917, #292524) !important;
  color: #fef3c7;
}
.theme-royal #start-screen {
  background: linear-gradient(45deg, #78350f, #d97706);
}

/* 8. TEMA RETRO */
body.theme-retro {
  background-color: #2e022d !important;
  background-image: linear-gradient(#db2777 1px, transparent 1px),
    linear-gradient(90deg, #db2777 1px, transparent 1px) !important;
  background-size: 50px 50px !important;
  background-position: center bottom !important;
  color: #fbcfe8;
}
.theme-retro #start-screen {
  background: linear-gradient(to top, #be185d, #6b21a8);
}

/* 9. TEMA MATRIX */
body.theme-matrix {
  background-color: #000 !important;
  background-image: linear-gradient(
      0deg,
      transparent 24%,
      rgba(34, 197, 94, 0.4) 25%,
      rgba(34, 197, 94, 0.4) 26%,
      transparent 27%,
      transparent 74%,
      rgba(34, 197, 94, 0.4) 75%,
      rgba(34, 197, 94, 0.4) 76%,
      transparent 77%,
      transparent
    ),
    linear-gradient(
      90deg,
      transparent 24%,
      rgba(34, 197, 94, 0.4) 25%,
      rgba(34, 197, 94, 0.4) 26%,
      transparent 27%,
      transparent 74%,
      rgba(34, 197, 94, 0.4) 75%,
      rgba(34, 197, 94, 0.4) 76%,
      transparent 77%,
      transparent
    ) !important;
  background-size: 50px 50px !important;
  color: #4ade80;
}
.theme-matrix #start-screen {
  background: #000;
  border: 2px solid #22c55e;
}

/* 10. TEMA SUNSET */
body.theme-sunset {
  background-color: #fdba74 !important;
  background: linear-gradient(to bottom, #fdba74, #fca5a5) !important;
  animation: moveGradient 10s ease infinite;
  background-size: 200% 200% !important;
  color: #881337;
}
.theme-sunset #start-screen {
  background: linear-gradient(to bottom right, #ea580c, #db2777);
}

/* UTILS */
.tile-transition {
  transition-property: transform, filter, top, left, opacity;
  transition-duration: 300ms;
  transition-timing-function: cubic-bezier(0, 0, 0.2, 1);
}
@keyframes popIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  80% {
    transform: scale(1.1);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
.animate-pop {
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes float {
  0%,
  100% {
    transform: translateY(0px) rotate(0deg);
  }
  50% {
    transform: translateY(-15px) rotate(2deg);
  }
}
.animate-float {
  animation: float 4s ease-in-out infinite;
}
.scrollbar-hide::-webkit-scrollbar {
  display: none;
}
.scrollbar-hide {
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.modal-box {
  max-width: calc(100% - 40px);
  width: 320px;
}

/* FIX POSISI TRAY & BOARD */
#tray-container-wrapper {
  position: absolute;
  top: 80px;
  left: 0;
  width: 100vw;
  display: flex;
  justify-content: center !important;
  align-items: center;
  z-index: 30;
  pointer-events: none;
  transition: top 0.3s ease;
}
#tray-scaler {
  transform-origin: top center;
  pointer-events: auto;
  margin: 0 auto !important;
  display: flex;
  justify-content: center;
}
#board-container {
  z-index: 10;
  pointer-events: auto;
  transition: margin-top 0.3s ease, transform 0.3s ease;
  will-change: transform, margin-top;
}
#tray-content {
  display: flex;
  justify-content: center !important;
  align-items: center;
  margin: 0 auto;
}

/* LANDSCAPE RESPONSIVE */
@media only screen and (min-width: 480px) and (max-height: 500px) {
  #start-screen {
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 40px !important;
    gap: 20px !important;
  }
  #start-screen > .animate-float {
    margin: 0 !important;
    margin-top: 40px !important;
    flex: 1;
    display: flex;
    justify-content: flex-end;
    transform: scale(0.8);
    position: relative;
  }
  #start-screen > .animate-float > div:first-child {
    top: -5px !important;
    left: -5px !important;
    transform: rotate(-12deg) scale(0.8) !important;
  }
  #start-screen > div:nth-child(2) {
    position: absolute !important;
    top: 10px !important;
    right: 15px !important;
    left: auto !important;
    bottom: auto !important;
    margin: 0 !important;
    width: auto !important;
    z-index: 50;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
    transform: scale(0.7);
    transform-origin: top right;
    background: rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(4px);
    border-radius: 10px;
    padding: 4px 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }
  #start-screen > div:nth-child(2) .text-left {
    text-align: right !important;
    order: 1;
  }
  #start-screen > div:nth-child(2) .text-right {
    order: 2;
    margin-left: 0 !important;
  }
  #start-screen > .w-full.max-w-xs {
    flex: 1;
    margin: 0 !important;
    margin-top: 40px !important;
    padding-bottom: 0 !important;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    transform: scale(0.85);
    max-width: 280px !important;
  }
  #start-screen button {
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
    font-size: 0.9rem;
  }
  #start-screen > div:nth-child(2) p.text-xs {
    font-size: 0.7rem;
    margin-bottom: 0;
  }
  #start-screen > div:nth-child(2) p.text-2xl {
    font-size: 1.25rem;
    line-height: 1.2;
  }
  #start-screen > p.mt-auto {
    position: absolute !important;
    bottom: 8px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    right: auto !important;
    margin: 0 !important;
    width: auto !important;
    z-index: 50;
    font-size: 9px;
    text-align: center;
    white-space: nowrap;
    opacity: 0.7;
  }
  #settings-modal .modal-box {
    width: 480px !important;
    max-height: 90vh;
    padding: 1rem !important;
  }
  #settings-modal .space-y-3 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }
  #settings-modal .space-y-3 > button:last-child,
  #settings-modal .space-y-3 > div:nth-child(2) {
    grid-column: span 2;
  }
  #tray-container-wrapper {
    top: 85px !important;
  }
  #game-header {
    height: 35px !important;
  }
  #game-header > div {
    padding: 2px 10px !important;
  }
  #game-footer {
    display: none !important;
  }
}

/* --- TAMBAHAN DI STYLE.CSS --- */

/* Pastikan Start Screen bisa di-scroll jika konten terlalu panjang di HP kecil */
#start-screen {
  overflow-y: auto;
  /* Fallback color biar tidak putih */
  background-color: #0f172a;
}

/* Kunci elemen agar tidak terpotong di mode potret ekstrem */
#start-screen .max-w-xs {
  width: 100%;
  max-width: 320px; /* Batasi lebar agar rapi */
}
