/* ============================================================
   Abdelrahmane Bensahla — portfolio
   Two states, one page: "home" (index of work) and "detail"
   (a case study open beside a collapsed rail). The state is the
   URL fragment, so it works with no JavaScript at all — every
   dynamic value below is a custom property flipped by
   `body:has(.panel:target)`, which lets the layout transition.
   ============================================================ */

:root {
  --bg:        #0A0A0A;
  --surface:   #131211;
  --line:      #1A1917;
  --line-soft: #1E1D1B;
  --hairline:  #232220;
  --border:    #2A2926;

  --text:      #EDEDEB;
  --text-2:    #C4C1B9;
  --text-3:    #A9A69E;
  --muted:     #8B887F;
  --muted-2:   #7A776F;
  --muted-3:   #6A675F;
  --faint:     #4E4B45;

  --accent:      #FFB000;
  --accent-2:    #FFC44D;
  --accent-line: #6E4A00;
  --accent-bg:   #1C1405;

  --serif: 'Newsreader', Georgia, serif;
  --sans:  'Instrument Sans', system-ui, sans-serif;
  --mono:  'IBM Plex Mono', ui-monospace, monospace;

  --ease: cubic-bezier(.22, .8, .25, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  /* iOS inflates text on rotation unless this is pinned */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;

  /* ── home-state values ───────────────────────────────────── */
  --shell-flex:  0 0 auto;
  --shell-cols:  minmax(0, 1fr) 0px;
  --shell-align: stretch;
  --rail-pos:    static;
  --row-cols:    minmax(0, 4fr) minmax(0, 5fr) auto;
  --row-gap-x:   clamp(24px, 4vw, 56px);
  --row-pad:     clamp(8px, 1.4vh, 18px) 14px;
  --row-dim:     1;
  --title-size:  clamp(18px, min(2.4vw, 3vh), 30px);
  --title-clamp: 2;
  --sub-max:     44px;
  --sub-opacity: 1;
  --blurb-max:   clamp(38px, 9vh, 110px);
  --blurb-opacity: 1;
  --rule-opacity:  1;
  --group-gap:   clamp(20px, 4.5vh, 52px);
  --identity:    none;
}

/* ── detail-state values ───────────────────────────────────── */
body:has(.panel:target) {
  --shell-flex:  1 1 auto;
  --shell-cols:  minmax(230px, 280px) minmax(0, 1fr);
  --shell-align: start;
  --rail-pos:    sticky;
  --row-cols:    minmax(0, 1fr) 0px auto;
  /* the blurb column is 0-wide here, so the wide gutter would be charged
     twice against a 280px rail and starve the title */
  --row-gap-x:   12px;
  --row-pad:     11px 14px;
  --row-dim:     0.42;
  --title-size:  16px;
  --title-clamp: 5;
  --sub-max:     0px;
  --sub-opacity: 0;
  --blurb-max:   0px;
  --blurb-opacity: 0;
  --rule-opacity:  0;
  --group-gap:   26px;
  --identity:    grid;
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: -.01em;
  margin: 0;
}
h4 { font-size: 21px; }
h6 { margin: 0; }
p  { margin: 0; }

a { color: var(--text); text-decoration: none; }
a:hover { color: var(--accent); }

em {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.06em;
}
.em-bright { color: var(--text); }

code {
  font-family: var(--mono);
  font-size: .82em;
  background: var(--surface);
  padding: 2px 6px;
}

::selection { background: rgba(255, 176, 0, .28); }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ── shared type utilities ─────────────────────────────────── */

.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.eyebrow--accent   { color: var(--accent); }
.eyebrow--accent-2 { color: var(--accent-2); }
.eyebrow--muted    { color: var(--muted-3); }
.eyebrow--faint    { color: var(--faint); }

.eyebrow-row {
  display: flex;
  align-items: baseline;
  gap: 22px;
  flex-wrap: wrap;
}

.link-rule {
  color: var(--muted-2);
  border-bottom: 1px solid var(--border);
  padding-bottom: 3px;
  transition: color .2s ease;
}
.link-rule:hover, .link-rule:focus-visible { color: var(--accent); }

.section-label {
  font-family: var(--serif);
  font-size: 17px;
  font-style: italic;
  font-weight: 300;
  letter-spacing: 0;
  color: var(--muted);
}
.section-label--spaced { margin-bottom: 12px; }

.caption { font-size: 12.5px; color: var(--muted-3); }

/* ── page frame ────────────────────────────────────────────── */

.page {
  min-height: 100vh;
  min-height: 100dvh; /* mobile browser chrome shrinks the visual viewport */
  padding: clamp(20px, 3vh, 28px) clamp(22px, 4vw, 56px) clamp(14px, 2.5vh, 26px);
  display: flex;
  flex-direction: column;
}

.main {
  width: 100%;
  max-width: 1560px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── masthead + intro (home only) ──────────────────────────── */

.masthead {
  display: flex;
  width: 100%;
  margin: 0 0 clamp(14px, 3vh, 40px);
  align-items: baseline;
  gap: clamp(18px, 4vw, 48px);
  padding: 28px 0 0;
}

.masthead-name {
  font-family: var(--serif);
  font-size: 21px;
  letter-spacing: -.01em;
}
.masthead-role   { color: var(--muted-2); }
.masthead-resume { margin-left: auto; }

.intro {
  display: grid;
  flex: 0 1 auto;
  align-content: start;
  padding: clamp(4px, 1.6vh, 34px) 0 clamp(10px, 2vh, 32px);
  gap: clamp(8px, 1.4vh, 18px);
  max-width: min(100%, 640px);
}

/* both are home-only chrome */
body:has(.panel:target) .masthead,
body:has(.panel:target) .intro { display: none; }

.intro-title {
  font-size: clamp(26px, min(4.4vw, 5.2vh), 58px);
  line-height: 1.04;
  letter-spacing: -.022em;
  font-weight: 300;
  text-wrap: balance;
}
.intro-lede {
  font-size: clamp(13px, min(1.4vw, 2vh), 16px);
  line-height: 1.6;
  max-width: 62ch;
  color: var(--text-3);
  text-wrap: pretty;
}
.intro-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 30px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted-3);
}

