/* Owned by S10. Case studies: one <dialog> per Work project. A sheet from the right on desktop (>= 900px),
   a full-screen sheet rising from the bottom on phones. Scripts off: :target shows the content as a block. */
dialog.case {
  --case-pad: clamp(22px, 4vw, 44px);
  --case-out: 420ms;
  box-sizing: border-box;
  margin: 0 0 0 auto; inset: 0 calc(-1 * var(--case-gutter, 0px)) 0 auto; /* case.js sets --case-gutter: the sheet runs under the reserved scrollbar gutter to the true edge */
  width: min(680px, 92vw); max-width: none;
  height: 100dvh; max-height: none;
  padding: 0; border: 0; border-left: 1px solid var(--line);
  background: var(--paper); color: var(--ink);
  box-shadow: var(--shadow);
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
  font-family: var(--font-sans);
}
dialog.case::backdrop {
  background: color-mix(in srgb, var(--dark) 55%, transparent);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
/* the page behind a sheet stays where it is */
html.case-lock { overflow: hidden; scrollbar-gutter: stable; }

/* ---- Bar: sticky strip with the close button, so text never slides under it ---- */
.case__bar { position: sticky; top: 0; z-index: 3; height: 68px; background: var(--paper); }
.case__grab { display: none; }
.case__close {
  position: absolute; top: 12px; right: 16px;
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 50%; cursor: pointer;
  background: var(--soft); color: var(--ink); box-shadow: var(--hair);
  transition: background-color 200ms;
}
@media (hover: hover) and (pointer: fine) {
  .case__close:hover { background: color-mix(in srgb, var(--soft) 80%, var(--ink)); }
}

/* ---- Header ---- */
.case__head { padding: 8px var(--case-pad) 0; }
.case__kind {
  font: 500 11px / 1.4 var(--font-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--accent-2-ink);
}
.case__title {
  margin-top: 12px;
  font: 500 clamp(2rem, 4vw, 3rem) / 1 var(--font-display); letter-spacing: -.02em;
}
.case__strip { position: relative; margin-top: 28px; padding-left: 40px; max-width: 62ch; }
.case__row { display: grid; gap: 6px; }
.case__lab { font: 500 11px / 1 var(--font-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--mute-text); }
.case__txt { font-size: 1.0625rem; line-height: 1.45; color: var(--ink-2); }
.case__row--after .case__lab { color: var(--accent-2-ink); }
.case__row--after .case__txt { font: 500 1.375rem / 1.25 var(--font-display); letter-spacing: -.01em; color: var(--ink); }
.case__txt::first-letter, .case__v::first-letter { text-transform: uppercase; }
.case__rule { display: block; position: relative; height: 0; margin: 16px 0; border-top: 1px solid var(--line); }
.case__rule i {
  position: absolute; left: -40px; top: 50%; width: 26px; transform: translateY(-50%);
  font: normal 500 1.25rem / 1 var(--font-sans); text-align: center; color: var(--accent-2-ink);
}

/* ---- Sections ---- */
.case__sec { margin-top: 36px; padding: 0 var(--case-pad); }
.case__sec h4 { font: 500 1.375rem / 1.1 var(--font-display); letter-spacing: -.02em; margin-bottom: 12px; }
.case__sec p { font-size: 1.0625rem; line-height: 1.6; max-width: 62ch; }
.case__list { list-style: none; padding: 0; display: grid; gap: 10px; max-width: 62ch; }
.case__list li { position: relative; padding-left: 22px; font-size: 1.0625rem; line-height: 1.6; }
.case__list li::before {
  content: ""; position: absolute; left: 0; top: .66em; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}
.case__foot { padding: 40px var(--case-pad) calc(var(--case-pad) + env(safe-area-inset-bottom, 0px)); }
.case__list--stack { gap: 14px; }
.case__list--stack li { padding-left: 0; }
.case__list--stack li::before { content: none; }
.case__v { display: block; }
.case__k {
  display: block; margin-bottom: 3px;
  font: 500 11px / 1.3 var(--font-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--mute-text);
}
.case__head + .case__sec { margin-top: 40px; }
.case__sec:last-child { padding-bottom: calc(var(--case-pad) + env(safe-area-inset-bottom, 0px)); }

/* ---- Phone: full-screen sheet from the bottom, grab bar, sticky close ---- */
@media (max-width: 899.98px) {
  dialog.case {
    inset: 0; margin: 0; width: calc(100% + var(--case-gutter, 0px)); border-left: 0; --case-pad: 20px;
  }
  .case__bar { height: 60px; }
  .case__grab {
    display: block; position: absolute; left: 50%; top: 8px; width: 40px; height: 4px; margin-left: -20px;
    border-radius: 2px; background: var(--faint);
  }
  .case__close { top: 8px; right: 12px; }
  .case__title { margin-top: 10px; }
}

/* ---- Motion: transform and opacity only ---- */
@media (prefers-reduced-motion: no-preference) {
  dialog.case[open] { animation: case-in var(--case-out) var(--ease); }
  dialog.case[open]::backdrop { animation: case-fade 300ms linear; }
  dialog.case.is-closing { animation: case-out var(--case-out) var(--ease) forwards; }
  dialog.case.is-closing::backdrop { animation: case-fade-out 300ms linear forwards; }
  dialog.case[open] .case__head, dialog.case[open] .case__sec, dialog.case[open] .case__foot {
    animation: case-sec 520ms var(--ease) backwards; animation-delay: calc(140ms + var(--k, 0) * 40ms);
  }
  dialog.case[open].is-closing .case__head, dialog.case[open].is-closing .case__sec, dialog.case[open].is-closing .case__foot { animation: none; }
  .case__head { --k: 0; }
  .case__sec:nth-of-type(1) { --k: 1; }
  .case__sec:nth-of-type(2) { --k: 2; }
  .case__sec:nth-of-type(3) { --k: 3; }
  .case__sec:nth-of-type(4) { --k: 4; }
  .case__sec:nth-of-type(5) { --k: 5; }
  .case__sec:nth-of-type(6) { --k: 6; }
  .case__sec:nth-of-type(7) { --k: 7; }
  .case__foot { --k: 8; }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 899.98px) {
  @keyframes case-in { from { transform: translateY(100%); } }
  @keyframes case-out { to { transform: translateY(100%); } }
}
@media (prefers-reduced-motion: no-preference) and (min-width: 900px) {
  @keyframes case-in { from { transform: translateX(100%); } }
  @keyframes case-out { to { transform: translateX(100%); } }
}
@keyframes case-fade { from { opacity: 0; } }
@keyframes case-fade-out { to { opacity: 0; } }
@keyframes case-sec { from { opacity: 0; transform: translateY(14px); } }
@media (prefers-reduced-motion: reduce) {
  dialog.case, dialog.case *, dialog.case::backdrop { animation: none; transition: none; }
}

/* ---- Scripts off: the targeted case study reads as a block in the page ---- */
html:not(.js) dialog.case:target {
  display: block; position: relative; inset: auto; width: auto; max-width: var(--content); height: auto;
  margin: clamp(28px, 4vw, 56px) auto 0; padding-bottom: 8px; overflow: visible;
  border: 0; border-radius: var(--radius); background: var(--card); box-shadow: var(--hair), var(--shadow);
  scroll-margin-top: 88px;
}
html:not(.js) .case__bar { display: none; }
html:not(.js) .case__head { padding-top: var(--case-pad); }

/* ---- S14: "How it fits together". One hand-set SVG per case study; a second, vertical SVG below 560px.
   The arrows draw in once when the figure scrolls into view (case.js adds .is-drawn); no motion when reduced. ---- */
.case__arch {
  margin: 0 -14px; padding: 20px 14px 16px; border-radius: 18px;
  background-color: color-mix(in srgb, var(--soft) 42%, var(--paper));
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 13%, transparent) 1px, transparent 1.3px);
  background-size: 16px 16px; background-position: 7px 7px;
  box-shadow: var(--hair);
}
.arch { display: block; width: 100%; max-width: 592px; height: auto; margin: 0 auto; overflow: visible; }
.arch--narrow { display: none; }
.arch text { font: 500 12.5px / 1 var(--font-sans); fill: var(--ink); }
.arch .s { fill: var(--ink-2); }
.arch .grp { font: 500 10.5px / 1 var(--font-mono); letter-spacing: .12em; text-transform: uppercase; fill: var(--accent-2-ink); }
.arch .n--zone .grp { fill: color-mix(in srgb, var(--accent-2-ink) 76%, var(--ink)); }
.arch .el { font-size: 12px; fill: var(--ink-2); }
.arch .n rect { fill: var(--card); stroke: var(--line); stroke-width: 1; }
.arch .n--ext rect { stroke: var(--mute); stroke-dasharray: 4 3; }
.arch .n--zone rect { fill: var(--soft); }
.arch .n--main rect { fill: var(--dark); stroke: none; }
.arch .n--main rect.tab { fill: var(--accent); }
.arch .n--main text { fill: var(--on-dark); }
.arch .n--main .s { fill: var(--on-dark-2); }
.arch .n--chip rect { stroke: none; }
.arch .n--main rect.notch { fill: var(--on-dark); opacity: .3; }
.arch .n--note rect { fill: color-mix(in srgb, var(--accent-2) 9%, var(--card)); stroke: var(--accent-2); }
.arch .a--warn .a-line { stroke: var(--accent-2); }
.arch .a--warn .a-head { fill: var(--accent-2); }
.arch .n--stop rect { stroke: var(--accent-2); }
.arch .sep { stroke: var(--line); stroke-width: 1; }
.arch .a-line { fill: none; stroke: var(--ink-2); stroke-width: 1.5; }
.arch .a-dash { stroke-dasharray: 4 4; }
.arch .a-head, .arch .a-dot { fill: var(--ink-2); }
.arch .a--dark .a-line { stroke: var(--on-dark-2); }
.arch .a--dark .a-head { fill: var(--on-dark-2); }
.case__arch figcaption {
  margin-top: 16px; padding-left: 10px; border-left: 2px solid var(--accent-2);
  font: 500 .9375rem / 1.45 var(--font-sans); color: var(--ink); max-width: 56ch;
}
@media (max-width: 559.98px) {
  .case__arch { margin: 0 -6px; padding: 14px 6px; }
  .arch--wide { display: none; }
  .arch--narrow { display: block; max-width: 340px; }
}
@media (prefers-reduced-motion: no-preference) {
  html.js .case__arch:not(.is-drawn) .a-line:not(.a-dash), html.js .case__arch:not(.is-drawn) .a-reveal { stroke-dasharray: 1; stroke-dashoffset: 1; }
  html.js .case__arch:not(.is-drawn) .a-head, html.js .case__arch:not(.is-drawn) .a-dot { opacity: 0; }
  html.js .case__arch.is-drawn .a-line:not(.a-dash), html.js .case__arch.is-drawn .a-reveal {
    stroke-dasharray: 1; animation: arch-draw 600ms var(--ease) backwards; animation-delay: calc(var(--i, 0) * 70ms);
  }
  html.js .case__arch.is-drawn .a-head, html.js .case__arch.is-drawn .a-dot {
    animation: arch-pop 220ms linear backwards; animation-delay: calc(var(--i, 0) * 70ms + 420ms);
  }
  /* once drawn it stays drawn: closing and reopening the sheet must not play it again */
  html.js .case__arch.is-drawn.is-done svg :is(.a-line, .a-reveal, .a-head, .a-dot) { animation: none; }
}
@keyframes arch-draw { from { stroke-dashoffset: 1; } }
@keyframes arch-pop { from { opacity: 0; } }
