/* ==========================================================================
   MontanaBid home page hero map
   --------------------------------------------------------------------------
   Loaded only by views/index.ejs (like map.css). Script: public/js/hero-map.js.
   Static no-JS copy of the map: views/partials/heroMapSnapshot.ejs.
   Every class and id uses the "hm-" prefix so these rules never touch the rest
   of the site (for example Bootstrap's .card) and site rules stay outside.
   State classes inside the hero: .is-in (shown), .is-lit (a project just
   arrived), .is-hot (hover/focus), .is-out (fading out).
   Root classes set by the script on <html>: .hm-js (script will run),
   .hm-running (intro started), .hm-static (reduced motion or saved pause).
   ========================================================================== */

/* Design tokens, scoped to the hero. Brand values follow
   standards/css-design-guidelines.md; --bp-* are the blueprint palette. */
.hm-hero {
  /* Brand tokens (standards/css-design-guidelines.md) */
  --mb-primary: #aad267;
  --mb-primary-dark: #8cb44b;
  --mb-accent-blue: #4a78a8;
  --mb-accent-blue-dark: #345b85;
  --mb-text: #222831;
  --mb-text-muted: #5c6370;
  --mb-border: #dadfe3;
  --mb-page-bg: #f7f9fa;
  --mb-white: #ffffff;

  /* Blueprint palette */
  --bp-ink: #0b1d2e;
  --bp-ink-2: #12304a;
  --bp-grid: rgba(160, 200, 235, 0.07);
  --bp-grid-major: rgba(160, 200, 235, 0.13);
  --bp-stroke: #d6e8f7;
  --bp-muted: #7fa3c4;
  --bp-fill: rgba(74, 120, 168, 0.18);
  --bp-glow: rgba(170, 210, 103, 0.55);

  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  /* Families and weights already loaded by public/css/mtbid.css:
     Raleway 400/700/900 and Lato 400/500/900. */
  --display: "Raleway", "Lato", system-ui, sans-serif;
  --sans: "Lato", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* --hm-scroll (window scroll offset) is set on <html> by the script. */
}

/* ---------- Hero shell ---------- */

/* Sized to its content (no full-screen height) so the next section shows.
   scroll-margin-top keeps the navbar HOME link (/#headerwrap) from hiding
   the top of the hero under the 70px sticky navbar. */
.hm-hero {
  position: relative;
  scroll-margin-top: 70px;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, var(--bp-ink-2) 0%, var(--bp-ink) 70%);
  color: var(--mb-white);
  font-family: var(--sans);
  font-size: 16px;
}

/* mtbid.css styles every <p> (dark gray, 14px). Hero copy inherits instead. */
.hm-hero p {
  color: inherit;
  font-size: inherit;
  line-height: inherit;
}

