/* =============================================================================
   Alex North, for Superbuilders

   Principle: clarify, don't decorate. The one expressive element is colleagues'
   quotes in the margin, tied to the claims they support by a highlighter mark.

   Sections in this file:
     1. Tokens: colours, fonts, sizes. Most tweaks happen here.
     2. Base: body text, links, lists, keyword emphasis
     3. Page grid and masthead
     4. Headings, letter, dividers
     5. Expandable sections (<details class="more">)
     6. Reading list
     7. Projects and screenshot galleries
     8. Lightbox (full-screen screenshots)
     9. Roles timeline
    10. Close
    11. Margin notes (quotes) and phone popovers
    12. Responsive layouts: medium (column + margin), wide (sidebar + column + margin)
    13. Print
   ========================================================================== */


/* ---------- 1. Tokens ---------- */

:root {
  /* Colours (light). Dark versions are just below. */
  --bg: #FBFCFD;            /* page background */
  --ink: #1C2330;           /* body text */
  --muted: #5D6675;         /* secondary text: captions, dates, attributions */
  --rule: #DFE3E9;          /* hairlines and borders */
  --fold: #CBD2DC;          /* left rule on open expandable sections */
  --link: #3E5AAA;          /* link text */
  --link-line: rgb(62 90 170 / 0.35); /* link underline */
  --mark: #F3E7A1;          /* highlighter: ties a quote to its claim */
  --panel: #FFFFFF;         /* popovers, screenshot backgrounds */

  --serif: "Literata", Georgia, "Times New Roman", serif;
  --sans: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* >>> Main tweak points <<< */
  --text-size: 1.02rem;   /* body text size. Letter is slightly larger (see .letter) */
  --measure: 39rem;         /* width of the main reading column */
  --margin-w: 16rem;        /* width of the quote margin on the right */
  --side-w: 13.5rem;        /* width of the sidebar on wide screens */
  --gap: 3.25rem;           /* space between columns */

  --emphasis: 540;          /* weight of keyword emphasis (<b>) in body text */
  --emphasis-note: 650;     /* weight of keyword emphasis in margin quotes */

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121519;
    --ink: #E4E7EC;
    --muted: #9AA3B2;
    --rule: #2A2F37;
    --fold: #39404B;
    --link: #8EA3E6;
    --link-line: rgb(142 163 230 / 0.4);
    --mark: #5C4F1C;
    --panel: #1A1E24;
    color-scheme: dark;
  }
}


/* ---------- 2. Base ---------- */

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

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 1.5rem; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--text-size);
  line-height: 1.65;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--link);
  text-decoration-line: underline;
  text-decoration-color: var(--link-line);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; border-radius: 2px; }

p { margin: 0 0 0.5em; }               /* small gap below, so "More" toggles sit close */
p + p { margin-top: 1em; }              /* full gap between consecutive paragraphs */
ul, ol { margin: 0 0 1em; }
ul { padding-left: 1.25em; }
li { margin: 0; }                       /* list items: just line spacing */

/* Keyword emphasis: a slight weight increase, not full bold.
   Use <b> around the words to emphasise. */
b { font-weight: var(--emphasis); }
strong { font-weight: 600; }
cite { font-style: italic; }

.skip {
  position: absolute; left: 1rem; top: -4rem;
  background: var(--ink); color: var(--bg); padding: 0.5rem 0.75rem;
  font-family: var(--sans); z-index: 10;
}
.skip:focus { top: 1rem; }


/* ---------- 3. Page grid and masthead ---------- */

/* Phones: one column. Medium and wide layouts are in section 12. */
.page {
  display: grid;
  grid-template-columns: minmax(0, var(--measure));
  justify-content: center;
  padding: 2rem 1.25rem 4rem;
}

main { position: relative; min-width: 0; }   /* notes are positioned against main */

