/* ============================================================================
   perf.css — Performance optimizations

   - content-visibility: auto on below-fold sections
   - contain: layout/style/paint for independent components
   - print styles
   - prefers-contrast support
   ============================================================================ */

/* ---------------------------------------------------------------------------
   Content Visibility — skip rendering of below-fold sections.
   contain-intrinsic-size provides a placeholder size to prevent layout shift.

   The placeholder values are the measured heights at a ~1440px viewport. They
   are 30-60% short of the old values, which made the scrollbar thumb visibly
   wrong on arrival and grow under the thumb as the visitor scrolled — a "still
   loading" impression on a page with nothing left to load. Real heights vary
   with viewport (contact-section is 1,270px at 1440 and ~1,800px at 390), so a
   single number cannot be right at both ends; `auto` makes the browser remember
   the real size once seen. Re-measure these after any layout change.
   --------------------------------------------------------------------------- */

.trust-strip {
  content-visibility: auto;
  contain-intrinsic-size: auto 88px;
}

.services-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 940px;
}

.approach-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 855px;
}

.contact-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 1270px;
}

.site-footer {
  content-visibility: auto;
  contain-intrinsic-size: auto 290px;
}

/* Kept on the static footer bar: it contains no animated children, and
   removing it changes the rendered height under the footer's containment. */
.footer-bottom {
  content-visibility: auto;
  contain-intrinsic-size: auto 80px;
}

/* ---------------------------------------------------------------------------
   CSS Contain — isolate layout, style and paint so internal changes
   cannot affect surrounding layout.
   --------------------------------------------------------------------------- */

.service-card,
.approach-art,
.contact-form {
  contain: layout style paint;
}

.contact-details {
  contain: layout style;
}

/* ---------------------------------------------------------------------------
   Print Styles — clean, minimal output
   --------------------------------------------------------------------------- */

@media print {
  /* Entrance animations use `animation-fill-mode: both` and normally live
     inside a prefers-reduced-motion block, which the print reset below does
     not touch. A visitor who prints within the first ~600ms of load therefore
     gets every .hero-copy child, all four service cards, the approach and
     contact blocks and the footer rendered at their `from` keyframe — which is
     opacity: 0. Blank pages. Kill all animation and transition for print. */
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    /* Paper has nothing behind it to blur, and a backdrop-filter left on in
       print is a full-size rasterisation for a result nobody can see. The three
       glass surfaces are all display:none further down so they never actually
       paint today — this is insurance for the next one that is added, which
       would otherwise print as a translucent grey panel. */
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
  html {
    scroll-behavior: auto;
  }

  /* The reveal observer leaves off-screen targets at opacity 0. A printed
     page has no scroll to reveal them, so pin every reveal target visible. */
  .js-reveal {
    opacity: 1 !important;
    transform: none !important;
    translate: 0 0 !important;
  }

  .site-header,
  .skip-link,
  .menu-toggle,
  [data-theme-toggle],
  .hero-visual,
  .hero-grid,
  .hero-bottom,
  .hero-note,
  .visual-orbit,
  .visual-label,
  .contact-glow,
  .contact-map,
  .map-link,
  .approach-art:before,
  .art-caption,
  .eyebrow-dot,
  .eyebrow-line,
  .note-line,
  .service-icon,
  .footer-main nav {
    display: none !important;
  }

  body {
    background: #fff !important;
    color: var(--ink) !important;
    font-size: 12pt;
  }

  .hero,
  .services-section,
  .approach-section,
  .contact-section,
  .site-footer,
  .trust-strip {
    background: #fff !important;
    color: var(--ink) !important;
    border-color: var(--border-card) !important;
  }

  .hero h1,
  .section-heading h2,
  .approach-copy h2,
  .contact-copy h2 {
    color: var(--ink) !important;
    font-size: 24pt;
  }

  .hero h1 span,
  .section-heading h2 span,
  .approach-copy h2 span,
  .contact-copy h2 span,
  .eyebrow,
  .eyebrow-dark {
    color: var(--ink) !important;
  }

  .button,
  .nav-cta {
    border: 1px solid #000 !important;
    background: #fff !important;
    color: var(--ink) !important;
  }

  .service-card {
    break-inside: avoid;
    border-color: var(--border-card) !important;
  }

  .contact-form {
    border: 1px solid #ccc !important;
    break-inside: avoid;
  }

  a {
    color: var(--ink) !important;
    text-decoration: underline;
  }

  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
  }

  .container {
    width: 100% !important;
  }

  .section,
  .approach-section,
  .contact-section {
    padding: 20px 0 !important;
  }

  /* The hero reserves 720px of height for a visual that print hides, so a
     printed page opened on mostly-blank space. */
  .hero,
  .trust-strip {
    min-height: 0 !important;
  }
  .hero-content {
    min-height: 0 !important;
    padding: 0 !important;
  }

  /* Every component size is in px, so the 12pt body above did nothing for
     them: the footer nav and card CTAs printed at 9px and the buttons and
     field labels at 10px — 6.75pt next to 12pt body copy. Give print its own
     type scale instead. */
  .eyebrow,
  .button,
  .nav-cta,
  .contact-form label,
  .form-top,
  .service-number,
  .footer-main nav,
  .service-card>a,
  .map-link {
    font-size: 10pt !important;
  }
  .service-card p,
  .footer-main>p,
  .contact-details dl>div,
  .form-feedback,
  .contact-form .consent {
    font-size: 11pt !important;
  }
  .service-card h3 {
    font-size: 16pt !important;
  }

  /* A printed form cannot be filled in. 400px of empty boxes is noise; the
     contact details beside it are the useful part. */
  .contact-form {
    display: none !important;
  }
}