.hm-hero-grid {
  position: absolute;
  inset: -40% 0 0;
  background-image:
    linear-gradient(var(--bp-grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--bp-grid-major) 1px, transparent 1px),
    linear-gradient(var(--bp-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bp-grid) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
  opacity: 0;
  transition: opacity 1.2s ease;
  transform: translate3d(0, calc(var(--hm-scroll, 0px) * 0.4), 0);
  will-change: transform;
}

.hm-running .hm-hero-grid,
.hm-static .hm-hero-grid {
  opacity: 1;
}

.hm-hero-inner {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 40px;
  text-align: center;
}

/* Title is drafted left to right in step with the state outline
   (same duration and easing as .hm-state), with a dimension-style rule. */
.hm-hero-title {
  display: inline-block;
  align-self: center; /* phone flex column: keep the rule as wide as the text */
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2rem, 4.4vw, 3.1rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.1;
}

.hm-title-text {
  display: inline-block;
  clip-path: inset(0 100% 0 0);
  transition: clip-path 1.6s cubic-bezier(0.65, 0, 0.35, 1);
}

.hm-title-accent {
  color: var(--mb-primary);
}

.hm-title-rule {
  position: relative;
  display: block;
  height: 2px;
  margin-top: 6px;
  background: var(--mb-primary);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 1.6s cubic-bezier(0.65, 0, 0.35, 1);
}

.hm-title-rule::before,
.hm-title-rule::after {
  content: "";
  position: absolute;
  top: -4px;
  width: 2px;
  height: 10px;
  background: var(--mb-primary);
}

.hm-title-rule::before {
  left: 0;
}

.hm-title-rule::after {
  right: 0;
}

.hm-running .hm-title-text,
.hm-static .hm-title-text {
  clip-path: inset(0 0 0 0);
}

.hm-running .hm-title-rule,
.hm-static .hm-title-rule {
  transform: scaleX(1);
}

/* No JavaScript: the title, grid, and the static map snapshot show in their
   finished state. With JavaScript, the snapshot stays hidden until the script
   rebuilds the map and animates it. */
html:not(.hm-js) .hm-title-text {
  clip-path: none;
}

html:not(.hm-js) .hm-title-rule {
  transform: none;
}

html:not(.hm-js) .hm-hero-grid {
  opacity: 1;
}

html:not(.hm-js) .hm-motion-toggle {
  display: none;
}

.hm-js [data-snapshot] {
  visibility: hidden;
}

/* ---------- Map stage ---------- */

.hm-stage {
  max-width: 1080px;
  margin: 0 auto;
}

/* Pause / play control for the ambient animation (WCAG 2.2.2) */
.hm-motion-toggle {
  display: block;
  margin: 2px 0 0 auto;
  padding: 6px 12px;
  border: 1px solid var(--bp-muted);
  border-radius: 999px;
  background: transparent;
  color: var(--bp-stroke);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}

.hm-motion-toggle:hover {
  border-color: var(--mb-primary);
  color: var(--mb-primary);
}

.hm-motion-toggle:focus-visible {
  outline: 2px solid var(--mb-primary);
  outline-offset: 2px;
}

.hm-map {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* Graticule and dimension line */
.hm-graticule line {
  stroke: var(--bp-muted);
  stroke-width: 0.6;
  stroke-dasharray: 2 5;
  opacity: 0;
  transition: opacity 1s ease;
}

.hm-graticule text,
.hm-dimension text,
.hm-city-label {
  font-family: var(--mono);
  fill: var(--bp-muted);
  letter-spacing: 0.12em;
}

.hm-graticule text {
  font-size: 9px;
  opacity: 0;
  transition: opacity 1s ease;
}

.hm-graticule.is-in line {
  opacity: 0.45;
}

.hm-graticule.is-in text {
  opacity: 0.8;
}

.hm-dimension path {
  fill: none;
  stroke: var(--bp-muted);
  stroke-width: 1;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 1s ease;
}

.hm-dimension text {
  font-size: 10px;
  opacity: 0;
  transition: opacity 0.6s ease 0.6s;
}

.hm-dimension.is-in path {
  stroke-dashoffset: 0;
}

.hm-dimension.is-in text {
  opacity: 1;
}

/* State outline: bold stroke over a faint wide glow line */
.hm-state-halo {
  fill: none;
  stroke: var(--bp-stroke);
  stroke-width: 12;
  stroke-opacity: 0.12;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 1.6s cubic-bezier(0.65, 0, 0.35, 1);
}

.hm-state-halo.is-in {
  stroke-dashoffset: 0;
}

.hm-state {
  fill: var(--bp-fill);
  fill-opacity: 0;
  stroke: var(--bp-stroke);
  stroke-width: 4;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition:
    stroke-dashoffset 1.6s cubic-bezier(0.65, 0, 0.35, 1),
    fill-opacity 1s ease 1.2s;
}

.hm-state.is-in {
  stroke-dashoffset: 0;
  fill-opacity: 1;
}

/* Reach lines: one project -> every exchange at the same moment */
.hm-reach {
  fill: none;
  stroke: var(--mb-primary);
  stroke-width: 1.25;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0.75;
  transition:
    stroke-dashoffset 0.7s cubic-bezier(0.65, 0, 0.35, 1),
    opacity 0.7s ease;
}

.hm-reach.is-in {
  stroke-dashoffset: 0;
}

.hm-reach.is-out {
  opacity: 0;
}

/* Project marker: a plan sheet that drops onto the town it will be built in */
.hm-project {
  transition: opacity 0.7s ease;
}

.hm-project.is-out {
  opacity: 0;
}

.hm-project-body {
  animation: hm-project-drop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes hm-project-drop {
  from {
    opacity: 0;
    transform: translateY(-18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hm-project-dot {
  fill: var(--mb-primary);
}

.hm-project-ping {
  fill: none;
  stroke: var(--mb-primary);
  stroke-width: 1.5;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  animation: hm-pulse 1s ease-out 0.3s 1;
}

.hm-project-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  fill: var(--bp-stroke);
}

/* Local contractors around a city; they light up when a project arrives */
.hm-contractor {
  fill: var(--bp-stroke);
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
}

.hm-contractors.is-lit .hm-contractor {
  animation: hm-contractor-ping 1.6s ease-out both;
}

@keyframes hm-contractor-ping {
  0% {
    opacity: 0;
    fill: var(--mb-primary);
    transform: scale(0.2);
  }
  25% {
    opacity: 1;
    fill: var(--mb-primary);
    transform: scale(1.3);
  }
  100% {
    opacity: 0;
    fill: var(--bp-stroke);
    transform: scale(1);
  }
}

/* Plan sheet drawing (used by the project marker) */
.hm-sheet-paper {
  fill: var(--bp-ink-2);
  stroke: var(--bp-stroke);
  stroke-width: 1.2;
  stroke-linejoin: round;
}

.hm-sheet-fold {
  fill: none;
  stroke: var(--bp-stroke);
  stroke-width: 1.2;
  stroke-linejoin: round;
}

.hm-sheet-accent,
.hm-sheet-line {
  fill: none;
  stroke-width: 1.2;
  stroke-linecap: round;
}

.hm-sheet-accent {
  stroke: var(--mb-primary);
}

.hm-sheet-line {
  stroke: var(--bp-muted);
}

/* Leader lines (pin -> logo card) */
.hm-leader {
  fill: none;
  stroke: var(--bp-muted);
  stroke-width: 1;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 0.6s ease, stroke 0.25s ease;
}

.hm-leader.is-in {
  stroke-dashoffset: 0;
}

/* Pins */
.hm-pin-body {
  opacity: 0;
  transform: translateY(-36px);
  transition:
    transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.3s ease;
}

.hm-pin.is-in .hm-pin-body {
  opacity: 1;
  transform: translateY(0);
}

.hm-pin-ring {
  fill: none;
  stroke: var(--bp-stroke);
  stroke-width: 1.25;
}

.hm-pin-cross {
  stroke: var(--bp-stroke);
  stroke-width: 1;
}

.hm-pin-dot {
  fill: var(--mb-primary);
  transition: r 0.25s ease;
}

.hm-pin-pulse {
  fill: none;
  stroke: var(--mb-primary);
  stroke-width: 2;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
}

.hm-pin.is-in .hm-pin-pulse {
  animation: hm-pulse 1.1s ease-out 0.35s 1;
}

/* Separate ring so a fire can restart it without replaying the intro */
.hm-pin-fire {
  fill: none;
  stroke: var(--mb-primary);
  stroke-width: 2;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
}

.hm-pin.is-lit .hm-pin-fire {
  animation: hm-pulse 0.8s ease-out 1;
}

@keyframes hm-pulse {
  from {
    opacity: 0.9;
    transform: scale(0.4);
  }
  to {
    opacity: 0;
    transform: scale(3.2);
  }
}

.hm-city-label {
  font-size: 10px;
  opacity: 0;
  transition: opacity 0.4s ease 0.3s, fill 0.25s ease;
}

.hm-pin.is-in .hm-city-label {
  opacity: 1;
}

/* Logo cards */
.hm-card-body {
  opacity: 0;
  transition:
    transform 0.6s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.45s ease;
}

.hm-card.hm-side-left .hm-card-body {
  transform: translateX(-40px);
}

.hm-card.hm-side-right .hm-card-body {
  transform: translateX(40px);
}

.hm-card.is-in .hm-card-body {
  opacity: 1;
  transform: translateX(0);
}

.hm-card-bg {
  fill: var(--mb-white);
  stroke: var(--bp-muted);
  stroke-width: 1;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35));
  transition: stroke 0.25s ease, stroke-width 0.25s ease;
}

.hm-card-name {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 500;
  fill: var(--mb-text-muted);
}

.hm-card a:focus {
  outline: none;
}

/* Exchange reached by a project pulse */
.hm-card.is-lit .hm-card-bg {
  animation: hm-card-lit 1.4s ease-out 1;
}

.hm-leader.is-lit {
  animation: hm-leader-lit 1.4s ease-out 1;
}

@keyframes hm-card-lit {
  0%,
  25% {
    stroke: var(--mb-primary);
    stroke-width: 3;
    filter: drop-shadow(0 0 12px var(--bp-glow));
  }
  100% {
    stroke: var(--bp-muted);
    stroke-width: 1;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35));
  }
}

@keyframes hm-leader-lit {
  0%,
  25% {
    stroke: var(--mb-primary);
    stroke-width: 2;
  }
  100% {
    stroke: var(--bp-muted);
    stroke-width: 1;
  }
}

/* Hover/focus highlight for one exchange */
.hm-leader.is-hot {
  stroke: var(--mb-primary);
}

.hm-card.is-hot .hm-card-bg {
  stroke: var(--mb-primary);
  stroke-width: 3;
}

.hm-pin.is-hot .hm-pin-dot {
  r: 8;
}

.hm-pin.is-hot .hm-city-label {
  fill: var(--mb-primary);
}

/* ---------- Phone logo strip (shown below 768px) ---------- */

.hm-logo-strip {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.hm-logo-strip li {
  opacity: 0;
  transform: translateY(12px);
  transition: transform 0.45s ease, opacity 0.45s ease;
}

.hm-logo-strip li.is-in {
  opacity: 1;
  transform: translateY(0);
}

.hm-logo-strip a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--mb-border);
  border-radius: 8px;
  background: var(--mb-white);
  color: var(--mb-text-muted);
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
}

