/* ===============================
   MODAL COMPONENT
   Game modal overlay + panel
   =============================== */

/* ── Overlay ── */
.game-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none; /* Changed from display:flex + hidden attribute */
  align-items: center;
  justify-content: center;
  padding: var(--spacing-md);
  background: rgba(61, 40, 18, 0.88); /* Brand color dark overlay */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.game-modal--visible {
  display: flex;
  opacity: 1;
  pointer-events: auto; /* Fix: correctly allows clicks */
}

.game-modal[hidden] {
  display: none;
}

/* ── Panel ── */
.game-modal__panel {
  position: relative;
  width: min(1140px, 95vw);
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  background: var(--color-background);
  border-radius: 20px;
  box-shadow: 0 32px 80px rgba(61,40,18,0.40), 0 8px 24px rgba(61,40,18,0.18);
  overflow: hidden;
  transform: scale(0.94) translateY(28px);
  transition: transform 380ms var(--ease-out-expo), opacity 300ms ease;
}

.game-modal--visible .game-modal__panel {
  transform: scale(1) translateY(0);
}

/* ── Header ── */
.game-modal__header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-md) var(--spacing-lg);
  background: var(--gradient-accent);
  color: var(--color-text-inverse);
  flex-shrink: 0;
  border-bottom: 2px solid rgba(255,255,255,0.12);
  min-height: 64px;
}

.game-modal__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  margin: 0;
  line-height: var(--line-height-tight);
  text-align: center;
  width: 100%;
}

.game-modal__close {
  position: absolute;
  right: var(--spacing-lg);
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10;
}

/* Premium CSS Icon for Close Button */
.game-modal__close::before,
.game-modal__close::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 3px;
  background-color: #fff;
  border-radius: 2px;
  transition: transform 0.3s ease, background-color 0.3s ease;
}

.game-modal__close::before { transform: translate(-50%, -50%) rotate(45deg); }
.game-modal__close::after { transform: translate(-50%, -50%) rotate(-45deg); }

.game-modal__close:hover {
  background: rgba(255, 255, 255, 0.3);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  transform: translateY(-50%) rotate(180deg) scale(1.15);
}

.game-modal__close:hover::before,
.game-modal__close:hover::after {
  background-color: #fff;
}

.game-modal__close:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.9);
  outline-offset: 2px;
}

/* ── Body (scrollable only when needed) ── */
.game-modal__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-xl) var(--spacing-2xl);
  scroll-behavior: smooth;
}

.game-modal__body::-webkit-scrollbar {
  width: 5px;
}

.game-modal__body::-webkit-scrollbar-track {
  background: transparent;
}

.game-modal__body::-webkit-scrollbar-thumb {
  background: var(--color-primary-lighter);
  border-radius: var(--radius-full);
}

/* ── Mobile (≤ 640px) ── */
@media (max-width: 640px) {
  .game-modal {
    padding: 0;
    align-items: flex-end;
  }

  .game-modal__panel {
    max-width: 100%;
    max-height: 96vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(48px) scale(0.98);
  }

  .game-modal--visible .game-modal__panel {
    transform: translateY(0) scale(1);
  }

  .game-modal__header {
    position: relative;
    display: flex;
    flex-direction: column; /* Stack if absolutely needed, but for now just height */
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md) 3.5rem; /* Large horizontal padding to avoid the X button */
    min-height: 72px; /* Increased to fit 2-3 lines comfortably */
    text-align: center;
  }

  .game-modal__title {
    font-size: 1.15rem; /* Slightly larger, better hierarchy */
    font-weight: var(--font-weight-bold);
    text-align: center;
    width: 100%;
    margin: 0;
    line-height: 1.25; /* Thinner line height for wrapped titles */
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Limit to 2 lines if possible, but auto-grow is better */
    -webkit-box-orient: vertical;
    overflow: hidden; /* Fallback for very long titles */
    text-overflow: ellipsis;
  }

  .game-modal__close {
    position: absolute;
    right: 0.75rem; /* Better breathing room from the edge */
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.25); /* More visible on mobile */
  }

  .game-modal__close::before,
  .game-modal__close::after {
    width: 14px;
  }

  .game-modal__body {
    padding: var(--spacing-lg);
  }
}

/* ── Tablet (641px – 900px) ── */
@media (min-width: 641px) and (max-width: 900px) {
  .game-modal__panel {
    width: min(740px, 90vw);
    max-height: 92vh;
  }

  .game-modal__body {
    padding: var(--spacing-xl);
  }
}
