/* Kairos v2 hero: a hand holding the glass orb, light mode.
   Layout and timing are measured from the Auracore hero (Bogdan Qclay) at 1436 x 807; see the PR for the spec.
   Everything here is scoped to #hero; the theme comes from the page's tokens in site.css. */

@scope (#hero) {
  /* The page's tokens under the names this section was measured with. */
  :scope {
    --mono: var(--sans);
    --radius: 3px;
    --hand-ink: color-mix(in oklab, var(--accent) 40%, var(--ink));
  }

  svg {
    width: 12px;
    height: 12px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.4;
    stroke-linecap: square;
    flex: none;
  }

  /* ---------- The voice button: an icon tile inside the filled button ---------- */

  .actions .btn-fill {
    padding-left: 5px;
  }

  .btn-ico {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 2px;
    background: var(--accent-deep);
  }

  .btn-fill[aria-pressed="true"] .btn-ico svg {
    rotate: 45deg;
  }

  .btn-ico svg {
    transition: rotate 200ms var(--ease-out);
  }

  /* ---------- Hero stage ---------- */

  :scope {
    position: relative;
    height: 100svh;
    min-height: 640px;
    overflow: hidden;
    isolation: isolate;
    /* Deepest under the hand, back to the page's ground at the bottom edge, so the next section meets it without a seam. */
    background:
      radial-gradient(ellipse 60% 70% at 52% 40%, rgb(255 255 255 / 0.9), transparent 70%),
      linear-gradient(180deg, var(--ground) 0%, var(--ground-deep) 62%, var(--ground) 100%);
  }

  .stage {
    position: absolute;
    inset: 0;
    z-index: 0;
    /* The forearm fades into the ground before the section ends, so the hand is never cut by its edge. */
    -webkit-mask: linear-gradient(to bottom, #000 82%, transparent);
    mask: linear-gradient(to bottom, #000 82%, transparent);
    /* Orb diameter and centre. The Auracore orb is 46% of the frame's height, centred at 51% / 45%. */
    --d: min(46svh, 34vw);
    --orb-x: 51%;
    --orb-y: 45%;
  }

  /* The rig is the hand photo's own box: 2269 x 1477 px, sphere centre at 1616.7 / 421.9, radius 414. */
  .rig {
    --rig-w: calc(var(--d) * 2.7403);
    --rig-h: calc(var(--d) * 1.7838);
    position: absolute;
    left: calc(var(--orb-x) - var(--rig-w) * 0.7125);
    top: calc(var(--orb-y) - var(--rig-h) * 0.28565);
    width: var(--rig-w);
    height: var(--rig-h);
    transform-origin: 71.25% 28.565%;
  }

  .orb-slot {
    position: absolute;
    left: 53.006%;
    top: 0.535%;
    width: var(--d);
    height: var(--d);
    animation: hero-orb-in 560ms var(--ease-out) 200ms both;
  }

  .orb-slot .orb-motion {
    --orb-diameter: var(--d);
  }

  .orb-slot .orb-chrome {
    opacity: 0.6;
  }

  .orb-fallback {
    transition: opacity 300ms ease;
  }

  .orb-slot .orb-fallback {
    background:
      radial-gradient(circle at 31% 25%, rgb(255 255 255 / 0.9) 0 1.2%, rgb(255 255 255 / 0.22) 3.5%, transparent 9%),
      radial-gradient(circle at 62% 38%, rgb(255 255 255 / 0.85) 0 0.4%, transparent 0.9%),
      radial-gradient(circle at 44% 64%, rgb(255 255 255 / 0.7) 0 0.35%, transparent 0.8%),
      radial-gradient(ellipse 38% 26% at 58% 68%, color-mix(in oklab, var(--accent-light) 38%, transparent), transparent 70%),
      radial-gradient(circle, #0f1011 0 64%, #232527 88%, color-mix(in oklab, var(--accent-light) 35%, #232527) 100%);
  }

  /* The hand is drawn by field.js as a grid of cells in a canvas over the orb. Without WebGL the
     photo itself stands in, tinted by the theme: ink where it is dark, the ground where it is bright. */
  .field {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
  }

  :scope:not(.programmed) .field {
    display: none;
  }

  /* The still hand shows only without script or when the programmed one cannot draw, so with script
     the photo is fetched once, by hero.js, and never also as a mask and a background. */
  .hand-still {
    display: none;
    position: absolute;
    inset: 0;
    pointer-events: none;
  }

  :scope.hand-fallback .hand-still {
    display: block;
  }

  @media (scripting: none) {
    .hand-still {
      display: block;
    }
  }

  .hand-still span {
    position: absolute;
    inset: 0;
  }

  .hand-still .hand-base {
    background: var(--hand-ink);
    -webkit-mask: url("hand-photo.webp") 0 0 / 100% 100% no-repeat;
    mask: url("hand-photo.webp") 0 0 / 100% 100% no-repeat;
  }

  .hand-still .hand-photo {
    background: url("hand-photo.webp") 0 0 / 100% 100% no-repeat;
    mix-blend-mode: screen;
  }

  /* ---------- Headline ---------- */

  .copy {
    position: absolute;
    left: var(--gutter);
    bottom: clamp(24px, 5.6svh, 56px);
    z-index: 2;
  }

  .status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 clamp(18px, 4.2svh, 40px);
    font: 500 11px/1 var(--mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink);
    animation: hero-fade 500ms var(--ease-out) 700ms both;
  }

  .status-glyph {
    display: inline-flex;
    align-items: center;
    gap: 2px;
  }

  .status-glyph i {
    width: 10px;
    height: 9px;
    background: var(--accent);
  }

  .status-glyph i + i {
    width: 4px;
  }

  .status-glyph b {
    margin-left: 3px;
    font-weight: 500;
  }

  :scope[data-orb-state="listening"] .status-glyph i + i,
  :scope[data-orb-state="thinking"] .status-glyph i + i {
    animation: hero-blink 900ms steps(2, jump-none) infinite;
  }

  h1 {
    margin: 0;
    font-size: min(6.1vw, 10.8svh, 6rem);
    font-weight: 400;
    line-height: 1.02;
    letter-spacing: -0.04em;
  }

  h1 .line {
    display: block;
    overflow: clip;
    padding-bottom: 0.06em;
    margin-bottom: -0.06em;
  }

  h1 .line > span {
    display: block;
    animation: hero-line-in 760ms var(--ease-out) both;
  }

  h1 .line:nth-child(1) > span { animation-delay: 760ms; }
  h1 .line:nth-child(2) > span { animation-delay: 860ms; }
  h1 .line:nth-child(3) > span { animation-delay: 950ms; }

  /* ---------- Right column ---------- */

  .side {
    position: absolute;
    left: 68.5%;
    bottom: clamp(24px, 5.6svh, 56px);
    z-index: 2;
    width: min(27.5vw, 400px);
    display: grid;
    gap: 14px;
  }

  .side > * {
    animation: hero-rise 560ms var(--ease-out) both;
  }

  .side > .orbs { animation-delay: 1250ms; }
  .side > .lede { animation-delay: 1300ms; }
  .side > .composer { animation-delay: 1380ms; }
  .side > .actions { animation-delay: 1440ms; }
  .side > .note { animation-delay: 1500ms; animation-name: hero-fade; }

  .orbs {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 6px;
  }

  .orbs-label {
    margin-right: 8px;
    font: 500 11px/1 var(--mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-soft);
  }

  .orbs button {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 30px;
    border: 0;
    border-radius: 2px;
    background: none;
    color: var(--ink-soft);
    font: 550 11px/1 var(--sans);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background-color 160ms ease, color 160ms ease, transform 120ms var(--ease-out);
    padding: 0 8px 0 5px;
  }

  .orbs button[aria-checked="true"] {
    background: rgb(255 255 255 / 0.85);
    color: var(--ink);
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.08), inset 0 0 0 1px var(--line);
  }

  .orbs button:active {
    transform: scale(0.97);
  }

  @media (hover: hover) and (pointer: fine) {
    .orbs button:hover { color: var(--ink); }
  }

  .chip {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.12), 0 1px 2px rgb(0 0 0 / 0.18);
  }

  .chip-obsidian {
    background:
      radial-gradient(circle at 34% 30%, rgb(255 255 255 / 0.85) 0 5%, transparent 20%),
      radial-gradient(ellipse 30% 55% at 66% 28%, color-mix(in oklab, var(--accent-light) 70%, transparent), transparent),
      radial-gradient(circle, #131415 62%, #36383b);
  }

  .chip-nebula {
    background:
      radial-gradient(circle at 34% 30%, rgb(255 255 255 / 0.8) 0 5%, transparent 20%),
      radial-gradient(ellipse at 60% 62%, var(--accent-light), transparent 42%),
      radial-gradient(ellipse at 36% 60%, var(--glow-color), transparent 40%),
      radial-gradient(circle, #111213 55%, #26282a);
  }

  .chip-halo {
    background:
      radial-gradient(circle at 34% 30%, rgb(255 255 255 / 0.85) 0 5%, transparent 20%),
      radial-gradient(circle at 50% 50%, transparent 38%, #fff 44%, var(--accent-light) 50%, transparent 60%),
      radial-gradient(circle, #101112 60%, #2a2b2d);
  }

  .lede {
    margin: 0;
    font-size: clamp(15px, 1.18vw, 17px);
    line-height: 1.6;
    letter-spacing: -0.005em;
    text-wrap: pretty;
  }

  .composer {
    display: flex;
    height: 42px;
    border-radius: var(--radius);
    background: rgb(255 255 255 / 0.7);
    box-shadow: inset 0 0 0 1px var(--line);
    transition: box-shadow 160ms ease;
  }

  .composer:focus-within {
    box-shadow: inset 0 0 0 1.5px var(--accent);
  }

  .composer input {
    flex: 1;
    min-width: 0;
    padding: 0 14px;
    border: 0;
    background: none;
    color: var(--ink);
    font: 400 15px/1 var(--sans);
    caret-color: var(--accent);
  }

  .composer input::placeholder {
    color: var(--ink-soft);
  }

  .composer input:focus {
    outline: none;
  }

  .composer button {
    display: grid;
    place-items: center;
    width: 42px;
    border: 0;
    border-left: 1px solid var(--line);
    background: none;
    color: var(--ink);
    cursor: pointer;
    transition: color 160ms ease, transform 120ms ease-out;
  }

  .composer button:active {
    transform: scale(0.94);
  }

  .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }

  .note {
    margin: 0;
    text-wrap: pretty;
    font-size: 12px;
    line-height: 1.5;
    color: var(--ink-soft);
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 1ms !important;
      animation-delay: 0ms !important;
      animation-iteration-count: 1 !important;
    }
  }

  /* ---------- Smaller screens ---------- */

  @media (max-width: 1080px) {
    .side { left: auto; right: var(--gutter); width: min(36vw, 360px); }
  }

  /* Phones and portrait screens: the hand and orb above, the words below. */
  @media (max-width: 760px), (max-aspect-ratio: 1/1) {
    :scope {
      height: auto;
      min-height: 0;
      display: flex;
      flex-direction: column;
    }

    .stage {
      position: relative;
      height: min(62svh, 120vw);
      -webkit-mask: linear-gradient(to bottom, #000 80%, transparent);
      mask: linear-gradient(to bottom, #000 80%, transparent);
      --d: min(52vw, 36svh);
      --orb-x: 58%;
      --orb-y: 46%;
    }

    .copy,
    .side {
      position: static;
      width: auto;
      padding: 0 var(--gutter);
    }

    .copy { margin-top: -12px; }
    .side { max-width: 560px; padding-top: 28px; padding-bottom: 40px; }

    h1 { font-size: clamp(2.4rem, 11vw, 4.5rem); }
  }
}

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

@keyframes hero-fade {
  from { opacity: 0; }
}

@keyframes hero-rise {
  from { opacity: 0; transform: translateY(10px); }
}

@keyframes hero-pill-in {
  from { opacity: 0; transform: scaleX(0.6); }
}

@keyframes hero-line-in {
  from { transform: translateY(105%); }
}

@keyframes hero-orb-in {
  from { opacity: 0; transform: translateY(calc(var(--d) * 1.25)) scale(0.94); }
  30% { opacity: 1; }
}

@keyframes hero-blink {
  50% { opacity: 0.25; }
}