.hm-logo-strip li.is-lit a {
  animation: hm-strip-lit 1.4s ease-out 1;
}

@keyframes hm-strip-lit {
  0%,
  25% {
    border-color: var(--mb-primary);
    box-shadow: 0 0 0 2px var(--mb-primary), 0 0 14px var(--bp-glow);
  }
  100% {
    border-color: var(--mb-border);
    box-shadow: none;
  }
}

.hm-logo-strip img {
  width: 100%;
  height: 34px;
  object-fit: contain;
}

/* ---------- Hero copy ---------- */

.hm-hero-copy {
  margin-top: 8px;
}

.hm-tagline {
  margin: 0 0 8px;
  color: var(--mb-primary);
  font-family: var(--display);
  font-size: clamp(1.15rem, 2.2vw, 1.5rem);
  font-weight: 700;
}

.hm-lede {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1rem, 1.8vw, 1.25rem);
  font-weight: 700;
  line-height: 1.45;
}

.hm-count {
  margin: 6px 0 18px;
  font-family: var(--display);
  font-size: clamp(1rem, 1.8vw, 1.25rem);
  font-weight: 700;
}

.hm-count-num {
  color: var(--mb-primary);
  font-variant-numeric: tabular-nums;
}

/* mtbid.css colors a:link / a:visited dark gray; those outrank one class,
   so the button names its link states. */
