/* ══════════════════════════════════════════════════════════════
   Opus Structure — shared resilience layer
   Loaded AFTER each page's inline <style> so these rules win.

   Everything here answers one question: what does the visitor see
   when something goes wrong — no JavaScript, a blocked CDN, a
   keyboard instead of a mouse, a finger instead of a cursor, or an
   operating system that has been told to stop animating things.
   ══════════════════════════════════════════════════════════════ */

/* ── Opus Ecosystem brand tokens ───────────────────────────────
   One division is live at a time via [data-brand] on <html>. Ink
   and paper are universal per the brand doc and never move; every
   other colour in the site is wired to these four roles, so a
   single attribute change reskins the whole page. Light/mid tints
   used for hover states are derived rather than hand-picked, so
   every division gets the same relationship to its own primary. */
html[data-brand="structure"] {
  --c-primary:       #0a4f4f;
  --c-primary-rgb:   10,79,79;
  --c-accent:        #e85d4e;
  --c-accent-rgb:    232,93,78;
  --c-surface-light: #e3eeec;
  --c-surface-dark:  #0a2b2b;
  --c-on-accent:     #1a1a1a;
}
html[data-brand="studio"] {
  --c-primary:       #1f6b3a;
  --c-primary-rgb:   31,107,58;
  --c-accent:        #9be28a;
  --c-accent-rgb:    155,226,138;
  --c-surface-light: #eaf6e4;
  --c-surface-dark:  #0e2216;
  --c-on-accent:     #0e2216;
}
html[data-brand="print"] {
  --c-primary:       #a3162c;
  --c-primary-rgb:   163,22,44;
  --c-accent:        #e0303f;
  --c-accent-rgb:    224,48,63;
  --c-surface-light: #fbe7e8;
  --c-surface-dark:  #2a0b10;
  --c-on-accent:     #ffffff;
}
html[data-brand="tech"] {
  --c-primary:       #1146a8;
  --c-primary-rgb:   17,70,168;
  --c-accent:        #4f95ff;
  --c-accent-rgb:    79,149,255;
  --c-surface-light: #e6eefb;
  --c-surface-dark:  #0b1a38;
  --c-on-accent:     #0b1a38;
}
:root {
  --c-ink:            #1a1a1a;
  --c-paper:          #f5f2eb;
  --c-primary-light:  color-mix(in srgb, var(--c-primary) 88%, white);
  --c-primary-mid:    color-mix(in srgb, var(--c-primary) 94%, white);
}

/* ── Ecosystem switcher bar ────────────────────────────────────
   Fixed strip above the main nav. Its own surface stays on the
   universal ink so it reads as permanent chrome, not a themed
   panel; only the active tab picks up the current division's
   accent, which is the whole point: the pill that lights up tells
   you which brand you are looking at. */
#ecosystem-bar {
  scrollbar-width: none;
  /* The division's own dark surface, not a flat black slab, so the
     strip already hints at the active brand before anything else
     on the page has reskinned. */
  background: var(--c-surface-dark);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
#ecosystem-bar::-webkit-scrollbar {
  display: none;
}
.eco-tab {
  display: inline-flex;
  align-items: center;
  padding: .4rem 1.05rem;
  border-radius: 9999px;
  background: transparent;
  color: rgba(255,255,255,.68);
  font-size: .75rem;
  font-weight: 500;
  letter-spacing: .01em;
  line-height: 1;
  white-space: nowrap;
  border: none;
  cursor: pointer;
  transition: color .25s, background-color .25s;
}
.eco-tab:hover {
  color: rgba(255,255,255,.8);
}
/* A tinted pill with coloured text, not a solid block: the system's
   own rule is that colour marks the one important thing and nothing
   carries a fill at rest, so the active tab should read as "lit",
   not as a loud button. */
.eco-tab.active {
  background: rgba(var(--c-accent-rgb),.16);
  color: var(--c-accent);
  font-weight: 600;
}
.eco-tab:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}

/* ── Division-scoped content ───────────────────────────────────
   Anything that belongs to one division only carries
   data-eco-service="tech|studio|print". Opus Structure is the
   master view, so it shows everything; picking a division hides
   whatever is tagged for one of the other two. Content with no
   tag (or explicitly structure-level work, like brand strategy)
   is cross-cutting and always stays visible. */
