/* David Hatley portfolio: site shell. The grid is described in GRID.md; keep the two in step.
   Units: --b is the 4px baseline (one lockup cell). Every block height and gap is a multiple of --b, every text
   baseline lands on a multiple of --b from the page top, and every column line is a whole pixel. */

@view-transition { navigation: auto; }
::view-transition-group(*) { animation-duration: var(--dur-move); animation-timing-function: var(--ease-move); }

/* ---------- the grid ---------- */
@property --col { syntax: "<length>"; inherits: true; initial-value: 64px; }
@property --w { syntax: "<length>"; inherits: true; initial-value: 944px; }
@property --x0 { syntax: "<length>"; inherits: true; initial-value: 16px; }
/* paper lives on html: body is the inline-size container (for cqw), and containment stops body's background
   from propagating, which would paint it over the ascii field */
html { -webkit-text-size-adjust: 100%; background: var(--paper); }
body { background: transparent; color: var(--ink); font: var(--type-body); margin: 0; container-type: inline-size; }
.site {
  --b: 4px;                  /* baseline unit = the lockup cell */
  --g: 16px;                 /* gutter, 4 cells */
  --n: 4;                    /* columns */
  --m: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));   /* minimum margin, 4 cells */
  --col: calc((100cqw - 2 * var(--m) - (var(--n) - 1) * var(--g)) / var(--n));
  --w: calc(var(--n) * var(--col) + (var(--n) - 1) * var(--g));
  --x0: calc((100cqw - var(--w)) / 2);
  --step: calc(var(--col) + var(--g));          /* one column + one gutter */
  --rowb: 40px;              /* first baseline inside an index row */
  --rowtail: 28px;           /* last baseline to the row's bottom edge */
  --tpx: 16px;               /* row titles and section heads: Stem 7 at 16 (phone) or 32 */
  --tlh: 20px;               /* their line box; Stem 7's baseline is at 7/8 em + half the leading */
  --tbl: 16px;               /* their baseline offset in that box */
  --glyph: 40px;             /* 5 x 8px cells */
  --rowh: 88px;              /* index row minimum height */
  box-sizing: border-box; max-width: none; width: var(--w); margin: 0 0 0 var(--x0);
  padding: var(--space-6) 0 0; display: block;
}
@media (min-width: 640px) {
  .site { --n: 8; --m: max(28px, env(safe-area-inset-left), env(safe-area-inset-right));   /* 7 cells = the mark */
    --col: round(down, (100cqw - 2 * var(--m) - 7 * var(--g)) / 8, 4px);
    --x0: round(down, (100cqw - var(--w)) / 2, 4px);
    --rowb: 48px; --rowtail: 20px; --tpx: 32px; --tlh: 40px; --tbl: 32px; padding-top: var(--space-8); }
}
@media (min-width: 1024px) { .site { --n: 12; --col: 64px; } }
.site > * { margin: 0; min-width: 0; }

/* ---------- head: lockup, H1 ---------- */
.site-head { padding: 0; height: 40px; }   /* the lockup is 10 cells tall; its mark and line sit on the grid */
.site-home { text-decoration: none; color: var(--ink); display: inline-block; vertical-align: top; }
.site-home .ss-lockup { vertical-align: top; }
.site-h1 { margin: var(--space-12) 0 0; overflow-wrap: anywhere; }
/* Stem 7 32/40: baseline 32 in the line box, on the grid with no nudge */
.site-h1 .ss-mast__c { font-family: var(--font-pixel); font-weight: 400; font-stretch: normal; font-size: 32px; line-height: 40px;
  letter-spacing: 0; text-transform: uppercase; text-wrap: balance; -webkit-font-smoothing: none; font-synthesis: none; }
