/* Owned by S4. Work: the expanding accordion gallery. Rail on desktop, stack below 1024px. */
.work {
  --ease-io: cubic-bezier(.65, 0, .35, 1);
  --ease-back: cubic-bezier(.34, 1.56, .64, 1);
  --t-fast: 200ms;
  --t-mid: 450ms;
  --t-slow: 700ms;
  --stagger: 55ms;
}

/* ---- Stack mode (default, also scripts off) ---- */
.work__gallery { max-width: var(--content); margin: 0 auto; display: grid; gap: 10px; }
.work__panel { min-width: 0; }
.work__panel:nth-child(2) { --p: 1; }
.work__panel:nth-child(3) { --p: 2; }
.work__panel:nth-child(4) { --p: 3; }
.work__panel:nth-child(5) { --p: 4; }
.work__panel:nth-child(6) { --p: 5; }

.work__spine {
  display: grid; grid-template-columns: 40px 1fr auto 36px; align-items: center; gap: 12px;
  width: 100%; padding: 18px 20px; text-align: left;
  border: 0; border-radius: var(--radius); background: var(--dark); box-shadow: var(--hair);
  color: var(--on-dark); cursor: pointer;
  transition: background-color var(--t-fast), color var(--t-fast);
}
.work__panel.is-open .work__spine { background: var(--accent); color: var(--accent-ink); }
@media (hover: hover) {
  .work__panel:not(.is-open) .work__spine:hover { background: var(--dark-2); }
}
.work__index { font: 500 12px / 1 var(--font-mono); letter-spacing: .08em; color: var(--accent); }
.is-open .work__index { color: var(--accent-ink); }
.work__spine-title { font: 500 1.5rem / 1 var(--font-display); letter-spacing: -.02em; white-space: nowrap; }
.work__spine-kind { font: 500 10px / 1 var(--font-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--on-dark-2); }
.is-open .work__spine-kind { color: var(--accent-ink); }
.work__plus {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  box-shadow: inset 0 0 0 1px currentColor; font: 400 18px / 1 var(--font-sans);
  transition: transform 450ms var(--ease);
}
.is-open .work__plus { transform: rotate(45deg); }

.work__body {
  display: grid; grid-template-columns: 1fr; gap: 24px; padding: 24px; margin-top: 8px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--hair), var(--shadow);
}
html.js .work__panel:not(.is-open) .work__body { display: none; }

.work__text { display: flex; flex-direction: column; gap: 12px; }
.work__title { font: 500 2rem / .98 var(--font-display); letter-spacing: -.02em; }
.work__meta {
  display: flex; flex-wrap: wrap; gap: 4px 10px;
  font: 500 11px / 1.4 var(--font-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--mute-text);
}
/* the separator hangs on the end of the first part, so a wrapped line never starts with it */
.work__meta span:not(:last-child)::after { content: "·"; margin-left: 10px; white-space: nowrap; }
.work__desc { font-size: 1rem; line-height: 1.55; color: var(--ink-2); max-width: 46ch; }
.work__desc strong { color: var(--ink); font-weight: 700; }
.work__facts { display: grid; gap: 10px; padding: 12px 0 0; border-top: 1px solid var(--line); list-style: none; }
.work__facts li { font-size: 14px; line-height: 1.4; color: var(--ink-2); }
.work__facts b { display: block; font: 500 1.5rem / 1.1 var(--font-display); letter-spacing: -.02em; color: var(--ink); }
.work__note { font-size: 13.5px; line-height: 1.5; color: var(--mute-text); }
.work__case-line {
  padding-left: 10px; border-left: 2px solid var(--accent-2);
  font: 500 .95rem / 1.4 var(--font-sans); color: var(--ink); max-width: 46ch;
}
.work__stack { display: flex; flex-wrap: wrap; gap: 5px 6px; padding: 0; list-style: none; }
.work__stack li {
  padding: 5px 9px; border-radius: 999px; background: var(--soft); color: var(--ink-2);
  font: 500 11.5px / 1 var(--font-mono);
}
.work__case-after { font-family: var(--font-display); font-style: italic; font-weight: 400; font-size: 1.05em; }
.work__case-arrow { margin: 0 .1em; color: var(--accent-2-ink); }
.work__links .link { color: var(--ink); text-decoration-color: var(--accent-2); }
.work__links .work__case-btn { font-weight: 600; }
.work__links { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin-top: 4px; }
.work__shot { margin: 0; align-self: center; }
.work__shot img {
  width: 100%; height: auto; aspect-ratio: 1600 / 1000; object-fit: contain;
  border-radius: var(--radius-sm); box-shadow: var(--hair);
}
.work__chat { display: flex; flex-direction: column; gap: 10px; align-self: center; width: 100%; }
.chat__msg {
  max-width: 85%; padding: 10px 14px; border-radius: 18px 18px 18px 6px; align-self: flex-start;
  background: var(--soft); color: var(--ink); font-size: 14px; line-height: 1.45;
}
.chat__msg--user { align-self: flex-end; border-radius: 18px 18px 6px 18px; background: var(--ink); color: var(--paper); }
.chat__cap { margin-top: 6px; font: 500 11px / 1.4 var(--font-mono); letter-spacing: .04em; color: var(--mute-text); text-align: center; }