html[data-brand="studio"] [data-eco-service="tech"],
html[data-brand="studio"] [data-eco-service="print"],
html[data-brand="print"]  [data-eco-service="tech"],
html[data-brand="print"]  [data-eco-service="studio"],
html[data-brand="tech"]   [data-eco-service="studio"],
html[data-brand="tech"]   [data-eco-service="print"] {
  display: none !important;
}

/* The opposite case: content that only makes sense on the Opus
   Structure master view (the ecosystem explainer on the homepage,
   the About nav link, the cross-cutting services group), gone the
   moment a visitor has picked one specific division. */
html:not([data-brand="structure"]) [data-eco-structure-only] {
  display: none !important;
}

/* The exact-match case: one of four variants of the same content
   (a hero headline, a marquee list) where every brand, including
   Structure, gets its own copy and the other three disappear. */
[data-eco-only] { display: none !important; }
html[data-brand="structure"] [data-eco-only="structure"],
html[data-brand="studio"]    [data-eco-only="studio"],
html[data-brand="print"]     [data-eco-only="print"],
html[data-brand="tech"]      [data-eco-only="tech"] {
  display: block !important;
}

/* A card-sized variant of .eco-tab, for "Explore Opus X" links
   that double as ecosystem-switcher triggers inside page content.
   Same click wiring, same active-state fill, different shape. */
.eco-tab.eco-tab--card {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  width: auto;
  padding: .65rem 1.25rem;
  font-size: .8rem;
  color: rgba(255,255,255,.8);
  background: rgba(255,255,255,.08);
}
.eco-tab.eco-tab--card:hover {
  color: #fff;
  background: rgba(255,255,255,.16);
}
.eco-tab.eco-tab--card.active {
  background: var(--c-accent);
  color: var(--c-on-accent);
}

/* ── Skip link ─────────────────────────────────────────────────
   First tab stop on every page. Invisible until focused. */
.skip-link {
  position: fixed;
  top: .75rem;
  left: .75rem;
  z-index: 10001;
  display: inline-block;
  padding: .75rem 1.25rem;
  background: var(--c-accent);
  color: #fff;
  font-size: .875rem;
  font-weight: 600;
  border-radius: 9999px;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform .2s ease;
}
.skip-link:focus {
  transform: translateY(0);
}

/* The skip target must not draw a focus ring when reached by skip link. */
[tabindex="-1"]:focus {
  outline: none;
}

/* ── Focus visibility ──────────────────────────────────────────
   The site had no focus styles at all outside the contact fields.
   Coral reads on cream, white and teal alike; the white outer ring
   keeps it legible where coral sits on coral. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* On coral surfaces, invert so the ring never disappears into the background. */
.bg-coral :where(a, button):focus-visible,
.submit-btn:focus-visible {
  outline-color: #fff;
}

/* Cards and pills already have their own radius — match it so the ring
   traces the shape instead of cutting its corners. */
.live-card:focus-visible,
.site-card:focus-visible,
.work-card:focus-visible,
.project-card:focus-visible {
  outline-offset: 4px;
  border-radius: 1rem;
}
.filter-btn:focus-visible,
.skip-link:focus-visible {
  border-radius: 9999px;
}

/* ── Custom cursor ─────────────────────────────────────────────
   Was: `cursor: none !important` on every element of every page,
   unconditionally. On touch devices the two cursor elements sat
   frozen at the top-left corner; with JS broken there was no
   pointer at all; and `!important` overrode assistive settings.

   Now the real cursor is only hidden once site.js has confirmed a
   fine pointer AND started tracking it — the class is the proof. */
#cursor,
#cursor-ring {
  display: none;
}
html.has-custom-cursor #cursor,
html.has-custom-cursor #cursor-ring {
  display: block;
}
html.has-custom-cursor,
html.has-custom-cursor * {
  cursor: none;
}
/* Text entry always keeps a real caret — an I-beam is information. */
html.has-custom-cursor :where(input, textarea, select, [contenteditable]) {
  cursor: auto;
}

/* ── Entrance animations degrade to "already there" ────────────
   The `js` class is set by an inline script in <head> and removed
   again by site.js if GSAP never arrived or motion is unwanted.
   Without it, every element that used to wait for an animation
   simply renders in its final state. */
.reveal,
.reveal-left,
.reveal-right,
.hero-line {
  opacity: 1;
  transform: none;
}

/* `hero-fade` only ever animated opacity. It must not reset transform —
   the scroll hint is centred with a Tailwind translate. */