/* ── shell: rail + stage ───────────────────────────────────── */

.shell {
  flex: var(--shell-flex);
  min-height: 0;
  display: grid;
  grid-template-columns: var(--shell-cols);
  gap: clamp(24px, 4vw, 68px);
  align-items: var(--shell-align);
  transition: grid-template-columns .55s var(--ease);
}

.rail {
  position: var(--rail-pos);
  top: clamp(20px, 3vh, 28px);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.rail-identity {
  display: var(--identity);
  gap: 10px;
  padding: 0 0 22px;
  border-bottom: 1px solid var(--line);
}
.rail-name {
  font-family: var(--serif);
  font-size: 20px;
  letter-spacing: -.012em;
  line-height: 1.15;
}
.rail-role { font-size: 10.5px; color: var(--muted-2); }
.rail-links {
  display: flex;
  gap: 18px;
  padding-top: 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.rail-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: clamp(6px, 2vh, 26px) 0 12px;
}

.rail-rule {
  height: 1px;
  background: var(--line-soft);
  opacity: var(--rule-opacity);
  transition: opacity .4s ease;
}

.rail-gap {
  height: var(--group-gap);
  transition: height .45s var(--ease);
}

.rail-row {
  position: relative;
  display: grid;
  grid-template-columns: var(--row-cols);
  gap: 8px var(--row-gap-x);
  align-items: baseline;
  align-content: center;
  padding: var(--row-pad);
  border-bottom: 1px solid var(--line);
  border-left: 2px solid transparent;
  flex: 0 0 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  opacity: var(--row-dim);
  transition: padding .45s var(--ease), gap .45s var(--ease), opacity .45s ease, border-color .35s ease;
}
.rail-row:hover { opacity: 1; color: var(--text); }

/* The accent mark. Absolutely positioned so it is not a grid item, and
   at left:0 rather than over the border — `overflow: hidden` clips to
   the padding box, which would eat a mark sitting in the border area. */
.rail-row::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent-line);
  transform: scaleY(0);
  transform-origin: top;
  transition: transform .3s var(--ease), background-color .3s ease;
}
.rail-row:hover::before,
.rail-row:focus-visible::before { transform: scaleY(1); }

