/*
 * MITORAHUB — Performance & Mobile Optimization Layer
 * Appended after style.css via <link> in pages that need it,
 * OR inlined into style.css for production.
 *
 * Covers: critical image loading, CLS prevention,
 * reduced-motion, print styles, high-contrast mode.
 */

/* ── Prevent CLS on images ───────────────────────────── */
img {
  content-visibility: auto;
}

/* Reserve space for background-image cards before load */
.cat-card,
.guide-card,
.featured-item,
.article-card-img,
.product-card-img,
.page-hero,
.hero {
  contain: layout style;
}

/* ── Lazy-loaded image fade-in ───────────────────────── */
img[loading="lazy"] {
  opacity: 0;
  transition: opacity 0.4s ease;
}
img[loading="lazy"].loaded {
  opacity: 1;
}

/* ── 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;
  }
  .fade-in {
    opacity: 1 !important;
    transform: none !important;
  }
  .hero-bg,
  .page-hero-bg {
    transform: none !important;
  }
}

/* ── High-contrast mode ──────────────────────────────── */
@media (forced-colors: active) {
  .btn-gold {
    border: 2px solid ButtonText;
  }
  .nav-logo span,
  .footer-brand-logo span {
    color: Highlight;
  }
}

/* ── Print styles ────────────────────────────────────── */
@media print {
  .nav,
  .hero-scroll,
  .cta-strip,
  .newsletter,
  #back-to-top,
  .nav-hamburger {
    display: none !important;
  }
  body {
    font-size: 12pt;
    color: #000;
    background: #fff;
  }
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #555;
  }
  a[href^="https://blog.mitorahub.com"]::after {
    content: " (blog.mitorahub.com)";
  }
  h1, h2, h3 {
    page-break-after: avoid;
  }
  .grid-2, .grid-3, .grid-4 {
    display: block;
  }
}

/* ── Focus styles (accessibility) ───────────────────── */
:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ── Skip link (screen readers / keyboard nav) ───────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  background: var(--gold);
  color: var(--black);
  padding: 10px 20px;
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: 0 0 4px 4px;
  z-index: 9999;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 0;
}

/* ── Mobile tap targets ──────────────────────────────── */
@media (max-width: 768px) {
  .btn,
  .nav-links a,
  .footer-links a,
  .footer-social a {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Prevent horizontal scroll from any overflow */
  body {
    overflow-x: hidden;
  }

  /* Larger text on smallest screens for readability */
  .lead {
    font-size: 1rem;
  }

  /* Full-width CTAs on mobile */
  .hero-actions .btn,
  .lp-hero-content .btn {
    width: 100%;
    text-align: center;
    justify-content: center;
  }
}

/* ── Smooth scrolling only when not prefers-reduced ─── */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

/* ── Core Web Vitals: prevent layout shift on fonts ─── */
@font-face {
  font-display: swap;
}

/* ── Article readability (guide pages) ──────────────── */
.article-body {
  font-size: 1.0625rem;
  line-height: 1.8;
  color: var(--text);
  max-width: 680px;
}
.article-body h2 {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  margin: 48px 0 16px;
  color: var(--dark);
}
.article-body h3 {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  margin: 32px 0 12px;
}
.article-body p {
  margin-bottom: 20px;
}
.article-body ul,
.article-body ol {
  padding-left: 24px;
  margin-bottom: 20px;
}
.article-body li {
  margin-bottom: 8px;
  line-height: 1.7;
}
.article-body strong {
  color: var(--dark);
  font-weight: 600;
}
.article-body a {
  color: var(--gold-dark);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.article-body a:hover {
  color: var(--gold);
}
.article-body blockquote {
  border-left: 3px solid var(--gold);
  padding: 16px 24px;
  background: var(--gold-light);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin: 28px 0;
  font-style: italic;
  color: var(--dark);
}

/* ── Details/Summary (FAQ) polishing ────────────────── */
details summary {
  cursor: pointer;
  user-select: none;
  padding-right: 32px;
  position: relative;
}
details summary::after {
  content: '+';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.3rem;
  color: var(--gold);
  font-weight: 300;
  transition: transform 0.2s;
}
details[open] summary::after {
  content: '−';
}
