/* ==========================================================================
   Home page · hero
   The 3D pit (js/pit-hero.js), the headline and the line of this
   morning's flags (js/hero-flags.js). Split out of home.css so the hero can change without
   touching the rest.
   ========================================================================== */

/* ── Stage ──────────────────────────────────────────────────────────── */
/* Fills the screen below the two sticky bars (64px topbar + 52px context
   bar). The canvas clears to the same ink, so the pit fades into the page. */
.hero {
  position: relative;
  display: flex;
  min-height: max(600px, calc(100vh - 116px));
  min-height: max(600px, calc(100svh - 116px));
  background: var(--ink);
  overflow: hidden;
  isolation: isolate;
}
#pit-canvas {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  display: block;
  z-index: 0;
}

/* Instrument labels, projected over the canvas by js/pit-hero.js. Plain
   text with a dark halo so it reads on the light ground; no boxes. */
.pit-labels {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}
.pit-label {
  position: absolute; top: 0; left: 0;
  margin: -21px 0 0 7px;
  font-size: 10.5px; font-weight: 700;
  line-height: 1;
  letter-spacing: 0.03em;
  white-space: nowrap;
  color: #EEF6F2;
  text-shadow: 0 1px 2px rgba(16,35,31,0.95), 0 0 7px rgba(16,35,31,0.85);
  opacity: 0;
  transition: opacity 0.35s ease;
  will-change: transform;
}
.pit-label.is-on { opacity: 1; }
.pit-label.is-off { visibility: hidden; }
/* Area of Concern names match the map section: a small dark tag with the
   amber flag, because amber text alone disappears on the light ground. */
.pit-label--flag {
  margin-top: -24px;
  padding: 3px 7px 3px 6px;
  border-radius: 3px;
  background: rgba(16,35,31,0.86);
  color: #fff;
  text-shadow: none;
}
.pit-label--flag::before {
  content: '';
  display: inline-block;
  width: 0; height: 0;
  margin-right: 5px;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-bottom: 7px solid var(--amber);
}

/* Keeps the headline column readable where the pit runs under it, and
   settles the bottom edge into the next section. */
.hero-shade {
  position: absolute; inset: 0; z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(90deg,
      rgba(16,35,31,0.94) 0%,
      rgba(16,35,31,0.84) 30%,
      rgba(16,35,31,0.42) 46%,
      rgba(16,35,31,0) 60%),
    linear-gradient(to bottom,
      rgba(16,35,31,0) 72%,
      rgba(16,35,31,0.7) 100%);
}
.hero::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: -1px;
  height: 80px; z-index: 2;
  background: linear-gradient(to bottom, rgba(16,35,31,0), var(--ink));
  pointer-events: none;
}

/* Loading: a slim indeterminate line along the top edge. The mesh is served
   compressed, so there is no honest percentage to show. */
.hero-loader {
  position: absolute; left: 0; right: 0; top: 0;
  height: 2px; z-index: 5;
  overflow: hidden;
  pointer-events: none;
  background: rgba(183,216,201,0.08);
  transition: opacity 0.5s ease;
}
.hero-loader::before {
  content: '';
  position: absolute; top: 0; bottom: 0; left: 0;
  width: 36%;
  background: linear-gradient(90deg, rgba(183,216,201,0), rgba(183,216,201,0.85), rgba(183,216,201,0));
  animation: hero-loader-run 1.5s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}
.hero-loader.is-done { opacity: 0; }
.hero-loader.is-done::before,
.hero.hero--offscreen .hero-loader::before { animation-play-state: paused; }
@keyframes hero-loader-run {
  from { transform: translateX(-100%); }
  to   { transform: translateX(280%); }
}

/* ── Copy ───────────────────────────────────────────────────────────── */
/* Lines up with the page grid below (.section: max-width + gutter). */
.hero-content {
  position: relative; z-index: 3;
  flex: 1;
  display: flex; flex-direction: column; justify-content: center;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 48px var(--gutter) 52px;
}
.hero-text { max-width: 620px; }
/* What it is and who it's for, above the headline. */
.hero-eyebrow {
  margin-bottom: 16px;
  font-size: 15px; font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--teal-mid);
  text-shadow: 0 1px 14px rgba(16,35,31,0.6);
}
/* The headline on two balanced lines, kept narrow
   enough (about 580px) to stay clear of the pit. */
.hero-h1 {
  font-size: clamp(40px, 3.7vw, 54px);
  font-weight: 800; color: #fff;
  line-height: 1.04;
  letter-spacing: -0.03em;
  max-width: 12.4em;
  margin-bottom: 22px;
  hyphens: none;
  text-wrap: balance;
  text-shadow: 0 2px 28px rgba(16,35,31,0.55);
}
/* The underline is a background, so it follows the words onto a second
   line on narrow screens instead of sitting under only one of them. */
