/**
 * Font Loading Optimisation
 * Prevents layout shift during font loading by matching font metrics
 */

/* Immediate font fallback to prevent FOUC */
html {
  font-feature-settings: 'kern' 1;
  text-rendering: optimizeSpeed;
}

/* Size adjust to match Lato's metrics with system fonts */
@font-face {
  font-family: 'Lato-fallback';
  src: local('Segoe UI'), local('system-ui'), local('-apple-system');
  font-display: swap;
  /* Adjust size to match Lato's x-height more closely */
  size-adjust: 100.06%;
  ascent-override: 87%;
  descent-override: 20%;
  line-gap-override: 0%;
}

/* Redirect font-family custom properties to the fallback stack until fonts load */
:root {
  --font-family-primary: 'Lato-fallback', var(--font-family-primary-base);
}

html.fonts-loaded {
  --font-family-primary: var(--font-family-primary-base);
}

/* Prevent invisible text during font load */
.font-display-swap {
  font-display: swap;
}

/* Force consistent line heights during font loading */
html:not(.fonts-loaded) body {
  line-height: var(--line-height-normal) !important;
}

html:not(.fonts-loaded) h1, html:not(.fonts-loaded) .h1,
html:not(.fonts-loaded) h2, html:not(.fonts-loaded) .h2 {
  line-height: var(--line-height-tight) !important;
}

html:not(.fonts-loaded) h3, html:not(.fonts-loaded) .h3,
html:not(.fonts-loaded) h4, html:not(.fonts-loaded) .h4,
html:not(.fonts-loaded) h5, html:not(.fonts-loaded) .h5,
html:not(.fonts-loaded) h6, html:not(.fonts-loaded) .h6 {
  line-height: var(--line-height-snug) !important;
}

/* Smooth transition when fonts load */
* {
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Performance optimisations */
html {
  font-variant-ligatures: none;
}