/* ---------------------------------------------------------------------------
   Prefers Contrast — strengthen borders and muted text
   --------------------------------------------------------------------------- */

@media (prefers-contrast: more) {
  /* `:root` alone is (0,1,0), which loses to `:root[data-theme="dark"]` (0,2,0)
     in tokens.css and to the `:root:not(...)` auto-dark block (0,3,0) — so
     everything below used to be inert in dark mode, exactly where high contrast
     is most often needed. Naming both selectors fixed that and immediately
     exposed the next bug: they shared ONE set of values, and those were the
     light ones. A dark-mode visitor got `--text-muted: #333` on the #151719
     page — 1.42:1, in the one mode where they explicitly asked for more
     contrast. The themes are separate blocks below and each names both
     selectors. Do not merge them again.
     `--glass-bg-strong` is forced opaque as well: a high-contrast visitor
     should not be reading body text through a 78%-translucent panel, with
     whatever happens to be scrolling behind it. `--glass-bg` is deliberately
     NOT made opaque — it is the fill on the service cards, which sit on
     `--paper`, and pinning it to the same value would erase the cards. */
  :root {
    --border: #8a8a8a;
    --border-strong: #5a5a5a;
    --text-muted: #333;
    --text-subtle: #3d3d3d;
    --text-placeholder: #454545;
    --header-border: rgba(128, 128, 128, .7);
    --surface-contrast-border: rgba(128, 128, 128, .7);
    --glass-border: rgba(128, 128, 128, .9);
    --glass-bg-strong: #ffffff;
  }

  :root[data-theme="dark"] {
    --border: #a8a8a8;
    --border-strong: #c0c0c0;
    --text-muted: #e6e6e6;
    --text-subtle: #dcdcdc;
    --text-placeholder: #d4d4d4;
    --header-border: rgba(210, 210, 210, .75);
    --surface-contrast-border: rgba(210, 210, 210, .75);
    --glass-border: rgba(210, 210, 210, .9);
    --glass-bg-strong: #1d2023;
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="dark"]) {
      --border: #a8a8a8;
      --border-strong: #c0c0c0;
      --text-muted: #e6e6e6;
      --text-subtle: #dcdcdc;
      --text-placeholder: #d4d4d4;
      --header-border: rgba(210, 210, 210, .75);
      --surface-contrast-border: rgba(210, 210, 210, .75);
      --glass-border: rgba(210, 210, 210, .9);
      --glass-bg-strong: #1d2023;
    }
  }

  .service-card {
    border-right-width: 2px;
  }

  .button-outline {
    border-width: 2px;
  }

  /* The controls that actually matter were not covered by the two rules
     above: 1px was not enough to read a boundary at high contrast. */
  .contact-form input:not([type="checkbox"]):not([type="radio"]),
  .contact-form textarea,
  .contact-form .consent input[type="checkbox"],
  .js .menu-toggle,
  [data-theme-toggle] {
    border-width: 2px;
  }
}
