/* ========================================
   DESAIN RESPONSIF
   Mobile-First, Ramah Sentuhan, Tipografi Cair
   ======================================== */

/* === TIPOGRAFI CAIR === */
html {
  /* Ukuran font dasar: 14px di HP, naik jadi 16px di desktop */
  font-size: clamp(14px, 1.5vw, 16px);
}

h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  line-height: var(--leading-tight);
}

h2 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  line-height: var(--leading-tight);
}

h3 {
  font-size: clamp(1.25rem, 2.5vw, 1.75rem);
  line-height: var(--leading-normal);
}

p {
  font-size: clamp(0.875rem, 1.5vw, 1rem);
  line-height: var(--leading-normal);
}

/* === GAYA DASAR MOBILE-FIRST === */

/* Kontainer - JANGAN timpa dashboard-container dari style.css */

/* Sidebar - JANGAN timpa, biarkan style.css yang atur */

/* Konten Utama - CUMA atur padding, jangan ubah flex */
.main-content {
  padding: var(--space-md);
}

/* Grid Game */
.grid-games {
  display: grid;
  grid-template-columns: 1fr; /* Satu kolom di HP */
  gap: var(--space-md);
}

/* Kartu Game */
.game-card {
  padding: var(--space-lg);
  min-height: 120px;
}

.game-icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-sm);
}

.game-title {
  font-size: var(--font-lg);
  margin-bottom: var(--space-xs);
}

.game-desc {
  font-size: var(--font-sm);
}

/* Tombol - Ramah Sentuhan */
button,
.btn,
.btn-menu,
.btn-play {
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--font-md);
  border-radius: var(--radius-md);
}

/* Header */
.main-header {
  padding: var(--space-sm);
  gap: var(--space-sm);
}

.logo-area {
  gap: var(--space-sm);
}

.portal-title {
  font-size: var(--font-sm);
}

.logo-img {
  width: 40px;
  height: 40px;
}

/* Wadah Chat */
#chat-container {
  width: 100%;
  max-width: 100%;
  height: 60vh;
  bottom: 0;
  right: 0;
  left: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

#chat-container.minimized {
  height: 50px;
}

/* === TABLET (640px+) === */
@media (min-width: 640px) {
  .grid-games {
    grid-template-columns: repeat(2, 1fr);
  }

  .game-icon {
    font-size: 3rem;
  }

  #chat-container {
    width: 400px;
    max-width: 400px;
    height: 500px;
    bottom: 20px;
    right: 20px;
    left: auto;
    border-radius: var(--radius-lg);
  }

  .main-header {
    padding: 10px 40px;
  }

  .logo-img {
    width: 60px;
    height: 60px;
  }

  .portal-title {
    font-size: 1.4rem;
  }
}

/* === TABLET LANDSCAPE / LAPTOP KECIL (768px+) === */
@media (min-width: 768px) {
  /* JANGAN timpa dashboard-container atau sidebar - CSS asli menangani dengan baik */

  .grid-games {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-lg);
  }
}

/* === LAPTOP (1024px+) === */
@media (min-width: 1024px) {
  .grid-games {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-xl);
  }

  .game-card {
    padding: var(--space-xl);
  }
}

/* === DESKTOP (1280px+) === */
@media (min-width: 1280px) {
  .main-content {
    max-width: 1400px;
    margin: 0 auto;
  }

  .grid-games {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* === DESKTOP BESAR (1536px+) === */
@media (min-width: 1536px) {
  .grid-games {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* === HP LANDSCAPE === */
@media (max-height: 600px) and (orientation: landscape) {
  /* Penyesuaian minimal aja */
  #chat-container {
    height: 80vh;
  }
}

/* === OPTIMISASI PERANGKAT SENTUH === */
@media (hover: none) and (pointer: coarse) {
  /* Perbesar target sentuh */
  button,
  .btn,
  a {
    min-height: 48px;
    padding: var(--space-md) var(--space-lg);
  }

  /* Hapus efek hover di layar sentuh */
  button:hover,
  .btn:hover,
  .game-card:hover {
    transform: none;
  }

  /* Tambah state aktif/tekan sebagai gantinya */
  button:active,
  .btn:active,
  .game-card:active {
    transform: scale(0.95);
    opacity: 0.8;
  }

  /* Area tap lebih besar untuk elemen kecil */
  .close-btn,
  .icon-btn {
    padding: var(--space-md);
  }
}

/* === GAYA CETAK (PRINT) === */
@media print {
  .sidebar,
  .main-header,
  #chat-container,
  .btn,
  button {
    display: none !important;
  }

  .main-content {
    width: 100%;
    padding: 0;
  }

  * {
    background: white !important;
    color: black !important;
  }
}

/* === LAYAR DPI TINGGI === */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Border dan bayangan lebih tajam */
  .game-card {
    border-width: 0.5px;
  }
}

/* === LEADERBOARD RESPONSIF === */
.leaderboard-table {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.leaderboard-table table {
  width: 100%;
  min-width: 600px;
}

@media (max-width: 767px) {
  .leaderboard-table table {
    font-size: var(--font-sm);
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: var(--space-xs) var(--space-sm);
  }

  /* Sembunyikan kolom kurang penting di HP */
  .leaderboard-table .hide-on-small {
    display: none;
  }
}

/* === MODAL RESPONSIF === */
.modal {
  width: 95vw;
  max-width: 500px;
  margin: auto;
  max-height: 90vh;
  overflow-y: auto;
}

@media (min-width: 768px) {
  .modal {
    width: 600px;
  }
}

/* === INPUT FORM RESPONSIF === */
input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  min-height: var(--touch-target-min);
  font-size: 16px; /* Mencegah zoom di iOS */
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
}

@media (min-width: 768px) {
  input[type="text"],
  input[type="password"],
  input[type="number"],
  select,
  textarea {
    font-size: var(--font-md);
  }
}

/* === SAFE AREA INSETS (buat HP berponi) === */
@supports (padding: env(safe-area-inset-top)) {
  .main-header {
    padding-top: max(var(--space-md), env(safe-area-inset-top));
  }

  .sidebar {
    padding-left: max(var(--space-md), env(safe-area-inset-left));
  }

  #chat-container {
    bottom: max(20px, env(safe-area-inset-bottom));
    right: max(20px, env(safe-area-inset-right));
  }
}

/* === UTILITAS GRID === */
.grid-auto-fit {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: var(--space-lg);
}

.grid-auto-fill {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: var(--space-lg);
}

/* === UTILITAS FLEX === */
.flex-responsive {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

@media (min-width: 768px) {
  .flex-responsive {
    flex-direction: row;
  }
}

/* === RASIO ASPEK (untuk gambar/video) === */
.aspect-16-9 {
  aspect-ratio: 16 / 9;
  overflow: hidden;
}

.aspect-4-3 {
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.aspect-square {
  aspect-ratio: 1;
  overflow: hidden;
}

/* === STYLE SCROLLBAR === */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 242, 255, 0.3);
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 242, 255, 0.5);
}

