:root {
  --ui-space-1: 8px;
  --ui-space-2: 12px;
  --ui-space-3: 16px;
  --ui-space-4: 20px;
  --ui-space-5: 24px;
  --ui-popup-max-width: 520px;
  --ui-popup-max-height: calc((var(--vh, 1vh) * 100) - 120px);
  --ui-touch-target: 44px;
}

body.game-ux .ux-back-button,
body.game-ux .back-btn,
body.game-ux .back-button,
body.game-ux #backButton {
  min-height: var(--ui-touch-target) !important;
  min-width: var(--ui-touch-target) !important;
  z-index: 10020 !important;
}

body.game-ux .dashboard-btn,
body.game-ux .gallery-btn {
  border: 0;
  border-radius: 10px;
  color: #fff;
  font-weight: 700;
  padding: 12px 18px;
  min-height: var(--ui-touch-target) !important;
  cursor: pointer;
}

body.game-ux .dashboard-btn {
  background: linear-gradient(45deg, #27ae60, #2ecc71);
}

body.game-ux .gallery-btn {
  background: linear-gradient(45deg, #f39c12, #e67e22);
}

body.game-ux .ux-back-button {
  position: fixed;
  top: calc(var(--safe-top, 0px) + 88px);
  left: 12px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(45deg, #667eea, #764ba2);
  color: #fff;
  font-weight: bold;
  padding: 10px 16px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

body.game-ux .gnb {
  transition: transform 0.22s ease, opacity 0.22s ease !important;
}

body.game-ux.is-playing {
  padding-top: 0 !important;
}

body.game-ux.is-playing .gnb {
  transform: translateY(-120%) !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.game-ux.is-playing .ux-back-button,
body.game-ux.is-playing .back-btn,
body.game-ux.is-playing .back-button,
body.game-ux.is-playing #backButton {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transform: translateY(-8px) !important;
}

body.game-ux.is-overlay .ux-back-button,
body.game-ux.is-overlay .back-btn,
body.game-ux.is-overlay .back-button,
body.game-ux.is-overlay #backButton {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

@media (max-width: 767px) {
  .game-start,
  .game-over,
  .game-over-popup,
  #startScreen,
  #gameOver,
  #stageSummary,
  #gameStartPopup,
  #gameOverPopup {
    max-height: var(--ui-popup-max-height) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    width: min(100%, calc(100dvw - 16px)) !important;
    max-width: var(--ui-popup-max-width) !important;
  }

  .start-btn,
  .login-btn,
  .play-btn,
  .restart-btn,
  .game-over-btn,
  .popup-button,
  #continueBtn,
  .filter-btn,
  .feedback-form button {
    min-height: var(--ui-touch-target) !important;
    font-size: 14px !important;
  }

  .popup-content,
  .feedback-form {
    gap: var(--ui-space-2);
  }

  .popup-content li,
  .feedback-form label {
    line-height: 1.4;
  }
}

@media (max-width: 430px) {
  :root {
    --ui-popup-max-width: calc(100dvw - 12px);
  }
}

/* 
 * Standardized Game Layout 
 * 1. Mobile First: The layout wraps the entire screen. Ad panels are hidden.
 * 2. Desktop: Flex layout with ad-panels on the left and right. Content area is fixed strictly.
 */

.game-layout-wrapper {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important; /* CENTER vertically for desktop */
  width: 100vw !important;
  height: 100vh !important;
  height: calc(var(--vh, 1vh) * 100) !important;
  background-color: #202020 !important; /* Desktop site background */
  overflow: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  z-index: 1000 !important;
}

.game-ad-panel {
  display: none !important; /* hidden on mobile */
  flex: 1 !important;
  height: 100% !important; /* ensure ad panels stretch top-to-bottom */
  background-color: #1a1a1a !important;
  color: #666;
  text-align: center;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

.game-ad-panel.left-ad {
  border-right: 1px solid #333;
}

.game-ad-panel.right-ad {
  border-left: 1px solid #333;
}

.game-content-area {
  flex: 0 0 100% !important;
  max-width: 100% !important;
  position: relative !important;
  height: 100% !important;
  overflow-y: auto !important; /* allow scrolling game contents if needed */
  overflow-x: hidden !important;
  /* background-color: #000; REMOVED so body styles inside can function if any, or game styles apply */
}

/* On larger screens, the content area takes finite max-width and ad panels appear */
@media (min-width: 768px) {
  .game-ad-panel {
    display: flex !important;
  }

  .game-content-area {
    flex: 0 0 var(--content-max, 430px) !important;
    max-width: var(--content-max, 430px) !important;
    
    /* Fixed phone-like height */
    height: 932px !important;
    max-height: 100% !important;

    /* Add a slight border radius to feel like a mobile screen */
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(0,0,0,0.8) !important;
    
    /* Hide scrollbars for neatness but keep functionality if needed */
    scrollbar-width: none;
  }
  .game-content-area::-webkit-scrollbar {
    display: none;
  }
}