@media (max-width: 639px) {
  /* Stem 7 16/24 has its baseline at 18; 2px down puts it on 20 */
  .site-h1 { margin-top: var(--space-8); }
  .site-h1 .ss-mast__c { font-size: 16px; line-height: 24px; position: relative; top: 2px; }
}
.muted { color: var(--ink-muted); }
.nw { white-space: nowrap; }
.acc { --accent: var(--acc-l, var(--cobalt-text)); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .acc { --accent: var(--acc-d, var(--acc-l, var(--cobalt-text))); } }
:root[data-theme="dark"] .acc { --accent: var(--acc-d, var(--acc-l, var(--cobalt-text))); }

/* ---------- glyphs and the pixel arrow ---------- */
.glyph { display: block; width: var(--glyph); height: var(--glyph); color: var(--accent, var(--cobalt-text)); flex: none; }
.glyph rect { animation: ss-appear var(--dur-cell) var(--ease-step) backwards; animation-delay: calc(var(--i, 0) * var(--dur-cell)); }
.glyph.is-armed rect { animation-play-state: paused; visibility: hidden; }
.parrow { display: block; width: 14px; height: 14px; flex: none; }   /* 7 x 2px cells, the cell of Stem 7 at 16px */
.parrow--l { transform: scaleX(-1); }

/* pixel type: Stem 7 at 16px on a 20px line puts the baseline at 16 */
.px16, .row__n, .cat__head, .pn, .back, .ibtn, .totop, .zoom__x { font-family: var(--font-pixel); font-size: 16px; line-height: 20px; font-weight: 400;
  letter-spacing: 0; text-transform: uppercase; -webkit-font-smoothing: none; font-synthesis: none; }

/* ---------- index: sections by category ---------- */
.index { margin-top: var(--space-16); }
.cat + .cat { margin-top: var(--space-12); }
.cat__head { position: relative; display: flex; justify-content: space-between; height: 32px; padding-top: var(--space-1); box-sizing: border-box; color: var(--ink);
  font-size: var(--tpx); line-height: var(--tlh); text-transform: none; }
/* 32px heads: 48px tall, baseline 32, descenders end at 40, ink rule in the last pixel row */
@media (min-width: 640px) { .cat__head { height: 48px; padding-top: 0; } }
.cat__head::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: var(--line-hair); background: var(--ink); }
.cat__label { font: inherit; margin: 0; }
.cat__n { color: var(--ink-muted); font-variant-numeric: tabular-nums; font-size: 16px; line-height: 20px; margin: calc(var(--tbl) - 16px) -2px 0 0; }   /* 16px on the label's baseline; Stem 7's 2px right bearing hangs so the ink ends on the edge */

.row { position: relative; }
.row::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: var(--line-hair); background: var(--rule); }
/* the open row's tint bleeds 3 cells into the margin so every text edge stays on its column line */
.row::before { content: ""; position: absolute; top: 0; bottom: 0; left: -12px; right: -12px; background: transparent; transition: background var(--dur-move) var(--ease-move); z-index: -1; }
.row { isolation: isolate; }
.row.is-open::before { background: color-mix(in srgb, var(--accent) 9%, var(--paper)); }
.row.is-open::after { background: var(--accent); }

/* Every bar item is centred between the dividers: the bar centres the boxes, and each item's --oy nudge moves its
   ink centre (cap band for one line of type, the whole block for wrapped text) onto the box centre. The nudges are
   measured, not guessed: see GRID.md "row centring". Rows are at least --rowh tall and grow in 4px steps. */