.masthead { font-family: var(--sans); margin-bottom: 2.5rem; }
.portrait {
  display: block;
  width: 5.5rem; height: 5.5rem;     /* portrait size */
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 1rem;
}
.name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.5rem;
  line-height: 1.2;
  margin: 0 0 0.5rem;
}
.tagline { color: var(--muted); font-size: 0.95rem; line-height: 1.45; margin-bottom: 1rem; }
.contact {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-wrap: wrap; gap: 0.25rem 1.1rem;
  font-size: 0.9375rem;
}
.toc { display: none; }


/* ---------- 4. Headings, letter, dividers ---------- */

h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.25; }
h2 { font-size: 1.5rem; margin: 3.5rem 0 1rem; }
h3 { font-size: 1.15rem; margin: 1.6rem 0 0.6rem; }
h4 { font-size: 1.05rem; margin: 0 0 0.35rem; }
section > h2:first-child { margin-top: 0; }

/* A plain rule between consecutive sections. (The letter is followed by the
   "Go deeper" divider instead.) */
main > section + section {
  border-top: 1px solid var(--rule);
  margin-top: 3rem;
  padding-top: 2rem;
}

.lead { color: var(--muted); }

.letter { font-size: 1.1rem; }     /* the letter reads a touch larger than the rest */
.salutation {
  font-style: italic; font-weight: 400;
  font-size: 1.9rem;
  margin: 0 0 1.25rem;
}
.letter .projects-line { margin-top: 1.5em; }
.letter .signoff { margin-bottom: 0.25em; }
.signature { font-style: italic; font-size: 1.3rem; margin: 0.75rem 0 0; }

.depth-divider {
  display: flex; align-items: center; gap: 1rem;
  margin: 3rem 0 2rem;
  font-family: var(--sans); font-size: 0.9375rem; color: var(--muted);
}
.depth-divider::after { content: ""; flex: 1; border-top: 1px solid var(--rule); }

/* Lines that read as a cascade: one idea per line, no bullets. */
.cascade { list-style: none; padding-left: 1.25rem; border-left: 1px solid var(--rule); }


/* ---------- 5. Expandable sections ---------- */

details.more { margin: 0 0 1.25rem; }
details.more > summary {
  display: inline-flex; align-items: center; gap: 0.45rem;
  cursor: pointer; list-style: none;
  font-family: var(--sans); font-size: 0.9375rem; color: var(--link);
  padding: 0.15rem 0;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before {
  content: ""; width: 0.45rem; height: 0.45rem;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform 150ms ease;
}
details.more[open] > summary::before { transform: rotate(45deg) translate(-1px, -2px); }
details.more[open] > summary { margin-bottom: 0.75rem; }

/* Open: a light rule hangs in the left gutter to show where the expanded text runs,
   and the text steps down slightly in size. */
details.more[open] {
  border-left: 2px solid var(--fold);
  padding-left: 1rem;
  margin-left: calc(-1rem - 2px);
}
details.more[open] > :not(summary) { font-size: 0.9375em; }
@media (prefers-reduced-motion: reduce) { details.more > summary::before { transition: none; } }


/* ---------- 6. Reading list ---------- */

.reading { display: grid; gap: 0.5rem 2rem; }
.reading h4 { font-family: var(--sans); font-size: 1rem; margin-bottom: 0.2rem; }
.reading .sub { color: var(--muted); font-size: 0.9375rem; margin-bottom: 0.4rem; }


/* ---------- 7. Projects and screenshot galleries ---------- */

.project { margin: 2rem 0 2.5rem; }
.project h3 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.9rem; margin-top: 0; }
.site-link { font-family: var(--sans); font-weight: 400; font-size: 0.9375rem; }

.gallery { margin: 2rem 0 1.25rem; }
.gallery-track {
  display: flex; align-items: flex-start; gap: 1rem;
  overflow-x: auto; scroll-snap-type: x mandatory; overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.gallery-track::-webkit-scrollbar { display: none; }
.slide { flex: 0 0 100%; margin: 0; scroll-snap-align: start; }
.slide-zoom { display: block; cursor: zoom-in; }
.slide img {
  display: block; width: 100%; height: 24rem;   /* gallery image height */
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--rule); border-radius: 6px;
}
.slide figcaption { font-family: var(--sans); font-size: 0.875rem; color: var(--muted); margin-top: 0.45rem; }

