/* ==================== BASE STYLES ==================== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  font-family: "Segoe UI", sans-serif;
  background: url("../bg_forest.jpg") no-repeat center center fixed;
  background-size: cover;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Prevent text selection on game elements */
.cell, .player, #dice, #rollBtn, .control-btn {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Prevent double-tap zoom on buttons */
button, .swal-option-btn, .control-btn {
  touch-action: manipulation;
}

/* Better focus indicators for accessibility */
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid #1976d2;
  outline-offset: 2px;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Loading indicator */
.loading {
  opacity: 0.7;
  pointer-events: none;
}

/* Ensure proper stacking context */
#lobby-screen {
  isolation: isolate;
}

#game-container {
  isolation: isolate;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  body {
    color-scheme: light;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .cell, .player, #dice {
    transition: none !important;
    animation: none !important;
  }
}

/* Print styles */
@media print {
  #game-container {
    display: none;
  }
  
  #lobby-screen {
    display: block;
    background: white;
  }
}

/* Optimize scrolling on mobile */
.swal2-html-container,
.lobby-container {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Ensure smooth scrolling on popups */
.swal2-popup {
  scroll-behavior: smooth;
}

.reading-text {
  scroll-behavior: smooth;
}

/* Better touch response */
@media (hover: none) and (pointer: coarse) {
  button:active {
    transform: scale(0.95);
  }
  
  .swal-option-btn:active {
    transform: scale(0.95);
  }
}

/* Better button states for mobile */
@media (hover: none) {
  button:hover {
    transform: none;
  }
  
  button:active {
    transform: scale(0.95);
    transition: transform 0.1s;
  }
}

/* Ensure proper layer ordering */
.swal2-container {
  z-index: 10000 !important;
}

#orientationWarning {
  z-index: 99999 !important;
}

/* Final mobile optimizations */
@media (max-width: 768px) {
  * {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  }
  
  button, .swal-option-btn {
    -webkit-tap-highlight-color: rgba(33, 150, 243, 0.3);
  }
}

/* Fix for Samsung Internet browser */
@supports (-webkit-appearance: none) {
  select.difficulty-select {
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
  }
}

/* Fallback for older browsers */
@supports not (gap: 10px) {
  .answer-row {
    display: flex;
    flex-wrap: wrap;
  }
  
  .swal-option-btn {
    margin: 5px;
  }
}

#board, .cell, .player {
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  will-change: transform;
}

/* Mobile viewport height fix */
@supports (-webkit-touch-callout: none) {
  body {
    height: -webkit-fill-available;
  }
}

/* Safe area padding for notched devices */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
}