/* ==========================================================================
   capabilities.css — the eight capability chapters.

   ONE IDEA: a sticky index that stays with the reader, and eight short
   chapters that each say a promise (the h2), the situations it answers and its
   scope. The hero is dark and full screen: the headline rises, the eight disciplines
   appear as links and light up in threes for example problems
   (js/cap-hero.js); the index carries a blue
   marker that follows the active chapter (js/page-capabilities.js). Nothing
   else moves.

   Structure:
     <div class="shell-wide cap-layout">
       <nav class="cap-layout__index">…</nav>          (stretches; inner sticks)
       <div class="cap-layout__chapters">
         <section class="cap-chapter" data-cap-chapter>
           <div class="cap-chapter__inner">
             <div class="cap-chapter__copy">kicker + h2</div>
             <div class="cap-chapter__detail">situations list + scope list</div>
           </div>
         </section>
       </div>
     </div>

   Sticky relies on the grid items STRETCHING to the row height: the sticky
   element lives inside the stretched item, never on the item itself. Below
   1024px the index becomes a sticky chip rail and the chapters stack.
   ========================================================================== */

.cap-layout {
  display: grid;
  /* The left index column is 264px, not 220px: +20% on the original width.
     Why: the index now lists NINE capabilities instead of six, and three of the
     new labels are long ("Product & Experience Design", "Brand, Creative &
     Communications"). At 220px those wrapped badly and the column read as a
     paragraph rather than an index. 220 x 1.20 = 264 is the brief's stated
     principle, applied to the column itself rather than as a viewport unit, and
     the content column stays `1fr` so the rebalance is automatic at every
     width. */
  grid-template-columns: minmax(0, 264px) minmax(0, 1fr);
  gap: clamp(32px, 5vw, 88px);
}

/* The index still shares 264px with a 2rem number bubble, the arrow and two
   gaps. Measured on the longest label ("Product & Experience Design"): it needs
   183px to break over two lines and the column was giving it 172px — an 11px
   shortfall that pushed it to three lines. The brief asks to "rebalance the
   content/gap appropriately" precisely for this, so the gaps tighten from
   --space-4 (16px) to 12px: the chrome drops from 92px to 84px and the name
   gains 8px, which with the tighter tracking below clears the requirement at
   1440 and above. The label still reads in two lines on a 1280 viewport and
   one line on the short labels at every width.

   `overflow-wrap: break-word` is the guard: if a future label is longer still,
   it breaks at the space rather than overflowing the column, and `hyphens: none`
   keeps it from inserting hyphenation the brand voice does not use. */
.cap-layout__index .p-index__link {
  gap: 12px;
}

.cap-layout__index .p-index__name {
  overflow-wrap: break-word;
  hyphens: none;
  /* The compact size used to cap at 1.25rem, which is a viewport-independent
     ceiling — so a 1920 screen rendered the label larger than a 1440 screen did
     and the longest one spilled to a third line while 1440 was fine. Lowering
     the cap to 1.2rem keeps every width on the same measured size (the one that
     already fits in two lines at 1440) and the difference is 0.8px at the top
     end, well inside the type scale's own steps. */
  font-size: clamp(1rem, 1.35vw, 1.2rem);
}

.cap-layout__index-inner {
  position: sticky;
  top: calc(var(--header-h) + 40px);
}

.cap-layout__index-label {
  display: block;
  margin-bottom: var(--space-6);
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gray-500);
}

/* The hero: dark and full screen. Everything is a CSS animation with a
   backwards fill, so the finished page is the default state. */
.cap-hero {
  display: grid;
  align-items: center;
  min-height: calc(100vh - var(--header-h));
  min-height: calc(100svh - var(--header-h));
  padding-block: clamp(40px, 8svh, 96px);
  overflow: hidden;
  background-color: var(--brand-ink);
  color: var(--white);
}

.cap-hero__inner {
  display: grid;
  justify-items: center;
  text-align: center;
}

