/* UTANA hero. Uses the tokens in css/base.css. Link it after base.css. */

.hero {
  /* Stage size. 100svh with a 640px floor. */
  --hh: max(100vh, 640px);
  --pad-x: var(--gutter);
  --pad-t: max(var(--gutter), 20px);
  --pad-b: max(var(--gutter), 20px);
  /* Dark base under the photo. The wordmark and cue live in it, so it must be
     tall enough to keep them clear of the lone figure on short screens. */
  --strip-h: max(calc(var(--hh) * 0.1), calc((var(--pad-b) + 90px - var(--hh) * 0.059) / 0.941));
  --hb: calc(var(--hh) - var(--strip-h)); /* photo height */
  /* One geometry unit in px. The SVG viewBox is 1600 x 900 units, the star radius is 285.
     Follows the photo height. Shrinks only when the screen is too short for the full star
     between the nav and the figure's head. */
  --k: min(var(--hb) / 810, (var(--hb) * 0.844 - 22px - var(--pad-t) - 46px) / 570, 100vw / 800);
  /* Where the photo starts to melt into the base (share of the photo height). */
  --melt: 90%;
  /* Star centre from the top of the stage. The top node sits on the arch apex,
     but never closer than 46px under the nav. */
  --cy: max(calc(var(--hb) * 0.1037 + 277 * var(--k)), calc(var(--pad-t) + 46px + 285 * var(--k)));
  --fade: 12%;
  --cols: 14.5;
  --hfs: clamp(var(--fs-xs), calc(12.5 * var(--k)), calc(var(--fs-sm) + 1px));

  position: relative;
  isolation: isolate;
  overflow: hidden;
  height: var(--hh);
  background: var(--ink);
  color: var(--paper);
  font-size: var(--hfs);
  line-height: 1.6;
  letter-spacing: var(--track);
  text-transform: uppercase;
}

@supports (height: 100svh) {
  .hero { --hh: max(100svh, 640px); }
}

/* ---------- Photo ---------- */

.hero__bg {
  position: absolute;
  inset: 0 0 var(--strip-h) 0;
  z-index: 0;
  overflow: hidden;
  /* The photo melts into the dark base under it. */
  -webkit-mask-image: linear-gradient(180deg, #000 0, #000 var(--melt), transparent 100%);
  mask-image: linear-gradient(180deg, #000 0, #000 var(--melt), transparent 100%);
  animation: hero-bg 2.6s var(--ease) both;
}

/* The photo is sized by height so the arch and the figure never get cropped.
   On wide screens a blurred copy fills the sides, so there is no visible edge. */
.hero__bg::before {
  content: "";
  position: absolute;
  inset: -60px;
  background: url("../assets/hero.jpg") 50% 50% / cover no-repeat;
  filter: blur(40px) brightness(0.82);
}

.hero__bg img {
  position: absolute;
  top: 0;
  left: 50%;
  height: 100%;
  width: auto;
  max-width: none;
  translate: -50% 0;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12%, #000 88%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 12%, #000 88%, transparent 100%);
}

.hero__tint {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: rgba(64, 80, 90, 0.2);
  mix-blend-mode: multiply;
}

.hero__shade {
  position: absolute;
  inset: 0;
  z-index: 2;
  background:
    linear-gradient(180deg, rgba(10, 13, 15, 0.55) 0, rgba(10, 13, 15, 0) 26%),
    radial-gradient(105% 85% at 50% 46%, rgba(10, 13, 15, 0) 45%, rgba(10, 13, 15, 0.42) 100%);
}

/* ---------- Geometry ---------- */

.hero__geo {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 var(--fade), #000 calc(100% - var(--fade)), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 var(--fade), #000 calc(100% - var(--fade)), transparent 100%);
}

.hero__svg {
  --u: 1; /* viewBox units per CSS px, hero.js keeps it exact */
  position: absolute;
  left: 50%;
  top: var(--cy);
  width: calc(1600 * var(--k));
  height: auto;
  max-width: none;
  aspect-ratio: 16 / 9;
  overflow: visible;
  translate: calc(-50% + var(--px, 0px)) calc(-50% + var(--py, 0px));
}

.hero__svg .draw {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  shape-rendering: geometricPrecision;
}
.hero__svg .draw.soft { stroke-opacity: 0.6; }

.hero__svg .nd {
  fill: var(--paper);
  transform: rotate(45deg) scale(var(--u));
  transform-origin: 0 0;
}

.hero__star {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: hero-spin 240s linear 3.2s infinite;
}

/* ---------- Text frame ---------- */

.hero__frame {
  position: absolute;
  inset: 0;
  z-index: 4;
  padding: var(--pad-t) var(--pad-x) var(--pad-b);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto 1fr auto;
  pointer-events: none;
  text-shadow: 0 0 16px rgba(8, 11, 13, 0.35);
}
.hero__frame a { pointer-events: auto; }

.hero__nav {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  gap: clamp(16px, 3.4vw, 56px);
  white-space: nowrap;
}
.hero__nav a { padding-bottom: 3px; pointer-events: auto; }

/* Corner blocks. Fixed width, hand set line breaks, every line justified. */
.hero__corner {
  margin: 0;
  width: calc(var(--cols) * (1ch + var(--track)));
}
.hero__corner .ln {
  display: block;
  text-align: justify;
  text-align-last: justify;
  white-space: nowrap;
}
.hero__corner .ln:last-child { text-align-last: left; }

.hero__corner a {
  background-image: linear-gradient(var(--line), var(--line));
  background-size: 100% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
}
.hero__corner a:hover,
.hero__corner a:focus-visible { background-image: linear-gradient(currentColor, currentColor); }

.hero__corner--tl { grid-column: 1; grid-row: 1; justify-self: start; }
.hero__corner--tr { grid-column: 3; grid-row: 1; justify-self: end; }
.hero__corner--bl { grid-column: 1; grid-row: 3; justify-self: start; align-self: end; }
.hero__corner--br { grid-column: 3; grid-row: 3; justify-self: end; align-self: end; }

/* Manifesto sits inside the star, on the dark upper part of the arch opening. */
.hero__manifesto {
  position: absolute;
  isolation: isolate;
  --mw: calc(22.5 * (1ch + var(--track)));
  width: var(--mw);
  left: calc(50% - var(--mw) / 2 + 10px);
  top: calc(var(--cy) - 128 * var(--k));
}
.hero__manifesto p { margin: 0 0 1.4em; text-align: left; }
.hero__manifesto p:last-child { margin-bottom: 0; }
.hero__manifesto::before {
  content: "";
  position: absolute;
  inset: -30px -40px;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(10, 13, 15, 0.4), rgba(10, 13, 15, 0));
  filter: blur(6px);
}

/* Wordmark and scroll cue, bottom centre. */
.hero__foot {
  grid-column: 2;
  grid-row: 3;
  align-self: end;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.hero__mark {
  margin: 0;
  font-size: clamp(var(--fs-md), calc(15 * var(--k)), 18px);
  font-weight: 500;
  line-height: 1;
  letter-spacing: var(--track-wide);
  padding-left: var(--track-wide); /* balances the trailing letter space */
  white-space: nowrap;
}

.hero__cue {
  position: relative;
  display: block;
  width: 24px;
  height: 34px;
  pointer-events: auto;
  --node: 6px;
}
.hero__cue::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--line-soft);
  translate: -0.5px 0;
}
.hero__cue .node {
  position: absolute;
  left: calc(50% - var(--node) / 2);
  top: 0;
  animation: hero-cue 3.4s cubic-bezier(0.55, 0, 0.25, 1) infinite both;
}