.rail-row:hover .rail-row-head { transform: translateX(3px); }

/* the open row stays lit and keeps the mark at full accent */
body:has(#jc:target)   .rail-row[href="#jc"],
body:has(#sahl:target) .rail-row[href="#sahl"],
body:has(#net:target)  .rail-row[href="#net"] { opacity: 1; }

body:has(#jc:target)   .rail-row[href="#jc"]::before,
body:has(#sahl:target) .rail-row[href="#sahl"]::before,
body:has(#net:target)  .rail-row[href="#net"]::before {
  transform: scaleY(1);
  background: var(--accent);
}

/* head / blurb / year are placed explicitly so that collapsing the
   blurb never lets the year reflow up into the blurb's track. */
.rail-row-head {
  grid-column: 1;
  display: grid;
  gap: 4px;
  min-width: 0;
  transition: transform .3s var(--ease);
}

.rail-row-title {
  font-family: var(--serif);
  font-size: var(--title-size);
  letter-spacing: -.012em;
  line-height: 1.12;
  transition: font-size .45s var(--ease);
  display: -webkit-box;
  -webkit-line-clamp: var(--title-clamp);
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.rail-row-sub {
  font-size: 12.5px;
  color: var(--muted-3);
  line-height: 1.35;
  max-height: var(--sub-max);
  opacity: var(--sub-opacity);
  overflow: hidden;
  transition: max-height .45s var(--ease), opacity .3s ease;
}
.rail-row-blurb {
  grid-column: 2;
  max-height: var(--blurb-max);
  opacity: var(--blurb-opacity);
  overflow: hidden;
  min-width: 0;
  transition: max-height .5s var(--ease), opacity .35s ease;
}
.rail-row-blurb p {
  font-size: clamp(13px, 1.6vh, 15px);
  line-height: 1.55;
  color: var(--text-3);
  max-width: 54ch;
  text-wrap: pretty;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.rail-row-year {
  grid-column: 3;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .06em;
  color: var(--muted-3);
  text-align: right;
}

.stage { min-width: 0; overflow: hidden; }

/* ── case-study panels ─────────────────────────────────────── */

.panel { display: none; max-width: 980px; }
.panel:target {
  display: block;
  animation: panelIn .55s cubic-bezier(.22, .9, .24, 1) both;
}

/* A deep-linked panel has nothing to slide in from. Scoped to the one
   panel that was linked to — a broader `[data-deep-link] .panel:target`
   would also mute the next panel you navigate to, since the attribute
   is not cleared until hashchange. Excluding .is-leaving keeps it able
   to animate out. */
[data-deep-link="jc"]   #jc:target:not(.is-leaving),
[data-deep-link="net"]  #net:target:not(.is-leaving),
[data-deep-link="sahl"] #sahl:target:not(.is-leaving) { animation: none; }

/* Closing plays out before the hash flips, so the panel leaves under
   its own power instead of being switched off. */
.panel.is-leaving {
  animation: panelOut .2s ease both;
  pointer-events: none;
}

@keyframes panelIn {
  from { opacity: 0; transform: translateX(26px); }
  to   { opacity: 1; transform: none; }
}
@keyframes panelOut {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateX(18px); }
}

/* Stacked layouts scroll the rail (and its Close link) off screen, and
   a phone has no Escape key — so panels carry their own way back. */
.panel-back { display: none; }

.panel-head { padding: 0 0 30px; display: grid; gap: 20px; }

.panel-title {
  font-size: clamp(34px, 5vw, 60px);
  letter-spacing: -.02em;
  line-height: 1.02;
  font-weight: 300;
}
.panel-lede {
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 300;
  line-height: 1.5;
  color: var(--text-2);
  max-width: 62ch;
  text-wrap: pretty;
}

.stack-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted-3);
}

.chip-row { display: flex; flex-wrap: wrap; gap: 10px 12px; padding-top: 4px; }
.chip {
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 7px 11px;
}
.chip--live {
  color: var(--accent-2);
  border: 1px solid var(--accent-line);
  transition: background .2s ease, color .2s ease;
}
.chip--live:hover { background: var(--accent-bg); color: var(--accent); }
.chip--todo {
  color: var(--muted-3);
  border: 1px dashed var(--border);
}

.callout {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--accent-2);
  background: var(--accent-bg);
  padding: 18px;
  max-width: 62ch;
}

.panel-section {
  border-top: 1px solid var(--line);
  padding: 30px 0;
  display: grid;
  gap: 20px;
}
.panel-section--wide { gap: 30px; }
.panel-section--last { padding-bottom: 0; }

.prose {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 300;
  line-height: 1.62;
  max-width: 66ch;
  text-wrap: pretty;
}
.prose--aside {
  padding-left: 20px;
  border-left: 2px solid var(--accent-line);
  color: var(--text-3);
}
.prose--aside-plain { border-left-color: var(--border); }

.note { display: grid; gap: 10px; max-width: 66ch; }
.note p {
  font-size: 16px;
  line-height: 1.65;
  color: var(--text-3);
  text-wrap: pretty;
}

/* ── diagrams ──────────────────────────────────────────────── */

.diagram {
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--hairline);
  padding: 30px;
}
.diagram--rows { display: grid; gap: 20px; }

.flow-node {
  box-shadow: 0 0 0 1px var(--hairline);
  background: var(--bg);
  padding: 13px 18px;
  font-size: 14.5px;
  line-height: 1.45;
}
.flow-edge { position: relative; height: 44px; }
.flow-edge::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 20px;
  width: 1px;
  background: var(--border);
}
.flow-edge span {
  position: absolute;
  left: 34px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12.5px;
  color: var(--muted-3);
}

.topo-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 20px;
  align-items: start;
}
.topo-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted-3);
  padding-top: 10px;
}
.topo-nodes { display: flex; flex-wrap: wrap; gap: 10px; }
.topo-nodes span {
  box-shadow: 0 0 0 1px var(--hairline);
  background: var(--bg);
  padding: 10px 13px;
  font-size: 13.5px;
}

