/* TeleWorld AI - Browser Compatibility & Web Standards CSS */
/* Ensures compatibility with all major browsers and devices worldwide */

/* CSS Reset and Normalization for Cross-Browser Consistency */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  /* Prevent iOS text size adjust after orientation change */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;

  /* Smooth scrolling */
  scroll-behavior: smooth;

  /* Font rendering optimization */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;

  /* Base font size for consistent rem calculations */
  font-size: 16px;
  line-height: 1.6;
}

body {
  /* Cross-browser font stack */
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
    "Segoe UI Symbol", "Noto Color Emoji";

  /* Prevent horizontal scroll on mobile */
  overflow-x: hidden;

  /* Improve text rendering */
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  /* Consistent line height */
  line-height: 1.6;

  /* Default colors */
  color: #ffffff;
  background-color: #0f172a;

  /* Remove default margins */
  margin: 0;
  padding: 0;
}

/* Typography Enhancements for All Browsers */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 1rem;
  margin-top: 0;

  /* Prevent text overflow */
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  -webkit-hyphens: auto;
}

/* Responsive Typography */
h1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  background: linear-gradient(135deg, #ffffff 0%, #a855f7 50%, #06b6d4 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;

  /* Fallback for browsers that don't support background-clip */
  color: #ffffff;
}

h2 {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  color: #ffffff;
}

h3 {
  font-size: clamp(1.25rem, 3vw, 2rem);
  color: #94a3b8;
}

h4 {
  font-size: clamp(1.125rem, 2.5vw, 1.5rem);
  color: #e2e8f0;
}

h5 {
  font-size: clamp(1rem, 2vw, 1.25rem);
  color: #e2e8f0;
}

h6 {
  font-size: clamp(0.875rem, 1.5vw, 1rem);
  color: #94a3b8;
}