/* Buat Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 242, 255, 0.3) rgba(255, 255, 255, 0.05);
}

/* ============================================
   UNIVERSAL GAME CANVAS CENTERING
   Untuk semua game berbasis Phaser/Canvas
   ============================================ */

/* Game Canvas Wrapper - Universal Centering */
.game-canvas-wrapper,
#game-container,
#game-container-p1,
#game-container-p2 {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: calc(100vh - 120px); /* Space untuk header/HUD */
  padding: 20px;
}

.game-canvas-wrapper canvas,
#game-container canvas,
#game-container-p1 canvas,
#game-container-p2 canvas {
  max-width: 100%;
  max-height: calc(100vh - 140px);
  object-fit: contain;
  border-radius: 15px;
  box-shadow: 0 0 50px rgba(0, 242, 255, 0.2);
}

/* Mobile Optimization */
@media (max-width: 768px) {
  .game-canvas-wrapper,
  #game-container,
  #game-container-p1,
  #game-container-p2 {
    min-height: calc(100vh - 80px);
    padding: 10px;
  }

  .game-canvas-wrapper canvas,
  #game-container canvas,
  #game-container-p1 canvas,
  #game-container-p2 canvas {
    max-height: calc(100vh - 100px);
    border-radius: 10px;
  }
}

/* Portrait Mode - Extra tight layout */
@media (max-width: 480px) and (orientation: portrait) {
  .game-canvas-wrapper,
  #game-container,
  #game-container-p1,
  #game-container-p2 {
    padding: 5px;
    min-height: calc(100vh - 60px);
  }

  .game-canvas-wrapper canvas,
  #game-container canvas,
  #game-container-p1 canvas,
  #game-container-p2 canvas {
    max-height: calc(100vh - 80px);
  }
}

/* ============================================
   UNIVERSAL GAME OVER BUTTONS FIX
   Applies to all game modals - Phase 3 Implementation
   ============================================ */

/* Button containers */
.modal-buttons,
.action-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
  max-width: 400px;
  margin: 15px auto 0;
}

/* All game over buttons - Touch-friendly sizing */
.btn-restart,
.btn-retry,
.btn-home,
.btn-action.btn-retry,
.btn-action.btn-home,
button[onclick*="reload"],
button[onclick*="location.href"] {
  min-width: 140px;
  min-height: 48px; /* WCAG touch target minimum */
  padding: 12px 24px;
  margin: 5px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

/* Mobile: Stack buttons vertically untuk eliminate overlap */
@media (max-width: 480px) {
  .modal-buttons,
  .action-buttons {
    flex-direction: column;
    gap: 12px;
    align-items: center;
  }

  .btn-restart,
  .btn-retry,
  .btn-home,
  .btn-action.btn-retry,
  .btn-action.btn-home,
  button[onclick*="reload"],
  button[onclick*="location.href"] {
    width: 100%; /* Full width di mobile */
    max-width: 280px; /* Limit untuk readability */
    margin: 0; /* Remove individual margins */
    min-height: 50px; /* Slightly larger untuk easy tapping */
  }
}

/* Tablet: Side by side dengan good spacing */
@media (min-width: 481px) and (max-width: 768px) {
  .btn-restart,
  .btn-retry,
  .btn-home {
    flex: 1 1 45%; /* Each button takes roughly half */
    max-width: 180px;
  }
}
