/* Enhanced iPhone-specific Khmer font fixes for Unicode rendering */

/* System font declarations for Khmer on iOS */
@font-face {
  font-family: 'KhmerSystemFont';
  src: local('Khmer OS System'), local('Khmer UI'), local('Battambang');
  font-weight: 100 900;
  font-style: normal;
  font-display: block;
  unicode-range: U+1780-17FF, U+19E0-19FF, U+200C-200D, U+25CC;
}

/* Target all iOS devices with high-DPI screens */
@media screen and (-webkit-min-device-pixel-ratio: 2) {
  /* Global iOS text rendering fixes */
  * {
    -webkit-text-size-adjust: none !important;
    text-size-adjust: none !important;
    -webkit-font-smoothing: subpixel-antialiased !important;
    -moz-osx-font-smoothing: auto !important;
  }

  /* Khmer-specific font overrides for iOS */
  .khmer-font,
  .universal-font,
  .mixed-content,
  .iphone-khmer-font,
  [lang="km"],
  .km {
    font-family: 'KhmerSystemFont', 'Khmer OS System', 'Khmer UI', 'Battambang', -apple-system, system-ui !important;
    font-weight: 400 !important;
    font-style: normal !important;
    font-synthesis: none !important;
    -webkit-font-synthesis: none !important;
    font-variant-ligatures: none !important;
    -webkit-font-variant-ligatures: none !important;
    font-feature-settings: normal !important;
    -webkit-font-feature-settings: normal !important;
    text-rendering: geometricPrecision !important;
    -webkit-font-smoothing: subpixel-antialiased !important;
    -moz-osx-font-smoothing: auto !important;
    letter-spacing: 0.5px !important;
    word-spacing: 0.2em !important;
    line-height: 1.8 !important;
    transform: translate3d(0, 0, 0) !important;
    -webkit-transform: translate3d(0, 0, 0) !important;
    will-change: transform !important;
    isolation: isolate !important;
    unicode-bidi: plaintext !important;
    direction: ltr !important;
  }

  /* Enhanced spacing for readability on iOS */
  .ios-khmer-fix {
    -webkit-backface-visibility: hidden !important;
    backface-visibility: hidden !important;
    perspective: 1000px !important;
    -webkit-perspective: 1000px !important;
  }

  /* Specific text element targeting */
  h1, h2, h3, h4, h5, h6, p, span, div, a, button, input, textarea, label {
    font-family: 'KhmerSystemFont', 'Khmer OS System', 'Khmer UI', 'Battambang', -apple-system !important;
  }

  /* Disable problematic web fonts on iOS */
  @font-face {
    font-family: "Noto Sans Khmer";
    src: local('KhmerSystemFont'), local('Khmer OS System'), local('Khmer UI'), local('Battambang');
    font-display: block;
  }

  @font-face {
    font-family: "Kantumruy Pro";
    src: local('KhmerSystemFont'), local('Khmer OS System'), local('Khmer UI'), local('Battambang');
    font-display: block;
  }
}

/* iPhone specific (not iPad) - smaller screens */
@media screen and (-webkit-min-device-pixel-ratio: 2) and (max-device-width: 480px) {
  .khmer-font,
  .universal-font,
  .mixed-content,
  .iphone-khmer-font {
    font-size: 16px !important;
    line-height: 1.9 !important;
    letter-spacing: 0.8px !important;
    word-spacing: 0.3em !important;
  }
}

/* iPhone X and newer (larger screens) */
@media screen and (-webkit-min-device-pixel-ratio: 3) and (min-device-width: 375px) {
  .khmer-font,
  .universal-font,
  .mixed-content,
  .iphone-khmer-font {
    font-size: 17px !important;
    line-height: 2.0 !important;
    letter-spacing: 0.6px !important;
    word-spacing: 0.25em !important;
  }
}

/* iPad targeting */
@media screen and (-webkit-min-device-pixel-ratio: 2) and (min-device-width: 768px) {
  .khmer-font,
  .universal-font,
  .mixed-content,
  .iphone-khmer-font {
    font-size: 18px !important;
    line-height: 1.8 !important;
    letter-spacing: 0.4px !important;
    word-spacing: 0.2em !important;
  }
}
