/* ==========================================================================
   compat.css — Cross-Browser Compatibility & Normalization
   Import this BEFORE index.css
   ========================================================================== */


/* ==========================================================================
   1. Modern CSS Reset
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
}

p, h1, h2, h3 {
  overflow-wrap: break-word;
}

ul, ol {
  list-style: none;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}


/* ==========================================================================
   2. Font Loading
   ========================================================================== */

/* @font-face declarations with font-display: swap ensure text remains
   visible while custom fonts are loading (FOUT over FOIT). Add any
   custom @font-face rules here with font-display: swap. */


/* ==========================================================================
   3. Dynamic Viewport Height
   ========================================================================== */

:root {
  --vh: 1vh;              /* Updated by JS for mobile address-bar handling */
  --app-height: 100vh;
  --app-height: 100dvh;   /* Modern browsers: uses dynamic viewport height */
}


/* ==========================================================================
   4. Vendor Prefixes for Common Properties
   ========================================================================== */

.backdrop-blur {
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.user-select-none {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

.gradient-text {
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}


/* ==========================================================================
   5. Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


/* ==========================================================================
   6. High Contrast
   ========================================================================== */

@media (prefers-contrast: high) {
  :root {
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --border-card: rgba(255, 255, 255, 0.3);
  }
}


/* ==========================================================================
   7. Touch Device Optimizations
   ========================================================================== */

@media (hover: none) and (pointer: coarse) {
  /* Minimum 44px tap targets (WCAG 2.5.5) */
  .btn {
    min-height: 44px;
  }

  .square {
    min-width: 44px;
    min-height: 44px;
  }

  /* Remove hover effects that don't work on touch */
  .square:hover .piece {
    transform: none;
  }

  .panel:hover {
    background: var(--bg-card);
  }
}


/* ==========================================================================
   8. Mobile Safari Fixes
   ========================================================================== */

/* Fix 100vh issue on iOS Safari */
@supports (-webkit-touch-callout: none) {
  body {
    min-height: -webkit-fill-available;
  }
}

/* Prevent tap highlight on all elements */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Momentum scrolling for scrollable containers */
.scrollable {
  -webkit-overflow-scrolling: touch;
}


/* ==========================================================================
   9. Print Styles
   ========================================================================== */

@media print {
  body {
    background: white !important;
    color: black !important;
  }

  #starfield,
  .aurora,
  .nebula,
  .grid-overlay,
  .scanlines,
  .top-bar,
  .particle,
  #loading-screen,
  nav,
  footer {
    display: none !important;
  }

  .panel {
    background: white !important;
    border: 1px solid #ccc !important;
    backdrop-filter: none !important;
  }

  .square.light {
    background: #f0f0f0 !important;
  }

  .square.dark {
    background: #b0b0b0 !important;
  }

  .piece {
    color: black !important;
    text-shadow: none !important;
    filter: none !important;
  }

  #chessboard {
    box-shadow: none !important;
    border: 2px solid #333 !important;
  }

  .btn {
    display: none !important;
  }
}


/* ==========================================================================
   10. Focus Visible
   ========================================================================== */

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid #00d4ff;
  outline-offset: 2px;
  border-radius: 4px;
}

button:focus-visible,
.btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.4);
}


/* ==========================================================================
   11. Safe Area (Notched Phones)
   ========================================================================== */

@supports (padding: env(safe-area-inset-top)) {
  body {
    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);
  }
}


/* ==========================================================================
   12. Cross-Browser Scrollbar
   ========================================================================== */

/* WebKit (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 212, 255, 0.2);
  border-radius: 3px;
}

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

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 212, 255, 0.2) rgba(0, 0, 0, 0.2);
}


/* ==========================================================================
   13. Chess Piece Font Stack
   ========================================================================== */

.piece {
  font-family: 'Segoe UI Symbol', 'Noto Sans Symbols2', 'Apple Color Emoji', 'Segoe UI Emoji', sans-serif;
  font-variant-emoji: text;
}


/* ==========================================================================
   14. Selection Styling
   ========================================================================== */

::selection {
  background: rgba(0, 212, 255, 0.3);
  color: #fff;
}

::-moz-selection {
  background: rgba(0, 212, 255, 0.3);
  color: #fff;
}


/* ==========================================================================
   15. Utility Classes
   ========================================================================== */

.sr-only,
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.no-scroll {
  overflow: hidden !important;
}