.hero-h1 .hero-accent {
  color: var(--teal-mid);
  padding-bottom: 0.06em;
  background: linear-gradient(90deg, rgba(183,216,201,0), rgba(183,216,201,0.9) 50%, rgba(183,216,201,0)) left bottom / 100% 4px no-repeat;
  -webkit-box-decoration-break: clone;
          box-decoration-break: clone;
}
.hero-sub {
  max-width: 540px;
  margin-bottom: 28px;
  font-size: 17.5px; font-weight: 500;
  line-height: 1.55;
  letter-spacing: 0.005em;
  color: rgba(231,239,234,0.9);
  text-shadow: 0 1px 18px rgba(16,35,31,0.6);
}
.hero-ctas {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 12px;
}
.hero-secondary {
  display: inline-flex; align-items: center;
  gap: 8px;
  background: rgba(16,35,31,0.35);
}
.hero-arrow {
  width: 14px; height: 14px;
  fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  transition: transform 0.16s ease;
}
.hero-secondary:hover .hero-arrow { transform: translateX(2px); }

/* Staggered entrance for the copy */
.hero-in {
  opacity: 0;
  transform: translateY(16px);
  animation: hero-in 0.8s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
  animation-delay: var(--d, 0ms);
}
@keyframes hero-in { to { opacity: 1; transform: translateY(0); } }

/* ── This morning's run (built by js/hero-flags.js) ──────────────────── */
/* A caption under the pit: what was flagged, while the pit flies to that
   wall and lights the instruments behind it. Centred on the pit (70% across
   on wide screens, matching pitAt in js/pit-hero.js); in the flow under the
   copy when the layout stacks. */