p {
  margin-bottom: 1.5rem;
  margin-top: 0;
  color: #94a3b8;
  font-size: clamp(1rem, 1.5vw, 1.1rem);
  line-height: 1.7;

  /* Improve text readability */
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Link Styles with Enhanced Accessibility */
a {
  color: #8b5cf6;
  text-decoration: none;
  transition: all 0.3s ease;
}

a:hover,
a:focus {
  color: #a855f7;
  outline: 2px solid #8b5cf6;
  outline-offset: 2px;
}

a:active {
  color: #7c3aed;
}

/* Button Styles for Consistency */
button,
input[type="button"],
input[type="submit"],
input[type="reset"],
.btn {
  /* Cross-browser button reset */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;

  /* Consistent styling */
  border: none;
  border-radius: 8px;
  padding: 0.75rem 1.5rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;

  /* Smooth transitions */
  transition: all 0.3s ease;

  /* Touch-friendly sizing */
  min-height: 44px;
  min-width: 44px;

  /* Focus styles */
  outline: none;
}

button:focus,
input[type="button"]:focus,
input[type="submit"]:focus,
input[type="reset"]:focus,
.btn:focus {
  outline: 2px solid #8b5cf6;
  outline-offset: 2px;
}

/* Form Elements Cross-Browser Styling */
input,
textarea,
select {
  /* Reset appearance */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;

  /* Consistent styling */
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  padding: 0.75rem;
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 8px;
  background-color: rgba(30, 41, 59, 0.6);
  color: #e2e8f0;

  /* Smooth transitions */
  transition: all 0.3s ease;

  /* Touch-friendly sizing */
  min-height: 44px;
  width: 100%;
  max-width: 100%;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #8b5cf6;
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

/* Image Optimization for All Browsers */
img {
  max-width: 100%;
  height: auto;
  display: block;
  aspect-ratio: auto; /* Preserve intrinsic aspect-ratio, reduces CLS during loading */

  /* Improve image rendering */
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Video and Media Elements */
video,
audio,
iframe,
embed,
object {
  max-width: 100%;
  height: auto;
  aspect-ratio: auto;
}

/* Table Responsiveness */
table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  overflow-x: auto;
  display: block;
  white-space: nowrap;
}

@media (min-width: 768px) {
  table {
    display: table;
    white-space: normal;
  }
}

/* List Styles */
ul,
ol {
  margin: 0 0 1.5rem 0;
  padding-left: 2rem;
}

li {
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

/* Code and Pre Elements */
code,
pre,
kbd,
samp {
  font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
  font-size: 0.9em;
  background-color: rgba(30, 41, 59, 0.8);
  color: #e2e8f0;
  border-radius: 4px;
  padding: 0.2em 0.4em;
}

pre {
  padding: 1rem;
  overflow-x: auto;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* .sr-only / .screen-reader-text — defined in accessibility.css */

/* Skip Links for Keyboard Navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  z-index: 999999;
  padding: 8px 16px;
  background-color: #8b5cf6;
  color: #ffffff;
  text-decoration: none;
  border-radius: 4px;
  font-weight: 600;
  transition: top 0.3s ease;
}

.skip-link:focus {
  top: 6px;
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  body {
    background-color: #000000;
    color: #ffffff;
  }

  a {
    color: #ffffff;
    text-decoration: underline;
  }

  button,
  .btn {
    background-color: #ffffff;
    color: #000000;
    border: 2px solid #ffffff;
  }

  input,
  textarea,
  select {
    background-color: #ffffff;
    color: #000000;
    border: 2px solid #000000;
  }
}

/* Reduced Motion Support */
@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;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
  }
}

/* Print Styles */
@media print {
  *,
  *::before,
  *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  a,
  a:visited {
    text-decoration: underline;
  }

  a[href]::after {
    content: " (" attr(href) ")";
  }

  abbr[title]::after {
    content: " (" attr(title) ")";
  }

  pre,
  blockquote {
    border: 1px solid #999;
    page-break-inside: avoid;
  }

  thead {
    display: table-header-group;
  }

  tr,
  img {
    page-break-inside: avoid;
  }

  img {
    max-width: 100% !important;
  }

  p,
  h2,
  h3 {
    orphans: 3;
    widows: 3;
  }

  h2,
  h3 {
    page-break-after: avoid;
  }
}

/* Mobile-First Responsive Design */
@media (max-width: 320px) {
  html {
    font-size: 14px;
  }

  .container {
    padding: 0 10px;
  }
}

@media (min-width: 321px) and (max-width: 480px) {
  html {
    font-size: 15px;
  }

  .container {
    padding: 0 15px;
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  html {
    font-size: 16px;
  }

  .container {
    padding: 0 20px;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .container {
    padding: 0 30px;
  }
}

@media (min-width: 1025px) {
  .container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 40px;
  }
}

/* Ultra-wide screen support */
@media (min-width: 1920px) {
  .container {
    max-width: 1600px;
    padding: 0 60px;
  }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
  .site-header {
    padding: 0.25rem 0;
  }

  h1 {
    font-size: 2rem;
  }

  h2 {
    font-size: 1.5rem;
  }
}

/* Browser-Specific Fixes */

/* Safari-specific fixes */
@supports (-webkit-appearance: none) {
  input[type="search"] {
    -webkit-appearance: none;
    appearance: none;
  }

  /* Fix Safari's default button styling */
  button,
  input[type="button"],
  input[type="submit"] {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 8px;
  }
}

/* Firefox-specific fixes */
@-moz-document url-prefix() {
  /* Firefox button fixes */
  button::-moz-focus-inner,
  input[type="button"]::-moz-focus-inner,
  input[type="submit"]::-moz-focus-inner {
    border: 0;
    padding: 0;
  }
}

/* Internet Explorer and Edge fixes */
@supports (-ms-ime-align: auto) {
  /* IE/Edge specific styles */
  img {
    -ms-interpolation-mode: bicubic;
  }
}

/* Chrome-specific fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  /* Chrome input autofill styling */
  input:-webkit-autofill,
  input:-webkit-autofill:hover,
  input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 30px rgba(30, 41, 59, 0.6) inset !important;
    -webkit-text-fill-color: #e2e8f0 !important;
  }
}

/* Focus Management for Better Accessibility */
*:focus {
  outline: 2px solid #8b5cf6;
  outline-offset: 2px;
}

/* Remove outline for mouse users, keep for keyboard users */
.js-focus-visible *:focus:not(.focus-visible) {
  outline: none;
}

/* Container and Layout Improvements */
.container {
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  position: relative;
}

/* Flexbox and Grid Fallbacks */
.flex {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}

.flex-wrap {
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
}

.justify-center {
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
}

.items-center {
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
}

/* Grid fallback for older browsers */
@supports not (display: grid) {
  .grid {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
  }

  .grid > * {
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    min-width: 300px;
  }
}

/* Modern CSS Grid */
@supports (display: grid) {
  .grid {
    display: grid;
    gap: 2rem;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }
}

/* Performance Optimizations */
.will-change-transform {
  will-change: transform;
}

.will-change-opacity {
  will-change: opacity;
}

/* GPU acceleration for smooth animations */
.gpu-accelerated {
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  -o-transform: translateZ(0);
  transform: translateZ(0);

  -webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  -ms-backface-visibility: hidden;
  backface-visibility: hidden;

  -webkit-perspective: 1000;
  -moz-perspective: 1000;
  -ms-perspective: 1000;
  perspective: 1000;
}

/* Smooth scrolling polyfill for older browsers */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

/* Custom scrollbar for webkit browsers */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(30, 41, 59, 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.6);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 92, 246, 0.8);
}

/* Selection styling */
::selection {
  background-color: rgba(139, 92, 246, 0.3);
  color: #ffffff;
}

::-moz-selection {
  background-color: rgba(139, 92, 246, 0.3);
  color: #ffffff;
}