/* ---------- Motion ---------- */

.hero [data-rise] {
  animation: hero-rise 1.3s var(--ease) both;
  animation-delay: var(--d, 0s);
}

@keyframes hero-bg {
  from { opacity: 0; scale: 1.05; }
}
@keyframes hero-rise {
  from { opacity: 0; translate: 0 14px; }
}
@keyframes hero-spin {
  to { transform: rotate(360deg); }
}
@keyframes hero-draw {
  to { stroke-dashoffset: 0; }
}
@keyframes hero-pop {
  from { opacity: 0; scale: 0; }
}
@keyframes hero-show {
  to { opacity: 1; }
}
@keyframes hero-cue {
  0%   { translate: 0 0; opacity: 0; }
  18%  { opacity: 1; }
  70%  { opacity: 1; }
  100% { translate: 0 calc(34px - var(--node)); opacity: 0; }
}

/* Lines and nodes start hidden only when JS can run and motion is allowed.
   hero.js adds .is-live (draw-in) and .is-done (clean final state).
   If the script never runs, the fail-safe below reveals everything after 6s. */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
  .hero:not(.is-live) .draw,
  .hero:not(.is-live) .nd {
    opacity: 0;
    animation: hero-show 0.01s linear 6s forwards;
  }

  .hero.is-live .draw {
    stroke-dasharray: var(--len);
    stroke-dashoffset: var(--len);
    animation: hero-draw 2.1s var(--ease) both;
    animation-delay: calc(0.25s + var(--i, 0) * 0.07s);
  }

  .hero.is-live .nd {
    animation: hero-pop 0.8s var(--ease) both;
    animation-delay: calc(2.3s + var(--i, 0) * 0.09s);
  }

  .hero.is-done .draw {
    stroke-dasharray: none;
    stroke-dashoffset: 0;
    animation: none;
  }
  .hero.is-done .nd { animation: none; }
}

/* Pause the loops while the hero is off screen. */
.hero.is-away .hero__star,
.hero.is-away .hero__cue .node { animation-play-state: paused; }

/* ---------- Portrait and phones ---------- */

@media (max-width: 699px), (max-aspect-ratio: 1/1) {
  .hero__bg::before { background-image: url("../assets/hero-mobile.jpg"); }

  .hero {
    --strip-h: calc(var(--hh) * 0.07);
    --melt: 78%;
    --fade: 7%;
    /* On portrait the arch size follows the photo height, so the star does too. */
    --k: calc(var(--hb) * 0.00064);
    --cy: calc(var(--hb) * 0.295 + 277 * var(--k));
    --pad-t: 20px;
    --pad-b: 20px;
  }

  .hero__frame {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto 1fr auto auto;
  }

  .hero__nav {
    grid-column: 1 / -1;
    grid-row: 1;
    justify-self: center;
    gap: 16px;
  }

  .hero__corner--tl { grid-column: 1; grid-row: 2; margin-top: 30px; }
  .hero__corner--tr { grid-column: 2; grid-row: 2; margin-top: 30px; }

  .hero__manifesto {
    position: relative;
    left: auto;
    top: auto;
    grid-column: 1;
    grid-row: 4;
    align-self: end;
  }

  .hero__corner--bl { display: none; }
  .hero__corner--br { grid-column: 2; grid-row: 4; align-self: end; }

  .hero__foot {
    grid-column: 1 / -1;
    grid-row: 5;
    margin-top: 28px;
  }
}

@media (max-width: 699px) {
  .hero__bg::before { display: none; }
}

@media (max-width: 399px) {
  .hero__nav { gap: 13px; }
}

/* ---------- Reduced motion: final state, nothing moves ---------- */

@media (prefers-reduced-motion: reduce) {
  .hero__star { animation: none; }
}