/* ── code + query plans ────────────────────────────────────── */

.code-block {
  margin: 0;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--hairline);
  padding: 30px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-3);
}

.explain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}
.explain {
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--hairline);
  padding: 20px;
  display: grid;
  gap: 12px;
}
.explain-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.explain-label--after { color: var(--accent-2); }
.explain pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-3);
  white-space: pre-wrap;
}

/* ── stats ─────────────────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 18px;
}
.stat {
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--hairline);
  padding: 20px;
  display: grid;
  gap: 8px;
}
.stat-value {
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 300;
  letter-spacing: -.015em;
}
.stat-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted-3);
}

/* ── image slots ───────────────────────────────────────────── */
/* A .shot with an <img> renders the image; an empty one renders
   its <figcaption> as a labelled placeholder until art lands. */

.shot {
  margin: 0;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--hairline);
  background: var(--surface);
  display: grid;
  place-items: center;
}
.shot--16x10 { aspect-ratio: 16 / 10; }
.shot--16x9  { aspect-ratio: 16 / 9; }
.shot--fixed { height: 230px; }
.shot--tall  { height: 240px; }

.shot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
}
.shot--contain img { object-fit: contain; }
.shot:has(img) figcaption { display: none; }

.shot figcaption {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 16px;
  text-align: center;
}

/* Capped rather than 1fr: a lone shot keeps its half-width scale instead
   of stretching across the panel, which would crop it to a letterbox. */
.shot-pair {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 480px));
  gap: 18px;
}

/* ── contact ───────────────────────────────────────────────── */