.hero-fade {
  opacity: 1;
}

html.js .reveal       { opacity: 0; transform: translateY(40px); }
html.js .reveal-left  { opacity: 0; transform: translateX(-40px); }
html.js .reveal-right { opacity: 0; transform: translateX(40px); }
html.js .hero-line    { opacity: 0; transform: translateY(110%); }
html.js .hero-fade    { opacity: 0; }

/* works.html hides two whole card grids ahead of a stagger. Those rules
   live in the page's own <style> and are not gated, so without this the
   eleven live-site cards and the print grid stay invisible forever when
   the animation library fails. */
html:not(.js) .live-grid .site-card,
html:not(.js) .print-grid .project-card,
html:not(.js) .cards-grid .project-card,
html:not(.js) .studio-grid .project-card {
  opacity: 1 !important;
  transform: none !important;
}

/* The escape hatch has to outrank GSAP, which writes opacity straight
   onto the element. Without !important a half-finished animation could
   leave content stranded at zero opacity with no way back. */
html:not(.js) .reveal,
html:not(.js) .reveal-left,
html:not(.js) .reveal-right,
html:not(.js) .hero-line {
  opacity: 1 !important;
  transform: none !important;
}
html:not(.js) .hero-fade {
  opacity: 1 !important;
}

/* The loader is a JS artefact. Without JS it must never exist. */
html:not(.js) #loader {
  display: none !important;
}

/* Its exit is CSS, not GSAP — see the note in site.js. */
#loader {
  transition: opacity .6s ease;
}
#loader.is-gone {
  opacity: 0;
  pointer-events: none;
}

/* ── Mobile menu ───────────────────────────────────────────────
   `max-height: 0` hides the menu visually but leaves its links in
   the tab order and readable by screen readers. `visibility` takes
   them out properly, delayed so the collapse still animates. */
#mobile-menu {
  visibility: hidden;
  transition: max-height .4s ease, visibility 0s linear .4s;
}
#mobile-menu.open {
  visibility: visible;
  transition: max-height .4s ease, visibility 0s linear 0s;
}

/* Same problem, same fix, for the contact page's FAQ panels. */
.faq-body {
  visibility: hidden;
  transition: max-height .35s ease, visibility 0s linear .35s;
}
.faq-body.is-open {
  visibility: visible;
  transition: max-height .35s ease, visibility 0s linear 0s;
}

/* ── Long and unexpected content ───────────────────────────────
   Real enquiries carry URLs, hashtags and unbroken foreign strings.
   Grid and flex children default to min-width:auto, so one long word
   pushes the whole row wider than the viewport. */
h1, h2, h3, h4, p, li, td, th, a, .field, .chrome-url {
  overflow-wrap: break-word;
}

/* An email address or URL is one unbreakable token. Left alone it pushes
   its flex row wider than the phone, and the whole page scrolls sideways. */
.info-card > *,
.live-card .p-6 > *,
.site-card .p-6 > * {
  min-width: 0;
}
.chrome-url {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Reduced motion ────────────────────────────────────────────
   Not a blanket `animation: 0.01ms` kill — that would freeze the
   reveal elements at opacity 0 and erase the page. Instead each
   moving thing is given a still resting state that still reads. */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  html.js .reveal,
  html.js .reveal-left,
  html.js .reveal-right,
  html.js .hero-line {
    opacity: 1 !important;
    transform: none !important;
  }
  html.js .hero-fade {
    opacity: 1 !important;
  }

  /* The ticker still communicates the service list — it just stops moving. */
  .marquee-inner {
    animation: none;
    flex-wrap: wrap;
    white-space: normal;
  }
  .marquee-wrap {
    white-space: normal;
  }

  .live-dot::after,
  .animate-pulse,
  .animate-spin {
    animation: none;
  }

  /* Hover feedback stays — it just arrives without travel. */
  .service-card,
  .live-card,
  .site-card,
  .project-card,
  .info-card,
  .team-card,
  .work-card {
    transition-duration: .01ms;
  }
  .service-card:hover,
  .live-card:hover,
  .site-card:hover,
  .project-card:hover,
  .info-card:hover,
  .team-card:hover {
    transform: none;
  }
  .work-card:hover .work-img,
  .live-card:hover .shot,
  .site-card:hover .shot,
  .project-card:hover .thumb,
  .team-card:hover .team-photo {
    transform: none;
  }
}