.hero-flags:empty { display: none; }
.hero-flags {
  position: absolute; z-index: 3;
  left: 71.5%; bottom: 40px;
  width: min(520px, 42vw);
  transform: translateX(-50%);
}
@media (max-width: 1199px) and (min-width: 901px) {
  .hero-flags { left: 71.5%; width: min(430px, 46vw); bottom: 32px; }
}
.flags-line {
  padding-left: 14px;
  border-left: 2px solid rgba(116,217,187,0.5);
  transition: opacity 0.26s ease, transform 0.26s ease;
}
.flags-line.is-out { opacity: 0; transform: translateY(4px); }
.flags-kicker {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 5px;
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: #74D9BB;
}
.flags-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #74D9BB;
  animation: flags-pulse 2s ease-out infinite;
}
@keyframes flags-pulse {
  0% { box-shadow: 0 0 0 0 rgba(116,217,187,0.5); }
  100% { box-shadow: 0 0 0 8px rgba(116,217,187,0); }
}
.flags-time { color: rgba(212,226,220,0.6); }
.flags-kind::before { content: '·'; margin-right: 8px; color: rgba(212,226,220,0.4); }
.flags-text {
  min-height: 3em;
  font-size: 14.5px; line-height: 1.5;
  color: rgba(231,239,234,0.82);
}
.flags-name { color: #fff; font-weight: 700; }

.flags-controls { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding-left: 16px; }
.flags-pause {
  flex: 0 0 26px;
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(15,28,26,0.6);
  transition: border-color 0.16s ease;
}
.flags-pause:hover { border-color: rgba(255,255,255,0.32); }
.flags-pause svg { width: 12px; height: 12px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.flags-pause .flags-i-play { display: none; fill: #fff; stroke: none; }
.flags-pause[aria-pressed="true"] .flags-i-play { display: block; }
.flags-pause[aria-pressed="true"] .flags-i-pause { display: none; }
.flags-segs { flex: 0 1 220px; display: flex; gap: 5px; }
.flags-seg { flex: 1; padding: 10px 0; }
.flags-seg span {
  position: relative;
  display: block; height: 2px;
  border-radius: 2px;
  background: rgba(255,255,255,0.16);
  overflow: hidden;
}
.flags-seg span::after {
  content: '';
  position: absolute; inset: 0;
  background: #74D9BB;
  transform: scaleX(0); transform-origin: left center;
}
.flags-seg:hover span { background: rgba(255,255,255,0.28); }
.flags-seg.is-done span::after { transform: none; }
.flags-seg.is-active span::after { animation: flags-fill var(--turn, 8s) linear forwards; }
.flags.is-paused .flags-seg.is-active span::after { animation-play-state: paused; }
@keyframes flags-fill { to { transform: none; } }
.flags-pause:focus-visible, .flags-seg:focus-visible {
  outline: 2px solid #74D9BB; outline-offset: 2px; border-radius: 6px;
}

/* screen-reader copy of the run */
.hero .sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── Fallback: a still of the pit when WebGL or the mesh is unavailable ── */
.hero.fallback {
  background: var(--ink) url('../../assets/pit-hero-still.jpg') 72% 42% / cover no-repeat;
}
.hero.fallback #pit-canvas { display: none; }
.hero-fallback-note {
  display: none;
  position: absolute; right: 24px; bottom: 18px; z-index: 4;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  background: rgba(16,35,31,0.7);
  font-size: 10.5px; letter-spacing: 0.01em;
  color: rgba(212,226,220,0.6);
}
.hero.fallback--local .hero-fallback-note { display: block; }

/* ── Mid widths: narrower copy so the pit keeps its side ─────────────── */
@media (max-width: 1199px) and (min-width: 901px) {
  .hero-text { max-width: 470px; }
  .hero-sub { font-size: 16.5px; max-width: 440px; }
  .hero-shade {
    background:
      linear-gradient(90deg,
        rgba(16,35,31,0.95) 0%,
        rgba(16,35,31,0.86) 34%,
        rgba(16,35,31,0.4) 50%,
        rgba(16,35,31,0) 62%),
      linear-gradient(to bottom, rgba(16,35,31,0) 72%, rgba(16,35,31,0.7) 100%);
  }
}

/* ── Short desktop screens (1366×768, 1280×720 and the like) ────────── */
/* The headline and buttons always stay above the fold; the panel's feed
   gives up height first. */
@media (min-width: 901px) and (max-height: 860px) {
  .hero-content { padding-top: 34px; padding-bottom: 36px; }
  .hero-eyebrow { margin-bottom: 12px; }
  .hero-h1 { font-size: clamp(36px, 3.3vw, 46px); margin-bottom: 18px; }
  .hero-sub { font-size: 16.5px; margin-bottom: 22px; }
  .hero-flags { bottom: 26px; }
}
@media (min-width: 901px) and (max-height: 740px) {
  .hero-content { padding-top: 26px; padding-bottom: 28px; }
  .hero-eyebrow { font-size: 14px; margin-bottom: 10px; }
  .hero-h1 { font-size: clamp(34px, 3vw, 42px); margin-bottom: 14px; }
  .hero-sub { font-size: 15.5px; line-height: 1.5; margin-bottom: 18px; }
  .hero-flags { bottom: 18px; }
  .flags-controls { margin-top: 6px; }
}

/* ── Stacked: pit on top, copy below ─────────────────────────────────── */
/* The canvas keeps a fixed height so the pit stays in view however tall
   the copy runs; the copy overlaps its faded lower edge. */
@media (max-width: 900px) {
  .hero {
    --pit-h: clamp(300px, 64vw, 470px);
    display: block;
    min-height: 0;
  }
  #pit-canvas,
  .pit-labels { height: var(--pit-h); }
  .hero-shade {
    background: linear-gradient(to bottom,
      rgba(16,35,31,0) calc(var(--pit-h) - 190px),
      rgba(16,35,31,0.82) calc(var(--pit-h) - 40px),
      var(--ink) var(--pit-h));
  }
  .hero-content {
    display: block;
    padding: calc(var(--pit-h) - 96px) var(--gutter-mobile) 52px;
  }
  .hero-text { max-width: 560px; }
  .hero-eyebrow { font-size: 14px; margin-bottom: 12px; }
  .hero-h1 { font-size: clamp(30px, 7vw, 46px); line-height: 1.06; margin-bottom: 18px; }
  .hero-sub { font-size: 15.5px; line-height: 1.6; margin-bottom: 24px; }
}

@media (max-width: 700px) {
  .hero-ctas {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .hero-ctas .btn-primary,
  .hero-ctas .hero-secondary { justify-content: center; }
}

@media (max-width: 900px) {
  .hero-flags {
    position: relative; left: auto; bottom: auto;
    width: auto; transform: none;
    margin: -20px var(--gutter-mobile) 0;
    padding-bottom: 44px;
  }
}
@media (max-width: 760px) {
  .flags-text { font-size: 14px; }
}

@media (max-width: 420px) {
  .hero { --pit-h: 330px; }
  .hero-h1 { font-size: clamp(28px, 8vw, 34px); }
  .hero-sub { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .hero-in { animation: none; opacity: 1; transform: none; }
  .hero-loader::before { animation: none; transform: translateX(90%); }
  .flags-line { transition: none; }
  .flags-dot { animation: none; }
}