.contact {
  margin-top: clamp(12px, 2.5vh, 24px);
  padding-top: clamp(10px, 2vh, 20px);
  display: flex;
  flex-wrap: wrap;
  gap: 14px clamp(24px, 5vw, 64px);
  align-items: baseline;
  border-top: 1px solid var(--line);
}
.contact-email {
  font-family: var(--serif);
  font-size: clamp(19px, 2.4vw, 28px);
  font-weight: 300;
  letter-spacing: -.015em;
}
.contact-social {
  margin-left: auto;
  display: flex;
  gap: 26px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.contact-social a { color: var(--muted-2); }
.contact-social a:hover { color: var(--accent); }

/* ============================================================
   Motion
   Everything that starts an element hidden is scoped to `.motion`,
   a class the head script adds only when JS is on AND the reader
   has not asked for reduced motion. No script, no hidden content.
   ============================================================ */

@keyframes riseIn  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes wipeIn  { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes drawDown{ from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }

/* ── 1. arrival ────────────────────────────────────────────── */

.motion [data-enter] {
  animation: riseIn .62s var(--ease) both;
  animation-delay: var(--d, 0ms);
}
.motion [data-enter="wipe"] {
  animation-name: wipeIn;
  animation-duration: .5s;
  transform-origin: left;
}

/* Runs once. `.entered` lands after the sequence finishes, so
   returning home later does not replay it. */
.entered [data-enter] { animation: none; }

.masthead              { --d: 0ms; }
.intro-title           { --d: 60ms; }
.intro-lede            { --d: 120ms; }
.intro-meta            { --d: 170ms; }
.rail-heading          { --d: 210ms; }
.rail-rule             { --d: 240ms; }
.rail > .rail-row:nth-of-type(1) { --d: 280ms; }
.rail > .rail-row:nth-of-type(2) { --d: 330ms; }
.section-label--spaced { --d: 380ms; }
.rail-rule--exp        { --d: 410ms; }
.rail > .rail-row:nth-of-type(3) { --d: 450ms; }
.contact               { --d: 500ms; }

/* ── 2. section reveal ─────────────────────────────────────── */

.motion .panel-section {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .5s ease, transform .5s var(--ease);
}
.motion .panel-section.is-visible { opacity: 1; transform: none; }

/* ── 3. the Job Cannon pipeline builds itself ──────────────── */

.motion .flow-node      { opacity: 0; }
.motion .flow-edge span { opacity: 0; }
.motion .flow-edge::before { transform: scaleY(0); transform-origin: top; }

.motion .flow-step                  { --i: 0; }
.motion .flow-step:nth-child(2)     { --i: 1; }
.motion .flow-step:nth-child(3)     { --i: 2; }
.motion .flow-step:nth-child(4)     { --i: 3; }

/* node lands, its connector draws down, then the edge label fades in */
.motion .panel-section.is-visible .flow-node {
  animation: riseIn .42s var(--ease) both;
  animation-delay: calc(150ms + var(--i) * 320ms);
}
.motion .panel-section.is-visible .flow-edge::before {
  animation: drawDown .3s linear both;
  animation-delay: calc(330ms + var(--i) * 320ms);
}
.motion .panel-section.is-visible .flow-edge span {
  animation: fadeIn .3s ease both;
  animation-delay: calc(480ms + var(--i) * 320ms);
}

/* ── 9. mono links wipe an accent rule in from the left ────── */

.link-rule, .contact-social a, .panel-back { position: relative; }

.link-rule::after,
.contact-social a::after,
.panel-back::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .32s var(--ease);
}
.link-rule::after       { bottom: -1px; } /* sits on the existing hairline */
.contact-social a::after { bottom: -4px; }
.panel-back::after      { bottom: 8px; }  /* .panel-back carries 10px of padding */

.link-rule:hover::after,       .link-rule:focus-visible::after,
.contact-social a:hover::after, .contact-social a:focus-visible::after,
.panel-back:hover::after,      .panel-back:focus-visible::after { transform: scaleX(1); }

/* ── responsive ────────────────────────────────────────────── */

/* Short viewports (landscape phones) drop the blurb, per the design.
   Collapse its track too, so the year is not stranded beside a void. */
@media (max-height: 660px) {
  body { --row-cols: minmax(0, 1fr) 0px auto; --row-gap-x: 12px; }
  .rail-row-blurb { max-height: 0; opacity: 0; }
}

@media (max-width: 900px) {
  body:has(.panel:target) {
    --shell-cols: minmax(0, 1fr);
    --rail-pos: static;
  }
  .shell { grid-template-columns: minmax(0, 1fr); }

  .panel-back {
    display: inline-block;
    margin-bottom: 22px;
    padding: 10px 0;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted-2);
  }
  .panel-back:hover { color: var(--accent); }
}