.row__bar { display: grid; grid-template-columns: repeat(var(--n), var(--col)); column-gap: var(--g); align-items: center;
  min-height: var(--rowh); padding-block: var(--space-4); box-sizing: border-box; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.row__bar > * { position: relative; top: var(--oy, 0); }
.row__bar > * { grid-row: 1; }
.row__bar:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.row__n { grid-column: 1; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.row__bar > .glyph { grid-column: 2; }
.row__title { grid-column: 3 / span 4; margin: 0; pointer-events: none; --oy: 1px;
  font-family: var(--font-pixel); font-weight: 400; font-size: var(--tpx); line-height: var(--tlh); letter-spacing: 0; text-transform: none;
  -webkit-font-smoothing: none; font-synthesis: none; overflow-wrap: anywhere; }
/* the open swap: each character steps into the project's own face (meta.json font_display) one --dur-cell at a
   time. line-height 0 keeps every character out of the line box, so the Stem 7 strut holds the baseline and the
   row height while faces and sizes change. */
.row__title .ch { line-height: 0; }
/* experiments: the dataset line under the title, Stem 7 16 muted, on its own 20px line */
/* the became tag: 0.4px tracking (7px a character) so "→ mise en place" clears the arrow */
.tag.tag--to { letter-spacing: .4px; }
.row__sub { display: block; margin-top: var(--space-1); font-size: 16px; line-height: 20px; color: var(--ink-muted); }
.row__title .ch--on { font-family: var(--font-title, var(--font-pixel)); font-weight: 800; font-size: var(--to-d, var(--tpx)); text-transform: var(--to-case, none);
  -webkit-font-smoothing: auto; font-synthesis: none; }
@media (max-width: 639px) { .row__title .ch--on { font-size: var(--to-p, var(--tpx)); } }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.row__one { grid-column: 7 / span 4; margin: 0; color: var(--ink-muted); font: var(--type-body); }
.row__tags { grid-column: -3 / span 2; justify-self: start; display: flex; gap: var(--space-1); }
/* Plex Mono 11px advances 6.6px; 1.4px tracking makes every character exactly 8px (2 cells), so the frame lands on
   whole pixels. The right pad is 1.4px short to absorb the trailing tracking. Baseline: 1 + 1 + 12 = 14 in the box. */
.tag { display: block; box-sizing: border-box; height: 20px; padding: 1px 4px 1px 5px; border: var(--line-hair) solid var(--rule); color: var(--ink-muted);
  font-family: var(--font-mono); font-weight: 500; font-size: 11px; line-height: 16px; letter-spacing: 1.4px; text-transform: uppercase; white-space: nowrap; }
.row__arrow { grid-column: -2; justify-self: end; color: var(--ink-muted); pointer-events: none;
  transition: transform var(--dur-move) var(--ease-move); }
.row.is-open .row__arrow { transform: rotate(90deg); color: var(--accent); pointer-events: auto; }

.row__panel { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--dur-move) var(--ease-move); }
.row.is-open .row__panel { grid-template-rows: 1fr; }
.row__inner { overflow: hidden; min-height: 0; }
.row:not(.is-open) .row__inner { visibility: hidden; transition: visibility 0s var(--dur-move); }
/* open-row content starts on the title's column line and ends on the right edge */
.row__pad { margin-left: calc(2 * var(--step)); display: grid; gap: var(--space-6); padding: 0 0 var(--space-8); }
.row__preview { min-width: 0; }
.row__preview > img { display: block; max-width: 100%; height: auto; max-height: 520px; object-fit: contain; }
.row__note, .row__one-m { margin: 0; font: var(--type-body); position: relative; top: -1px; }   /* Archivo 16/24: baseline 17 -> 16 */
.row__note { color: var(--ink-muted); }
.row__one-m { display: none; }
.open-btn { display: inline-flex; align-items: center; gap: var(--space-2); justify-self: start; height: 20px; color: var(--ink); text-decoration: none;
  font-family: var(--font-pixel); font-size: 16px; line-height: 20px; text-transform: uppercase; -webkit-font-smoothing: none; }
.open-btn span { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.open-btn .parrow { color: var(--accent); }
.acts { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.act { display: inline-flex; align-items: center; height: 40px; padding: 0 var(--space-4); box-sizing: border-box; border: 2px solid var(--accent); color: var(--ink); text-decoration: none;
  font-family: var(--font-pixel); font-size: 16px; line-height: 16px; text-transform: uppercase; -webkit-font-smoothing: none; }
.act:hover, .act:focus-visible { background: color-mix(in srgb, var(--accent) 12%, var(--paper)); }
.act--primary, .act--primary:hover, .act--primary:focus-visible { background: var(--accent); color: var(--paper); }
.act:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* tablet: the oneliner moves into the open panel; title takes columns 3-6 */
@media (max-width: 1023px) {
  .row__one { display: none; }
  .row__one-m { display: block; }
}
/* phone: glyph, then the title on the lockup name's line (60px), tags, arrow */
@media (max-width: 639px) {
  .row__bar { grid-template-columns: 60px minmax(0, 1fr) auto 26px; column-gap: 0; }
  .row__bar { --rowh: 72px; }
  .row__n { display: none; }
  .row__bar > .glyph { grid-column: 1; }
  .row__title { grid-column: 2; }
  .row__tags { grid-column: 3; margin-left: var(--space-3); }
  .row__arrow { grid-column: 4; }
  .row__pad { margin-left: 0; }
  /* 48px touch target; the label hangs at 16 (baseline 32 on the grid, cap 18-32, within 1px of the frame's centre) */
  .open-btn { display: flex; justify-self: stretch; justify-content: center; align-items: flex-start; height: 48px; padding-top: 14px; border: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--paper)); box-sizing: border-box; }
  .open-btn .parrow { margin-top: 2px; }
}

/* ---------- about ---------- */
.about { margin-top: var(--space-16); padding-bottom: var(--space-16); display: grid; grid-template-columns: repeat(var(--n), var(--col)); column-gap: var(--g); }
.about .h2 { grid-column: 1 / span 2; font: var(--type-h2); margin: 0; position: relative; top: 2px; }   /* 25/28: baseline 22 -> 24 */
.about .ss-prose { grid-column: 3 / span 7; max-width: none; }
.about .ss-prose p { position: relative; top: -1px; }
@media (max-width: 1023px) { .about .ss-prose { grid-column: 3 / -1; } }
@media (max-width: 639px) { .about { grid-template-columns: minmax(0, 1fr); row-gap: var(--space-4); } .about .h2, .about .ss-prose { grid-column: 1; } }

/* ---------- ascii field + grid overlay ---------- */
.field { position: fixed; left: 0; top: 0; z-index: -1; pointer-events: none; display: block; }
.gridx { position: fixed; inset: 0; z-index: 50; pointer-events: none; }

/* ---------- media ---------- */
.zoomable { display: block; min-width: 0; max-width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; margin-inline: auto; }
.zoomable img, .fig img { display: block; max-width: 100%; width: auto; height: auto; max-height: 80vh; object-fit: contain; margin-inline: auto; }
.fig video { display: block; max-width: 100%; max-height: 80vh; width: auto; height: auto; margin-inline: auto; }
.fig { margin: 0; }

/* ---------- case shell: bar, body, prev/next ---------- */
/* the bar is 64px (16 cells); text baselines at 40, arrows centred on the cap height (26-40) */
.case-bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: flex-start; gap: var(--space-4); height: 64px; box-sizing: border-box;
  margin: var(--space-8) 0 var(--space-8); background: var(--paper); }
