/* ==========================================================================
   layout.css — container, section rhythm, nav, page shells.
   Specificity note: section padding is set once, on `.section`, and the
   modifiers below only ever change it via custom properties — so no two
   rules ever fight over the same declaration.
   ========================================================================== */

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.section {
  --section-pad: var(--section-y);
  padding-block: var(--section-pad);
  border-top: var(--rule);
}

.section--flush { border-top: 0; }
.section--tight { --section-pad: var(--section-y-tight); }

@media (max-width: 900px) {
  .section { --section-pad: var(--section-y-sm); }
  .section--tight { --section-pad: var(--s7); }
}

.section__head {
  margin-bottom: var(--s6);
}

.section__head p {
  margin-top: var(--s3);
  color: var(--text-muted);
  max-width: 60ch;
}

/* Heading beside the content rather than stacked above it.

   These sections are narrow by nature — body text is capped at 62–68ch for
   readability — so in a 1180px container they left most of the right-hand
   side empty. Putting the heading in its own column uses that width, and
   drops roughly 80px of stacked height per section at the same time. */
.section--split > .container {
  display: grid;
  grid-template-columns: minmax(0, 240px) minmax(0, 1fr);
  gap: var(--s8);
  align-items: start;
}

.section--split .section__head { margin-bottom: 0; }

@media (max-width: 900px) {
  .section--split > .container {
    grid-template-columns: 1fr;
    gap: var(--s5);
  }
}

/* ==========================================================================
   Navigation
   ========================================================================== */

.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--nav-h);
  background: transparent;
  border-bottom: 1px solid transparent;
  transition: background var(--dur-base) var(--ease),
              border-color var(--dur-base) var(--ease);
}

.nav.is-stuck {
  background: var(--bg);
  border-bottom-color: var(--border);
}

.nav__inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s5);
}

.nav__brand {
  font-weight: var(--fw-medium);
  letter-spacing: -0.01em;
  text-decoration: none;
}

.nav__list {
  display: flex;
  align-items: center;
  gap: var(--s6);
}

.nav__link {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-decoration: none;
}

.nav__link:hover { color: var(--text); }

