/* ============================================================================
   Scene: capabilities  (section.caps #services + section.logos)
   Owned by js/scenes/capabilities.js. Tokens only; both themes come from the
   token layer. The single theme-specific rule is the logo ink filter.

   Three layouts, one markup:
   1. BASE (no JS, reduced motion, ?noanim): a plain list, all five open.
   2. .caps--pin (desktop, fine pointer, >= 900 x 640): a pinned row of five
      slats. The script drives flex-grow per slat from the scroll position.
   3. .caps--acc (touch, narrow or short screens): an accordion, first open.
   Traps honoured: no overflow on .caps or .caps-stage (the stage is the pinned
   element, the section is its ancestor); the stage sizes itself to 100svh.
   ========================================================================== */

/* ------------------------------------------------------------------ base -- */
.caps {
  position: relative;
  padding-block: var(--sec-pad);
}

.caps-head {
  display: grid;
  gap: 22px;
  margin-bottom: clamp(40px, 5.6vw, 72px);
}
.caps-head-main { display: grid; gap: 20px; }
.caps-head h2 { max-width: 15ch; }
.caps-sub {
  color: var(--ink-2);
  font-size: clamp(1.0625rem, 1.3vw, 1.1875rem);
  line-height: 1.55;
  max-width: 36ch;
}
.caps-count { display: none; }

@media (min-width: 900px) {
  .caps-head {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    align-items: end;
    gap: 48px;
  }
  .caps-head-side { justify-self: end; }
}

/* The list. Hairlines between disciplines, nothing else. */
.caps-row { border-top: 1px solid var(--line); }
.slat {
  position: relative;
  border-bottom: 1px solid var(--line);
}
.slat-h { font: inherit; margin: 0; }
.slat-btn {
  display: flex;
  align-items: baseline;
  gap: 18px;
  width: 100%;
  padding: 26px 0 20px;
  text-align: start;
  cursor: default;
}
.slat-idx {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex: none;
  min-width: 2.2ch;
  transition: color var(--t) var(--ease);
}
.slat-name {
  font-size: clamp(1.375rem, 2.1vw, 1.875rem);
  font-weight: 510;
  letter-spacing: -0.024em;
  line-height: 1.1;
  color: var(--ink);
  text-wrap: balance;
}
.slat-icon { display: none; }
.slat-title { display: none; }

.slat-body {
  display: grid;
  gap: 24px;
  padding-bottom: 32px;
}
.slat-desc {
  color: var(--ink-2);
  font-size: 1rem;
  line-height: 1.6;
  max-width: 46ch;
}
.slat-list {
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
}
.slat-list li {
  position: relative;
  padding: 9px 0 9px 20px;
  border-top: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 0.9375rem;
  line-height: 1.45;
}
.slat-list li::before {
  content: "";
  position: absolute;
  inset-inline-start: 1px;
  top: calc(9px + 0.725em - 2.5px);
  width: 5px; height: 5px;
  border-radius: 1px;
  background: var(--accent);
}

/* The micro-visual: a sunken plate with a dot grid, the SVG on top. */
.slat-viz {
  position: relative;
  aspect-ratio: 2 / 1;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background:
    radial-gradient(circle at 1px 1px, var(--line-2) 1px, transparent 1.4px) 0 0 / 16px 16px,
    var(--sunken);
  box-shadow: var(--hl);
  overflow: hidden; /* clips the plate only; never an ancestor of the pin */
}
.slat-viz .viz {
  position: absolute;
  inset: 7% 4% 12%;
  width: 92%;
  height: 81%;
}
.viz-tag {
  position: absolute;
  inset-inline-start: 14px;
  bottom: 11px;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* Static list on wide screens: index + name | copy | visual, one row each. */
@media (min-width: 900px) {
  .caps:not(.caps--pin):not(.caps--acc) .slat {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 2.1fr);
    gap: 32px;
    padding-block: 34px;
  }
  /* index (and, with motion off, the toggle) on one line, the name below */
  .caps:not(.caps--pin):not(.caps--acc) .slat-btn {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "idx icon" "name name";
    align-items: center;
    gap: 14px 16px;
    padding: 0;
  }
  .caps:not(.caps--pin):not(.caps--acc) .slat-idx { grid-area: idx; }
  .caps:not(.caps--pin):not(.caps--acc) .slat-name { grid-area: name; }
  .caps:not(.caps--pin):not(.caps--acc) .slat-icon { grid-area: icon; margin: 0; }
  .caps:not(.caps--pin):not(.caps--acc) .slat-body {
    grid-template-columns: minmax(0, 1fr) minmax(0, 0.92fr);
    gap: 32px;
    padding-bottom: 0;
  }
  .caps:not(.caps--pin):not(.caps--acc) .slat-list { margin-top: 20px; }
}

