/* ==========================================================================
   Client stories — "The drift wall"  (/familyoffice/)
   site/stories_drift.py renders it, js/stories-drift.js moves it.

   A dark band with a window onto a slow, living wall of clay story cards —
   a gallery wall you walk past. Light clay slabs on --dark-2, so the cast is
   black rather than the ground's warm stone, and it still falls +x +y: one
   light source, top-left, as everywhere else on the site.

   Two states share one card:
     · static (no JS, prefers-reduced-motion): a plain grid of the 3 stories
     · .is-drifting: columns of fixed-height cards inside a masked window,
       each column's track translated by the script (transform only)
   ========================================================================== */

.drift {
  --gap: 22px;
  --bleed: min(var(--gutter), 44px);
  --h-tall: 560px;
  --h-mid: 468px;
  --h-compact: 392px;
  --lh: 1.62em;
  --drift-cast:
     1px  2px  3px rgba(0, 0, 0, .30),
     6px 10px 18px rgba(0, 0, 0, .30),
    16px 27px 46px rgba(0, 0, 0, .30),
    inset 0 -4px 8px rgba(104, 90, 66, .14),
    inset 0  1px 1px rgba(255, 255, 255, .72);
  --drift-cast-hover:
     2px  4px  6px rgba(0, 0, 0, .30),
    11px 19px 32px rgba(0, 0, 0, .34),
    28px 46px 76px rgba(0, 0, 0, .36),
    inset 0 -4px 8px rgba(104, 90, 66, .12),
    inset 0  1px 1px rgba(255, 255, 255, .76);
  overflow-x: clip;
}

/* ── head ──────────────────────────────────────────────────────────────── */
.drift__head { margin-bottom: clamp(36px, 4.6vw, 64px); }
.drift__head .display-lg { max-width: 15ch; }
.drift__aside {
  display: flex; flex-direction: column; align-items: flex-end; gap: 16px;
  flex: 0 0 auto; margin-bottom: 10px;
}
.drift__hint { display: none; max-width: 31ch; text-align: right; }
.drift--js .drift__hint--static { display: block; }
.drift--live .drift__hint--static { display: none; }
.drift--live .drift__hint--live { display: block; }
@media (hover: none) {
  .drift--live .drift__hint--live { display: none; }
  .drift--live .drift__hint--touch { display: block; }
}
.section--dark .drift__hint { color: rgba(248, 243, 232, .56); }

.drift__toggle {
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 40px; padding: 0 17px 0 15px;
  border: 0; border-radius: var(--r-pill); cursor: pointer;
  background: linear-gradient(178deg, #251e16 0%, #1d1711 60%, #17110b 100%);
  box-shadow: var(--clay-dark);
  color: rgba(248, 243, 232, .76);
  font: 500 12.5px/1 Inter, sans-serif; letter-spacing: .02em;
  transition: color .3s var(--ease), box-shadow .3s var(--ease), transform .3s var(--ease);
}
.drift__toggle[hidden] { display: none; }
.drift__toggle:hover { color: var(--cream); transform: translate3d(-1px, -2px, 0); box-shadow: var(--clay-dark-hover); }
.drift__toggle:active { transform: none; box-shadow: var(--clay-dark-in); }
.drift__toggle .drift__ico { color: var(--bronze-bright); }
.drift__toggle .drift__ico--play { display: none; }
.drift__toggle[data-paused="true"] .drift__ico--play { display: block; }
.drift__toggle[data-paused="true"] .drift__ico--pause { display: none; }

.drift__vh {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ── the static grid (no JS / reduced motion) ──────────────────────────── */
.drift__grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--gap); align-items: stretch;
}
.drift__grid[hidden] { display: none; }