/* ── Forced colours (Windows high contrast) ────────────────────
   Overlays and hover reveals lose their meaning when the system
   replaces every colour, so pin the ones that carry information. */
@media (forced-colors: active) {
  .skip-link,
  .submit-btn {
    border: 1px solid;
  }
  :where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid CanvasText;
  }
  .live-overlay,
  .site-overlay,
  .work-overlay,
  .card-overlay,
  .team-overlay {
    background: Canvas;
  }
}

/* ── Print ─────────────────────────────────────────────────────
   Someone will print the services or contact page for a meeting. */
@media print {
  #loader,
  #cursor,
  #cursor-ring,
  #navbar,
  .skip-link,
  .marquee-wrap {
    display: none !important;
  }
  .reveal,
  .reveal-left,
  .reveal-right,
  .hero-line,
  .hero-fade {
    opacity: 1 !important;
    transform: none !important;
  }
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: .75em;
    word-break: break-all;
  }
}

/* ── Brand logo ─────────────────────────────────────────────
   Light-artwork horizontal lockups from the Opus brand guide
   (the pages' nav and footer sit on teal / ink). All four are in
   the markup; only the one matching <html data-brand> shows, so
   switching division in the ecosystem bar swaps the logo too. */
.brand-logo { display: block; }
.brand-logo--nav    { height: 34px; }
.brand-logo--footer { height: 44px; }
.brand-logo img { display: none; height: 100%; width: auto; }
html:not([data-brand]) .brand-logo img[data-logo="structure"],
html[data-brand="structure"] .brand-logo img[data-logo="structure"],
html[data-brand="tech"]      .brand-logo img[data-logo="tech"],
html[data-brand="studio"]    .brand-logo img[data-logo="studio"],
html[data-brand="print"]     .brand-logo img[data-logo="print"] { display: block; }


/* ── Text on the accent colour ─────────────────────────────────
   White on coral is 3.4:1 and white on the Tech blue is 3.0:1, so
   anything that sits on a solid accent fill takes its colour from
   --c-on-accent instead (ink on coral, deep navy on Tech blue,
   deep green on Studio, white only where it clears AA on Print). */
.bg-coral { color: var(--c-on-accent); }
.bg-coral.text-white,
.bg-coral [class*="text-white"] { color: var(--c-on-accent); }
.hover:bg-coral:hover { color: var(--c-on-accent); }

/* ── Ecosystem tabs: bigger hit area, same look ───────────────
   The pill stays 24px tall so the 40px bar is unchanged; an
   invisible ::before stretches the target to the bar's height. */
.eco-tab { position: relative; }
.eco-tab::before { content: ""; position: absolute; inset: -8px -4px; }

/* ── Division switch: the reveal ───────────────────────────────
   The new division's page expands from the tab that was pressed
   (--vt-x / --vt-y / --vt-r are set in site.js). The switcher bar
   and the custom cursor are lifted out of the snapshot so they stay
   live while the page behind them changes. */
#ecosystem-bar { view-transition-name: eco-bar; }
html.has-custom-cursor #cursor { view-transition-name: eco-cursor; }
html.has-custom-cursor #cursor-ring { view-transition-name: eco-cursor-ring; }

::view-transition-old(root),
::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) {
  animation: eco-reveal .7s cubic-bezier(.16, 1, .3, 1) both;
}
@keyframes eco-reveal {
  from { clip-path: circle(0 at var(--vt-x, 50%) var(--vt-y, 0)); }
  to   { clip-path: circle(var(--vt-r, 150vmax) at var(--vt-x, 50%) var(--vt-y, 0)); }
}
/* The switcher and cursor groups should follow the live elements, not fade. */
::view-transition-group(eco-bar),
::view-transition-group(eco-cursor),
::view-transition-group(eco-cursor-ring) { animation-duration: 0s; }

/* Reduced motion: no travel, just a short crossfade. */
html.eco-vt-fade::view-transition-old(root) { animation: eco-fade-out .2s ease both; }
html.eco-vt-fade::view-transition-new(root) { animation: eco-fade-in .2s ease both; }
@keyframes eco-fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes eco-fade-out { from { opacity: 1; } to { opacity: 0; } }

/* Press feedback on the switcher tabs. */
.eco-tab { transition: color .25s, background-color .25s, transform .12s ease-out; }
.eco-tab:active { transform: scale(.96); }