/* A closed item (accordion, or a disclosure toggled with motion off). The
   0fr -> 1fr row is how height animates without measuring anything. */
.slat-panel {
  display: grid;
  grid-template-rows: 1fr;
}
.slat-clip { min-height: 0; overflow: hidden; }
.slat.is-closed .slat-panel { grid-template-rows: 0fr; visibility: hidden; }

/* Interactive list (accordion or toggles): the heading becomes a real control. */
.caps--acc .slat-btn,
.caps--toggle .slat-btn {
  cursor: pointer;
  align-items: center;
}
.caps--acc .slat-icon,
.caps--toggle .slat-icon {
  display: block;
  position: relative;
  flex: none;
  width: 30px; height: 30px;
  margin-inline-start: auto;
  border: 1px solid var(--line-2);
  border-radius: 50%;
  transition: border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.caps--acc .slat-icon::before,
.caps--acc .slat-icon::after,
.caps--toggle .slat-icon::before,
.caps--toggle .slat-icon::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 10px; height: 1.5px;
  margin: -0.75px 0 0 -5px;
  background: var(--ink);
  transition: transform var(--t) var(--ease);
}
.caps--acc .slat-icon::after,
.caps--toggle .slat-icon::after { transform: rotate(90deg); }
.caps--acc .slat:not(.is-closed) .slat-icon::after,
.caps--toggle .slat:not(.is-closed) .slat-icon::after { transform: rotate(0deg); }
.caps--acc .slat:not(.is-closed) .slat-icon,
.caps--toggle .slat:not(.is-closed) .slat-icon { border-color: var(--accent-line); background: var(--accent-wash); }
.caps--acc .slat:not(.is-closed) .slat-idx,
.caps--toggle .slat:not(.is-closed) .slat-idx { color: var(--accent); }
.caps--acc .slat-btn:hover .slat-icon,
.caps--toggle .slat-btn:hover .slat-icon { border-color: var(--line-3); }
.slat-btn:focus-visible { outline-offset: 4px; }

.caps--acc .slat-panel {
  transition: grid-template-rows 0.55s var(--ease), visibility 0s linear 0s;
}
.caps--acc .slat.is-closed .slat-panel {
  transition: grid-template-rows 0.45s var(--ease), visibility 0s linear 0.45s;
}
.caps--acc .slat-body { padding-top: 2px; }
.caps--acc .slat-viz { order: -1; }
@media (min-width: 640px) {
  .caps--acc .slat-body { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; }
  .caps--acc .slat-viz { order: 0; align-self: start; }
}

/* ================================================================ PINNED == */
.caps--pin { padding-block: 0; }
.caps--pin .caps-stage {
  height: 100vh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* the fixed nav is 68px tall; keep the label clear of it */
  padding-top: clamp(84px, 11.5vh, 132px);
  padding-bottom: clamp(26px, 5vh, 64px);
}
.caps--pin .caps-inner {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 860px;
  display: flex;
  flex-direction: column;
}
.caps--pin .caps-head {
  flex: none;
  margin-bottom: clamp(22px, 4vh, 44px);
}
.caps--pin .caps-head-main { gap: clamp(12px, 2vh, 20px); }
.caps--pin .caps-head-side {
  display: grid;
  gap: 18px;
  justify-items: end;
}
.caps--pin .caps-sub { text-align: end; }