@media (max-width: 699.98px) {
  .work__spine { grid-template-columns: 32px 1fr 36px; row-gap: 4px; }
  .work__index, .work__plus { grid-row: 1 / 3; }
  .work__spine-title { grid-column: 2; font-size: 1.375rem; }
  .work__spine-kind { grid-column: 2; grid-row: 2; }
  .work__plus { grid-column: 3; }
  .work__meta { flex-direction: column; gap: 2px; }
  .work__meta span:not(:last-child)::after { content: none; }
  html.js .work__spine-kind { display: none; }
  html.js .work__spine { row-gap: 0; }
  .work__body { padding: 18px; }
}

/* ---- Desktop two-column body (also scripts off) ---- */
@media (min-width: 1024px) {
  .work__body { grid-template-columns: 360px minmax(0, 1fr); gap: 28px; align-items: center; padding: 28px; margin-top: 0; }
  .work__title { font-size: clamp(2rem, 3vw, 2.75rem); }
  .work__desc { font-size: 15.5px; }
  .work__chat { max-width: 440px; justify-self: center; }
}
@media (min-width: 1024px) and (max-width: 1279.98px) {
  .work__body { grid-template-columns: 300px minmax(0, 1fr); gap: 20px; padding: 22px; }
}
/* Narrow rail (six spines leave too little room): text only, no side picture or chat */
@media (min-width: 1024px) and (max-width: 1365.98px) {
  .work__body { grid-template-columns: minmax(0, 1fr); }
  .work__body > .work__shot, .work__body > .work__chat { display: none; }
  .work__desc { max-width: 60ch; }
}

/* ---- Rail mode ---- */
@media (min-width: 1024px) {
  html.js .work__gallery {
    display: block; position: relative; overflow: clip; overflow-clip-margin: 6px;
    height: clamp(600px, calc(100svh - 140px), 760px);
  }
  html.js .work__panel {
    position: absolute; top: 0; left: 0; height: 100%; width: calc(76px + 8px + var(--b, 900px));
    pointer-events: none;
  }
  html.js .work__panel:nth-child(1) { z-index: 1; }
  html.js .work__panel:nth-child(2) { z-index: 2; }
  html.js .work__panel:nth-child(3) { z-index: 3; }
  html.js .work__panel:nth-child(4) { z-index: 4; }
  html.js .work__panel:nth-child(5) { z-index: 5; }
  html.js .work__panel:nth-child(6) { z-index: 6; }
  html.js .work__spine {
    position: absolute; left: 0; top: 0; width: 76px; height: 100%; pointer-events: auto;
    display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 22px 0;
  }
  html.js .work__spine-title {
    writing-mode: vertical-rl; transform: rotate(180deg); font-size: 1.875rem;
  }
  html.js .work__spine-kind { writing-mode: vertical-rl; transform: rotate(180deg); }
  html.js .work__body {
    position: absolute; top: 0; left: 84px; width: var(--b, 900px); height: 100%; margin-top: 0;
    pointer-events: auto; visibility: hidden; clip-path: inset(0 100% 0 0 round var(--radius));
  }
  html.js .work__panel:not(.is-open) .work__body { display: grid; }
  html.js .work__panel.is-open .work__body { visibility: visible; clip-path: inset(0 0 0 0 round var(--radius)); }
  html.js .work__gallery.is-ready .work__panel { transition: transform 700ms var(--ease); }
  html.js .work__gallery.is-ready .work__body {
    transition: clip-path 700ms var(--ease), visibility 0s 700ms, opacity 600ms linear 300ms;
  }
  html.js .work__gallery.is-ready .work__panel.is-open .work__body {
    transition: clip-path 700ms var(--ease), visibility 0s, opacity 600ms linear 300ms;
  }
}