/* ── a story card ──────────────────────────────────────────────────────── */
.drift__card {
  position: relative;
  display: flex; flex-direction: column;
  padding: 10px;
  border-radius: 26px;
  background: linear-gradient(178deg, #fbf8f2 0%, #f4f0e6 58%, #ece7db 100%);
  box-shadow: var(--drift-cast);
  color: var(--ink);
  transition: transform .55s var(--ease), box-shadow .55s var(--ease), opacity .55s var(--ease);
  contain: layout;
}

/* the palette block, set INTO the slab: its inner shadow falls from the
   top-left edge, the way a recess catches a top-left light */
.drift__art {
  position: relative;
  flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 17px;
  background: var(--block, #E7E0D0);
  box-shadow: inset 2px 3px 7px rgba(0, 0, 0, .13), inset -1px -1px 0 rgba(255, 255, 255, .05);
  overflow: hidden;
}
.drift__art svg {
  width: auto; height: min(86%, 290px); max-width: 92%;
  transition: transform .7s var(--ease);
}

.drift__body {
  flex: none;
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 18px 14px 8px;
}
.drift__no {
  font: 500 10.5px/1 Inter, sans-serif; letter-spacing: .24em;
  text-transform: uppercase; color: var(--bronze-deep);
}
.drift .drift__title {
  margin-top: 12px;
  font: 300 clamp(1.375rem, 1.75vw, 1.625rem)/1.16 Newsreader, Georgia, serif;
  letter-spacing: -.018em; color: var(--ink);
}
.drift__btn {
  appearance: none; -webkit-appearance: none;
  display: inline; padding: 0; margin: 0; border: 0; background: none;
  font: inherit; letter-spacing: inherit; color: inherit; text-align: left;
  cursor: pointer;
}
/* the whole slab is the button's hit area */
.drift__btn::after {
  content: ""; position: absolute; inset: 0; z-index: 2;
  border-radius: 26px;
}
.drift__btn:focus-visible { outline: none; }
.drift__btn:focus-visible::after { outline: 2px solid var(--bronze-bright); outline-offset: 5px; }

.drift__text {
  margin-top: 10px;
  max-height: calc(var(--lines, 2) * var(--lh));
  overflow: hidden;
  font: 400 14.5px/1.62 Inter, sans-serif; color: var(--ink-muted);
  -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - .95em), transparent);
          mask-image: linear-gradient(180deg, #000 calc(100% - .95em), transparent);
  transition: max-height .65s var(--ease);
}
.drift__text p { margin: 0; }

.drift__read {
  margin-top: 14px;
  display: inline-flex; align-items: center; gap: 9px;
  font: 500 13px/1 Inter, sans-serif; letter-spacing: .02em;
  color: var(--bronze-deep);
}
.drift__read .drift__arrow { transition: transform .35s var(--ease); }

/* lifted toward the light: up and a hair left, the cast travels further.
   Pointer hover only where hover is real (no sticky lift after a tap), and
   keyboard focus only when it is visible focus. Separate rules, so an engine
   without :has() still keeps the hover ones. */
@media (hover: hover) {
  .drift__card:hover { transform: translate3d(-1px, -6px, 0); box-shadow: var(--drift-cast-hover); }
  .drift__card:hover .drift__read .drift__arrow { transform: translateX(4px); }
  .drift__card:hover .drift__art svg { transform: scale(.97); }
}
.drift__card:has(.drift__btn:focus-visible) { transform: translate3d(-1px, -6px, 0); box-shadow: var(--drift-cast-hover); }
.drift__card:has(.drift__btn:focus-visible) .drift__read .drift__arrow { transform: translateX(4px); }

/* static grid card: a fixed plate ratio, a longer excerpt, no reveal */
.drift__grid .drift__art { flex: none; aspect-ratio: 16 / 10.5; }
.drift__grid .drift__text { --lines: 4; }
/* no script, no story view: the card simply carries the whole story */
.drift:not(.drift--js) .drift__text { max-height: none; -webkit-mask-image: none; mask-image: none; }
.drift:not(.drift--js) .drift__read,
.drift:not(.drift--js) .drift__btn::after { display: none; }
.drift:not(.drift--js) .drift__btn { cursor: text; }

/* ── the drifting wall ─────────────────────────────────────────────────── */
.drift__wall.is-drifting {
  --cols: 3;
  position: relative;
  display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: var(--gap); align-items: start;
  height: min(86vh, 920px);
  height: min(86svh, 920px);
  min-height: 520px;
  /* the window bleeds into the gutter so the cards' casts are not clipped */
  margin-inline: calc(-1 * var(--bleed)); padding-inline: var(--bleed);
  overflow: hidden; overflow: clip;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 13%, #000 87%, transparent 100%);
          mask-image: linear-gradient(180deg, transparent 0, #000 13%, #000 87%, transparent 100%);
}
.drift__col { position: relative; min-width: 0; height: 100%; }
.drift__track {
  display: flex; flex-direction: column; gap: var(--gap);
  will-change: transform; backface-visibility: hidden;
}
.drift__set { display: flex; flex-direction: column; gap: var(--gap); }

.is-drifting .drift__card { height: var(--h-mid); }
.is-drifting .drift__card[data-size="tall"]    { height: var(--h-tall); }
.is-drifting .drift__card[data-size="compact"] { height: var(--h-compact); }

/* hover reveals more of the story: the text panel grows and the drawing
   gives up the room — the card itself never changes height, so the column
   (and the loop's period) stays exactly where it was */
.is-drifting .drift__card { --more: 6; }
.is-drifting .drift__card[data-size="tall"]    { --more: 8; }
.is-drifting .drift__card[data-size="compact"] { --more: 4; }
@media (hover: hover) {
  .is-drifting .drift__card:hover .drift__text { --lines: var(--more); }
  /* the rest of the wall steps back while one story is held */
  .is-drifting:has(.drift__card:hover) .drift__card:not(:hover) { opacity: .74; }
}
.is-drifting .drift__card:has(.drift__btn:focus-visible) .drift__text { --lines: var(--more); }

/* ── the story view ────────────────────────────────────────────────────── */
html.drift-lock { overflow: hidden; }

.drift__dialog {
  position: fixed; inset: 0;
  width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; padding: clamp(14px, 4vw, 56px);
  border: 0; color: var(--ink);
  background: rgba(13, 10, 6, 0);
  display: grid; place-items: center;
  overflow-y: auto; overscroll-behavior: contain;
  transition: background-color .45s var(--ease);
}
.drift__dialog:not([open]) { display: none; }
.drift__dialog::backdrop { background: transparent; }
.drift__dialog[data-open="true"] { background: rgba(13, 10, 6, .74); }

.drift__sheet {
  position: relative;
  width: min(1060px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  column-gap: clamp(28px, 3.6vw, 56px);
  padding: 14px;
  border-radius: var(--r-xl);
  background: linear-gradient(178deg, #fbf8f2 0%, #f4f0e6 58%, #ece7db 100%);
  box-shadow:
     3px  5px  8px rgba(0, 0, 0, .30),
    14px 24px 40px rgba(0, 0, 0, .34),
    34px 56px 96px rgba(0, 0, 0, .36),
    inset 0 -5px 10px rgba(104, 90, 66, .12),
    inset 0  1px 1px rgba(255, 255, 255, .76);
  opacity: 0;
  transform: translate3d(0, 26px, 0) scale(.982);
  transition: opacity .42s var(--ease), transform .7s var(--ease);
}
.drift__dialog[data-open="true"] .drift__sheet { opacity: 1; transform: none; }

.drift__story { display: contents; }
.drift__story[hidden] { display: none; }

.drift__plate {
  grid-column: 1; grid-row: 1 / span 2;
  display: flex; align-items: center; justify-content: center;
  min-height: min(560px, 62vh);
  border-radius: calc(var(--r-xl) - 13px);
  background: var(--block, #E7E0D0);
  box-shadow: inset 3px 4px 10px rgba(0, 0, 0, .14);
}
.drift__plate svg { width: 92%; height: auto; max-height: 92%; }

.drift__copy {
  grid-column: 2; grid-row: 1;
  display: flex; flex-direction: column; justify-content: center;
  padding: clamp(56px, 6vw, 84px) clamp(10px, 2vw, 34px) 12px 0;
}
.drift__eye { color: var(--bronze-deep); }
.drift .drift__dtitle {
  margin-top: 20px;
  font: 250 clamp(2rem, 3.3vw, 3rem)/1.06 Newsreader, Georgia, serif;
  letter-spacing: -.026em; color: var(--ink);
  outline: none;
}
.drift__full p {
  margin-top: 24px; max-width: 46ch;
  font: 400 clamp(1rem, 1.15vw, 1.0625rem)/1.76 Inter, sans-serif;
  color: var(--ink-muted);
}
.drift__metrics { display: flex; flex-wrap: wrap; gap: 18px 34px; margin-top: 28px; }
.drift__metric-val { display: block; font: 300 2.25rem/1 Newsreader, Georgia, serif; color: var(--ink); }
.drift__metric-lab { display: block; margin-top: 8px; font: 400 13px/1.5 Inter, sans-serif; color: var(--ink-soft); }

.drift__foot {
  grid-column: 2; grid-row: 2;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 14px 20px;
  margin-right: clamp(10px, 2vw, 34px);
  padding: 22px 0 clamp(12px, 1.6vw, 22px);
  border-top: 1px solid var(--line);
}
.drift__pager { display: flex; align-items: center; gap: 4px; }
.drift__step {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 12px;
  border: 0; border-radius: var(--r-pill); background: none; cursor: pointer;
  font: 500 13px/1 Inter, sans-serif; color: var(--ink-muted);
  transition: color .3s var(--ease), background-color .3s var(--ease);
}
.drift__step:first-child { margin-left: -12px; }
.drift__step:hover { color: var(--ink); background: rgba(255, 255, 255, .55); }
.drift__count { min-width: 64px; text-align: center; font: 500 12px/1 Inter, sans-serif;
  letter-spacing: .16em; color: var(--ink-faint); }
.drift__cta { min-height: 48px; }

.drift__close {
  position: absolute; top: 18px; right: 18px; z-index: 3;
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  border: 0; cursor: pointer; color: var(--ink);
  background: linear-gradient(178deg, #fbf8f2 0%, #f1ece1 100%);
  box-shadow: var(--clay-sm);
  transition: transform .35s var(--ease), box-shadow .35s var(--ease);
}
.drift__close:hover { transform: translate3d(-1px, -2px, 0); box-shadow: var(--clay-md); }
.drift__close:active { transform: none; box-shadow: var(--clay-in); }

/* the plate draws itself in when a story opens */
.drift__plate .dw { stroke-dasharray: 1; stroke-dashoffset: 1; }
.drift__plate .dw-fade { opacity: 0; }
.drift__story[data-drawn="true"] .drift__plate .dw {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1.6s var(--ease) .12s;
}
.drift__story[data-drawn="true"] .drift__plate .dw-fade {
  opacity: 1;
  transition: opacity .9s var(--ease) .75s;
}

/* ── responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1099.98px) {
  .drift__wall.is-drifting { --cols: 2; }
  .drift__grid { grid-template-columns: minmax(0, 1fr); }
  .drift__grid .drift__card { flex-direction: row; }
  .drift__grid .drift__art { width: 44%; aspect-ratio: auto; min-height: 250px; }
  .drift__grid .drift__body { flex: 1 1 0; justify-content: center; padding: 22px 26px; }
}
@media (max-width: 940px) {
  .drift__head .chapter__row { flex-direction: column; align-items: flex-start; gap: 22px; }
  .drift__aside { align-items: flex-start; }
  .drift__hint { text-align: left; }
}
@media (max-width: 820px) {
  .drift__sheet { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto; padding: 10px; }
  .drift__plate { grid-column: 1; grid-row: 1; min-height: 0; height: clamp(220px, 34vh, 320px); }
  .drift__plate svg { width: auto; height: 88%; max-width: 92%; }
  .drift__copy { grid-column: 1; grid-row: 2; padding: 26px 14px 6px; }
  .drift__foot { grid-column: 1; grid-row: 3; margin: 0 14px; padding: 18px 0 14px; }
  .drift__dialog { place-items: start center; }
  .drift__close { top: 20px; right: 20px; }
}
@media (max-width: 599.98px) {
  .drift { --gap: 16px; --h-tall: 520px; --h-mid: 456px; --h-compact: 400px; }
  .drift__wall.is-drifting { --cols: 1; height: min(76svh, 660px); min-height: 480px; }
  .drift__grid .drift__card { flex-direction: column; }
  .drift__grid .drift__art { width: auto; min-height: 0; aspect-ratio: 16 / 11; }
  .drift__grid .drift__body { padding: 18px 12px 8px; }
  .drift .drift__title { font-size: 1.4375rem; }
  .drift .drift__dtitle { font-size: 2rem; }
  .drift__foot { flex-direction: column; align-items: stretch; }
  .drift__pager { justify-content: space-between; }
  .drift__step:first-child { margin-left: -8px; }
  .drift__cta { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .drift__card:hover { transform: none; }
  .drift__card:has(.drift__btn:focus-visible) { transform: none; }
  .drift__sheet { transform: none; }
}
@media print {
  .drift__dialog, .drift__toggle, .drift__hint { display: none !important; }
}