/* ── phone ─────────────────────────────────────────────────────
   The design is laid out for a wide canvas: three-column index
   rows, a 110px label gutter on the topology, and 30px insets on
   every panel. All three eat a 331px content width alive, so they
   relax here. Type comes down a step with them — 20px Newsreader
   only fits ~33 characters at this width. */
@media (max-width: 700px) {

  /* index rows: blurb wraps under the title, year stays on its line */
  .rail-row { grid-template-columns: minmax(0, 1fr) auto; }
  .rail-row-head  { grid-area: 1 / 1; }
  .rail-row-year  { grid-area: 1 / 2; }
  .rail-row-blurb { grid-area: 2 / 1 / 3 / -1; }
  .rail-row-blurb p { max-width: none; }

  /* masthead: name on its own line, role + résumé beneath it */
  .masthead {
    flex-wrap: wrap;
    gap: 4px 16px;
    padding-top: 4px;
    margin-bottom: clamp(18px, 4vh, 40px);
  }
  .masthead-name { flex: 1 0 100%; font-size: 19px; }

  /* panel chrome: reclaim the 30px insets */
  .panel-head { padding-bottom: 24px; gap: 16px; }
  .panel-section { padding: 24px 0; gap: 16px; }
  .panel-section--wide { gap: 24px; }
  .panel-section--last { padding-bottom: 0; }
  .diagram { padding: 18px; }
  .code-block { padding: 18px; }
  .explain { padding: 16px; }
  .callout { padding: 14px; }
  .stat { padding: 16px; }

  /* topology: the 110px label gutter left 141px for the nodes */
  .topo-row { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .topo-label { padding-top: 0; }

  /* type steps down with the measure */
  .panel-lede { font-size: 19px; }
  .prose { font-size: 17px; line-height: 1.6; }
  .prose--aside { padding-left: 16px; }
  .note p { font-size: 15px; }
  .stat-value { font-size: 28px; }

  /* footer stacks rather than hanging right */
  .contact-social { margin-left: 0; gap: 22px; }
  .contact-email { overflow-wrap: anywhere; }

  /* the small mono links are 11px — give them a 44px touch target
     without moving the underline that sits under them */
  .link-rule::before,
  .contact-social a::before,
  .panel-back::before {
    content: "";
    position: absolute;
    inset: -14px -6px;
  }
}

@media (max-width: 420px) {
  .page { padding-left: 18px; padding-right: 18px; }
  .panel-title { font-size: 30px; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
  .shot--fixed, .shot--tall { height: 200px; }
}

/* Landscape phones: the design already hides blurbs under 660px tall;
   claw back the vertical chrome too. */
@media (max-height: 500px) and (orientation: landscape) {
  .masthead { padding-top: 0; margin-bottom: 12px; }
  .intro { padding-top: 0; }
}

/* The head script withholds `.motion` here, so the arrival, reveal and
   pipeline rules never apply — nothing starts hidden and there is
   nothing to switch off. What remains is the motion that runs on
   elements which are visible either way. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .panel:target, .panel.is-leaving { animation: none; }
  .shell, .rail-row, .rail-row-title, .rail-row-sub,
  .rail-row-blurb, .rail-rule, .rail-gap { transition: none; }
  .rail-row::before, .rail-row-head,
  .link-rule::after, .contact-social a::after,
  .panel-back::after { transition: none; }
}