.case-bar::before { content: ""; position: absolute; top: 0; bottom: 0; left: -12px; right: -12px; background: var(--paper); z-index: -1; }
.case-bar::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: var(--line-hair); background: var(--rule); }
.case-bar .back { display: inline-flex; align-items: flex-start; gap: var(--space-2); height: 64px; box-sizing: border-box; padding-top: 24px; color: var(--ink); text-decoration: none; }
.case-bar .back .parrow { margin-top: 2px; }
.case-bar__t { flex: 1; min-width: 0; padding-top: 26px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-display); font-weight: 600; font-size: 13px; line-height: 20px; font-stretch: var(--stretch-expanded); }   /* Archivo 13/20: baseline 14 -> 40 */
.ibtn { width: 48px; height: 48px; margin-top: var(--space-2); display: inline-flex; align-items: center; justify-content: center; border: var(--line-hair) solid var(--ink); color: var(--ink); text-decoration: none; box-sizing: border-box; flex: none; }
.ibtn.is-off { border-color: var(--rule); color: var(--rule); }
.case-body { min-width: 0; }
.pn { position: relative; display: flex; justify-content: space-between; gap: var(--space-4); margin-top: var(--space-16); padding: var(--space-4) 0 var(--space-16); }
.pn::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--accent); }
/* links: Stem 7 baseline at 28 (12 + 16), 20px glyphs and the arrows centred on the cap height (14-28) */
.pn a { color: var(--ink); display: inline-flex; align-items: flex-start; gap: var(--space-2); min-height: 48px; box-sizing: border-box; padding-top: 12px; text-decoration: none; }
.pn a > .glyph { --glyph: 20px; margin-top: -1px; }   /* 11-31: centred on the cap height */
.pn a > .parrow { margin-top: 2px; }
.pn a:hover span { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 4px; }
@media (max-width: 639px) { .pn { flex-direction: column; align-items: flex-start; gap: 0; } }