.caps--pin .caps-count {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.caps-count-cur { color: var(--ink); }
.caps-count-bar {
  position: relative;
  width: 88px; height: 1px;
  background: var(--line-2);
}
.caps-count-bar i {
  position: absolute; inset: 0;
  background: var(--accent);
  transform-origin: 0 50%;
  transform: scaleX(0.2);
}

/* The row. Every slat is the width of an OPEN slat and sits absolutely; the
   script places it with translateX and writes, inline, how much of it shows:
   a mask on the slat (feathered while it moves) and the button's width. The
   next slat covers the hidden rest. Nothing changes a layout position per
   frame, so the motion registers no layout shift (flex-grow did: about 0.4
   CLS per pass). No inherited custom property is animated: one on the slat
   re-styled every SVG node inside it, every frame. */
.caps--pin .caps-row {
  --closed: clamp(58px, 5.5vw, 84px);
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  max-height: 640px;
  border-top: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line-2);
  overflow: hidden; /* the last slat's hidden remainder; the row is inside the pin, not around it */
  container: capsrow / inline-size;
}
.caps--pin .slat {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: calc(100cqw - 4 * var(--closed));
  border-bottom: 0;
  border-left: 1px solid var(--line);
}
.caps--pin .slat:first-child { border-left: 0; }
.caps--pin .slat-h { position: static; }

/* The button is exactly the visible part of the slat, so its hover wash,
   accent bar and focus ring always match what you see. --g is the slat's
   share of the open width (0..1), written by the script. */
.caps--pin .slat-btn {
  --g: 0;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--closed); /* the script writes the visible width */
  display: block;
  padding: 0;
  cursor: pointer;
}
.caps--pin .slat:first-child .slat-btn { --g: 1; }
.caps--pin .slat-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--surface);
  box-shadow: var(--hl);
  opacity: var(--g);
  /* No transition here: --g changes every frame of a scrub, and each change
     restarted a 0.42s transition on five buttons (measured: 513 animation
     style invalidations in one pass). */
}
.caps--pin .slat-btn:hover::before { opacity: max(var(--g), 0.55); }
.caps--pin .slat-btn::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--accent);
  opacity: calc(var(--g) * 1.6 - 0.6);
}
/* Inside the masked slat Chrome does not show the button's outline, so the
   keyboard ring is drawn by the button's own wash layer instead. */