.gallery-controls {
  display: flex; align-items: center; gap: 0.75rem;
  margin-top: 0.4rem;
  font-family: var(--sans); font-size: 0.875rem; color: var(--muted);
}
.gallery-controls button, .lightbox-controls button {
  font: inherit; color: var(--link);
  background: none; border: 1px solid var(--rule); border-radius: 999px;
  padding: 0.2rem 0.75rem; cursor: pointer;
}
.gallery-controls button:disabled { opacity: 0.4; cursor: default; }
.gallery-count { font-variant-numeric: tabular-nums; min-width: 3.5em; text-align: center; }
html:not(.js) .gallery-controls { display: none; }


/* ---------- 8. Lightbox ---------- */

dialog.lightbox {
  width: 100vw; height: 100vh; max-width: none; max-height: none;
  margin: 0; padding: 1.25rem; border: 0;
  background: rgb(12 14 18 / 0.94); color: #E4E7EC;
  font-family: var(--sans);
}
dialog.lightbox[open] { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.75rem; }
dialog.lightbox::backdrop { background: rgb(12 14 18 / 0.6); }
.lightbox figure { margin: 0; display: flex; flex-direction: column; align-items: center; min-height: 0; }
.lightbox img {
  max-width: min(100%, 1600px); max-height: calc(100vh - 8rem);
  object-fit: contain; background: #fff; border-radius: 6px;
}
.lightbox figcaption { margin-top: 0.6rem; font-size: 0.95rem; color: #C9CFD8; text-align: center; }
.lightbox-controls { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }
.lightbox-controls button { color: #E4E7EC; border-color: #3A404A; }
.lightbox-count { font-variant-numeric: tabular-nums; }


/* ---------- 9. Roles timeline ---------- */

.roles { list-style: none; padding: 0; margin: 1.5rem 0 2rem; }
.role { margin: 0 0 1.2rem; }

/* Head line: company, title and logo | dates, with location underneath. */
.role-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 0.75rem;
  align-items: baseline;
  margin-bottom: 0.4rem;
}
.role-head h4 { grid-column: 1; margin: 0; font-size: 1.05rem; }
.role-head .title { font-weight: 400; font-style: italic; margin-left: 0.35rem; }
.role-head .logo {
  display: inline-block; vertical-align: -0.3rem;   /* sits on the title line */
  width: 1.7rem; height: 1.7rem; margin-left: 0.5rem;
  border-radius: 4px; background: #fff;
}
.role-head .when {
  grid-column: 2; grid-row: 1; margin: 0;
  font-size: 0.9375rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.role-head .where {
  grid-column: 1 / -1; margin: 0;
  font-family: var(--sans); font-size: 0.875rem; color: var(--muted);
}
.earlier { padding-left: 1.1em; font-size: 0.9375rem; }

/* Phones: job title on its own line under the company. */
@media (max-width: 40rem) {
  .role-head .title { display: block; margin-left: 0; }
}

.aside-links { font-family: var(--sans); font-size: 0.9375rem; }


/* ---------- 10. Close ---------- */

.close-line { font-size: 1.5rem; font-style: italic; margin-bottom: 0.5rem; }
.close-links { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; font-family: var(--sans); }
.ps { color: var(--muted); font-size: 0.9375rem; margin-top: 2rem; }


/* ---------- 11. Margin notes (quotes) ---------- */

.note blockquote { margin: 0 0 1.1rem; }
.note blockquote:last-child { margin-bottom: 0; }
.note blockquote p { margin: 0 0 0.3rem; }
.note blockquote p::before { content: "\201C"; }
.note blockquote p::after { content: "\201D"; }
.note b { font-weight: var(--emphasis-note); }
.note footer { color: var(--muted); font-family: var(--serif); font-style: italic; font-size: 0.9em; }

[data-note] { transition: background-color 200ms ease; border-radius: 3px; }
.is-noted { background: var(--mark); box-shadow: 0 0 0 0.3rem var(--mark); }

/* Phones: notes open as popovers from a small button after the claim. */
.note-toggle {
  display: inline-flex; align-items: center; gap: 0.15rem;
  margin: 0.25rem 0 0.5rem;
  padding: 0.3rem 0.65rem;
  font: inherit; font-family: var(--sans); font-size: 0.875rem;
  color: var(--ink);
  background: var(--mark);
  border: 0; border-radius: 999px;
  cursor: pointer;
}
.note-toggle::before { content: "\201C"; }
.note-toggle::after { content: "\201D"; }
.note-toggle::before, .note-toggle::after { font-family: var(--serif); font-size: 1.2em; line-height: 0.5; }

.note[popover] {
  font-family: var(--sans); font-size: 1rem; line-height: 1.5;
  color: var(--ink); background: var(--panel);
  border: 1px solid var(--rule); border-radius: 10px;
  padding: 1.25rem 1.25rem 1.1rem;
  width: min(32rem, calc(100vw - 2rem));
  max-height: calc(100vh - 4rem);
}
.note[popover]::backdrop { background: rgb(18 21 25 / 0.35); }


/* ---------- 12. Responsive layouts ---------- */

/* Medium: reading column plus a margin for notes; masthead on top. */
@media (min-width: 64rem) {
  .page {
    grid-template-columns: minmax(0, var(--measure)) var(--margin-w);
    column-gap: var(--gap);
    padding-top: 3rem;
  }
  .masthead { grid-column: 1 / -1; }

  .note-toggle { display: none; }

  /* Notes sit in the right margin, level with the claim they support. */
  .note[popover],
  .note[popover]:not(:popover-open) {
    display: block;
    position: absolute;
    inset: auto;
    left: calc(100% + var(--gap));
    width: var(--margin-w);
    max-height: none;
    margin: 0.3rem 0 0;
    padding: 0 0 0 0.9rem;
    overflow: visible;
    background: none;
    border: 0;
    border-left: 3px solid var(--mark);
    border-radius: 0;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--ink);
  }

  /* Fade notes in as they enter the viewport, and out as they leave the top. */
  .js .note { opacity: 0; transition: opacity 500ms ease; }
  .js .note.is-seen { opacity: 1; }
  @media (prefers-reduced-motion: reduce) { .js .note { transition: none; } }

  .reading { grid-template-columns: 1fr 1fr; }
}

/* Wide: sticky sidebar, column, margin. */
@media (min-width: 82rem) {
  .page {
    grid-template-columns: var(--side-w) minmax(0, var(--measure)) var(--margin-w);
    column-gap: var(--gap);
  }
  .masthead { grid-column: 1; margin: 0; }
  .masthead-inner { position: sticky; top: 3rem; }
  .contact { flex-direction: column; gap: 0.2rem; }
  main { grid-column: 2; margin-top: -0.4em; }

  .toc { display: block; margin-top: 2.25rem; padding-top: 1.25rem; border-top: 1px solid var(--rule); }
  .toc ol { list-style: none; padding: 0; margin: 0; font-size: 0.9375rem; }
  .toc li { margin: 0 0 0.3rem; }
  .toc a { color: var(--muted); text-decoration: none; }
  .toc a:hover, .toc a[aria-current="true"] { color: var(--ink); }
  .toc a[aria-current="true"] { box-shadow: inset 3px 0 0 var(--mark); padding-left: 0.6rem; margin-left: -0.6rem; }
}


/* ---------- 13. Print ---------- */

@media print {
  .masthead .toc, .note-toggle, .skip, .gallery-controls { display: none; }
  .note[popover] { display: block; position: static; border: 0; padding: 0; margin: 0 0 1rem 1.5rem; font-size: 0.85rem; }
  details > :not(summary) { display: block; }
}