/* case template (fallback when a project has no case.js) */
.case-top { display: flex; align-items: center; gap: var(--space-4); margin: 0 0 var(--space-4); flex-wrap: wrap; }
.case-top .glyph { --glyph: 60px; }
.case-h { font-family: var(--font-title, var(--font-display)); font-weight: 850; font-size: 48px; line-height: 48px; font-stretch: var(--stretch-expanded); letter-spacing: -.015em; margin: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { .case-h { font-size: 32px; line-height: 36px; } }
.case-n { color: var(--ink-muted); margin-left: auto; }
.case-hero { margin: var(--space-4) 0; min-width: 0; border-top: 2px solid var(--accent); padding-top: var(--space-3); }
.case-hero > img { display: block; max-width: 100%; max-height: 80vh; object-fit: contain; }
.case-col { max-width: 40rem; display: grid; gap: var(--space-4); margin: var(--space-6) 0; }
.case-col p { margin: 0; font: var(--type-body); }
.oneliner { font: var(--type-lead) !important; }
.case-col a, .links a { color: var(--ink); text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.ss-spec { border-color: var(--accent); font-family: var(--font-mono); }
.ss-spec > span { min-width: 0; overflow-wrap: anywhere; }
.fig .ss-spec, .case-col .ss-spec { text-transform: none; letter-spacing: .04em; }
.figs { display: grid; grid-template-columns: minmax(0,1fr); gap: var(--space-6); margin: var(--space-6) 0; }
.links { margin: var(--space-6) 0; padding: 0; list-style: none; display: grid; gap: var(--space-2); font: 13px/20px var(--font-mono); }
.yt { position: relative; aspect-ratio: 16 / 9; }
.yt iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------- zoom, back to top (fixed to the viewport, outside the page grid) ---------- */
.zoom { position: fixed; inset: 0; z-index: 10; background: var(--paper); display: grid; grid-template-rows: minmax(0,1fr) auto; place-items: center; cursor: zoom-out;
  touch-action: none; overflow: hidden; padding: max(var(--space-4), env(safe-area-inset-top)) var(--space-4) max(var(--space-4), env(safe-area-inset-bottom)); }
.zoom[hidden] { display: none; }
.zoom img { max-width: 100%; max-height: 100%; object-fit: contain; touch-action: none; transform-origin: center; cursor: grab; }
.zoom__cap { font: var(--type-caption); color: var(--ink-muted); margin: var(--space-2) 0 0; }
.zoom__x { position: absolute; top: max(var(--space-2), env(safe-area-inset-top)); right: max(var(--space-2), env(safe-area-inset-right)); z-index: 2; min-width: 48px; height: 48px; padding: 0 var(--space-3); background: var(--paper); color: var(--ink); border: var(--line-hair) solid var(--ink); cursor: pointer; }
.totop { position: fixed; right: max(var(--space-4), env(safe-area-inset-right)); bottom: max(var(--space-4), env(safe-area-inset-bottom)); z-index: 6; min-width: 48px; height: 48px; padding: 0 var(--space-3); background: var(--paper); color: var(--ink); border: var(--line-hair) solid var(--ink); cursor: pointer; }
.totop[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  .row__panel, .row__arrow, .row::before { transition: none; }
}