.caps--pin .slat-btn:focus-visible { outline: none; }
.caps--pin .slat-btn:focus-visible::before {
  opacity: 1;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.caps--pin .slat-idx {
  position: absolute;
  top: clamp(20px, 3.2vh, 28px);
  inset-inline-start: 0;
  width: var(--closed);
  text-align: center;
}
.caps--pin .slat.is-active .slat-idx { color: var(--accent); }

/* Physical "left" on purpose: in a vertical writing mode the logical
   inline-start is the TOP edge, which would stretch and centre the name. */
.caps--pin .slat-name {
  position: absolute;
  bottom: clamp(20px, 3.2vh, 28px);
  left: 0;
  width: var(--closed);
  display: flex;
  align-items: center;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: clamp(1.0625rem, 1.3vw, 1.25rem);
  letter-spacing: -0.015em;
  white-space: nowrap;
  color: var(--ink-2);
  opacity: calc(1 - var(--g) * 3);
  transition: color var(--t-fast) var(--ease);
}
.caps--pin .slat-btn:hover .slat-name { color: var(--ink); }

/* The panel is as wide as an OPEN slat at all times (100cqw is the row), so
   its text never re-wraps while the slat grows; the slat clips it instead. */
/* The panel starts right of the index column, so a closed slat's button is
   never under it and nothing has to toggle pointer-events or visibility per
   slat. Both are INHERITED: flipping either re-styled and re-laid out every
   node of the SVG inside (SVG text included), 50-120ms a frame at 4x CPU.
   A closed panel is invisible anyway (fully masked, parts at opacity 0)
   and the script hides it from assistive tech with aria-hidden. */
.caps--pin .slat-panel {
  position: absolute;
  z-index: 1;
  top: 0; bottom: 0;
  left: var(--closed);
  right: 0;
  display: block;
  padding: clamp(20px, 3.2vh, 28px) clamp(20px, 2.4vw, 32px) clamp(20px, 3.2vh, 28px) 0;
}
/* The parts that slide in always carry a 2D transform, so the script only
   ever changes its value. Adding or removing a transform forces layout. */
.caps--pin .slat-title,
.caps--pin .slat-desc,
.caps--pin .slat-list,
.caps--pin .slat-viz { transform: translateX(0); }
.caps--pin .slat-clip { height: 100%; overflow: visible; }
/* Open slat: title and text top-left, the five capabilities top-right, and
   the micro-visual as a wide plate taking whatever height is left. The copy
   is its own 2x2 grid; its "1fr" second row is what absorbs the list's extra
   height, so the description sits right under the title. */
.caps--pin .slat-body {
  height: 100%;
  padding: 0;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(16px, 2.6vh, 28px);
}
.caps--pin .slat-copy {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "title list"
    "desc  list";
  column-gap: clamp(24px, 2.8vw, 44px);
}
.caps--pin .slat-title {
  grid-area: title;
  display: block;
  font-size: clamp(1.625rem, 2.3vw, 2.25rem);
  font-weight: 510;
  letter-spacing: -0.028em;
  line-height: 1.04;
  margin-top: -0.18em; /* optical: cap height lines up with the mono index */
  text-wrap: balance;
}
.caps--pin .slat-desc {
  grid-area: desc;
  align-self: start;
  margin-top: clamp(12px, 1.8vh, 18px);
  font-size: clamp(0.9375rem, 1.05vw, 1.0625rem);
  line-height: 1.55;
}
.caps--pin .slat-list { grid-area: list; margin: 0; align-self: start; }
.caps--pin .slat-list li {
  padding-block: clamp(6px, 0.95vh, 9px);
  font-size: clamp(0.875rem, 0.98vw, 0.9375rem);
  line-height: 1.4;
}
.caps--pin .slat-list li:first-child { border-top: 0; padding-top: 0; }
.caps--pin .slat-list li::before { top: calc(clamp(6px, 0.95vh, 9px) + 0.7em - 2.5px); }
.caps--pin .slat-list li:first-child::before { top: calc(0.7em - 2.5px); }
.caps--pin .slat-viz {
  aspect-ratio: auto;
  height: auto;
  min-height: 0;
}

/* Narrow open slat (row under ~1000px): smaller type, same arrangement. */
@container capsrow (max-width: 1000px) {
  .caps--pin .slat-title { font-size: clamp(1.375rem, 2.6vw, 1.75rem); }
  .caps--pin .slat-desc { font-size: 0.9375rem; }
  .caps--pin .slat-list li { font-size: 0.8125rem; }
}

/* ============================================================ VISUALS ===== */
/* Shared SVG vocabulary. Colours are tokens, so both themes just work. */
.viz { overflow: visible; }
.viz .v-txt {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  fill: var(--muted);
}
.viz .v-num { font-family: var(--font-mono); font-size: 7.5px; fill: var(--muted); opacity: 0.7; }
.viz .v-edge { stroke: var(--line-3); stroke-width: 1; }
.viz .v-edge-soft { stroke-dasharray: 2 3; }
.viz .v-sep { stroke: var(--line-2); stroke-width: 1; }
.viz .v-orbit { fill: none; stroke: var(--line); stroke-width: 1; stroke-dasharray: 1 4; }
.viz .v-orbit-2 { stroke: var(--line-2); }
.viz .v-node { fill: var(--raised); stroke: var(--line-3); stroke-width: 1; }
.viz .v-core { fill: var(--muted); }
.viz .v-hub { fill: var(--raised); stroke: var(--accent-line); stroke-width: 1.2; }
.viz .v-hit { fill: none; stroke: var(--accent); stroke-width: 1; opacity: 0; }
.viz .v-acc { fill: var(--accent); }
.viz .v-halo { fill: var(--accent-glow); }
.viz .ai-node.is-hit .v-core { fill: var(--accent); }
.viz .ai-node .v-core { transition: fill 0.5s var(--ease); }

/* custom software */
.viz .v-panel { fill: var(--surface); stroke: var(--line-2); stroke-width: 1; }
.viz .v-dot { fill: var(--line-3); }
.viz .t-acc { fill: var(--accent); opacity: 0.85; }
.viz .t-ink { fill: var(--ink-2); opacity: 0.8; }
.viz .t-mut { fill: var(--muted); opacity: 0.55; }
.viz .web-caret { fill: var(--accent); }
.viz .v-card { fill: var(--raised); stroke: var(--line-2); stroke-width: 1; }
.viz .v-avatar { fill: var(--accent-wash); stroke: var(--accent-line); stroke-width: 1; }
.viz .v-toggle-on { fill: var(--accent); }
.viz .v-knob { fill: var(--surface); }
.viz .v-toggle-off { fill: var(--line-2); }
.viz .v-knob-off { fill: var(--muted); }
.viz .v-button { fill: var(--ink); }
.viz .v-button-label { fill: var(--ground); opacity: 0.7; }

/* cloud */
.viz .v-unit { fill: var(--raised); stroke: var(--line-2); stroke-width: 1; }
.viz .cl-led { fill: var(--line-3); }
.viz .cl-led-main { fill: var(--accent); }
.viz .cl-unit.is-old .cl-led-main { fill: var(--muted); }
.viz .cl-led-act { fill: var(--muted); opacity: 0.6; }
.viz .v-meter { fill: var(--line); }
.viz .cl-load { fill: var(--line-3); }
.viz .v-vent { stroke: var(--line-2); stroke-width: 1.4; stroke-linecap: round; }
.viz .v-track { fill: var(--line-2); }
.viz .cl-fill { fill: var(--accent); }
.viz .cl-step { fill: var(--muted); }

/* design */
.viz .v-grid { stroke: var(--line); stroke-width: 1; }
.viz .v-grid-2 { stroke: var(--line-2); stroke-width: 1; }
.viz .ds-guide { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; }
.viz .ds-handle { stroke: var(--accent); stroke-width: 1; opacity: 0.8; }
.viz .ds-curve { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.viz .ds-anchor { fill: var(--ink); }
.viz .ds-knob { fill: var(--sunken); stroke: var(--accent); stroke-width: 1.6; }

/* organisational consulting */
.viz .op-dot { fill: var(--ink-2); }
.viz .op-node { fill: var(--raised); stroke: var(--line-3); stroke-width: 1; }
.viz .op-bn { stroke: var(--muted); stroke-dasharray: 3 2.5; transition: stroke 0.4s var(--ease), fill 0.4s var(--ease); }
.viz .op-bn.is-clear { stroke: var(--accent); stroke-dasharray: none; fill: var(--accent-wash); }
.viz .op-ring { fill: none; stroke: var(--accent); stroke-width: 1; }
.viz .op-bar { fill: var(--line-3); }
.viz .op-bar.is-hi { fill: var(--accent-line); }

/* ============================================================ LOGO WALL == */
.logos {
  position: relative;
  padding-block: clamp(56px, 8vw, 104px) var(--sec-pad);
}
.logos-cap {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: clamp(26px, 3.4vw, 40px);
  color: var(--muted);
  font-size: 0.9375rem;
  letter-spacing: -0.005em;
  text-align: center;
}
.logos-cap { justify-content: center; text-wrap: balance; }
/* hairlines either side of the caption, once there is room for them */
@media (min-width: 640px) {
  .logos-cap::before,
  .logos-cap::after {
    content: "";
    flex: 1 1 0;
    height: 1px;
    background: var(--line);
  }
}

/* A hairline grid whose short last row is centred. Each cell draws its own
   right and bottom edge; the first cell of every row adds the left edge, and
   the list adds the top (the first row is always full). Works for 2, 3 and 4
   columns with 11 logos. */
.logos-grid {
  --cols: 2;
  --logo-k: 0.74;
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  border-top: 1px solid var(--line);
}
.logo-cell {
  flex: 0 0 calc(100% / var(--cols));
  display: grid;
  place-items: center;
  height: clamp(104px, 13vw, 148px);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.logo-cell:nth-child(2n + 1) { border-left: 1px solid var(--line); }

@media (min-width: 640px) {
  .logos-grid { --cols: 3; --logo-k: 0.86; }
  .logo-cell:nth-child(2n + 1) { border-left: 0; }
  .logo-cell:nth-child(3n + 1) { border-left: 1px solid var(--line); }
}
@media (min-width: 1000px) {
  .logos-grid { --cols: 4; --logo-k: 1; }
  .logo-cell:nth-child(3n + 1) { border-left: 0; }
  .logo-cell:nth-child(4n + 1) { border-left: 1px solid var(--line); }
}

/* One ink for every mark: a light silhouette on dark, a dark one on light.
   --h is set per logo in the markup (equal ink area, see the fragment). */
.logo-cell img {
  height: calc(var(--h, 44) * var(--logo-k) * 1px);
  width: auto;
  max-width: 78%;
  object-fit: contain;
  filter: grayscale(1) brightness(0) invert(1);
  opacity: 0.6;
  transition: opacity var(--t) var(--ease);
}
[data-theme="light"] .logo-cell img { filter: grayscale(1) brightness(0); opacity: 0.62; }
.logo-cell:hover img { opacity: 1; }