.hm-upload,
.hm-upload:link,
.hm-upload:visited {
  display: inline-block;
  padding: 12px 20px;
  border: 2px solid var(--mb-white);
  border-radius: 6px;
  color: var(--mb-white);
  font-size: 1.05rem;
  text-decoration: none;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.hm-upload:hover,
.hm-upload:focus-visible {
  background: var(--mb-primary);
  border-color: var(--mb-primary);
  color: var(--bp-ink);
}

.hm-help-links {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 20px 0 0;
  font-size: 0.9rem;
}

.hm-help-links a {
  color: var(--mb-white);
  text-decoration: none;
}

.hm-help-links a:hover {
  text-decoration: underline;
}

/* ---------- Phone ---------- */

@media (max-width: 767.98px) {
  .hm-map .hm-card,
  .hm-map .hm-leader,
  .hm-map .hm-city-label,
  .hm-map .hm-project-label,
  .hm-map .hm-dimension {
    display: none;
  }

  /* Keep the Upload button above the logos on phones. */
  .hm-hero-inner {
    display: flex;
    flex-direction: column;
  }

  .hm-hero-copy {
    order: 1;
  }

  /* Logos only, in two centered rows (4 + 3) with no sideways scrolling.
     Exchange names stay in the links for screen readers and tooltips. */
  .hm-logo-strip {
    display: flex;
    order: 2;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 28px;
  }

  .hm-logo-strip li {
    flex: 0 0 calc((100% - 3 * 8px) / 4);
    min-width: 0;
  }

  .hm-logo-strip a {
    height: 100%;
    justify-content: center;
    padding: 6px;
  }

  .hm-logo-strip img {
    height: 38px;
  }

  .hm-logo-strip span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* The phone viewBox scales the map down; keep the outline bold. */
  .hm-state {
    stroke-width: 6;
  }

  .hm-state-halo {
    stroke-width: 16;
  }

  .hm-lede br {
    display: none;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .hm-hero *,
  .hm-hero *::before,
  .hm-hero *::after {
    transition: none !important;
    animation: none !important;
  }

  .hm-hero-grid {
    transform: none;
  }
}