.cap-hero__eyebrow {
  margin: 0 0 var(--space-4);
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--blue-300);
  animation: cap-fade 700ms var(--ease-standard) backwards;
}

.cap-hero__title {
  font-size: clamp(2.5rem, 0.5rem + 5.4vw, 6.75rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.045em;
  color: var(--white);
}

.cap-hero__w {
  display: inline-block;
  overflow: hidden;
  padding-bottom: 0.1em;
  vertical-align: bottom;
}

.cap-hero__w > span {
  display: inline-block;
  animation: cap-rise 900ms var(--ease-standard) calc(250ms + var(--i, 0) * 90ms) backwards;
}

.cap-hero__support {
  max-width: 40ch;
  margin-top: clamp(20px, 4svh, 40px);
  font-size: clamp(1.0625rem, 0.95rem + 0.45vw, 1.3125rem);
  line-height: 1.5;
  color: var(--gray-300);
  animation: cap-fade 800ms var(--ease-standard) 900ms backwards;
}

/* The eight disciplines: links to their chapters. */
.cap-hero__field {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
  max-width: 62rem;
  margin: clamp(24px, 5svh, 48px) 0 0;
  padding: 0;
  list-style: none;
}

.cap-hero__field li {
  animation: cap-fade 700ms var(--ease-standard) calc(1100ms + var(--i, 0) * 90ms) backwards;
}

.cap-hero__pill {
  display: inline-block;
  padding: 0.65em 1.2em;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  font-size: clamp(0.9375rem, 0.85rem + 0.4vw, 1.25rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--white);
  text-decoration: none;
  transition:
    background-color 500ms var(--ease-standard),
    border-color 500ms var(--ease-standard),
    transform 500ms var(--ease-standard);
}

.cap-hero__pill:hover,
.cap-hero__pill:focus-visible,
.cap-hero__pill.is-lit {
  border-color: var(--kuneo-blue);
  background-color: var(--kuneo-blue);
}

.cap-hero__pill.is-lit {
  transform: translate3d(0, -3px, 0);
}

/* The example the three lit disciplines answer. It keeps its height while
   empty, so nothing shifts when it changes. */
.cap-hero__example {
  min-height: 1.6em;
  margin-top: var(--space-4);
  font-size: var(--fs-small);
  color: var(--gray-300);
  transition: opacity 400ms var(--ease-standard);
}

.cap-hero__example.is-out {
  opacity: 0;
}

.cap-hero__actions {
  margin-top: clamp(20px, 4svh, 40px);
  animation: cap-fade 800ms var(--ease-standard) 2000ms backwards;
}

/* Phones: smaller pills so the eight wrap two or three to a row and the hero
   stays close to one screen. */
@media (max-width: 599px) {
  .cap-hero__field {
    gap: 8px;
  }

  .cap-hero__pill {
    padding: 0.5em 0.85em;
    font-size: 0.8125rem;
  }
}

@keyframes cap-rise {
  from {
    transform: translate3d(0, 110%, 0);
  }
}

@keyframes cap-fade {
  from {
    opacity: 0;
    transform: translate3d(0, 12px, 0);
  }
}

/* The delivery line is said once, here. */
.cap-strip {
  padding-block: var(--space-6);
}

.cap-strip__text {
  font-size: var(--fs-small);
  color: var(--gray-600);
}

.cap-strip__link {
  font-weight: 600;
  color: var(--brand-ink);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* Chapters are separated by a hairline with a short blue segment. */
.cap-chapter {
  position: relative;
  border-top: 1px solid var(--gray-200);
  padding-block: clamp(48px, 8svh, 96px);
}

.cap-chapter::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 0;
  width: 48px;
  height: 2px;
  background-color: var(--kuneo-blue);
}

.cap-chapter:first-child {
  padding-top: clamp(32px, 5svh, 56px);
}

.cap-chapter:last-child {
  padding-bottom: 0;
}

.cap-chapter__inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(32px, 5vw, 80px);
  align-items: start;
}

.cap-chapter__copy {
  display: grid;
  gap: var(--space-4);
  align-content: start;
}