/* Desktop card text. At 900px height and above the rail is at its 760px cap: slightly tighter than the base sizes, enough for the card line, chips and links */
@media (min-width: 1024px) {
  html.js .work__body { padding: 24px 28px; }
  html.js .work__text { gap: 10px; }
  html.js .work__desc { font-size: 15px; line-height: 1.5; }
  html.js .work__facts { gap: 8px; padding-top: 10px; }
  html.js .work__facts li { font-size: 14px; line-height: 1.4; }
  html.js .work__facts b { font-size: 1.375rem; }
}
/* Short screens (under 900px tall) and the 300px text column (1180 to 1279 wide): no inner scrolling, the text always fits */
@media (min-width: 1024px) and (max-height: 899.98px), (min-width: 1180px) and (max-width: 1279.98px) {
  html.js .work__body { padding: 20px 28px; }
  html.js .work__text { gap: 8px; }
  html.js .work__title { font-size: clamp(2rem, 2.6vw, 2.375rem); }
  html.js .work__desc { font-size: 14px; line-height: 1.45; }
  html.js .work__facts { gap: 5px; padding-top: 8px; }
  html.js .work__facts li { font-size: 13.5px; line-height: 1.35; }
  html.js .work__facts b { font-size: 1.125rem; }
  .work__note { font-size: 13px; line-height: 1.45; }
}
/* Laptop heights (1366x680, 1280x720) and the 300px text column (1180 to 1279): spacing tightens one more step */
@media (min-width: 1024px) and (max-height: 760px), (min-width: 1180px) and (max-width: 1279.98px) {
  html.js .work__body { padding: 16px 28px; }
  html.js .work__text { gap: 6px; }
  html.js .work__title { font-size: clamp(1.75rem, 2.2vw, 2rem); }
  html.js .work__desc { line-height: 1.4; }
  html.js .work__stack { gap: 4px 5px; }
  html.js .work__stack li { padding: 4px 8px; }
  html.js .work__links { margin-top: 0; }
}
@media (min-width: 1024px) and (max-width: 1279.98px) {
  html.js .work__gallery { height: clamp(720px, calc(100svh - 140px), 760px); }
}

/* ---- Entrances ---- */
@media (prefers-reduced-motion: no-preference) {
  html.js .work__gallery:not(.is-in) .work__spine { opacity: 0; transform: translateY(40px); }
  html.js .work__gallery:not(.is-in) .work__body { opacity: 0; }
  html.js .work__body { transition: opacity 600ms linear 300ms; }
  html.js .work__gallery.is-in .work__spine {
    transition: opacity 600ms var(--ease), transform 800ms var(--ease), background-color var(--t-fast), color var(--t-fast);
    transition-delay: calc(var(--p, 0) * 80ms), calc(var(--p, 0) * 80ms), 0s, 0s;
  }
  .work__text > :nth-child(2) { --k: 1; }
  .work__text > :nth-child(3) { --k: 2; }
  .work__text > :nth-child(4) { --k: 3; }
  .work__text > :nth-child(5) { --k: 4; }
  .work__text > :nth-child(6) { --k: 5; }
  .work__text > :nth-child(7) { --k: 6; }
  .work__text > :nth-child(8) { --k: 7; }
  .work__chat > :nth-child(1) { --i: 0; }
  .work__chat > :nth-child(2) { --i: 1; }
  .work__chat > :nth-child(3) { --i: 2; }
  .work__chat > :nth-child(4) { --i: 3; }
  .work__chat > :nth-child(5) { --i: 4; }
  .work__chat > :nth-child(6) { --i: 5; }
  .work__chat > :nth-child(7) { --i: 6; }
  html.js .work__gallery.is-in .work__panel.is-open .work__text > * {
    animation: work-in 600ms var(--ease) backwards;
    animation-delay: calc(80ms + var(--k, 0) * var(--stagger));
  }
  html.js .work__gallery.is-in .work__panel.is-open .work__shot { animation: shot-in 900ms var(--ease) 300ms backwards; }
  html.js .work__gallery.is-in .work__panel.is-open .chat__msg,
  html.js .work__gallery.is-in .work__panel.is-open .chat__cap {
    animation: work-in 500ms var(--ease) backwards;
    animation-delay: calc(400ms + var(--i, 0) * 260ms);
  }
}
@media (prefers-reduced-motion: no-preference) and (min-width: 1024px) {
  html.js .work__gallery.is-in .work__panel.is-open .work__text > * { animation-delay: calc(320ms + var(--k, 0) * var(--stagger)); }
}
@keyframes work-in { from { opacity: 0; transform: translateY(14px); } }
@keyframes shot-in { from { clip-path: inset(6% 6% 6% 6% round 18px); opacity: .3; } }

@media (prefers-reduced-motion: reduce) {
  #work, #work *, #work *::before, #work *::after { transition: none; animation: none; }
}