.nav__link--resume {
  color: var(--text);
  padding: var(--s2) var(--s4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
}

.nav__link--resume:hover {
  color: var(--accent-hover);
  border-color: var(--accent);
}

/* ---- Theme toggle ------------------------------------------------------- */

.nav__theme {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  width: 40px;
  height: 40px;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  transition: color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}

.nav__theme:hover { color: var(--text); border-color: var(--border-strong); }

.nav__theme svg {
  width: 18px;
  height: 18px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Sun while the page is dark (press it for light), moon while it is light. */
[data-theme="dark"]  .nav__theme .icon-moon { display: none; }
[data-theme="light"] .nav__theme .icon-sun  { display: none; }

.nav__theme-label { display: none; }

/* ---- Hamburger ---------------------------------------------------------- */

.nav__toggle {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
}

/* `:not(.visually-hidden)` matters. The button holds a second span carrying
   the screen-reader label, and a bare `.nav__toggle span` outranks
   `.visually-hidden` on specificity — it was handing that label
   `position: relative` and `width: 18px`, so the hidden text kept its place
   in the flex row while clip-path made it invisible. The bars were pushed a
   measured 8px left of centre by a sibling nobody could see. */
.nav__toggle span:not(.visually-hidden) {
  display: block;
  position: relative;
  width: 18px;
  height: 1px;
  background: var(--text);
}

.nav__toggle span:not(.visually-hidden)::before,
.nav__toggle span:not(.visually-hidden)::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 1px;
  background: var(--text);
}

.nav__toggle span:not(.visually-hidden)::before { top: -6px; }
.nav__toggle span:not(.visually-hidden)::after  { top: 6px; }

.nav__toggle[aria-expanded="true"] span:not(.visually-hidden) { background: transparent; }
.nav__toggle[aria-expanded="true"] span:not(.visually-hidden)::before { top: 0; transform: rotate(45deg); }
.nav__toggle[aria-expanded="true"] span:not(.visually-hidden)::after  { top: 0; transform: rotate(-45deg); }

@media (max-width: 768px) {
  .nav__toggle { display: flex; }

  .nav__brand,
  .nav__toggle {
    position: relative;
    z-index: 2;
  }

  .nav__list {
    position: fixed;
    inset: 0;
    z-index: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: var(--s6);
    padding: var(--nav-h) var(--gutter) var(--s9);
    background: var(--bg);
    visibility: hidden;
    opacity: 0;
    /* Visibility flips instantly when opening and only after the fade when
       closing. If it eased in like the opacity, the first link would still be
       `visibility: hidden` — and so unfocusable — at the moment the open
       handler tries to move focus into the menu. */
    transition: opacity var(--dur-base) var(--ease),
                visibility 0s linear var(--dur-base);
  }

  .nav__list.is-open {
    visibility: visible;
    opacity: 1;
    transition: opacity var(--dur-base) var(--ease), visibility 0s;
  }

  /* 33px was inside AA but tight under a thumb; padding takes each menu
     row to a comfortable 44 without disturbing the gap rhythm. */
  .nav__link {
    font-size: var(--fs-md);
    color: var(--text);
    padding: var(--s2) var(--s4);
  }
  .nav__link--resume { align-self: center; font-size: var(--fs-base); }

  .nav__theme {
    order: 1;
    width: 100%;
    height: auto;
    justify-content: center;
    padding: var(--s4) 0 0;
    font-size: var(--fs-md);
    color: var(--text);
    border-top: var(--rule);
    border-radius: 0;
  }

  .nav__theme:hover { border-color: transparent; border-top-color: var(--border); }
  .nav__theme-label { display: inline; }

  body.menu-open { overflow: hidden; }
}

/* ==========================================================================
   Hero
   ========================================================================== */

.hero {
  position: relative;
  padding-block: var(--s7) var(--s7);
  background: var(--grad-hero);
}

.hero__grid {
  display: grid;
  grid-template-columns: 58fr 42fr;
  gap: var(--s8);
  align-items: center;
}

.hero__title { max-width: 18ch; }

.hero__lede {
  margin-top: var(--s5);
  font-size: var(--fs-md);
  color: var(--text-muted);
  max-width: 60ch;
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  margin-top: var(--s7);
}

.hero__meta {
  margin-top: var(--s5);
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

.hero__figure {
  justify-self: end;
  margin: 0;
  width: 360px;
  max-width: 100%;
}

.hero__photo {
  width: 360px;
  height: 450px;
  object-fit: cover;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
}

@media (max-width: 900px) {
  .hero { padding-block: var(--s7) var(--s8); }
  .hero__grid {
    grid-template-columns: 1fr;
    gap: var(--s7);
  }
  .hero__figure {
    grid-row: 1;
    justify-self: center;
    width: min(300px, 70vw);
  }

  .hero__photo {
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 5;
  }
  .hero__title { max-width: none; }
}

/* ==========================================================================
   Case-study shell
   ========================================================================== */

.case {
  display: grid;
  /* minmax(0, 1fr), not 1fr. A bare `1fr` is `minmax(auto, 1fr)`, so a long
     unbreakable token inside the prose — `prefetch_related`, or the response
     envelope written out — sets the track's minimum and pushes the whole
     column past the viewport. All three case studies overflowed by 59px at
     360px because of it. */
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s8);
  padding-block: var(--s7) var(--s9);
}

.case__index { display: none; }

.case__body > * + * { margin-top: var(--s5); }
.case__body p, .case__body li { max-width: var(--measure); }

@media (min-width: 1024px) {
  .case {
    grid-template-columns: 200px minmax(0, 1fr);
    gap: var(--s9);
    align-items: start;
  }

  .case__index {
    display: block;
    position: sticky;
    top: calc(var(--nav-h) + var(--s5));
  }
}