.cap-chapter__title {
  font-size: clamp(1.75rem, min(3.4vw, 5.5svh), 3.25rem);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.035em;
  max-width: 20ch;
}

.cap-chapter__kicker {
  display: block;
  font-size: var(--fs-label);
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gray-500);
}

.cap-chapter__num {
  color: var(--kuneo-blue);
  margin-right: var(--space-3);
}

.cap-chapter__when {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--space-3);
}

.cap-chapter__when li {
  position: relative;
  padding-left: var(--space-4);
  color: var(--gray-600);
}

.cap-chapter__when li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.62em;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--kuneo-blue);
}

/* The scope is a real list, set as plain items with room between them. */
.cap-chapter__scope {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) 20px;
  list-style: none;
  margin: 20px 0 0;
  padding: var(--space-4) 0 0;
  border-top: 1px solid var(--gray-200);
  font-size: var(--fs-small);
  color: var(--gray-600);
  letter-spacing: 0.01em;
}

@media (max-width: 1023px) {
  .cap-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .cap-chapter__inner {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Desktop index: a rail on the left with a blue marker that slides to the
   active row (positions come from js/page-capabilities.js). */
@media (min-width: 1024px) {
  .cap-layout__index .p-index__list {
    position: relative;
    padding-left: 16px;
  }

  .cap-layout__index .p-index__list::before,
  .cap-layout__index .p-index__list::after {
    content: "";
    position: absolute;
    left: 0;
    width: 2px;
  }

  .cap-layout__index .p-index__list::before {
    top: 0;
    bottom: 0;
    background-color: var(--gray-200);
  }

  .cap-layout__index .p-index__list::after {
    top: var(--cap-top, 0px);
    height: var(--cap-h, 0px);
    background-color: var(--kuneo-blue);
    transition:
      top 280ms var(--ease-standard),
      height 280ms var(--ease-standard);
  }

  /* The index names are readable at rest (gray-400 measured 3.77:1). */
  .cap-layout__index .p-index__row:not(.is-active) .p-index__name {
    color: var(--gray-600);
  }

  .cap-layout__index .p-index__row:not(.is-active) .p-index__link:hover .p-index__name,
  .cap-layout__index .p-index__row:not(.is-active) .p-index__link:focus-visible .p-index__name {
    color: var(--brand-ink);
  }
}

/* ==========================================================================
   CAPABILITIES — THE INDEX BECOMES A STICKY RAIL (§18)

   On desktop the index is a 264px column that sticks beside the chapters. On
   a phone that column is the first thing the reader has to scroll past, and
   once past it there is no wayfinding at all across eight chapters. The brief
   asks for a horizontal rail directly below the hero, sticky under the header,
   with short labels — so this is the same `<nav>`, the same eight `<a>`, the
   same anchors and the same numbers, re-laid horizontally. Nothing is
   duplicated and no second navigation exists in the DOM.
   ========================================================================== */
@media (max-width: 1023px) {
  .cap-layout__index {
    /* THE STICKY ELEMENT IS THE NAV, and it must be the nav rather than the
       inner: the inner is a grid item that stretches with the index's own row,
       which on desktop is what lets it hold while the chapters pass. Here the
       row is the whole page, so sticking the inner would pin it for the entire
       document. The nav itself is only as tall as the rail. */
    position: sticky;
    top: var(--header-h-mobile);
    z-index: var(--z-sticky);
    /* Bleed to the viewport edges so chips can travel off-screen — the same
       negative-margin technique the other rails use. */
    margin-inline: calc(var(--page-gutter) * -1);
    background: var(--white);
    border-block: var(--border-subtle);
    /* The rail is a sibling of the chapters inside one grid; as a sticky item
       it stays at the top of the scroll while the chapters run past. */
    align-self: start;
  }

  .cap-layout__index-inner {
    position: static;
    margin-bottom: 0;
  }

  /* The "On this page" label is the rail's own heading; on a phone the rail
     explains itself and the label would take a second row of chrome. Hidden
     from the accessibility tree too, because the nav carries an aria-label
     with the same meaning. */
  .cap-layout__index-label {
    display: none;
  }

  .p-index__list {
    display: flex;
    flex-wrap: nowrap;
    gap: var(--space-2);
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    padding-inline: var(--page-gutter);
    padding-block: var(--space-3);
    scroll-padding-inline: var(--page-gutter);
    margin: 0;
  }

  .p-index__list::-webkit-scrollbar {
    display: none;
  }

  .p-index__row {
    flex: none;
    scroll-snap-align: start;
  }

  /* Each chip is a real touch target: the whole row is the link. */
  .cap-layout__index .p-index__link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: 0 var(--space-4);
    border: var(--border-subtle);
    border-radius: var(--radius-pill);
    background: var(--white);
    font-size: var(--fs-small);
    font-weight: 600;
    color: var(--brand-ink);
    text-decoration: none;
  }

  /* The number keeps the chip scannable and ties it to the chapter's own
     kicker, which carries the same two digits. */
  .cap-layout__index .p-index__num {
    font-size: var(--fs-label);
    font-weight: 700;
    color: var(--kuneo-blue);
  }

  .cap-layout__index .p-index__name {
    font-size: var(--fs-small);
    overflow-wrap: normal;
    white-space: nowrap;
    /* THE CHIP READS AT FULL CONTRAST, unlike the desktop index.
       The desktop value is `--gray-400` (#7B8494), which was tuned for a
       264px column beside a light chapter, where the row's number and the
       hover state carry the hierarchy. On the phone the chip IS the control:
       measured, #7B8494 on white is 3.77:1, under the 4.5:1 floor for 14px
       text. The chip uses the ink the rest of the site's body copy uses. */
    color: var(--brand-ink);
  }

  /* The arrow is a desktop hover affordance; on a chip it is noise. */
  .cap-layout__index .p-index__go {
    display: none;
  }

  /* The active chapter (§18: "Use IntersectionObserver to highlight the active
     section", "use aria-current where appropriate").
     The class name is `.is-active`, which is what js/page-capabilities.js
     already toggles for the desktop index — the same observer drives both
     presentations, so no new JS was needed. `[aria-current]` is accepted as
     well, because the brief asks the active state to be exposed to assistive
     tech and the attribute is the standard way to say it. */
  .cap-layout__index .p-index__link.is-active,
  .cap-layout__index .p-index__link[aria-current] {
    border-color: var(--kuneo-blue);
    color: var(--kuneo-blue);
    background: var(--blue-050);
  }

  /* THE ACTIVE NUMBER MUST BE WHITE, BECAUSE IT SITS ON A BLUE DISC.
     On the active row the desktop bubble rule draws the blue circle at full
     size (`transform: scale(1)` behind the number), and the chip also tints
     its surface. A blue number on that blue disc is invisible — the defect
     reported. White is the value the bubble was designed against: the base
     stylesheet's own active rule already says `color: var(--white)` for the
     desktop index, so the phone now matches it instead of contradicting it. */
  .cap-layout__index .p-index__link.is-active .p-index__num,
  .cap-layout__index .p-index__link[aria-current] .p-index__num {
    color: var(--white);
  }

  /* ANCHORS MUST CLEAR THE RAIL, NOT ONLY THE BAR.
     The rail stacks under the sticky header, so the generic `[id]` offset
     (bar + 16px) would leave a chapter title behind it. The rail's height is
     its chip row: 44px + 12px padding twice + 1px borders. */
  .cap-chapter {
    scroll-margin-top: calc(70px + 16px); /* + bar via html scroll-padding-top */
  }
}

@media (prefers-reduced-motion: reduce) {
  .cap-hero__eyebrow,
  .cap-hero__w > span,
  .cap-hero__support,
  .cap-hero__field li,
  .cap-hero__actions {
    animation: none;
  }

  .cap-hero__pill,
  .cap-hero__example {
    transition: none;
  }

  .cap-layout__index .p-index__list::after {
    transition: none;
  }
}
